const qs = require('qs'); const $ = require('jquery'); const axios = require('axios'); var Utils = require('./rePromise'); require("./modal.js") const { ywCheckApi } = require('./api.js'); require('./scrollBar.js'); const baseUrl = ''; //页面映射 const pageMap = { 'YH-KZT': 'console.html', 'YH-KZTKS': 'deptConsole.html', 'YH-JCSJWH-MKSJWH': 'moduleManager.html', 'YH-JCSJWH-TMSJWH': 'itemManager.html', 'YH-BLZK-ZKPF': 'qcList.html', 'YH-BLZK-ZKPFKS': 'qcListDept.html', 'YH-BLZK-ZKPFGR': 'qcListPerson.html', 'YH-TJFX': 'statistics.html', 'YH-QXGL-YHGL': 'userManager.html', 'YH-QXGL-JSGL': 'roleManager.html', 'YH-KSZR-GMKQXZB_XQ': 'mukuai.html?from=2', 'YH-KSZR-TMQXZB_XQ': 'singleVeto.html?from=2&special=1', 'YH-ZKK-GMKQXZB_XQ': 'mukuaiControl.html?from=1', 'YH-ZKK-TMQXZB_XQ': 'singleVeto.html?from=1&special=1', 'YH-YCSJJK': 'abnormal.html', 'YH-ZKK-KSPJZYTS_XQ': 'dayDetail.html', 'YH-ZKK-KSPJZYHF_XQ': 'payDetail.html', 'YH-ZKK-GKSQXZB_XQ': 'deptScoreDetailControl.html',//各科室缺陷占比 'YH-KSZR-KSQXZB_XQ': 'deptScoreDetailControlDept.html?from=2', 'YH-ZKK-GKSJJBLZB_XQ': 'jiaji.html', 'YH-ZKK-BASYHGLZB_XQ': 'partDetailControl.html', 'YH-KSZR-BASYHGLZB_XQ': 'partDetailControlDept.html', 'YH-ZKK-ZKHCTJ': 'checkControl.html', 'YH-KSZR-ZKHCTJ_XQ': 'checkControlDept.html', 'YH-KSZR-SXXXGTJ_XQ': 'uncorrectedCasesStatisticsDept.html', 'YH-KSZR-31TZRYRS_XQ': 'readmissionDept.html', 'YH-KSZR-ZMBLJCS_XQ': 'uncorrectedCopyDept.html', 'YH-KSZR-YXBLJCS_XQ': 'uncorrectedCopyDept.html', 'YH-JCSJWH-ZKLXWH': 'assertType.html', 'YH-BLZK-ZKPFYLZ': 'qcListDocteam.html', 'YH-ZKK-GJTMQXZB': 'keyItemFlawControl.html', 'YH-ZKK-BASYHGLYSZB_XQ': 'qualifiedPhysician.html', 'YH-KSZR-BASYHGLYSZB_XQ': 'deptQualifiedPhysician.html', 'YH-ZKK-CYRSTJ': 'qcListOutHospital.html', 'YH-ZKK-RYRSTJ': 'qcListOutHospital.html?inner=2', 'YH-ZKK-WZGBLTJ': 'uncorrectedCasesStatistics.html', 'YH-ZKK-31TZRYRS': 'readmission.html', 'YH-ZKK-YXBLJCB': 'uncorrectedCopy.html', 'YH-ZKK-ZMBLJCB': 'uncorrectedCopy.html', 'YH-KSZR-GJTMQXZB_XQ': 'keyItemFlawControlDept.html', 'YH-KSZR-CYRSTJ_XQ': 'qcListOutHospitalDept.html?from=2', 'YH-KSZR-RYRSTJ_XQ': 'qcListOutHospitalDept.html?inner=2&from=2', 'YH-ZKK-BLZK_XQ': 'qcListYw.html', 'YH-KSZR-BLZK_XQ': 'qcListDeptYw.html', 'YH-ZKHC-SCHCRW': 'creatCheckTask.html', //义乌-生成核查任务 'YH-ZKHC-FPHCRW': 'allotCheckTask.html', //义乌-分配核查任务 'YH-ZKHC-HCRWLB': 'checkTaskList.html', //义乌-核查任务列表 'YH-ZKK-YLZLKZZB_XQ': 'qualityControl.html', 'YH-SJBJ': 'editableDetail.html', //数据编辑 'YH-ZKK-TMQXGSTJ': 'improveStatistics.html', //条目缺陷改善统计 "YH-ZKK-LCZKSYTJ": 'useStatistics.html', //临床质控使用统计 'YH-KSZR-TMQXGSTJ': 'improveStatisticsDept.html', //条目缺陷改善统计(科室) "YH-KSZR-LCZKSYTJ": 'useStatisticsDept.html', //临床质控使用统计(科室) "YH-SSXX-SSJL": 'appealHistory.html', //申诉记录 "YH-SSXX-SSSH": 'appealCheck.html', //申诉审核 "YH-SSXX-SSFQ": 'appealInit.html', //申诉发起列表 "YH-XXTZ": 'messageNoti.html', //申诉发起列表 "YH-RZGL-CZRZ": 'operationalLogs.html', //操作日志 "YH-RZGL-DLRZ": 'loginLogs.html', //登录日志 }; //导出时间天数 const exportTimeLimit = { defectTime: 90, normalTime: 7, yiwuTime: 30, }; //重写assign方法 if (typeof Object.assign != 'function') { Object.assign = function (target) { 'use strict'; if (target == null) { throw new TypeError('Cannot convert undefined or null to object'); } target = Object(target); for (var index = 1; index < arguments.length; index++) { var source = arguments[index]; if (source != null) { for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } } return target; }; } window.console = window.console || (function () { var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function () { }; return c; })(); const getUrlArgObject = function getQueryString(name) { var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'); var reg_rewrite = new RegExp('(^|/)' + name + '/([^/]*)(/|$)', 'i'); var r = window.location.search.substr(1).match(reg); var q = window.location.pathname.substr(1).match(reg_rewrite); if (r != null) { return decodeURIComponent(r[2]); } else if (q != null) { return decodeURIComponent(q[2]); } else { return null; } }; const getUrlArgObjectNew = function (name, srcUrl) { if (srcUrl.indexOf('?') == -1) { return ''; } var r = srcUrl.split('?')[1].split('&'), obj = {}; for (let i = 0; i < r.length; i++) { let tmp = r[i].split('='); obj[tmp[0]] = tmp[1]; } return obj[name]; }; window.abortAjax = ''; const post = function (url, data, opts) { const token = localStorage.getItem('accessToken'); if (localStorage.getItem('toLogin') === '1' && token) { //如果前面已经被标记为登录失效,接下来的请求都不发送 return new Promise(() => { }); } let isPlacefile = getCookie('isPlacefile') || 1; if (!token && window.location.href.indexOf('login') == -1) { setCookie('behosDateStart', ''); setCookie('behosDateEnd', ''); } for (let i = 0; i < $('.typeFilter').children().length; i++) { if ( $('.typeFilter') .children() .eq(i) .html() == '出院日期:' && isPlacefile == 0 ) { $('.typeFilter') .children() .eq(i) .html('入院日期:'); } } let need = window.location.href.indexOf('localhost') != -1; return new Utils((resolve, reject) => { abortAjax = $.ajax({ method: 'post', url: (need ? baseUrl : '') + url, async: true, cache: false, processData: false, data: (opts && opts.needqs) ? qs.stringify(data) : JSON.stringify(Object.assign({}, data, { isPlacefile: (opts && opts.noPlacefile ? undefined : isPlacefile) })), contentType: 'application/json; charset=UTF-8', beforeSend: function (xmlHttp) { xmlHttp.setRequestHeader('isPlacefile', isPlacefile); if (url.indexOf("sys/user/getHospitalMark") === -1) { xmlHttp.setRequestHeader('If-Modified-Since', '0'); xmlHttp.setRequestHeader('Cache-Control', 'no-cache'); xmlHttp.setRequestHeader('Authorization', token ? 'Bearer ' + token : ''); } }, success: function (resq) { const doc = parent ? parent.document : document; //console.log($(doc).find(".alertModal:visible")) //失效后不点知道了直接刷新处理:跳回登录页 if (localStorage.getItem('toLogin') === '1' && $(doc).find(".alertModal:visible").length === 0) { (parent || window).location.href = 'login.html'; } let res = resq; if (typeof resq === 'string') { res = JSON.parse(resq); } const code = res.code; const isOut = code === '10020011' || code === '10020012' || code === '10020013'; if (isOut) { //登录信息失效处理 unloginPop(res.msg); }else if(code === '00020007'){ toast(res.msg) } else { resolve({ data: res }); } }, error: function (error) { if (error.status === 403 || error.status === 401) { setCookie('behosDateStart', ''); setCookie('behosDateEnd', ''); if (!token && window.location.href.indexOf('login') == -1) { } else { if ($(".alertModal:visible").length) { return; } $.alerModal({ "message": "没有该权限" + error.status, type: "tip", time: '1000', isFather: true, fatherWrapper: $("#mainBox", parent.document) }); } } else if (error.status === 500 || error.status === 501 || error.status === 404 ) { $.alerModal({ "message": '接口错误', type: "tip", time: '1000', isFather: true, fatherWrapper: $("#mainBox", parent.document) }); } reject(error); }, }); }); }; //登录失效弹窗处理 function unloginPop(msg) { /*const isOut = code === '10020011' || code === '10020012' || code === '10020013'; if(isOut){*/ const isQcScore = parent && parent.location.href.indexOf("qcScore.html") === -1; if (self != top && isQcScore) {//子窗口并且不是病例列表 const dialogmessage = { iframemessage: 1, data: msg } console.log('子窗口') window.parent.postMessage(JSON.stringify(dialogmessage), '*') } else { console.log('父窗口') $.alerModal({ gobackBtn: true, title: "提示", type: "modal", width: '470', time: 1000, cancalText: '我知道了', isFather: true, fatherWrapper: $("#mainBox", parent.document), sureBtn: false, message: msg || '登录过期', callback: function () { clearAllCookie(); (parent || window).location.href = 'login.html' } }); //失效后不点知道了直接刷新处理标记 localStorage.setItem('toLogin', 1); } /*}else{ callback() }*/ } // 导出 const expJson = (url, data) => { const token = localStorage.getItem('accessToken'); if (!token && window.location.href.indexOf('login') == -1) { setCookie('behosDateStart', ''); setCookie('behosDateEnd', ''); window.location.href = '../login.html'; } let isPlacefile = getCookie('isPlacefile') || 1; let excelName = encodeURIComponent(getCookie('excelName'))||"" console.log(1,excelName) console.log(2,decodeURIComponent(excelName)) let need = window.location.href.indexOf('localhost') != -1; return axios({ method: 'post', url: (need ? baseUrl : '') + url, data: data, contentType: 'application/vnd.ms-excel', responseType: 'blob', //必须添加,否则会乱码 headers: { excelName:excelName, isPlacefile:isPlacefile, Authorization: 'Bearer ' + token, }, }); }; //导出接口返回流下载 function downloadExportedData(data, fileName) { var blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8', }); //application/vnd.openxmlformats-officedocument.spreadsheetml.sheet这里表示xlsx类型 var downloadElement = document.createElement('a'); var href = window.URL.createObjectURL(blob); //创建下载的链接 downloadElement.href = href; downloadElement.download = fileName; //下载后文件名 document.body.appendChild(downloadElement); downloadElement.click(); //点击下载 document.body.removeChild(downloadElement); //下载完成移除元素 window.URL.revokeObjectURL(href); } //判断浏览器是否为Ie8 const isIe8 = function () { var DEFAULT_VERSION = 8.0; var ua = navigator.userAgent.toLowerCase(); var isIE = ua.indexOf('msie') > -1; var safariVersion; if (isIE) { safariVersion = ua.match(/msie ([\d.]+)/)[1]; } if (safariVersion <= DEFAULT_VERSION) { return true; } }; const setCookie = function (name, value) { let Days = 30; let exp = new Date(); exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); document.cookie = name + '=' + escape(value) + ';expires=' + exp.toGMTString(); }; //读取cookies const getCookie = function (name) { let arr, reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); if ((arr = document.cookie.match(reg))) return unescape(arr[2]); else return null; }; const setLocal = function (name, value) { localStorage.setItem(name, value); }; //读取cookies const getLocal = function (name) { return localStorage.getItem(name); }; //删除cookies const delCookie = function (name) { let exp = new Date(); exp.setTime(exp.getTime() - 1); let cval = getCookie(name); if (cval != null) document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString(); }; const clearAllCookie = function () { var keys = document.cookie.match(/[^ =;]+(?=\=)/g); if (keys) { for (var i = keys.length; i--;) document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString() } } //弹窗关闭事件 $('.modal .close').click(function () { $('.modal').hide(); }); //计算容器高度 function setBoxHeight() { const ht = window.innerHeight; const hw = window.innerWidth; if (hw < 1169) { $('.content-box').height(ht - 110 + 'px'); } else { $('.content-box').height(ht - 60 + 'px'); } //$('.content-box').height(ht - 60 + 'px'); $('.flaw-table').height(ht - 70 + 'px'); $('.content-ht').height(ht - 120 + 'px'); $('.scroll-table tbody').css('max-height', ht - 210 + 'px'); } setBoxHeight(); $(window).resize(function () { setBoxHeight(); }); //判断有无某一权限 function hasData(data) { let lis = JSON.parse(getCookie('codeLis')) || []; if (lis.indexOf(data) > -1) { //有权限 return true; } return false; } //定位对应明细菜单 function focusMenuItem(code) { const ele = $(parent.document).find('.menu .page[code=' + code + ']'); const parEle = ele.parents('.list-1'); if (!parEle.is('.list-1-show')) { parEle.click(); } //console.log($(parent.document).find(".menu .page[code='YH-ZKK-GMKQXZB_XQ']")) ele.click(); } function emptyBox(name, showNum, type) { let showNumer = showNum || 30; let str = `
${name || '暂无数据~'}
${str || '暂无数据~'}