define(function(require, exports, module) { var Biz = require('system/base/biz'); var etpTpl = require('text!apps/edp/frs/frs004/etp.tpl'); var QuickSetEtp = require('apps/edp/frs/frs004/QuickSetEtp'); var multiWindow = require("system/views/pages/multiwindow/multiwindow"); var utils = require('system/base/extend'); var FuncScriptwin = require('apps/edp/frs/frs004/funcscriptwin'); var fixQuery; var fill = 'edp-stretch'; var _treeId; //当前选定树的菜单编码 var _funcName; //当前选定树的功能名称 var _propData; //用于保存对象编码对应的企业模板字段属性数据 var _langData; //用于保存对象编码对应的企业模板显示属性数据 var _langItem; //保存原始对象编码的显示属性信息 function EtpBiz(vm) { Biz.call(this, vm); }; inherits(EtpBiz, Biz); EtpBiz.prototype.initCompleted = function() { this.dsMaster.onlySaveCurrent = true; this.super('initCompleted'); var self = this; var dsEtpTree = this.getDataSrc('dsEtpMenuTree'); dsEtpTree.defaultOrder = 'MenuCode'; dsEtpTree.search(function(isOk) { if (isOk) { var treedata = parseMenuData(dsEtpTree.rows); self.callView('setTreeData', treedata); self.treedata = treedata; } }); self.dsDetail2.on('onCollectChanged', function(ds, e) { ds.allowInsert = ds.rows.length > 0 ? false : true; }); }; EtpBiz.prototype.treeSelected = function(selectValue, selectColName, treeNode) { var self = this; var dsMaster = this.dsMaster; var moduleCode = treeNode.id; _treeId = moduleCode; _funcName = treeNode.name; if (moduleCode && moduleCode != 'other') { if (moduleCode !== '*') { fixQuery = { 'FuncCode': selectValue }; } else { fixQuery = {}; } dsMaster.fixQuery = fixQuery; dsMaster.search(); } if(moduleCode === 'other'){ self.dsMaster.clear(); self.getOtherDataSrc(self); } } EtpBiz.prototype.refresh = function() { var self = this; if (_treeId === 'other') { self.dsMaster.clear(); self.getOtherDataSrc(self); } else { utils.refresh(this); } }; //对主表其它节点灌入数据 EtpBiz.prototype.getOtherDataSrc = function(win) { var self = win; var params = { plugin: 'etpTreeOtherPlugin', pluginData: {} }; Store.services.executeplugin(params, function(isOk, result) { if (isOk) { self.dsMaster.loadData(result.data); if (self.callback) { self.callback(); } }; }); } EtpBiz.prototype.getCustomTpl = function() { //多语言转换 etpTpl = Store.compile(etpTpl, { FRS004_01: Store.MSG.FRS004_01, FRS004_04: Store.MSG.FRS004_04, }); return $('
') .append(etpTpl); } EtpBiz.prototype.getTreeTitle = function() { return Store.MSG.FRS004_03 }; EtpBiz.prototype.getOpEnabled = function(opCode) { var self = this; if (self.dsMaster !== null) { var currentRow = self.dsMaster.currentRow; switch (opCode) { case 'quickSet': if (currentRow === null || self.getState() === 'edit') { return false; } break; case 'reset': if (self.getState() === 'edit') { return false; } break; } } return this.super('getOpEnabled', opCode); }; EtpBiz.prototype.doOp = function(opCode) { this.super('doOp'); var self = this; switch (opCode) { //快速设置按钮操作事件 case 'quickSet': var curRow = this.dsMaster.currentRow; if (!curRow) { Store.messager.warn(Store.MSG.FRS004_12); //请先选择一条数据后进行快速设置。 return; } var UiObjCode = curRow["FuncObjCode"]; var quickSetEtp = new QuickSetEtp(UiObjCode, function() { //self.opRouter("refresh"); self.dsMaster.loadDetails(); }); quickSetEtp.open(); break; case 'exportscript': var dstree = this.getDataSrc('dsEtpMenuTree'); var args = { dsEtpMenuTree: dstree, treedata: this.treedata }; var scriptwin = new FuncScriptwin(args); scriptwin.open(); break; case 'reset': if (_treeId === undefined) { Store.messager.tip(Store.MSG.FRS004_24); //当前未选中任何树节点,请先在左侧树中选中要执行恢复默认功能的树节点。 return; } //确定要将({0})节点下的企业模板数据恢复默认设置吗? Store.messager.confirm(Store.format(Store.MSG.FRS004_21, _funcName), function(confirmIsOk) { if (confirmIsOk) { var params = { plugin: 'etpResetPlugin', pluginData: { menuCode: _treeId } }; Store.services.executeplugin(params, function(isOk, result) { if (isOk) { self.dsMaster.loadDetails(); Store.messager.tip(Store.MSG.FRS004_22); //恢复成功。 } else { Store.messager.tip(Store.MSG.FRS004_23); //恢复失败,请重试。 } }); } }); break; } return true; } EtpBiz.prototype.dataColumnValidate = function(dataSrc, dr, dc, value) { var self = this; if (dataSrc.uiObjCode === 'tEtpUIProp01') { if ((dc.fieldName === 'IsEditable' || dc.fieldName === 'IsRequired' || dc.fieldName === 'IsStrictRef' || dc.fieldName === 'IsZeroSpace') && value !== '' && value !== null && value !== "N" && value !== "0" && value !== "1") { Store.messager.warn(Store.MSG.FRS004_19); //该字段值只能为0或1,请重新输入。 return false; } if (dc.fieldName === "DefaultValue") { var defaultValue; _.each(_propData, function(item, index) { if (item['fieldname'] === dr.FieldName) { defaultValue = item["DefaultValue".toLowerCase()]; return false; } }); //if ((defaultValue === null || defaultValue === '') && value !== '' && value != 'N/A') { // Store.messager.tip(Store.MSG.FRS004_17); //初始默认值为空时,不允许设置默认值。 // dr.setColumnText('DefaultValue', "N/A"); // return false; //} if (defaultValue !== null && (value === "" || value === "N/A")) { Store.messager.tip(Store.MSG.FRS004_16); //默认值不允许修改为空,请重新输入。 return false; } } if (dc.fieldName === "IsRequired") { var isRequired; _.each(_propData, function(item, index) { if (item['fieldname'] === dr.FieldName) { isRequired = item["IsRequired".toLowerCase()]; return false; } }); if (isRequired === "1" && value !== '1') { Store.messager.tip(Store.MSG.FRS004_18); //初始值为必填时,不允许修改为不必填。 dr.setColumnText('IsRequired', "1"); return false; } } } return this.super('dataColumnValidate'); }; EtpBiz.prototype.fieldChanged = function(dataSrc, dr, dc, value) { var self = this; if (dataSrc.uiObjCode === 'tEtpUIProp01' && dc.fieldName === 'FieldName' && !value && value !== 0) { dr.setColumnValue('DispIndex', "-1"); dr.setColumnValue('IsEditable', "N"); dr.setColumnValue('IsRequired', "N"); dr.setColumnValue('IsStrictRef', "N"); dr.setColumnValue('IsZeroSpace', "N"); dr.setColumnValue('DispPosition', "N/A"); dr.setColumnValue('DefaultValue', "N/A"); dr.setColumnValue('DispFormat', "N/A"); dr.setColumnValue('KeyBoardType', "N/A"); var uiObjCode = dr['UIObjCode']; var fieldName = dr['FieldName']; if (uiObjCode === null || fieldName === null) return; self.getLangData(uiObjCode, fieldName); self.dsDetail1.columns.forEach(function(c) { if (c == dc) return; self.dsDetail1.onValueChanged(dr, c); }); } if (dataSrc.uiObjCode === 'tEtpUIPropLang01' && dc.fieldName === 'LangCode' && !value && value !== 0) { dr.setColumnValue('DispName', "N/A"); dr.setColumnValue('DispWidth', "-1"); dr.setColumnValue('LabelWidth', "-1"); dr.setColumnValue('HeaderWidth', "-1"); self.dsDetail3.columns.forEach(function(c) { if (c == dc) return; self.dsDetail3.onValueChanged(dr, c); }); } } EtpBiz.prototype.currentChanged = function(dataSrc, oldRow, newRow) { //this.super('currentChanged', dataSrc, oldRow, newRow); var self = this; if (dataSrc === this.dsMaster) { var curRow = self.dsMaster.currentRow; if (curRow === null) return; var uiObjCode = curRow['FuncObjCode']; if (uiObjCode === null) return; self.getPropData(uiObjCode); } if (dataSrc === this.dsDetail1) { var curDetailRow = self.dsDetail1.currentRow; if (curDetailRow === null) return; var uiObjCode = curDetailRow['UIObjCode']; var fieldName = curDetailRow['FieldName']; if (uiObjCode === null || fieldName === null) return; self.getLangData(uiObjCode, fieldName); } }; EtpBiz.prototype.getColumnFormatter = function(dc, defaultFormatter) { var self = this; //对字段属性显示的重置 if (dc.dataSrc.uiObjCode === 'tEtpUIProp01') { return function DispFormatter(row, cell, value, columnDef, dataContext) { var data = _propData; var dispValue = ''; _.each(_propData, function(item, index) { if (item['fieldname'] === dataContext.FieldName) { //若修改了值,应带出修改的值 if (value !== 'N' && value !== 'N/A' && value !== '-1') { if (dc.fieldName === 'FieldName' || dc.fieldName === 'DispName') { dispValue = value; } else { dispValue = "" + value + ""; } } else { dispValue = item[dc.fieldName.toLowerCase()]; } } }); return dispValue; } } //对显示属性显示的重置 if (dc.dataSrc.uiObjCode === 'tEtpUIPropLang01') { return function DispFormatter(row, cell, value, columnDef, dataContext) { var data = _langData; var dispValue = null; _.each(_langData, function(item, index) { if (item['langid'] === '*') { _langItem = item; } if (item['langid'] === dataContext.LangID && item['fieldname'] === dataContext.FieldName) { if (value !== 'N' && value !== 'N/A' && value !== '-1') { if (dc.fieldName === 'LangCode') { dispValue = value; } else { dispValue = "" + value + ""; } } else { dispValue = item[dc.fieldName.toLowerCase()]; } } }); //对界面直接新增的语言进行展示 if (dispValue === null) { if (value !== 'N' && value !== 'N/A' && value !== '-1') { if (dc.fieldName === 'LangCode') { dispValue = value; } else { dispValue = "" + value + ""; } } else { dispValue = _langItem[dc.fieldName.toLowerCase()]; } } return dispValue; } } return this.super('getColumnFormatter'); }; /** * 获取对应对象编码的企业模板最新数据,用于字段属性的展示 * @param {[type]} uiObjCode [对象编码] */ EtpBiz.prototype.getPropData = function(uiObjCode) { var params = { sync: 1, //同步操作获取数据 plugin: 'quickSetEtpFrushPlugin', pluginData: { uiobjcode: uiObjCode, } }; Store.services.executeplugin(params, function(isOk, result) { if (isOk) { _propData = result.data; }; }); } /** * [getData 获取对应对象编码的企业模板最新数据,用于显示属性的展示] * @param {[type]} uiObjCode [对象编码] * @param {[type]} fieldName [字段编码] */ EtpBiz.prototype.getLangData = function(uiObjCode, fieldName) { var params = { sync: 1, //同步操作获取数据 plugin: 'quickSetEtpLanPlugin', pluginData: { uiobjcode: uiObjCode, fieldname: fieldName } }; Store.services.executeplugin(params, function(isOk, result) { if (isOk) { _langData = result.data; }; }); } EtpBiz.prototype.beforeSave = function () { var self =this; self.dsDetail3.removeEmptyRow(); var detailRows = self.dsDetail3.getAllRows(); for(var j=0; j 2 ? item.MenuCode.substring(0, idLen - 2) : "*"; node.name = item.MenuCaption; node.value = item.FuncCode || ''; node.checked = false; if (idLen > 4) { node.icon = './images/icons/node2.png'; } nodes.push(node); }); var node = { icon: './images/icons/node.png' } node.id = 'other'; var idLen = ''; node.pId = ''; node.name = Store.MSG.FRS004_26, //其它 node.value = "*"; node.checked = false; nodes.push(node); return nodes; } return EtpBiz; })