/******** foundation ********/ /* 1. 由main.html引用 */ /* 2. 其他界面不使用 */ /****************************/ token = window.top.Root.getToken(); RootSetting = { //1. 主数据、业务数据 url: window.top.config.url_root + "worder/fee/", //2. 奖金计算公式 url_fee: window.top.config.url_root + "worder/fee/", //3.工作流 url_act: "http://maywell.highdatas.com/act/", appName: "distributor", isClientMode: true, isDebug: true, }; baseUrl = RootSetting.url; /*********** 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); }, 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); }, 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 + 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) { parentObject.items = []; if (!itemOptions) { return; } if (this.beforeCreateItems) { this.beforeCreateItems(this.config); } for (var i = 0; i < itemOptions.length; i++) { var option = itemOptions[i]; this.doAddItem(parentObject, container, option, level); }; }; } 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, onSuccess, onFail) { var me = this; var clientMode = RootSetting.isClientMode; if (!url) { return; } 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 (url.substring(0, 5) == "root/") { url = RootSetting.url + "root/" + url.substring(5); } param = util.encode(param); if (token) { if (url.indexOf("?") > 0) { url = url + "&" + "token=" + token; } else { url = url + "?" + "token=" + token; } if (!param.token) { param.token = token; } } //3. request try { $.ajax(url, { contentType: "text/plain", dataType: "json", type: "post", data: param, success: function(result) { if (result) { if ("timeout" == result.errorcode) { window.top.location.href = me.sysParams.timeoutPage; } else if (!result.success) { if (onFail) { onFail(callback, result); } else { var error = result.errorcode + ": " + util.decode(result.errormessage); try { if (console.log) { console.log(error); } } catch (e) { } alert(error); } } } onSuccess(callback, result); }, error: function(d1, error, message) { alert(error); try { if (console.log) { console.log(error); } } catch (e) { } } }); } catch(e) { } }, 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) { if (!url) {return;} var me = this; if ($.isFunction(param)) { callback = param; param = null; } param = $util.objectToURI(param); me.ajaxRequest(url, param, callback, 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); } }); }, call: function(url, param, callback) { 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, 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(); function toClientURL(url) { if (!url) { return; } if (url.substring(0, 5) == "root/") { var pos = url.indexOf("root/"); url = "../../" + url.substr(pos + 5); } /* var pos = url.indexOf("root/"); if (pos >= 0) { url = "../../" + url.substr(pos + 5); } */ return url; } /********* root *************/ var RootClass = Object.subClass({ popupParames: {}, popupList: [], user: {}, role: {}, tab: null, message: null, confirm11: null, init: function(config) { Object.call(this, {}); this.tab = config.tab; this.loadStorage(); }, loadStorage: function() { this.role = { code: localStorage.getItem("rolecode")?localStorage.getItem("rolecode").split(";") : [], name: localStorage.getItem("rolename")?localStorage.getItem("rolename").split(";") : [] } }, showSubTab: function(config) { this.tab.showSubItem(config); }, hideSubTab: function(config) { this.tab.hideSubItem(config); }, showPopup: function(config) { 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; }, }); Root = new RootClass({ }) //////////////////////////////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.date = dateFormat; itemMap.money = formatter_money; itemMap.percent = formatter_percent; itemMap.TF1 = formatter_TF1; itemMap.TF2 = formatter_TF2; itemMap.TF3 = formatter_TF3; itemMap.TF4 = formatter_TF4; itemMap.TF5 = formatter_TF5; itemMap.TF6 = formatter_TF6; itemMap.null1 = formatter_null1; itemMap.target = formatter_Target; itemMap.openState = formatter_OpenState; 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; } }); 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(); var PopupWindowClass = Object.subClass({ width: 600, height: 400, 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_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.container = $("#win_container", el); el.body = $("#win_body", el); //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(); }); // 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 }); //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 (obj == undefined) { return "null"; } else 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(obj1, obj2, override) { if (!obj1) { return obj2; } if (!obj2) { return obj1; } for (var name in obj2) { //如果1没有该属性 if (override || obj1[name] === undefined) { obj1[name] = obj2[name]; } //如果1存在该属性 else if(typeof(obj1[name]) == "object"){ util.combine(obj1[name], obj2[name]); } } return obj1; }; 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; }; 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; if (url.substring(0, 5) == "root/") { var pos = current.indexOf("root/"); url = current.substring(0, pos) + url; } /* 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; } }; ///////////////////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) { return dateFormat(cellValue, "yyyy-MM-dd"); } return cellValue; }; function formatter_money(row, column, cellValue, index) { if(cellValue) { return toMoney(cellValue); } return "¥0"; }; function formatter_percent(row, column, cellValue, index) { if(cellValue) { return cellValue + '%'; } return "0%"; }; function toMoney(num) { if (num) { if (isNaN(num)) { alert('金额中含有不能识别的字符'); return; } 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 = '¥0'; } }; 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_TF4(row, column, cellValue, index) { if (cellValue == true || cellValue=="T"|| cellValue=="1") { return "是" } else if (cellValue != null && (cellValue == false || cellValue=="F"|| cellValue=="0")) { return "否" } return null }; function formatter_TF5(row, column, cellValue, index) { if (cellValue == true || cellValue=="T"|| cellValue=="1") { return "男" } else if (cellValue != null && (cellValue == false || cellValue=="F"|| cellValue=="0")) { return "女" } return null }; function formatter_TF6(row, column, cellValue, index) { if (cellValue == "Input") { return "输入"; } else if (cellValue == "Calculated") { return "计算完成"; } else if (cellValue == "Commit") { return "审批完成"; } else if (cellValue == "Open") { return "生效"; } else if (cellValue == "Cancel") { return "取消"; } return null }; function formatter_null1(row, column, cellValue, index) { if (!cellValue) { return 0 } return cellValue }; function formatter_Target(row, column, cellValue, index) { if (cellValue == "Target") { return "目标客户"; } else if(cellValue == "NotTarget") { return "非目标客户"; } else return ""; }; function formatter_OpenState(row, column, cellValue, index) { if (cellValue == "open") { return "已开户"; } else if (cellValue == "working") { return "审批中"; } else if (cellValue == "input") { 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 (cellValue == "open") { return "审批完成"; } else if (cellValue == "working") { return "审批中"; } else if (cellValue == "submit") { return "待审批"; } else if (cellValue == "refused") { return "审批未通过"; } else if (cellValue == "input") { 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 == "zs") { return "招商"; } else if (cellValue == "xs") { return "学术"; } else if (cellValue == "yb") { return "院部"; } else if (cellValue == "ty") { return "特药"; } else if (cellValue == "djk") { return "大健康"; } else return ""; }; function formatter_matchstatus(row, column, cellValue, index) { if (cellValue == "1") { return "没有匹配协议"; } else if (cellValue == "2") { return "匹配多个协议"; } else return ""; }; FormatCenter.load();