/*---------------------------------------------\ StringBuffer:模仿java的StringBuffer类,调用方法 于java StringBuffer一致, -----------------------------------------------*/ function StringBuffer() { this.__strings__ = new Array; } StringBuffer.prototype.append = function (str) { this.__strings__.push(str); } StringBuffer.prototype.toString = function () { return this.__strings__.join(""); } String.prototype.trim = function () { return this.replace(/(^[\s]*)|([\s]*$)/g, ""); } String.prototype.lTrim = function () { return this.replace(/(^[\s]*)/g, ""); } String.prototype.rTrim = function () { return this.replace(/([\s]*$)/g, ""); } String.prototype.lengthB = function () { return this.replace(/[^\x00-\xff]/g, "**").length; } String.prototype.replaceAll = function (reallyDo, replaceWith, ignoreCase) { if (!RegExp.prototype.isPrototypeOf(reallyDo)) { return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi" : "g")), replaceWith); } else { return this.replace(reallyDo, replaceWith); } } /******************************* 判断浏览器是否是IE *******************************/ function IsIE() { if (window.navigator.userAgent.indexOf("MSIE") >= 1) //如果浏览器为IE { return true; } else //如果浏览器为Firefox { return false; { } } } /******************************** 一些供用的方法 *********************************/ JSUtil.attachEvent = function (obj, event, fun) { if (window.attachEvent) obj.attachEvent(event, fun); if (window.addEventListener) { var e = event.substr(0, 2); if (e == 'on') e = event.substr(2); else e = event; obj.addEventListener(e, fun, false); } } /************************************ IE8或者更老的浏览器版本提示信息,错误信息,警告信息和显示子页面 ************************************/ var sMessagePageStyle = "help: no; scroll:no; status: no; dialogWidth:400px;dialogHeight:151px"; //add by baojl at 2008-1-31,判断IE版本,如果是IE6,那么提示框的高度需要调大 if (navigator.appVersion.indexOf("MSIE 6") > 0) { sMessagePageStyle = "help: no; scroll:no; status: no; dialogWidth:400px;dialogHeight:177px"; } var sMessagePageUrl = JSUtil.WebRoot + "/FrameWorkUI/include/Message.jsp"; function MessageOldBox(title, content, msgbuttontype, icon, isshowerror, msgerror) { var obj = new Object(); var sReturnValue; obj.title = title; obj.content = content; obj.msgbuttontype = msgbuttontype; obj.icon = icon; obj.isshowerror = isshowerror; obj.msgerror = msgerror; sReturnValue = window.showModalDialog(sMessagePageUrl, obj, sMessagePageStyle); if (typeof(sReturnValue) == "undefined") sReturnValue = false; return sReturnValue; } //提示信息弹出 function AlertOldMessage(Message) { var stitle = "提示信息"; var btntype = "1"; var icon = "ts-ts.gif"; var Flag = "2"; var errmsg = " "; MessageOldBox(stitle, Message, btntype, icon, Flag, errmsg); } //确认信息提示 function ConfirmOldMessage(Message) { var stitle = "确认信息"; var btntype = "2"; var icon = "ts-wt.gif"; var Flag = "2"; var errmsg = " "; return MessageOldBox(stitle, Message, btntype, icon, Flag, errmsg); } //错误信息提示 function ErrorOldMessage(Message, errmsg) { var stitle = "提示信息"; var btntype = "1"; var icon = "ts-ts.gif"; var Flag = "1"; return MessageOldBox(stitle, Message, btntype, icon, Flag, errmsg); } /******************************** 提示信息,错误信息,警告信息和显示子页面 *********************************/ var sMessagePageStyle = "help: no; scroll:no; status: no; dialogWidth:400px;dialogHeight:151px"; //add by baojl at 2008-1-31,判断IE版本,如果是IE6,那么提示框的高度需要调大 if (navigator.appVersion.indexOf("MSIE 6") > 0) { sMessagePageStyle = "help: no; scroll:no; status: no; dialogWidth:400px;dialogHeight:177px"; } var sMessagePageUrl = JSUtil.WebRoot + "/FrameWorkUI/include/Message.jsp"; function MessageBox(sTitle, content, msgbuttontype, icon, isshowerror, msgerror, fnCallback) { var sIcon = ''; if (icon != '') { sIcon = ""; } if (msgbuttontype == '1') { dhtmlx.alert({ title: sTitle, text: sIcon + content, callback: fnCallback }); } else { if (isshowerror == '1') { dhtmlx.confirm({ title: sTitle, text: sIcon + content, cancel: '高级', callback: function (result) { if (!result) { dhtmlx.modalbox({title: '具体错误信息', text: msgerror, width: "450px", height: "300px", buttons: ["确定"]}); } } }); } else { var returnFlag = false; dhtmlx.confirm({ title: sTitle, text: sIcon + content, callback: fnCallback }); } } } //提示信息弹出 function AlertMessage(Message, callback) { $.messageBox('info', Message, '', callback); } //确认信息提示 function ConfirmMessage(Message, callback) { $.messageBox('warn', Message, '', callback); } //错误信息提示 function ErrorMessage(Message, errmsg, callback) { $.messageBox('error', Message, errmsg, callback); } /***************************************************************** 通用窗口弹出, 参数为, url:弹出窗口的标题, DialogWidth:弹出窗口的宽度, DialogHeight: 弹出窗口的高度 sArgs:弹出窗口的特定属性 ******************************************************************/ function ShowModalDialog(sUrl, Title, DialogWidth, DialogHeight, sArgs) { DialogWidth = parseInt(DialogWidth) + 100; DialogHeight = parseInt(DialogHeight); var sDialogStyle = "resizable:yes;help: no; edge: raised; status:off;dialogWidth:" + (DialogWidth + 10) + "px;dialogHeight:" + (DialogHeight + 10) + "px"; var ssUrl = JSUtil.WebRoot + "/FrameWorkUI/include/popup.html"; var params = new Object(); params.parentWindow = window; params.title = Title; params.nextURL = sUrl; if (sArgs) for (var arg in sArgs) params[arg] = sArgs[arg]; if (params.debug) { window.open(sUrl); return false; } sReturnValue = window.showModalDialog(ssUrl, params, sDialogStyle); if (typeof(sReturnValue) == "undefined") sReturnValue = false; return sReturnValue; } /********************************** function getElementPos(elemmentID) desc:获取某个表单的位置,x值和y值 例子: var pos=getElementPos("divId"); alert(pos.x +",pos.y); ***********************************/ function getElementPos(obj) { var ua = navigator.userAgent.toLowerCase(); var isOpera = (ua.indexOf('opera') != -1); var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof var el = document.getElementById(obj); if (el.parentNode === null || el.style.display == 'none') { return false; } var parent = null; var pos = []; var box; if (el.getBoundingClientRect) //IE { box = el.getBoundingClientRect(); var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop); var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft); return {x: box.left + scrollLeft, y: box.top + scrollTop}; } else if (document.getBoxObjectFor) // gecko { box = document.getBoxObjectFor(el); var borderLeft = (el.style.borderLeftWidth) ? parseInt(el.style.borderLeftWidth) : 0; var borderTop = (el.style.borderTopWidth) ? parseInt(el.style.borderTopWidth) : 0; pos = [box.x - borderLeft, box.y - borderTop]; } else // safari & opera { pos = [el.offsetLeft, el.offsetTop]; parent = el.offsetParent; if (parent != el) { while (parent) { pos[0] += parent.offsetLeft; pos[1] += parent.offsetTop; parent = parent.offsetParent; } } if (ua.indexOf('opera') != -1 || (ua.indexOf('safari') != -1 && el.style.position == 'absolute')) { pos[0] -= document.body.offsetLeft; pos[1] -= document.body.offsetTop; } } if (el.parentNode) { parent = el.parentNode; } else { parent = null; } while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') { // account for any scrolled ancestors pos[0] -= parent.scrollLeft; pos[1] -= parent.scrollTop; if (parent.parentNode) { parent = parent.parentNode; } else { parent = null; } } return {x: pos[0], y: pos[1]}; } /**************************** showProcessBar(),显示进度条, hideProcessBar(),隐藏进度条 ******************************/ function showProcessBar(b) { $.toggleLoading(); /* blurActiveElement(); var bar = document.getElementById("Page_In_Process"); if (bar){ bar.style.display = "block"; //alert(bar.style.display ); } if (!b) disabledBody(); try{ if(null!=ifwaiting&&"undefined"!=typeof(ifwaiting)){ ifwaiting=true; } }catch(e){} */ } function showProcessBar(b) { $.toggleLoading(); /* blurActiveElement(); var bar = document.getElementById("Page_In_Process"); if (bar){ bar.style.display = "block"; //alert(bar.style.display ); } if (!b) disabledBody(); try{ if(null!=ifwaiting&&"undefined"!=typeof(ifwaiting)){ ifwaiting=true; } }catch(e){} */ } function hideProcessBar(b) { $.toggleLoading(); /* blurActiveElement(); var bar = document.getElementById("Page_In_Process"); if (bar){ bar.style.display = "none"; } if (!b) enabledBody(); try{ //在请求的时候完成缓存数据的清除 if(ecRow_selectRowId!=null&&typeof ecRow_selectRowId !="undefined"){ ecRow_selectRowId=null; } if(ecRowSelect!=null&&typeof ecRowSelect !="undefined"){ ecRowSelect=null; } if(ecRow_backgroundColor!=null&&typeof ecRow_backgroundColor !="undefined"){ ecRow_backgroundColor=null; } if(null!=ifwaiting&&"undefined"!=typeof(ifwaiting)){ ifwaiting=false; } }catch(e){} */ } /**判断读条是否显示 如果显示就返回true,如果没有显示就显示 false**/ function IsProcessBar() { var bar = document.getElementById("Page_In_Process"); if (!bar || bar.style.display == "none") { return false; } else { return true; } } function blurActiveElement() { try { var a = document.activeElement; if (!a) return; var b = a == document || a == document.body; if (!b) a.blur(); } catch (ex) { } } /* * 对 Body 的所有内容用DIV进行覆盖,不允许操作。 * * 说明:如果有内容不想要被覆盖,则z-index大于200 * */ function disabledBody() { if (document.getElementById("Body_HideDiv_haha")) document.getElementById("Body_HideDiv_haha").style.display = "block"; } /************************ * 根据url提取参数 add by baojl * @param item 需要提取的参数 * @retrun 返回的参数值 * ***********************/ function QueryParamByURL(item) { var sValue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)", "i")) return sValue ? sValue[1] : sValue; } /* * 撤销 对Body 内容的撤销。 */ function enabledBody() { if (document.getElementById("Body_HideDiv_haha")) document.getElementById("Body_HideDiv_haha").style.display = "none"; } /*********************************** 进度条 *************************************/ function init_write_ProcessBar_code() { /*var k=document.getElementById("xx_abcdefg");if(k&&k.style)k.style.display="none"; //disabled body div var iframe = document.createElement("iframe"); iframe.frameBorder = "0"; iframe.style.cssText = "width:expression(document.body.clientWidth);background:green;position:absolute;left:0;right:0;top:0;bottom:0;-moz-opacity:0.01;filter:alpha(opacity=1);z-index:199;height:expression(document.body.clientHeight);"; var processDiv = document.createElement("div"); processDiv.id = "Body_HideDiv_haha"; processDiv.style.cssText = "display:none;"; processDiv.appendChild(iframe); document.body.appendChild(processDiv); if (!document.getElementById("Page_In_Process")) { var processDiv = document.createElement("div"); processDiv.id = "Page_In_Process"; processDiv.style.cssText = "display:none;Z-INDEX: 8888; padding:3 3 3 3;BACKGROUND-COLOR: F0FFF0; BORDER: 1 solid #82AAD2; VISIBILITY: visible; POSITION: absolute;LEFT:expression((document.body.clientWidth - 200)/2); WIDTH: 200px; TOP: expression((document.body.clientHeight - 60)/2); HEIGHT: 50px; "; var iframe = document.createElement("iframe"); iframe.frameborder = "0"; processDiv.appendChild(iframe); var s = ''; s += ''; s += '
系统正在处理,请稍候......'; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += '
'; s += '
'; s += '
'; processDiv.innerHTML = s; //return; document.body.appendChild(processDiv); } try{ JSUtil.attachEvent(document, "onmousemove", onMouseMove); document.execCommand("BackgroundImageCache", false, true); }catch(ex){}*/ } function Body_HideDiv_haha_click() { alert("Body_HideDiv_haha_click"); } JSUtil.attachEvent(window, "onload", init_write_ProcessBar_code); function onMouseMove() { try { var e = window.event.srcElement; if (e == __auto_e) return; var hh = e.getAttribute("autohint"); if (!hh) _autohint.hide(); else _autohint.show(hh); __auto_e = e; } catch (ex) { } } /************************* 判断是否按的是字符键或者数字键 *************************/ function CheckIscharkey(e) { e = window.event || e; nkey = e.keyCode; if (!event.altKey && !event.ctrlKey && ((nkey >= 65 && nkey <= 90) || (nkey >= 48 && nkey <= 57) || (nkey >= 96 && nkey <= 105))) return true; else return false; } /*************************** 日期转换 传入参数格式: 2009 200901 20090101 200901010101 20090101010112 ****************************/ function conversionDateToCh(str) { var retStr = ""; if (str.length < 4) return retStr; if (str.length >= 4) retStr += str.substr(0, 4) + "年"; if (str.length >= 6) retStr += str.substr(4, 2) + "月"; if (str.length >= 8) retStr += str.substr(6, 2) + "日"; if (str.length >= 10) retStr += str.substr(8, 2) + "时"; if (str.length >= 12) retStr += str.substr(10, 2) + "分"; if (str.length >= 14) retStr += str.substr(12, 2) + "秒"; return retStr; } function conversionTimeToCh(str) { var retStr = ""; if (str.length > 4) return retStr; retStr += str.substr(0, 2) + "时"; retStr += str.substr(2, 2) + "分"; return retStr; } /*************************** 日期转换 传入参数格式: 2009-- 200901 20090101 200901010101 20090101010112 ****************************/ function conversionDateToGang(str) { if (!str) { return ""; } var retStr = ""; if (str.length < 4) return retStr; if (str.length >= 4) retStr += str.substr(0, 4) + "-"; if (str.length >= 6) retStr += str.substr(4, 2) + "-"; if (str.length >= 8) retStr += str.substr(6, 2) + ""; if (str.length >= 10) retStr += " " + str.substr(8, 2) + ":"; if (str.length >= 12) retStr += str.substr(10, 2) + ":"; if (str.length >= 14) retStr += str.substr(12, 2) + ""; return retStr; } /*************************** 日期转换 传入参数格式: 2009 2009-01 2009-01-01 2009-01-010101 20090101010112 ****************************/ function conversionDateRemoveGang(str) { if (!str) { return ""; } str = str.replace(/([' ']*)/g, ""); str = str.replace(/([':']*)/g, ""); str = str.replace(/(['\-']*)/g, ""); return str; } /****************************** 键盘监听事件,不同的空间要实现不同的监听 这里暂时实现两个键盘监听 1是快速索引,1是代码选择 ********************************/ //设置初始的时候高亮显示第一个行 var currentCodeLine = 0; //设置初始的时候高亮显示第一个行 var currentLine = 1; //键盘监听事件,按上下键高亮显示行 document.onkeydown = function (e) { try { if (publicParemt != null) { if (publicParemt.TempDIV != null && document.getElementById(publicParemt.TempDIV).style.display != "none") { e = window.event || e; switch (e.keyCode) { //如果按向上按钮,则currentLine--,并着色,如果按向下按钮 则currentLine++,并着色,如果是按回车,则返回选中的行的值 case 38: currentLine--; changeItem(document.getElementById(publicParemt.TempDIV + "-table")); break; case 40: currentLine++; changeItem(document.getElementById(publicParemt.TempDIV + "-table")); break; //如果按键是回车,则返回数据 case 13: onKeyDownReturn(document.getElementById(publicParemt.TempDIV + "-table")); break; //如果按键是esc,则隐藏DIV case 27: displayQuickSearchDIV(); event.cancelBubble = true; break; //向前翻页 case 37: roll(0); break; //向后翻页 case 39: roll(1); break; default : break; } } } } catch (e) { } try { if (publicCodeParemt != null) { if (publicCodeParemt.TempDIV != null && (publicCodeParemt.TempDIV.div_ID) != null && document.getElementById(publicCodeParemt.TempDIV.div_ID).style.display != "none") { e = window.event || e; switch (e.keyCode) { //如果按向上按钮,则currentCodeLine--,并着色,如果按向下按钮 则currentCodeLine++,并着色,如果是按回车,则返回选中的行的值 case 38: currentCodeLine--; changeCodeItem(document.getElementById(publicCodeParemt.TempDIV.div_ID + "-table")); break; case 40: currentCodeLine++; changeCodeItem(document.getElementById(publicCodeParemt.TempDIV.div_ID + "-table")); break; //如果按键是回车,则返回数据 case 13: onKeyDownReturnCode(document.getElementById(publicCodeParemt.TempDIV.div_ID)); break; //如果按键是esc,则隐藏DIV case 27: closeCodeCodeSearchDIV(); break; default : break; } } } } catch (e) { } } /********************************设置下拉列表框根据值选中*******************************/ function setSelectValue(selectOp, value) { if (selectOp != null && selectOp.length > 0 && selectOp != null) { for (var i = 0; i < selectOp.options.length; i++) { if (selectOp.options[i].value == value) { selectOp.options[i].selected = true; break; } } } } /************获取复选框的value值,并且以“,”号隔开*******************/ function getSelectValue(check) { if (!check) { return ""; } var ywdhs = ""; for (var i = 0; i < check.length; i++) { var oneCheck = check[i]; if (oneCheck.checked == true) { ywdhs += "," + oneCheck.value; } } return ywdhs; } /********在ectable操作完成之后的一个钩子,待完成刷新工作,可以做里面的事情*********/ function afterShowEcFormResponse(retStr) { } /********另外一个在ectable操作完成之后的一个钩子,待完成刷新工作,可以做里面的事情*********/ function afterShowEcFormResponseAndSearch(retStr) { } //计算日期之差传入参数是 yyyy-mm-dd格式 function better_time(strDateStart, strDateEnd) { var strSeparator = "-"; //日期分隔符 var strDateArrayStart; var strDateArrayEnd; var intDay; strDateArrayStart = strDateStart.split(strSeparator); strDateArrayEnd = strDateEnd.split(strSeparator); var strDateS = new Date(strDateArrayStart[0] + "/" + strDateArrayStart[1] + "/" + strDateArrayStart[2]); var strDateE = new Date(strDateArrayEnd[0] + "/" + strDateArrayEnd[1] + "/" + strDateArrayEnd[2]); intDay = (strDateE - strDateS) / (1000 * 3600 * 24); return intDay; } function showAJAXFormResponse(originalRequest) { //获取结果数据 var retStr = originalRequest.responseText; var errorMess = retStr.substring(retStr.indexOf('[AjaxErrorMessage]'), retStr.indexOf('[/AjaxErrorMessage]')).trim(); ; //判断是否有错误,如果没有错误,则直接输出结果集,否则,输出错误 if (errorMess == null || typeof errorMess == "undefiend" || errorMess == "" || errorMess == "[AjaxErrorMessage]'),retStr.indexOf('") { //如果有提示消息,输入提示消息 var Mess = retStr.substring(retStr.indexOf('[AjaxMessage]'), retStr.indexOf('[/AjaxMessage]')); if (Mess != null && typeof Mess != "undefiend" && Mess != "" && Mess != "[AjaxMessage]'),retStr.indexOf('") { AlertMessage(Mess.substring(13, Mess.length)); } } else { //输出错误 var errorMessDetail = retStr.substring(retStr.indexOf('[AjaxErrorMessageDetail]'), retStr.indexOf('[/AjaxErrorMessageDetail]')).trim(); ErrorMessage(errorMess.substring(18, errorMess.length), errorMessDetail.substring(24, errorMessDetail.length)); } hideProcessBar(); ifwaiting = false; //钩子,在操作完ajax刷新之后的其他自定义操作,如赋值。。 afterShowEcFormResponse(retStr); } /**获取路径url后面的参数值***/ function QueryString(item) { var sValue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)", "i")) return sValue ? sValue[1] : sValue; } /**获取路径url后面的参数值的原型,返回例如:jzxh=00000&zhbh=77777&dh=9999***/ function QueryStringUrl() { var urls = location.search; var len = location.search.indexOf("?"); if (len + 1 > 0) { var retval = urls.substring(len + 1, urls.length); return retval; } else { return ""; } } /**获取DIV中所有有name的input和select标签,暂时还没有处理radio和checkBOX,形成的结果如下jzxh=00000&zhbh=77777&dh=9999**/ function getDivInputParamNameValue(divID) { var retNameVar = new StringBuffer(); //根据DIV获取对象 var divObj = document.getElementById(divID); if (!divObj) { AlertMessage("找不到指定的DIV"); return; } retNameVar.append("1=1"); //获取input标签 var inputTag = document.getElementById(divID).getElementsByTagName("input"); //循环 for (var i = 0; i < inputTag.length; i++) { var ta = inputTag[i]; if (ta.name != "") { retNameVar.append("&"); retNameVar.append(ta.name); retNameVar.append("="); retNameVar.append(ta.value); } } //获取select标签 var selectTag = document.getElementById(divID).getElementsByTagName("select"); //循环 for (var i = 0; i < inputTag.length; i++) { var ta = inputTag[i]; if (ta.name != "") { retNameVar.append("&"); retNameVar.append(ta.name); retNameVar.append("="); retNameVar.append(ta.value); } } //返回值 return retNameVar.toString(); } /***获取单选框被选中的值**/ function getRadioValue(na) { var radioName = document.getElementsByName(na); if (radioName) { for (var i = 0; i < radioName.length; i++) { if (radioName[i].checked == true) { return radioName[i].value; } } } return null; } function setRadioChecked(na, val) { var radioName = document.getElementsByName(na); if (radioName && val) { for (var i = 0; i < radioName.length; i++) { if (radioName[i].value == val) { radioName[i].checked = true; return; } else { radioName[i].checked = false; } radioName[0].checked = true; } } } /**获取默认分隔符*/ function getDefalutSplitString() { return JSUtil.defaultSplitString; } /** 关闭从系统右下角自动弹出的消息提示框, add by baojl 2012-03-08 **/ function closeTongzhiTanchuKuangDIV() { var tanchutongzhi = document.getElementById("tanchutongzhi"); if (tanchutongzhi) { tanchutongzhi.style.visibility = "hidden"; } } /********************************************************************* fineReport函数 *********************************************************************/ /**************中文编码*****************/ function cjkEncode(text) { if (text == null) { return ""; } var newText = ""; for (var i = 0; i < text.length; i++) { var code = text.charCodeAt(i); if (code >= 128 || code == 91 || code == 93) {//91 is "[", 93 is "]". newText += "[" + code.toString(16) + "]"; } else { newText += text.charAt(i); } } return newText; } /************************************* 下载 *************************************/ function downloadFlashPlay() { var thisHost = "http://" + document.location.host + "/"; window.open(thisHost + "download/flash.exe"); } // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, "d+": this.getDate(), "h+": this.getHours(), "m+": this.getMinutes(), "s+": this.getSeconds(), "q+": Math.floor((this.getMonth() + 3) / 3), "S": this.getMilliseconds() }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; } function DateStringFormat(fmt) { if (fmt == '' || fmt == null) return ''; var len = fmt.length, ret = ''; if (len <= 4) return fmt; if (len >= 4) ret += fmt.substring(0, 4); if (len >= 6) ret += '-' + fmt.substring(4, 6); if (len >= 8) ret += '-' + fmt.substring(6, 8); if (len >= 10) ret += ' ' + fmt.substring(8, 10); if (len >= 12) ret += ':' + fmt.substring(10, 12); if (len >= 14) ret += ':' + fmt.substring(12, 14); return ret; } function DateStringFormat2(fmt) { if (fmt == '' || fmt == null) return ''; var len = fmt.length, ret = ''; if (len <= 4) return fmt; if (len >= 4) ret += fmt.substring(0, 4) + '年'; if (len >= 6) ret += '' + fmt.substring(4, 6) + '月'; if (len >= 8) ret += '' + fmt.substring(6, 8) + '日'; if (len >= 10) ret += ' ' + fmt.substring(8, 10); if (len >= 12) ret += ':' + fmt.substring(10, 12); if (len >= 14) ret += ':' + fmt.substring(12, 14); return ret; } function returnYearMonthDay(returnType, dateString) { if (dateString == '' || dateString == null) return ''; var len = dateString.length, year, month, day; year = dateString.substring(0, 4); //日期格式为xxxx-xx-xx,如2015-04-29 if (len == 10) { month = dateString.substring(5, 7); day = dateString.substring(8, 10); } else {//日期格式为xxxxxxxx,如20150429 month = dateString.substring(4, 6) day = dateString.substring(6, 8); } if ('year' == returnType) { return year; } else if ('month' == returnType) { return month; } else if ('day' == returnType) { return day; } else { return ''; } } Date.prototype.addDays = function (d) { this.setDate(this.getDate() + d); }; // 阻止KEYDOWN时间冒泡 function NOT_KEYDOWN() { var e = e || event, keynum = (window.event) ? event.keyCode : e.which; switch (keynum) { case 13: if (e && e.preventDefault) { //阻止默认浏览器动作(W3C) e.preventDefault(); } else { //IE中阻止函数器默认动作的方式 window.event.returnValue = false; } return false; } } /*计算年龄*/ function jsGetAge(strBirthday) { if (!strBirthday) return; if (strBirthday.length != 8) { layer.msg("出生日期:" + strBirthday + "格式不正确,如:19900101", {time: 3000, icon: 2}); return ''; } var year = '', month = '', day = '', nowYear = '', nowMonth = '', nowDay = ''; if (strBirthday.length == 8) { year = parseInt(strBirthday.substring(0, 4)) , month = parseInt(strBirthday.substring(4, 6)), day = parseInt(strBirthday.substring(6, 8)); } else { var csrqS = strBirthday.split('-'); year = parseInt(csrqS[0]) , month = parseInt(csrqS[1]), day = parseInt(csrqS[2]); } var bDay = new Date(year, month, day), nowDate = new Date(), nowYear = parseInt(nowDate.getFullYear()), nowMonth = parseInt(nowDate.getMonth()) + 1, nowDay = parseInt(nowDate.getDate()), //nbDay = new Date(nDay.getFullYear(),bDay.getMonth(),bDay.getDate()), age = nowYear - year; if ((nowMonth - month) < 0) { age = age - 1; } else if ((nowMonth - month) == 0) { if ((nowDay - day) > 0) { age = nowYear - year; } else { age = age - 1; } } else if ((nowMonth - month) > 0) { age = nowYear - year; } var flagDate = false; if (nowYear > year) { flagDate = true; } else if (nowYear == year) { if (nowMonth > month) { flagDate = true; } else if (nowMonth == month) { if (nowDay >= day) { flagDate = true; } } } var dw = '周岁'; if (age == 0) { age = (nowYear - year) * 12 + (nowMonth - month); dw = '个月'; if (age <= 0) { age = nowDay - day; dw = '天'; if (age <= 0) { age = ''; dw = ''; } } } if (!flagDate) { layer.msg("出生日期错误,日期超过当前!", {time: 3000, icon: 2}); return ''; } return age + dw; } function jsGetNl(strBirthday) { var returnAge; var birthYear = '', birthMonth = '', birthDay = ''; if (strBirthday.length == 8) { birthYear = parseInt(strBirthday.substring(0, 4)) , birthMonth = parseInt(strBirthday.substring(4, 6)), birthDay = parseInt(strBirthday.substring(6, 8)); } else { var csrqS = strBirthday.split('-'); birthYear = parseInt(csrqS[0]) , birthMonth = parseInt(csrqS[1]), birthDay = parseInt(csrqS[2]); } var d = new Date(); var nowYear = d.getFullYear(); var nowMonth = d.getMonth() + 1; var nowDay = d.getDate(); if (nowYear == birthYear) { returnAge = 0;//同年 则为0岁 } else { var ageDiff = nowYear - birthYear; //年之差 if (ageDiff > 0) { if (nowMonth == birthMonth) { var dayDiff = nowDay - birthDay;//日之差 if (dayDiff < 0) { returnAge = ageDiff - 1; } else { returnAge = ageDiff; } } else { var monthDiff = nowMonth - birthMonth;//月之差 if (monthDiff < 0) { returnAge = ageDiff - 1; } else { returnAge = ageDiff; } } } else { returnAge = -1;//返回-1 表示出生日期输入错误 晚于今天 } } return returnAge;//返回周岁年龄 } /** * 根据身份证获取 出生日期 xb */ (function () { var getIdentityCardInformation = function (res) { var data = { birthday: "", gender: "" } var IdNO = res.IdNO; var patrn = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/; if (!patrn.test(IdNO)) { layer.msg("请输入合法的身份证号码,合法身份证号为15位或18位", {time: 3000, icon: 2}); return ''; return; } else if (IdNO.length = "") { layer.msg("请输入合法的身份证号码,合法身份证号为15位或18位", {time: 3000, icon: 2}); return ''; return; } if (IdNO.length == 18) { var birthday = IdNO.substr(6, 8); data["birthday"] = birthday.replace(/(.{4})(.{2})/, "$1$2"); data["gender"] = IdNO.charAt(16) % 2 == 0 ? "F" : "M"; } else if (IdNO.length == 15) { var birthday = "19" + IdNO.substr(6, 6); data["birthday"] = birthday.replace(/(.{4})(.{2})/, "$1-$2-"); data["gender"] = IdNO.charAt(14) % 2 == 0 ? "F" : "M"; } if (res.hasOwnProperty("callback")) { res.callback(data); } } getIdentityCard = { Information: getIdentityCardInformation } })() String.prototype.endWith = function (s) { if (s == null || s == "" || this.length == 0 || s.length > this.length) return false; if (this.substring(this.length - s.length) == s) return true; else return false; return true; } String.prototype.startWith = function (s) { if (s == null || s == "" || this.length == 0 || s.length > this.length) return false; if (this.substr(0, s.length) == s) return true; else return false; return true; } function getMaxLengthTitle(value, maxLength) { var abledName = ""; if (value.length > maxLength) { abledName = value.substring(0, maxLength); abledName += "..."; } else { abledName = value; } return abledName; } /* * 两个时间相差天数 sDate1和sDate2是2019-11-27格式 * */ function datedifference(sDate1, sDate2) { //sDate1和sDate2是2006-12-18格式 var dateSpan, tempDate, iDays; sDate1 = Date.parse(sDate1); sDate2 = Date.parse(sDate2); dateSpan = sDate2 - sDate1; dateSpan = Math.abs(dateSpan); iDays = Math.floor(dateSpan / (24 * 3600 * 1000)); return iDays } function getNow(s) { return s < 10 ? '0' + s : s; } function getDateTime() { var myDate = new Date(); var year = myDate.getFullYear(); //获取当前年 var month = myDate.getMonth() + 1; //获取当前月 var date = myDate.getDate(); //获取当前日 var h = myDate.getHours(); //获取当前小时数(0-23) var m = myDate.getMinutes(); //获取当前分钟数(0-59) var s = myDate.getSeconds(); var now = year + '-' + getNow(month) + "-" + getNow(date) + " " + getNow(h) + ':' + getNow(m) + ":" + getNow(s); return now; } /*计算出生年份,月份日期默认一月一号*/ function jsGetBirthday(nl) { if (!nl) return; if (nl.length > 3 || nl.length < 1) { layer.msg("输入年龄:" + nl + "格式不正确,如:18", {time: 3000, icon: 2}); return ''; } var nowDate = new Date(), nowYear = parseInt(nowDate.getFullYear()), nowMonth = parseInt(nowDate.getMonth()) + 1, nowDay = parseInt(nowDate.getDate()); var year = nowYear - parseInt(nl); return year + '0101'; } /*金额格式化如:1,234,567.00*/ function numFun(value) { var newStr = ""; var count = 0; if (value.indexOf(".") == -1) { if (value.charAt(0) == '0') { //不存在小数点时,判断第一位数字是否为0 value = value.substring(1); } for (var i = value.length - 1; i >= 0; i--) { if (count % 3 == 0 && count != 0) { newStr = value.charAt(i) + "," + newStr; } else { newStr = value.charAt(i) + newStr; } count++; } value = newStr + ".00"; } else { for (var i = value.indexOf(".") - 1; i >= 0; i--) { if (count % 3 == 0 && count != 0) { newStr = value.charAt(i) + "," + newStr; } else { newStr = value.charAt(i) + newStr; } count++; } value = newStr + (value + "00").substr((value + "00").indexOf("."), 3); } return value; } /** * Layer iframe弹出窗 close关闭的时候 end 没有返回值 这里自定义一个iframeClose方法 用于iframe关闭的时候 end 回调可以拿到返回值 */ (function () { layui.use(['layer'], function () { var layer = parent.layui.layer; var closeWindow = function (res) { var data = ''; var type = typeof(res) != "undefined" ? data = res : ""; var index = parent.layer.getFrameIndex(window.name); layer.iframeClose({e: index, data: data}); }; $wn = { iframeClose: closeWindow }; }); })() /*计算出生年份,年份+月份*/ function jsGetBirthday_yf(nl, yf) { if (!nl && nl != 0) return;//由于0也会被认为是空数 if (nl.length > 3 || nl.length < 1) { layer.msg("输入年龄:" + nl + "格式不正确,如:18", {time: 3000, icon: 2}); return ''; } try { var nowDate = new Date(); var nlyf = parseInt(yf) + parseInt(nl) * 12; var csrq = stringDashDateDToDateString(formatTime(addMonths(nowDate, -nlyf))); var rnl = jsGetNl(csrq); $("#nl").val(rnl); return csrq; } catch (e) { return jsGetBirthday(nl); } } function getYf_Yb(yb_csrq) {//部分地区的医保 返回是带-的 if (yb_csrq) { yb_csrq = conversionDateToGang(stringDashDateDToDateString(yb_csrq)); var newcsrq = new Date(yb_csrq); var now = new Date(); var yf = completeDateLife(newcsrq, now); return yf; } else { return 1; } } function stringDashDateDToDateString(csrq) { //去除掉出生日期里面的- if (csrq) { csrq = csrq + ''; if (csrq.indexOf('-') > -1) { return csrq.substring(0, 4) + csrq.substring(5, 7) + csrq.substring(8, 10); } else { return csrq; } } } function formatTime(date) { var year = date.getFullYear(); var month = date.getMonth() + 1, month = month < 10 ? '0' + month : month; var day = date.getDate(), day = day < 10 ? '0' + day : day; return year + '-' + month + '-' + day; } function addMonths(dateTmp, mounthTmp) //需要操作的日期,相加的月份 { var d = dateTmp.getDate(); dateTmp.setMonth(dateTmp.getMonth() + mounthTmp); if (dateTmp.getDate() < d) { dateTmp.setDate(0); } return dateTmp; } function completeDate(time1, time2, m) { var diffyear = time2.getFullYear() - time1.getFullYear(); var diffmonth = diffyear * 12 + time2.getMonth() - time1.getMonth(); if (diffmonth < 0) { return 0; } var diffDay = time2.getDate() - time1.getDate(); if ((time2.getMonth() - time1.getMonth()) == 0) {//相同月份 if (diffDay < 0) { diffmonth--; } } return diffmonth; } function completeDateLife(time1, time2) { // 出生 现在 var diffyear = time2.getFullYear() - time1.getFullYear(); var diffmonth = time2.getMonth() - time1.getMonth(); if (diffmonth < 0) { //比如现在3月份 在1月份出生 diffmonth = diffmonth + 12; } return diffmonth; } function getDate_rq() { var myDate = new Date; var year = myDate.getFullYear(); //获取当前年 var mon = myDate.getMonth() + 1; //获取当前月 var date = myDate.getDate(); //获取当前日 return year + "" + mon + "" + date; } var textarea = { __inner: function (height_in) { $('textarea').each(function () { if(!height_in){ height_in = 50; } var height = height_in+'px'; // 为 textarea 设置初始高度 $(this).css({'height': height, 'overflow-y': 'hidden'}); // 监听 input 事件,在用户输入时重设高度 }).on('input', function () { // 这行是删除文本时,减高度用的 this.style.height = 'auto'; // 将 textarea 的高度设为文本的高度,达到自适应效果 this.style.height = (this.scrollHeight) + 'px'; }); }, _init: function () { $('textarea').each(function () { // 这行是删除文本时,减高度用的 this.style.height = 'auto'; // 将 textarea 的高度设为文本的高度,达到自适应效果 this.style.height = (this.scrollHeight) + 'px' $(this).css({'overflow-y': 'hidden'}); }) } } var wn_tips = function (data) { $(data.id).unbind(); $(data.id).hover(function () { layer.tips( data.content , data.id , { tips: [1, '#327CB7'] //设置tips方向和颜色 类型:Number/Array,默认:2 tips层的私有参数。支持上右下左四个方向,分别通过1-4进行方向设定。 , tipsMore: false//允许同时多个tips , time: -1 //显示时长 毫秒 -1表示永久 , area: ['auto', 'auto'] } ) }, function () { var index = layer.tips(); layer.close(index); }) } var getAppointTime = function (n) { var time = new Date().Format("yyyyMMdd"); if (n > 0) { var date = new Date() date.setMonth(date.getMonth() - n) date.toLocaleDateString() var year = date.getFullYear() var month = date.getMonth() + 1 var day = date.getDate(); month = month < 10 ? '0' + month : month day = day < 10 ? '0' + day : day time = year + '' + month + '' + day } return time; } /** * 根据传入时间,月份,前后 换算新时间 * 有问题:请使用addMonthsToDate * @param time * @param n * @param type * @returns {string} */ function getNewDate(flag, many,time) { const thirtyDays = [4, 6, 9, 11] // 30天的月份 const thirtyOneDays = [1, 3, 5, 7, 8, 10, 12] // 31天的月份 const currDate = new Date(time) // 今天日期 const year = currDate.getFullYear() let month = currDate.getMonth() + 1 let targetDateMilli = 0 let GMTDate = '' // 中国标准时间 let targetYear = '' // 年 let targetMonth = '' // 月 let targetDate = '' // 日 let dealTargetDays = '' // 目标日期 const isLeapYear = !!((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) // 是否是闰年 let countDays = 0 // 累计天数 for (let i = 0; i < many; i++) { if (flag === 'before') { month = month - 1 <= 0 ? 12 : month - 1 } else { month = month + 1 > 12 ? 1 : month + 1 } thirtyDays.includes(month) ? (countDays += 30) : thirtyOneDays.includes(month) ? (countDays += 31) : isLeapYear ? (countDays += 29) : (countDays += 28) } targetDateMilli = currDate.setDate( currDate.getDate() - (flag === 'before' ? countDays : countDays * -1) ) GMTDate = new Date(targetDateMilli) targetYear = GMTDate.getFullYear() targetMonth = GMTDate.getMonth() + 1 targetDate = GMTDate.getDate() targetMonth = targetMonth.toString().padStart(2, '0') targetDate = targetDate.toString().padStart(2, '0') dealTargetDays = `${targetYear}-${targetMonth}-${targetDate}` console.log(dealTargetDays, '处理的日期啊') return dealTargetDays } //根据传入时间,月份,前后 换算新时间 function addMonthsToDate(direction,months, dateStr ) { // 将日期字符串转换为日期对象 var date = new Date(dateStr); // 确定方向是往后还是往前计算 var multiplier = 1; if (direction === 'before') { multiplier = -1; } // 获取年份、月份和日期 var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDate(); // 增加月份 month += (multiplier * months); // 处理年份和月份溢出 year += Math.floor(month / 12); month %= 12; // 处理月份为 0-11 的情况 if (month < 0) { month += 12; year -= 1; } // 获取新日期的天数 var newDate = new Date(year, month, day); // 处理新日期超出该月的天数的情况 while (newDate.getMonth() !== month) { day -= 1; newDate = new Date(year, month, day); } // 将新日期格式化为字符串 var newDateStr = newDate.toISOString().slice(0,10); return newDateStr; } /** * 按钮事件点击后,3秒内按钮事件失效 * */ function buttonThreeSecondsDisable() { $('.iwonnet-button-disabled').unbind('click',buttonThreeSecondsDisableClick).on('click', buttonThreeSecondsDisableClick); } function buttonThreeSecondsDisableClick() { var $that = $(this); buttonThreeSecondsDisableClickBind($that); } function buttonThreeSecondsDisableClickBind($that) { $that.find('.layui-icon-loading').remove(); $that.prop('disabled', true).prepend(''); setTimeout(function () { $that.removeAttr('disabled').find('.layui-icon-loading').remove(); }, 3000); } /** * 绑定输入域清空多码符号事件 */ function bindClearMultiCodeSymbols() { $('.clear-multi-code-symbols').off('input',clearMultiCodeSymbols).bind('input',debounce(clearMultiCodeSymbols,50)); } /** * 输入域清空多码符号 */ function clearMultiCodeSymbols() { var value = $(this).val().trim() + ''; if (value) { var symbol = value.substr(-1); if (['&','|',','].includes(symbol)) { value = value.substring(0,value.length - 1); $(this).val(value) } } } /** * 锁住当前点击事情 */ var lastClick; function lockClick(){ var nowClick = new Date(); console.log('lastClick',lastClick); if (lastClick === undefined){ lastClick = nowClick; return true; }else { if (Math.round((nowClick.getTime() - lastClick.getTime())) > 1000) { lastClick = nowClick; return true; }else { lastClick = nowClick; return false; } } } $(function () { buttonThreeSecondsDisable(); bindClearMultiCodeSymbols(); }); /** * 防抖 */ function debounce(fn,delay) { var timer; return function () { var context = this; // 当前指向对象 var args = arguments; // fn函数入参 timer = clearTimeout(timer); // 清除原来的任务 timer = setTimeout(function () { fn.apply(context,args); },delay) } } /** * 节流 * @param fn 执行方法 * @param wait 多少时间内防流 */ function throttle(fn,wait) { var pre = Date.now(); return function () { var context = this; // 当前指向对象 var args = arguments; // fn函数入参 var now = Date.now(); // 当前时间 if (now - pre >= wait) { fn.apply(context,args); // 执行fn拼把之前指向this对象和参数传入 pre = Date.now(); //更新之前的时间 } } } /** * 隐藏数据,只显示后面4位 * @param row * @returns {string|string} */ function hideStringByFour(row){ var str=row[this.field]; return hideString(str,4); } /** * 隐藏数据,只显示后面5位 * @param row * @returns {string|string} */ function hideStringByFive(row){ var str=row[this.field]; return hideString(str,5); } /** * 隐藏数据,只显示后面num位,适用于 * @param str * @param num */ function hideString(str,num){ str=str.toString(); var length=str.length; if (lengthPDF下载"); var script = document.createElement("script"); script.src = "/FrameWorkUI/js/pdf/jspdf.umd.js"; // 设置脚本文件的路径 newWindowDoc.head.appendChild(script); var script1 = document.createElement("script"); script1.src = "/FrameWorkUI/js/pdf/jspdf.plugin.autotable.js"; // 设置脚本文件的路径 newWindowDoc.head.appendChild(script1); var script2 = document.createElement("script"); script2.src = "/FrameWorkUI/js/pdf/simhei-normal.js"; // 设置脚本文件的路径 newWindowDoc.head.appendChild(script2); newWindowDoc.pdfHead = pdfHead; newWindowDoc.pdfBody = pdfBody; var scriptText = document.createElement("script"); scriptText.innerText = " function downLoadPDF(){" + " applyPlugin(jspdf.jsPDF);" + " var obj = new jspdf.jsPDF({format: 'a3',orientation :'landscape'});" + " obj.addFileToVFS(\"MyFont.ttf\", myFontPdf);" + " obj.addFont(\"MyFont.ttf\", \"MyFont\", \"normal\");" + " obj.setFont(\"MyFont\");" + " obj.autoTable({" + " startX: 10," + " startY: 10," + " head: window.document.pdfHead," + " body: window.document.pdfBody" + " });" + " obj.save('"+downName+".pdf');" + " }" + " function exportStart() {" + " if (myFontPdf) {" + " downLoadPDF();setTimeout(function () {window.close();},200);" + " }else{" + " if (index) clearTimeout(index);" + " index = setTimeout(function () {" + " exportStart();" + " },500);" + " }" + " };" + " exportStart();" newWindowDoc.body.appendChild(scriptText); } // 产品信息场景模板映射,定义了不同场景下需要展示的字段 var CPXX_FIELDS_MAP = { // 默认场景下的字段 规格/厂家/剂型/单位 default: ['ggmc', 'cdmc', 'jx', 'kcdw'], // 需要使用 dw 字段的场景 altDw: ['ggmc', 'cdmc', 'jx', 'dw'] }; /** * 获取指定场景下的非空产品信息 * @param res 包含产品信息的对象 @param {string|Array} type - 场景类型,用于决定使用哪些字段。可以是 'default'、'altDw' 等预定义场景名, * 也可以是自定义的字段数组。如果未提供该参数,默认使用 'default' 场景。 * @returns {*} 以 " / " 分隔的字段值字符串。如果某个字段为空或 null,则返回 '-' */ function getNotNullCommonCpxx(res, type) { if (!res) return '-'; var fields; if (Array.isArray(type)) { fields = type; } else { fields = CPXX_FIELDS_MAP[type || 'default']; } var sourceValues = fields.map(function(field) { if (field === 'cdmc') { var value = ""; if(res['ssxkcyr']){ value = res['ssxkcyr']; }else { value = res[field]; } return !value || value.trim() === '' ? '-' : value.trim(); } var value = res[field]; return !value || value.trim() === '' ? '-' : value.trim(); //判断 null 和 空字符串 }); return sourceValues.join(' / '); }