/******** foundation ********/ /* 1. 由main.html引用 */ /* 2. 其他界面不使用 */ /****************************/ RootSetting = { //测试环境 // url: "https://csec.jemincare.com/worder/", // url_fee: "https://csec.jemincare.com/", // url_jemin: "https://csec.jemincare.com/rootjemin/", // url_jeminrootact: "http://jemin.highdatas.com/act/", // jeminact/rootact/ // url_jeminact: "http://jemin.highdatas.com/", // jeminact/root/ // url_act: "https://csec.jemincare.com/act/", // url_stock: "https://csec.jemincare.com/japi/", // url_file: "https://csec.jemincare.com/source/", // url_act_pdf: "https://csec.jemincare.com/pdf/", // url_jsp_ip: "http://oaqas01.jemincare.com:88", // url_page_pdf: "https://csec.jemincare.com/", //url: "http://192.168.43.143:80/worder/", //正式环境 // url: "https://ec.jemincare.com/worder/", // url_act: "https://ec.jemincare.com/act/", // url_stock: "https://ec.jemincare.com/japi/", // url_file: "https://ec.jemincare.com/source/", // url_act_pdf: "https://ec.jemincare.com/pdf/", // url_jsp_ip: "http://oa.jemincare.com:88", // url_page_pdf: "https://ec.jemincare.com/", //开发环境 // url: "http://jemin.highdatas.com:80/worder/", // url_fee: "http://jemin.highdatas.com:80/", // url_jemin: "http://jemin.highdatas.com:80/rootjemin/", //url_jeminrootact: "http://jemin.highdatas.com/act/", // jeminact/rootact/ //url_jeminact: "http://127.0.0.1:80/worder/root/", // jeminact/root/ //本地环境 url: "http://127.0.0.1:80/worder/", url_fee: "http://127.0.0.1:80/", url_jemin: "http://127.0.0.1:80/rootjemin/", url_cal: "http://127.0.0.1:80/cal/", url_jeminact: "http://127.0.0.1:80/worder/root/", // jeminact/root/ url_page_pdf: "http://127.0.0.1:8848/jemin_rebate_h5/", // url: "http://127.0.0.1:89/worder/", // url_fee: "http://127.0.0.1:89/", // url_jemin: "http://127.0.0.1:89/rootjemin/", // url_jeminact: "http://127.0.0.1:89/worder/root/", // jeminact/root/ url_jeminrootact: "http://jemin.highdatas.com/act/", // jeminact/rootact/ // url: "http://9c7jrj.natappfree.cc/worder/", //url_act: "http://9c7jrj.natappfree.cc/", url_act: "http://jemin.highdatas.com/act/", // 开发 url_stock: "http://192.168.31.72:9001/", url_stock: "http://p7nskj.natappfree.cc/", url_japi: "https://ec.jemincare.com/test/japi/", /* url: "http://10.67.3.225/worder/", */ /* url_act: "http://10.67.3.225:8090/", url_stock: "http://10.67.3.225:9001/", */ //url_file: "https://ec.jemincare.com/source/",//pdf附件预览 //url_act_pdf: "https://ec.jemincare.com/pdf/",//act XML文件下载 //url: "http://172.21.12.187:80/worder/", /* url_act: "http://10.67.3.221:8090/", url_stock: "http://10.67.3.221:9001/", */ appName: "distributor", isClientMode: true, isDebug: true, }; baseUrl = RootSetting.url; stockUrl = RootSetting.url_stock; $.fn.toggle = function( fn, fn2 ) { var args = arguments,guid = fn.guid || $.guid++,i=0, toggle = function( event ) { var lastToggle = ( $._data( this, "lastToggle" + fn.guid ) || 0 ) % i; $._data( this, "lastToggle" + fn.guid, lastToggle + 1 ); event.preventDefault(); return args[ lastToggle ].apply( this, arguments ) || false; }; toggle.guid = guid; while ( i < args.length ) { args[ i++ ].guid = guid; } return this.click( toggle ); }; /*********** object *************/ Object.init = function(config) { if (prototyping) { return; } this.config = config; if (config) { var name = null, value; for (name in config) { value = config[name]; if ($.isFunction(value)) { this[name] = value; } } } }; Object.subClass = function(properties) { if (!properties) { return; } var clazz = properties.init; delete properties.init; if (!clazz) { clazz = new Function(); } prototyping = true; try { var prototype = new this(); } finally { prototyping = false; } $.extend(prototype, properties); clazz.prototype = prototype; clazz.subClass = arguments.callee; return clazz; }; /********* control *************/ Control = Object.subClass({ init: function(config) { if (prototyping) { return; } //0. default settings this.style = config.style = config.style || "A"; this.visible = config.visible; this.sequence = 0; //1. call object create Object.init.call(this, config); //2. create container this.visible = (this.visible === undefined) || this.visible; //3. try create content if (this.create) { this.create(config); return; } //4. create container this.container = this.createContainer(this.visible); //5. append to parent if (config.element == "body") { this.parent = $("body"); } else { this.parent = config.element ? util.getEl(config.element) : $("body"); } this.parent.append(this.container); //6. create items if (this.createContent) { if (this.beforeCreateContent) { this.beforeCreateContent(config); } this.createContent(config); } else if (this.items) { this.createItems(this, this.container, config.items, 1); } }, createContainer: function(visible) { var config = this.config; var template = this.getContainerTemplate(config); var el = $(template); if (config.css) { this.addClass(el, config.css.container); } var container = $("#body", el); if (!container.length) { container = el; } if (this.onCreateContainer) { this.onCreateContainer(container, config); } if (!visible) { container.hide(); } return container; }, getContainerTemplate: function(config) { return config.element; }, setText: function(el, text, css) { if (!el || !el.length) { return; } el.html(text); this.addClass(el, css); }, setTitle: function(el, title) { if (!el || !el.length) { return; } el.attr("title", title); }, setImage: function(el, imageURL, imageCss) { if (!el || !el.length) { return; } if (imageURL) { var element = el.get(0); var node = element.nodeName; if (node == "IMG") { el.attr("src", imageURL); } else { el.css({ "background-image": "url(" + imageURL + ")" }); } return; } this.addClass(el, imageCss); }, setIcon: function(el, iconClass, iconCss) { if (!el || !el.length) { return; } this.addClass(el, iconClass); this.addClass(el, iconCss); }, setBadge: function(el, num, badgeCss) { if (!el || !el.length) { return; } if (isNaN(num + "")) { } else { el.html(num); } el[0].style.display = "inline"; }, addClass: function(el, css) { if (css) { el.addClass(css); } }, removeClass: function(el, css) { if (css) { el.removeClass(css); } }, setVisible: function(visible) { if (visible) { this.container.show(); } else { this.container.hide(); } }, replaceParameter: function(obj) { for (var name in obj) { var value = obj[name]; if (typeof value == "string") { obj[name] = value.replace("@{style}", this.style); } } }, getTemplate: function(ctrlName, segmentName) { var name = ctrlName + "_Template" + this.config.style; var template = window[name]; if (!segmentName) { return template.join(""); } return template[segmentName].join(""); }, createSequenceValue: function(ctrlName) { this.sequence = this.sequence + 1; return ctrlName + this.sequence; }, averageTo: function(total, size) { if (size <= 0) { return null; } var result = new Array(size); var max = size - 1; var value = Math.floor(total / size); var sum = 0; for (var i = 0; i < max; i++) { result[i] = value; sum = sum + value; } result[max] = total - sum; return result; } }); Control.subClass = function(properties) { if (!properties.items) { return Object.subClass.call(this, properties); } if (!properties.createItem) { properties.createItem = function(container, option, level) {}; } if (!properties.attachItem) { properties.attachItem = function(container, item) { container.append(item); }; } if (!properties.doAddItem) { properties.doAddItem = function(parentObject, container, option, level) { var item = this.createItem(container, option, level); item.option = option; this.attachItem(container, item); parentObject.items.push(item); return item; }; } if (!properties.deleteItem) { properties.deleteItem = function(item) { item.header.remove(); item.body.remove(); }; } if (!properties.createItems) { properties.createItems = function(parentObject, container, itemOptions, level, item0_) { parentObject.items = []; if (!itemOptions) { return; } if (this.beforeCreateItems) { this.beforeCreateItems(this.config); } for (var i = 0; i < itemOptions.length; i++) { var option = itemOptions[i]; var item_ = this.doAddItem(parentObject, container, option, level); if (!item0_) { item0_ = item_; } }; return item0_; }; } properties.getItemBy = function(name, value) { for (var i = 0; i < this.items.length; i++) { var item = this.items[i]; if (item[name] == value) { return item; } } return null; }; return Object.subClass.call(this, properties); }; /********* RootParent *************/ RootBodyClass = Object.subClass({ init: function() { this.controls = []; this.win = $(window); this.document = $(document); this._width = this.win.width(); this._height = this.win.height(); }, width: function() { return this._width; }, height: function() { return this._height; }, append: function(element) { if (!this.body) { this.body = $('body'); var me = this; this.document.click(function() { me.notifyAll(); }); } this.body.append(element); }, register: function(control) { this.controls.push(control); }, notifyAll: function() { for (var i = 0; i < this.controls.length; i++) { this.notifyOne(this.controls[i]); } }, notifyOne: function(control) { if (control && control.onNotify) { control.onNotify.call(control, "rootClick"); } } }); RootBody = new RootBodyClass(); /********* Server *************/ var ServerClass = Object.subClass({ dataNames: ["line", "dataset", "entityset", "rows", "tree", "user"], excludeNames: { "success": true, "error": true }, sysParams: { timeoutPage: "root/page/system/index.html" }, ajaxRequest: function(url, param, callback, onFail, onSuccess, onError) { var me = this; var clientMode = RootSetting.isClientMode; if (!url) { return; } //1. handle url var to = url.lastIndexOf("root/"); if (to) { var from = -1, temp = url.length; while (temp >= 0) { temp = url.lastIndexOf("root/", temp - 1); if (temp >= 0) { from = temp; } } if (from >= 0) { url = url.substring(0, from) + url.substring(to); } } //2. handle param let contentType_ = "text/plain"; let type_ = "post"; let datatype_ = "json"; if (param.ajaxtype) { type_ = clone(param.ajaxtype); param.ajaxtype = null; } if (param) { if ($.isFunction(param)) { callback = param; param = null; } else { if (RootSetting.isClientMode && (param && param.isClientMode != null && !param.isClientMode)) { //默认本地的请求但是请求中不是本地的,需要访问服务器 clientMode = false; } else if (!RootSetting.isClientMode && param.isClientMode) { //默认服务器的请求但是请求中是本地的,需要本地 clientMode = true; } /* if (typeof param == "object") { param = util.objectToURI(param); } */ /* if (url.indexOf("?") > 0) { url = url + "&" + param; } else { url = url + "?" + param; } */ } var param_temp = clone(param); var do_param = {}; for (var k in param_temp) { if (k == "contains") {} else if (k == "remove") {} else if (k != "isClientMode" && param_temp[k] != null) { do_param[k] = param_temp[k]; } } param = do_param; } //var clientMode = (RootSetting.isClientMode && (!param || (param && param.isClientMode)));// RootSetting.isClientMode || (!RootSetting.isClientMode && (!param || (param && param.isClientMode))); //(RootSetting.isClientMode && (!param || (param && param.isClientMode))) //"application/json;charset=utf-8"; //"application/x-www-form-urlencoded; charset=utf-8"; var token = ""; if (Root) { token = Root.getToken(); if(!token) {token = ""}; // if(localStorage.getItem("hdtoken") != token) { // window.top.location.href = config.page_timeout; // return // } if (!param.token) { param.token = token; } // if (param_.type && param_.type == "get") { // if (url.indexOf("?") > 0) { // url = url + "&" + "token=" + token; // } // else { // url = url + "?" + "token=" + token; // } // } } let param_ = util.encode(param); if (type_ == "get") { if (param.isnull) { param_ = null } if (url.indexOf("?") != -1 ) { for (p in param) { url += "&" + p + "=" + encodeURI(param[p]); } } else { var url_ = ""; for (p in param) { if (!url_) { url_ = p + "=" + encodeURI(param[p]); } else { url_ += "&" + p + "=" + encodeURI(param[p]); } } url += "?" + url_; } } let headers_ = {}; let headersObj = {}; /* if (url != "root/client/login") { if (window.top.userinfo.user.id) { headersObj = { "userId": window.top.userinfo.user.id } } else { util.pageTo("../../login.html"); } } */ /* if (clientMode) { var result = loadClientData(url); onSuccess(callback, result); return; } else */ if (url.substring(0, 5) == "root/") { if (RootSetting.url.indexOf("https://ec.jemincare.com") != -1) { url = RootSetting.url + "root/" + url.substring(5); } else { url = RootSetting.url + "root/" + url.substring(5); //url = RootSetting.url + url.substring(5); } } else if (url.substring(0, 10) == "rootoaact/") { contentType_ = "application/json;charset=utf-8"; datatype_ = "json"; url = RootSetting.url_act + url.substring(10); } else if (url.substring(0, 8) == "rootact/") { /* if (param.ajaxtype) { type_ = param.ajaxtype; } else { type_ = "POST"; } */ //param_ = {}; contentType_ = "application/json;charset=utf-8"; datatype_ = "json"; url = RootSetting.url_act + url.substring(8); //url = RootSetting.url + "rootact/" + url.substring(8); headers_ = { "userId": window.top.userinfo.user.id, } } else if (url.substring(0, 17) == "jeminact/rootact/") { contentType_ = "application/json;charset=utf-8"; datatype_ = "json"; url = RootSetting.url_jeminrootact + url.substring(17); headers_ = { "userId": window.top.userinfo.user.id, } } else if (url.substring(0, 14) == "jeminact/root/") { // contentType_ = "application/json;charset=utf-8"; // datatype_ = "json"; url = RootSetting.url_jeminact + url.substring(14); } else if (url.substring(0, 4) == "mdm/") { type_ = "get"; param_ = {}; url = RootSetting.url_stock + "mdm/" + url.substring(4); } else if (url.substring(0, 6) == "stock/") { type_ = "get"; param_ = {}; url = RootSetting.url_stock + url.substring(6); } else if (url.substring(0, 11) == "stock_post/") { contentType_ = "application/json;charset=utf-8"; datatype_ = "json"; url = RootSetting.url_stock + url.substring(11); } else if (url.substring(0, 10) == "rootjemin/") { contentType_ = "application/json;charset=utf-8"; datatype_ = "json"; url = RootSetting.url_jemin + url.substring(10); } else if (url.substring(0, 4) == "cal/") { contentType_ = "application/json;charset=utf-8"; datatype_ = "json"; url = RootSetting.url_cal + url.substring(4); } else if (url.substring(0, 5) == "japi/") { contentType_ = "application/json;charset=utf-8"; url = RootSetting.url_japi + url.substring(5); } else if (url.substring(0, 4) != "http") { url = RootSetting.url_fee + url; } var hl_url = [ "root/client/login", "OA/token/", "api/loginByEmployeeCode", "client/getUser", "test/delOANode" ]; var hl_bo_ = false; hl_url.map(u=>{ if (url.indexOf(u) != -1) { hl_bo_ = true; } }); //if (url.indexOf("root/client/login") != -1 || url.indexOf("OA/token/") != -1) { if(hl_bo_){ } else { if(localStorage.getItem("id") && window.top.userinfo.user.id && window.top.userinfo.user.id != "0" && localStorage.getItem("id") != window.top.userinfo.user.id) { console.log("登陆信息1:", localStorage.getItem("id")); console.log("登陆信息2:", window.top.userinfo.user); util.pageTo("../../../login.html"); return; } console.log(url); if (url.indexOf("?") != -1) { if (window.top.userinfo.user.id) { url += "&userId=" + window.top.userinfo.user.id } else { util.pageTo("../../../login.html"); } } else { if (url.substring(url.length - 1, url.length) == "/") { url = url.substring(0, url.length - 1); } if (window.top.userinfo.user.id) { url += "?userId=" + window.top.userinfo.user.id } else { util.pageTo("../../../login.html"); } } } /* if (url.indexOf("saveCustomer") != -1) { return } */ //3. request try { //alert("请求:" + url); //alert("参数:" + (param_)); $.ajax(url, { contentType: contentType_, /* beforeSend: function(request) { for (var item in headersObj) { request.setRequestHeader(item, headersObj[item]); } }, */ timeout: 5*60*1000, //超时时间设置,单位毫秒 dataType: datatype_, type: type_, headers: headers_, data: param_, success: function(result) { if (result) { if ("timeout" == result.errorcode) { window.top.location.href = me.sysParams.timeoutPage; } else if (!result.success) { console.log(result); if (onFail) { onError(onFail, result); } else if(!result.success && result.message && Root) { Root.message({ type: 'error', message: result.message }); } else { var error = result.errorcode + ": " + util.decode(result.errormessage); try { if (console.log) { console.log(error); } } catch (e) {} alert(error); } } else if (result.success){ onSuccess(callback, result); } } }, error: function(d1, error, message) { //alert(error); if (error == "parsererror" && d1.responseText) { var result_ = clone(d1.responseText); result_ = result_.replace(/[\t\r\n]/g,""); result_ = result_.replace(/\\/g, "*") if (me.isJson(result_)) { result_ = new Function('return ' + result_)() } else { onSuccess(callback, result_); return } //JSON.parse(result_); if (result_.success) { onSuccess(callback, result_); return } } if (onFail) { onError(onFail, d1.responseText); } else { alert(error); } try { if (console.log) { console.log(error); } } catch (e) {} } }); } catch (e) { } }, isJson: function(str) { if (typeof str == 'string') { try { var obj = JSON.parse(str); // 等于这个条件说明就是JSON字符串 会返回true if (typeof obj == 'object' && obj) { return true; } else { //不是就返回false return false; } } catch (e) { return false; } } return false; }, getResultData: function(result) { if (!result) return; // 1. for (var i = 0; i < this.dataNames.length; i++) { var name = this.dataNames[i]; if (result[name]) { var data = result[name]; var page = result['page']; return [util.decode(data), util.decode(page), "byPage"]; } } // 2. var names = []; for (var prop in result) { if (!this.excludeNames[prop]) { names.push(prop); } } if (names.length == 1) { var data = result[names[0]]; return util.decode(data); } }, getData: function(url, param, callback, onFail) { if (!url) { return; } var me = this; if ($.isFunction(param)) { callback = param; param = null; } param = $util.objectToURI(param); var afterRequest = function(doCallback, result) { if (doCallback) { var data = me.getResultData(result) || result; if ($.isArray(data) && data[2] == "byPage") { doCallback(data[0], data[1]); return; } doCallback(data); } }; me.ajaxRequest(url, param, callback, onFail, afterRequest, afterRequest); }, call: function(url, param, callback, onFail) { if (!url) { return; } var me = this; var afterRequest = function(doCallback, result) { if (doCallback) { try { result = util.decode(result); } finally { doCallback(result); } } }; me.ajaxRequest(url, param, callback, onFail, afterRequest, afterRequest); }, upload: function(url, file, onProgress, onSuccess, onError) { var formdata = new FormData(); formdata.append("fileList", file); try { $.ajax({ cache: true, type: "POST", url: serverAddress + url, data: formdata, dataType: "json", processData: false, contentType: false, xhr: function() { var xhr = $.ajaxSettings.xhr(); if (onProgress && xhr.upload) { xhr.upload.addEventListener("progress", onProgress, false); return xhr; } }, error: function(request) { if (onError) { onError(); } }, success: function(data) { data = util.decode(data); if (onSuccess) { onSuccess(data); } } }); } catch (e) { if (onError) { onError(); } } }, }); Server = new ServerClass(); loadClientData = function(url) { var result = DataCache[url]; if (!result) { result = { success: true, data: null } var name, prop; for (name in DataMap) { if (url.indexOf(name) >= 0) { prop = DataMap[name]; result.data = prop; break; } } } return result; }; DataMap = {}; DataCache = {}; function initDataMap() { var name, prop, subname, subprob; for (name in dataRoot) { prop = dataRoot[name]; if (!prop) { continue; } for (subname in prop) { subprob = prop[subname]; DataMap[subname] = subprob; } } }; initDataMap(); function toClientURL(url) { if (!url) { return; } var pos = url.indexOf("root/"); if (pos >= 0) { url = "../../" + url.substr(pos + 5); } return url; } /********* root *************/ var RootClass = Object.subClass({ popupParames: {}, popupList: [], userInfo: {}, user: {}, role: {}, tab: null, message: null, confirm11: null, init: function(config) { Object.call(this, {}); this.tab = config.tab; this.userInfo = config.userInfo; this.loadStorage(); }, setUserInfo: function(userInfo) { this.userInfo = userInfo; }, loadStorage: function() { this.role = { id: localStorage.getItem("roleid").split(";"), code: localStorage.getItem("rolecode").split(";"), name: localStorage.getItem("rolename").split(";") } }, showSubTab: function(config) { this.tab.showSubItem(config); }, hideSubTab: function(config) { this.tab.hideSubItem(config); }, showPopup: function(config) { var newdate_ = new Date(); var newdate_day_ = newdate_.getMonth() + newdate_.getDay(); if (config.url.indexOf("?") != -1 ) { config.url += "&v=" + newdate_; } else { config.url += "?v=" + newdate_; } config.url = util.buildURL(config.url); this.popupParames = config; var popup = new PopupWindowClass(config); this.popupList.push(popup); popup.show(); }, setPopupWH: function(w, h) { if (!this.popupList.length) { return; } var popup = this.popupList[this.popupList.length - 1]; popup.setSize(w, h); }, hidePopup: function() { if (!this.popupList.length) { return; } var popup = this.popupList.pop(); popup.hide(); }, init_vue: function() { this.confirm = vue.$confirm; this.message = vue.$message; }, getToken: function() { return this.userInfo.token; } }); Root = null; //////////////////////////////FormatCenterClass/////////////// FormatCenterClass = Object.subClass({ init: function() { }, format: function(value, formatterCode) { var formatter = this.itemMap[formatterCode]; if (!formatter) { return value; } var result = formatter(null, null, value); return result; }, load: function() { var itemMap = this.itemMap = {}; itemMap.json = formatter_json; itemMap.date = dateFormat; itemMap.money = formatter_money; itemMap.TF1 = formatter_TF1; itemMap.TF2 = formatter_TF2; itemMap.TF3 = formatter_TF3; itemMap.target = formatter_Target; itemMap.commitState = formatter_CommitState; itemMap.grade = formatter_Grade; itemMap.orderState = formatter_OrderState; itemMap.date = formatter_date; itemMap.isreconciliation = formatter_isreconciliation; itemMap.businessline = formatter_businessline; itemMap.matchstatus = formatter_matchstatus; itemMap.OTCorCF = formatter_OTCorCF; itemMap.saletype = formatter_saletype; itemMap.salesBusinessType = formatter_salesBusinessType; itemMap.pass = formatter_pass; itemMap.deliverySended = formatter_deliverySended; itemMap.deliveryStatus = formatter_deliveryStatus; itemMap.invoiceStatus = formatter_invoiceStatus; itemMap.returnType = formatter_returnType; itemMap.businessType = formatter_businessType; itemMap.agreeStatus = formatter_agreeStatus; itemMap.businessStatus = formatter_businessStatus; itemMap.formatter_demandProductState = formatter_demandProductState; itemMap.sourceType = formatter_sourceType; itemMap.invoiceType = formatter_invoiceType; itemMap.licenceType = formatter_licenceType; itemMap.formatter_produceType = formatter_produceType; itemMap.formatter_needType = formatter_needType; itemMap.TagPriceType = formatter_TagPriceType; itemMap.CashType = formatter_CashType; itemMap.RebateType = formatter_RebateType; itemMap.ControlType = formatter_ControlType; itemMap.transType = formatter_transType; itemMap.Receipt = formatter_Receipt; itemMap.formatter_percentage = formatter_percentage; itemMap.settleType = formatter_settleType; itemMap.rate = formatter_rate; itemMap.produceType = formatter_productStatus; itemMap.checkoutStatus = formatter_checkoutStatus; itemMap.orderSource = formatter_orderSource; itemMap.actStatus = formatter_actStatus; itemMap.approvaluser = formatter_approvaluser; itemMap.a1deliveryamt = formatter_a1deliveryamt; itemMap.return_money = formatter_return_money; itemMap.Type=formatter_Type; itemMap.Sync = formatter_Sync; itemMap.formatter_terminalPosition = formatter_terminalPosition }, }); FormatCenter = new FormatCenterClass(); /* 旧版字典,但是仍需使用 */ DictionaryClass = Object.subClass({ init: function() { data: {} }, getLabel: function(value, dictCode) { var dict = this.data[dictCode]; if (!dict) { return value; } var result = dict.map[value]; if (!result) { return value; } return result.label; }, getList: function(dictCode) { var dict = this.data[dictCode]; if (!dict) { return []; } return dict.list; }, load: function(datalist) { if (!datalist) { return; } var data = {}; for (var prop in datalist) { var dict = datalist[prop]; var list = dict, map = {}; for (var i = 0; i < list.length; i++) { var item = list[i]; map[item.value] = item; } data[prop] = { "list": list, "map": map } } this.data = data; } }); Dictionary = new DictionaryClass(); // /* */ /* 新版字典 */ newDictionaryClass = Object.subClass({ init: function() { data: {} }, getLabel: function(value, dictCode) { var dict = this.data[dictCode]; if (!dict) { return value; } var result = dict.map[value]; if (!result) { return value; } return result.label; }, getList: function(dictCode) { var dict = this.data[dictCode]; if (!dict) { return []; } return dict.list; }, getMap: function(dictCode) { var dict = this.data[dictCode]; if (!dict) { return {}; } return dict.map; }, load: function(datalist) { if (!(datalist && datalist.length > 0)) { return; } var dataobj_ = {}; var dictionary_list = [ {code: "sysdictionary", value: "字典组名"} ]; var dictionary_map = {code: "sysdictionary", value: "字典组名"}; datalist.map(e=>{ if (e.code == "truefalse") { e.items.map(ed=>{ if (ed.code == "true") { ed.code = true } else if (ed.code == "false") { ed.code = false } }) } var dictionary_ = { code: e.code, value: e.name } dictionary_list.push(dictionary_); dictionary_map[e.code] = dictionary_; if (e.items.length) { dataobj_[e.code] = e.items; } }); var data = {}; data.sysdictionary = { "list": dictionary_list, "map": dictionary_map } for (var prop in dataobj_) { var dict = dataobj_[prop]; var list = dict, map = {}; for (var i = 0; i < list.length; i++) { var item = list[i]; map[item.code] = item.value; } data[prop] = { "list": list, "map": map } } this.data = data; } }); newDictionary = new newDictionaryClass(); ///* */ var PopupWindowClass = Object.subClass({ width: 600, height: 450, template: [ '' ], init: function(config) { config = config ? config : {}; Object.call(this, {}); this.createElement(config); }, createElement: function(config) { // 1. create var el = this.el = $(this.template.join("")); el.popup_drag = $(".popup-drag", el); el.popup_title = $(".popup-title", el); el.popup_body = $(".popup-body", el); el.icon = $("#win_icon", el); el.title = $("#win_title", el); el.btnClose = $("#win_btn_close", el); el.btnClosepopup = $("#win_btn_closepopup", el); el.container = $("#win_container", el); el.body = $("#win_body", el); //拖拽设置 var dv = el.popup_drag[0]; var x = 0; var y = 0; var l = 0; var t = 0; var isDown = false; //鼠标按下事件 dv.onmousedown = function(e) { //获取x坐标和y坐标 x = e.clientX; y = e.clientY; //开关打开 isDown = true; //设置样式 dv.style.cursor = 'move'; if (dv.parentElement.style.left && dv.parentElement.style.left != "") { l = dv.parentElement.style.left.replace(/px/g,"") * 1; } if (dv.parentElement.style.top && dv.parentElement.style.top != "") { t = dv.parentElement.style.top.replace(/px/g,"") * 1; } } //鼠标悬浮出事件 /* dv.onmouseover = function() { //开关关闭 isDown = false; dv.style.cursor = 'default'; } */ //鼠标抬起事件 dv.onmouseup = function() { //开关关闭 isDown = false; dv.style.cursor = 'default'; } //鼠标移动 window.onmousemove = function(e) { if (isDown == false) { return; } /* if (e.toElement.style.cursor != 'move') { isDown = false; return; } */ //获取x和y var nx = e.clientX; var ny = e.clientY; //获取左部和顶部的偏移量 /* l = dv.parentElement.offsetLeft; t = dv.parentElement.offsetTop; */ //计算移动后的左偏移量和顶部的偏移量 /* var nl = nx - (x - l); var nt = ny - (y - t); */ var nl = l + (nx - x); var nt = t + (ny - y); if (nt < 0) { nt = 0 } dv.parentElement.style.left = nl + 'px'; dv.parentElement.style.top = nt + 'px'; } //2. title if (!config.title) { el.popup_title.hide(); el.popup_body.css("top", "0px"); } else { if (config.icon) { el.icon.addClass(config.icon); } if (config.title) { el.title.html(config.title); } } el.btnClose.click(function() { Root.hidePopup(); }); el.btnClosepopup.click(function() { Root.hidePopup(); }); /* if (config.hide_close) { el.btnClose.hide(); } */ el.btnClose.hide(); if (config.show_close) { el.btnClose.show(); } // 2. width and height this.width = config.width || this.width; this.height = config.height || this.height; el.container.css({ "width": this.width, "height": this.height, //"left": "20%" }); //3. z-index and src // el.css("z-index", Root.popup.zindex + Root.popup.zno); el.body.attr("src", config.url); }, show: function(config) { RootBody.append(this.el); this.el.animate({ "margin-left": "0px" }); }, hide: function() { this.el.hide(); this.el.remove(); }, setSize: function(w, h) { let w_ = w.substring(0, w.length - 2); this.el.container.css({ "width": w, "height": h, //"max-height": "90vh" }); } }); /********* Object rebuild *************/ Array.getString = function(array, propName, spliter, defaultValue) { var result = null; if (!array || !array.length) { return defaultValue; } for (var i = 0; i < array.length; i++) { var line = array[i]; result = result ? result + spliter + line[propName] : line[propName]; } return result; }; /********* util *************/ util = {}; util.debug = function(message) { if (RootSetting.isDebug) { console.log(message); } }; util.buildURL = function(url) { if (!url) { return null; } if (url.startsWith("http")) { return url; } if (url.startsWith("/")) { return "/" + RootSetting.appName + url; } return url; }; util.decode = function(obj) { if (!obj) { return null; } if ($.isArray(obj)) { return this.decodeArray(obj); } else if (typeof obj == "object") { return this.decodeObject(obj); } else if (typeof obj == "string") { try { return decodeURIComponent(obj); } catch (e) { return obj; } } else { return obj; } }; util.decodeArray = function(data) { for (var i = 0; i < data.length; i++) { if (typeof data[i] == 'string') { data[i] = this.decode(data[i]); } else { data[i] = this.decodeObject(data[i]); } } return data; }; util.decodeObject = function(data) { for (var prop in data) { if (data[prop]) { data[prop] = this.decode(data[prop]); } } return data; }; util.encode = function(obj) { if ($.isArray(obj)) { return this.encodeArray(obj); } else if (typeof obj == "object") { return this.encodeObject(obj); } else if (typeof obj == "string") { return "\"" + encodeURI(obj) + "\""; } else if (typeof obj == "boolean") { return String(obj); } else if (typeof obj == "number") { return String(obj); } else if (typeof obj === "function") { return ""; } }; util.encodeArray = function(o) { var a = ["[", ""], len = o.length, i; for (i = 0; i < len; i += 1) { a.push(this.encode(o[i]), ','); } a[a.length - 1] = ']'; return a.join(""); }; util.encodeObject = function(o) { if (!o) { return "null"; } if (o.length) { return "el"; } var a = ["{", ""]; for (var i in o) { if (i == 'parent') { continue; } a.push(this.encode(i), ":", this.encode(o[i]), ','); } a[a.length - 1] = '}'; return a.join(""); }; util.objectToURI = function(object) { if (!object) { return null; } if (typeof object == "String") { return encodeURI(object); } var param = null; for (var prop in object) { if (object[prop] != null) { if (param) { param = param + "&" + prop + "=" + encodeURI(object[prop]); } else { param = prop + "=" + encodeURI(object[prop]); } } } return param; }; util.combine = function(obj1, obj2, override) { if (!obj1) { return obj2; } if (!obj2) { return obj1; } for (var name in obj2) { if (override || obj1[name] === undefined) { obj1[name] = obj2[name]; } } return obj1; }; util.combineObj = function combineObj(target, source, override) { if (!target) { return source; } if (!source) { return target; } for (var name in source) { //如果1没有该属性 if (override) { target[name] = source[name]; }else if(target[name] === undefined){ target[name] = source[name]; } //如果1存在该属性 if (typeof(target[name]) == "object") { combineObj(target[name], source[name], override); } } return target; }; util.setVisible = function(el, visible) { if (visible) { el.show(); } else { el.hide(); } }; util.getEl = function(element) { var type = typeof element; if (type == "string") { if ("#" != element.substring(0, 1)) { element = "#" + element; } var el = $(element); return el; } return element; }; function copyBy(obj1, obj2) { if(!obj2) { return obj1; } for(let field in obj2) { if(!obj1[field]) { obj1[field] = clone(obj2[field]); } } return obj1; } util.pageTo = function(frame, url) { if (!url) { url = frame; frame = null; } if (!url) { return; } //1. root var exists = url && url.lastIndexOf("root/"); if (exists >= 0) { var current = window.top.location.pathname; var pos = current.indexOf("root/"); if (pos >= 0) { url = current.substring(0, pos) + url; } } //2. random if (url.indexOf("?") > 0) { url = url + "&" + new Date().getTime(); } else { url = url + "?" + new Date().getTime(); } //3. set if (frame) { frame.attr("src", url); } else { window.top.location.href = url; } }; function setIframeHeight(iframe) { if (iframe) { var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow; if (iframeWin.document.body) { iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight; } } }; ///////////////////formatter////////////////// function dateFormat(date, fmt) { if (typeof date == 'string') { date = new Date(date); } if (null == date || undefined == date) return ''; var o = { "M+": date.getMonth() + 1, //月份 "d+": date.getDate(), //日 "h+": date.getHours(), //小时 "m+": date.getMinutes(), //分 "s+": date.getSeconds(), //秒 "S": date.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.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 formatter_date(row, column, cellValue, index) { // if (cellValue) { // if(cellValue.length == 8) { // cellValue = cellValue.substring(0,4) + "/" + cellValue.substring(4,6) + "/" + cellValue.substring(6) // } // return dateFormat(cellValue, "yyyy-MM-dd"); // } // return cellValue; // }; function formatter_money(row, column, cellValue, index) { if (cellValue) { return toMoney(cellValue); } return 0; }; function formatter_Showpolicy(row, column, cellValue, index) { if (cellValue) { return "有"; } return "无"; }; function toMoney(num) { if (num) { if (isNaN(num)) { alert('金额中含有不能识别的字符'); return; } num = typeof num == 'string' ? parseFloat(num) : num // 判断是否是字符串如果是字符串转成数字 num = num.toFixed(4); // 保留两位 num = parseFloat(num); // 转成数字 var length_ = 2; if (num && num.toString().split('.')[1]) { length_ = num.toString().split('.')[1].length; } num = num.toLocaleString('en-US', { minimumFractionDigits: length_ }); // 转成金额显示模式 // 判断是否有小数 if (num.indexOf('.') === -1) { num = '¥' + num + '.00'; } else { // console.log(num.split('.')[1].length) num = num.split('.')[1].length < 2 ? '¥' + num + '0' : '¥' + num; } return num; // 返回的是字符串23,245.12保留2位小数 } else { return num = null; } }; // function formatter_json(row, column, cellValue, index, json_) { // var json = json_; // var val = ""; // if (typeof(json_)=="string") { // json = JSON.parse(json_); // } // if (json[cellValue]) { // return json[cellValue]; // } // else { // return cellValue // } // }; function formatter_TF1(row, column, cellValue, index) { if (cellValue == true || cellValue == "T") { return "√" } else if (cellValue == false || cellValue == "F") { return "×" } return null }; function formatter_TF2(row, column, cellValue, index) { if (cellValue == true || cellValue == "T") { return "已签章" } else if (cellValue == false || cellValue == "F") { return "" } return null }; function formatter_TF3(row, column, cellValue, index) { if (cellValue == true || cellValue == "T") { return "通过" } else if (cellValue != null && (cellValue == false || cellValue == "F")) { return "不通过" } return null }; function formatter_Target(row, column, cellValue, index) { if (cellValue == "Target") { return "目标客户"; } else if (cellValue == "NotTarget") { return "非目标客户"; } else return ""; }; function formatter_CommitState(row, column, cellValue, index) { if (cellValue == "open") { return "审批完成"; } else if (cellValue == "working") { return "审批中"; } else return "草稿"; }; function formatter_OrderState(row, column, cellValue, index) { if (row.recall == 1) { return "已撤回"; } else if (cellValue == "working") { /* if(row.node_name) { return row.node_name }else */ return "审批中"; } else if (cellValue == "exist_open") { return "部分完成"; } else if (cellValue == "close" && row.recall && row.delivery_status || (cellValue == "open" && row.withdraw && row.revocation_delivery_status == '部分退货')) { return "已关闭"; } else if (cellValue == "close" && row.recall && !row.delivery_status ) { return "已撤回"; } else if (cellValue == "open" && row.withdraw && (row.revocation_delivery_status == '未退货' || row.revocation_delivery_status == '全部退货')) { return "已撤回"; } else if (cellValue == "close") { return "作废"; } else if (cellValue == "refuse" || cellValue == "exist_open_all") { return "待修改"; } else if (cellValue == "input" ){ return "待提交"; } else if (cellValue == "open" && row.end_status && (row.end_status == "working" || row.end_status == "refuse") && row.b_trans_type && row.b_trans_type == "end"){ return "终止中"; } else if (cellValue == "open" && row.end_status && (row.end_status == "working" || row.end_status == "refuse") && row.b_trans_type && row.b_trans_type == "trans"){ return "变更中"; }else if (cellValue == "open") { return "审批完成"; } else { return "待提交"; } // else return "草稿"; }; function formatter_Grade(row, column, cellValue, index) { if (cellValue == "One") { return "一级商业"; } else if (cellValue == "Two") { return "二级商业"; } else if (cellValue == "Three") { return "未知"; } else return ""; }; function formatter_isreconciliation(row, column, cellValue, index) { if (cellValue == "T") { return "已对账"; } else if (cellValue == "F") { return "未对账"; } else return ""; }; function formatter_businessline(row, column, cellValue, index) { if (cellValue == "zsx") { return "招商线"; } else if (cellValue == "zyx") { return "自营线"; } else if (cellValue == "djk") { return "大健康"; } else if (cellValue == "xls") { return "新零售"; }else if (cellValue == "sdfx") { return "深度分销"; } else return ""; }; function formatter_matchstatus(row, column, cellValue, index) { if (cellValue == "1") { return "没有匹配协议"; } else if (cellValue == "2") { return "匹配多个协议"; } else return ""; }; function formatter_OTCorCF(row, column, cellValue, index) { if (cellValue == "CFY") { return "处方药"; } else if (cellValue == "OTC") { return "OTC"; } else return cellValue; }; function formatter_saletype(row, column, cellValue, index) { if (cellValue == "07") { return "正常销售"; } else if (cellValue == "08") { return "样品销售"; } else if (cellValue == "09") { return "其他销售"; } else return ""; }; function formatter_salesBusinessType(row, column, cellValue, index) { if (cellValue == "1") { return "分期收款"; } else if (cellValue == "2") { return "普通销售"; } else return ""; }; function formatter_pass(row, column, cellValue, index) { if (cellValue == "1") { return "同意"; } else if (cellValue == "0") { return "拒绝"; } else return ""; }; function formatter_deliverySended(row, column, cellValue, index) { if (cellValue) { return "已发货"; } else{ return "待发货"; } }; function formatter_deliveryStatus(row, column, cellValue, index) { if (row.status == "open" && (cellValue == "0" || cellValue == null)) { return "未发货"; } else if (cellValue == "0" || cellValue == null) { return "未发货"; } else if (cellValue == "1") { return "部分发货"; } else if (cellValue == "2") { return "全部发货"; } else if (cellValue == "3") { return "部分关闭"; } else if (cellValue == "4") { return "待发货"; } else return cellValue; }; function formatter_invoiceStatus(row, column, cellValue, index) { if (cellValue == "0" || cellValue == null) { return "未开票"; } else if (cellValue == "1") { return "部分开票"; } else if (cellValue == "2") { return "全部开票"; } else return cellValue; }; function formatter_returnType(row, column, cellValue, index, json) { if(row.sub_typereason && row.data_type == '1') { return row.sub_typereason } else if (json[cellValue]) { return json[cellValue] } else return cellValue; }; function formatter_businessType(row, column, cellValue, index) { if (cellValue == "1") { return "直管"; } else if (cellValue == "2") { return "非直管"; } else return cellValue; }; function formatter_agreeStatus(row, column, cellValue, index) { if (cellValue == "1" || cellValue === true || cellValue === "T") { return "是"; } else if (cellValue == "0" || cellValue === false || cellValue === "F" || !cellValue) { return "否"; } else return cellValue; }; function formatter_businessStatus(row, column, cellValue, index) { if (cellValue == "close") { return "已终止"; } else if (cellValue == "open") { return "有效"; } else if (cellValue) { return cellValue; } else { return "待生效"; } }; function formatter_gender(row, column, cellValue, index) { if (cellValue == "1") { return "男"; } else if (cellValue == "2") { return "女"; }else return cellValue; }; function formatter_demandProductState(row, column, cellValue, index) { if (cellValue == "open") { return "审批完成"; } else if (cellValue == "working") { return "审批中"; } else if (cellValue == "exist_open") { return "部分完成"; } else if (cellValue == "close" && row.recall) { return "退回"; } else if (cellValue == "close") { return "作废"; } else if (cellValue == "refuse" || cellValue == "exist_open_all") { return "待修改"; } else if (cellValue == "input" ){ return "录入"; } } function formatter_sourceType(row, column, cellValue, index) { if (cellValue == "1") { return "SAP"; } else if (cellValue == "2") { return "U8"; } else return cellValue; }; function formatter_invoiceType(row, column, cellValue, index) { if (cellValue == "RB01") { return "开票申请"; } else if (cellValue == "RB02") { return "销售折让"; }else if (cellValue == "RB03") { return "大健康票折"; } else return cellValue; }; function formatter_licenceType(row, column, cellValue, index) { //{\"consignee\": \"\",\"\": \"\",\"licence\": \"资质证照\"} if (cellValue == "consignee") { return "收货信息"; } else if (cellValue == "procure") { return "采购信息"; } else if (cellValue == "licence") { if (row.sub_type_code == "ZGL12") { return "质保协议"; } else { return "资质证照"; } } else return cellValue; }; function formatter_produceType(row, column, cellValue, index) { if (cellValue == "1") { return "正常"; } else if (cellValue == "2") { return "增补"; } else return cellValue; }; function formatter_needType(row, column, cellValue, index) { if (cellValue == "0") { return "按需生产"; } else if (cellValue == "1") { return "安全库存"; } else if (cellValue == "2") { return "周期额定批次"; } else return cellValue; }; function formatter_TagPriceType(row, column, cellValue, index) { if (cellValue == "1") { return "省标"; } else if (cellValue == "2") { return "军标"; } //else return cellValue; else if (cellValue == "3") { return "GPO"; } else if (cellValue == "4") { return "医保支付价"; } else if (cellValue == "5") { return "其他"; } else return cellValue; }; function formatter_CashType(row, column, cellValue, index) { if (cellValue == "1") { return "季度"; } else if (cellValue == "2") { return "年度"; } else if (cellValue == "3") { return "半年"; } else if (cellValue == "4") { return "月度"; } else return cellValue; }; function formatter_RebateType(row, column, cellValue, index) { if (cellValue == "1") { return "商返金额"; } else if (cellValue == "2") { return "其他"; } else return cellValue; }; function formatter_ControlType(row, column, cellValue, index) { if (cellValue == "1") { return "预付款"; } else if (cellValue == "2") { return "账期"; } else return cellValue; }; function formatter_transType(row, column, cellValue, index) { if (cellValue == "01") { return "汽运"; }else if (cellValue == "02") { return "火车"; }else if (cellValue == "03") { return "航空"; }else if (cellValue == "04") { return "快递"; }else if (cellValue == "05") { return "冷藏车"; }else if (cellValue == "06") { return "普通货车+保温箱"; }else if (cellValue == "07") { return "自提"; } else return cellValue; }; function formatter_Receipt(row, column, cellValue, index) { if (cellValue == "1") { return "已回挂"; } else if (cellValue == "0") { return "未回挂"; } else return cellValue; }; function formatter_percentage(row, column, cellValue, index) { if (cellValue != null) { return (cellValue * 100) + "%"; } else return cellValue; }; function formatter_rate(row, column, cellValue, index) { if (cellValue) { return toRate(cellValue); }else if(cellValue === null || cellValue === undefined || isNaN(cellValue)) return ""; return 0; }; function formatter_Type(row, column, cellValue, index) { if (row.is_offline == "1" || row.is_offline === true || row.is_offline === "T") { return "线下合同"; } else if (row.is_offline == "0" || row.is_offline === false || row.is_offline === "F" || !row.is_offline) { return "线上合同"; } }; function toRate(num) { if (num) { num = typeof num == 'string' ? parseFloat(num) : num // 判断是否是字符串如果是字符串转成数字 num = num.toFixed(2); // 保留两位 num = parseFloat(num); // 转成数字 num = num.toLocaleString(); // 转成金额显示模式 // 判断是否有小数 if (num.indexOf('.') === -1) { num = num + '.00' + ' %' ; } else { // console.log(num.split('.')[1].length) num = num.split('.')[1].length < 2 ? num + '0' +" %": num +" %"; } return num; // 返回的是字符串23,245.12保留2位小数 } else { return num = null; } }; function formatter_settleType(row, column, cellValue, index) { if (cellValue == "9") { return "Y"; } else if (cellValue == "10") { return "D"; } else if (cellValue == "11") { return "G"; } else if (cellValue == "15") { return "FL"; } else if (cellValue == "14" ) { return "ZY"; } else return cellValue; }; function formatter_productStatus(row, column, cellValue, index) { if (cellValue == "0") { return "冻结"; } else if (cellValue == "1") { return "正常"; } else return cellValue; }; function formatter_checkoutStatus(row, column, cellValue, index) { let checkout_total_amount_ = 0,total_amount_ = 0; if (row.checkout_total_amount) { checkout_total_amount_ = row.checkout_total_amount } if (row.total_amount) { total_amount_ = row.total_amount } if(total_amount_ - checkout_total_amount_ == 0) { return '全部收货' }else if(total_amount_ - checkout_total_amount_ > 0 && total_amount_ - checkout_total_amount_ != total_amount_) { return '部分收货' }else { return '未收货' } }; function formatter_orderSource(row, column, cellValue, index) { if (row.revocation_id) { return "正负订单" }else { return "新增" } }; function formatter_agreementStatus(row, column, cellValue, index) { if(row.status == 'close' ) { return "已作废" } else if (cellValue == 'freeze') { return "已冻结" }else if (cellValue == 'termination') { return "已终止" }else if (cellValue == 'active' && row.status == 'open') { return "已生效" }else if (cellValue == 'end') { return "已过期" }else { return "未生效" } }; function formatter_actStatus(row, column, cellValue, index) { if(row.status == 'open' ) { return "已完成" } else if (cellValue == "商业盖章") { return "合同盖章" } else if (cellValue == "特殊审批") { return "特殊审批" } else return cellValue }; function formatter_approvaluser(row, column, cellValue, index) { if(row.pre_proxy_name) { return row.pre_proxy_name + "→" + row.user_name; } else if(cellValue) { return cellValue } else if(!row.node_name && !row.user_name) { return "完成" } else return "查询" }; function formatter_a1deliveryamt(row, column, cellValue, index) { var a1deliveryamt = 0; if(row.a1_trans_price && row.qty_needreturn) { a1deliveryamt = (row.a1_trans_price * 1) * (row.qty_needreturn * 1); } return toMoney(a1deliveryamt); }; function formatter_return_money(row, column, cellValue, index) { var returnamt = 0; if(row.qty_needreturn && row.product_price) { returnamt = (row.qty_needreturn * 1) * (row.product_price * 1); } return toMoney(returnamt); }; function formatter_Sync(row,column,cellValue,index) { if(cellValue == "新增成功!" || cellValue == "获取信息成功" || row.sync == true){ return "订单已推送工厂成功" } else return cellValue }; function formatter_terminalPosition(row, column, cellValue, index) { if (cellValue == "1") { return "全渠道"; } else if (cellValue == "2") { return "医院"; } else if (cellValue == "3") { return "体系内药店"; } else if (cellValue == "4") { return "体系外药店"; } else if (cellValue == "5") { return "基层"; } else return cellValue; }; ///////////////////具体实现//////////////////// //日期格式转换 function dateFormat(date, fmt) { if (typeof date == 'string') { date = new Date(date); } if (null == date || undefined == date) return ''; var o = { "M+": date.getMonth() + 1, //月份 "d+": date.getDate(), //日 "h+": date.getHours(), //小时 "m+": date.getMinutes(), //分 "s+": date.getSeconds(), //秒 "S": date.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.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 toMoney(num, digit) { if (digit == null || digit == "" || isNaN(digit)) { digit = 2; } else { digit = typeof digit == 'string' ? digit * 1 : digit } if (num) { if (isNaN(num)) { //alert('金额中含有不能识别的字符'); return; } num = typeof num == 'string' ? parseFloat(num) : num // 判断是否是字符串如果是字符串转成数字 num = num.toFixed(4); // 保留两位 num = parseFloat(num); // 转成数字 num = num.toLocaleString(); // 转成金额显示模式 // 判断是否有小数 if (num.indexOf('.') === -1) { num = '¥' + num + ''; } else { // console.log(num.split('.')[1].length) // num = num.split('.')[1].length < 4 ? '¥' + num + '0' : '¥' + num; if (num.split('.')[1].length == 1) { num = '¥' + num + '' } else if (num.split('.')[1].length == 2) { num = '¥' + num + '' } else if (num.split('.')[1].length == 3) { num = '¥' + num + '' } else if (num.split('.')[1].length == 4) { num = '¥' + num } } return num; // 返回的是字符串23,245.12保留2位小数 } else { return num = null; } }; //数值转率,可设置小数位数 function toPercent(num, digit) { if (digit == null || digit == "" || isNaN(digit)) { digit = 2; } else { digit = typeof digit == 'string' ? digit * 1 : digit } if (num) { if (isNaN(num)) { //alert('金额中含有不能识别的字符'); return; } num = typeof num == 'string' ? parseFloat(num) : num // 判断是否是字符串如果是字符串转成数字 num = num.toFixed(digit); // 保留两位 num = parseFloat(num); // 转成数字 num += "%"; return num; // 返回的是字符串23,245.12保留2位小数 } else { return num = null; } }; function toPercent100(num, digit) { if (digit == null || digit == "" || isNaN(digit)) { digit = 2; } else { digit = typeof digit == 'string' ? digit * 1 : digit } if (num) { if (isNaN(num)) { //alert('金额中含有不能识别的字符'); return; } num = num * 100 num = typeof num == 'string' ? parseFloat(num) : num // 判断是否是字符串如果是字符串转成数字 num = num.toFixed(digit); // 保留两位 num = parseFloat(num); // 转成数字 num += "%"; return num; // 返回的是字符串23,245.12保留2位小数 } else { return num = null; } } //数值保留几位小数 function toFloat(num, digit) { if (digit == null || digit == "" || isNaN(digit)) { digit = 2; } else { digit = typeof digit == 'string' ? digit * 1 : digit } if (num) { if (isNaN(num)) { //alert('金额中含有不能识别的字符'); return; } num = typeof num == 'string' ? parseFloat(num) : num // 判断是否是字符串如果是字符串转成数字 num = num.toFixed(digit); // 保留两位 num = parseFloat(num); // 转成数字 return num; // 返回的是字符串23,245.12保留2位小数 } else { return num = null; } }; function toSplit(row, format) { var str_ = ""; //format = "#{name}-{name}%" var treeTxtList_ = []; var treeTxtFormatter_ = []; treeTxtFormatter_ = format.split("{"); treeTxtFormatter_.map(f=>{ if (f.indexOf('}') != -1) { var fa_ = f.split("}"); if (fa_[0]) { if (row[fa_[0]]) { treeTxtList_.push(row[fa_[0]]); } } if (fa_[1]) { treeTxtList_.push(fa_[1]); } } else if (f) { treeTxtList_.push(f); } }) treeTxtList_.map(s=>{ str_ += s; }) return str_; }; /////////////////组件中的formatter/////////////////// //通用formatterjson转换,根据json对应关系显示, function formatter_json(row, column, cellValue, index, json_) { var json = json_; var val = ""; var cellValue_ = null; if (cellValue || cellValue == false || cellValue == 0) { cellValue_ = cellValue.toString() } if (typeof(json_)=="string") { json = JSON.parse(json_); } if (json[cellValue]) { return json[cellValue]; } else if (cellValue && json.othervaldefaultval) { //没有对应关系但是有值,可设置其它数值的显示值 return json.othervaldefaultval; } else if (!cellValue && json.defaultval) { //没有值,可设置默认显示值 return json.defaultval; } else { return cellValue } }; // 字段加密 function formatter_password(row, column, cellValue, index) { return "********"; }; //字段拼接显示 function formatter_split(row, column, cellValue, index, format) { if (cellValue) { return toSplit(row, format); } return cellValue; }; //日期格式化 function formatter_date(row, column, cellValue, index, format) { var format_ = "yyyy-MM-dd"; if (format) { format_ = format; } if (cellValue) { return dateFormat(cellValue, format_); } return cellValue; }; //小数格式化 function formatter_float(row, column, cellValue, index, digit) { if (cellValue) { return toFloat(cellValue, digit); } return cellValue; }; //率转换格式化 function formatter_percent(row, column, cellValue, index, digit) { if (cellValue) { return toPercent(cellValue, digit); } return cellValue; }; //率转换格式化(*100) function formatter_percent100(row, column, cellValue, index, digit) { if (cellValue) { return toPercent100(cellValue, digit); } return cellValue; }; //有前缀或后缀的格式化 function formatter_prefixorunit(row, column, cellValue, index, prefix, unit) { if (cellValue != null) { var cellValue_ = cellValue; if (prefix) { cellValue_ = prefix + (cellValue_); } if (unit) { cellValue_ = (cellValue_) + unit; } return cellValue_; } return cellValue; }; FormatCenter.load();