define(function (require, exports, module) { let BaseBiz = require('apps/rht/base/rhtBiz'); let rhtComm = require('apps/rht/comm/rhtComm'); let service = require('./cls130101service'); let ClsDivide = require('./ClsDivide'); /** * 控制按钮的可用 * @param opCode 按钮编码 * @return [description] */ function Biz(vm) { //继承第一步,构造继承 BaseBiz.call(this, vm); } //继承第二步,方法继承 inherits(Biz, BaseBiz); let orgType = rhtComm.GetOrgType(Store.logOn.orgCode); Biz.prototype.initCompleted = function () { this.super('initCompleted'); this.initTree(); this.selTreeNode = null; this.isAddLast = false; // 是否在添加末级品类 this.isUsed = false; // 品类是否已经被使用(编辑时用) // this.isDivide// 是否在将末级品类转化为非末级 // this.divideClsCode;// 被转为非末级的品类编号 this.addClsCodeLen = 0; // 添加时限制品类编码长度,由特殊选项计算得出 this.dsMaster.state = { preclscode: '' } this.dsMaster.setServerBiz('cn.qdhezheng.rht.app.cls.cls130101.SavePlugin'); } // 树组件 Biz.prototype.getTreeTitle = function () { return ''; }; Biz.prototype.initTree = function() { // 获取品类树 let clsTreeInfo = service.GetClsTree(); if (clsTreeInfo.result != 1) { Store.messager.err(clsTreeInfo.message); } else { let treedata = []; treedata.push({ id: '*', pId: '', clscode: '', // 品类编码 clsname: '', // 品类类型 name: '全部', // 节点显示信息 islast: '0', // 是否末级 isexplucode: '0', // 是否进行特征码管理 explutype: '00', // 特征码组成模式 isbz: '0', // 管理保质期 iscurrday: '0', // 日配商品 isseason: '0', // 季节性商品 cxprecision: '0', // 促销优惠精度 cxcalcutype: '0', // 促销价格计算方法 open: true // 是否展开 }); for (let i = 0; i < clsTreeInfo.data.length; i++) { let row = clsTreeInfo.data[i]; if(row['pid'] == '-1') { continue; } treedata.push({ id: row['id'], pId: row['pid'], clscode: row['clscode'], // 品类编码 clsname: row['clsname'], // 品类类型 name: row['clscode'] + '-' + row['clsname'], // 节点显示信息 islast: row['islast'], // 是否末级 isexplucode: row['isexplucode'], // 是否进行特征码管理 explutype: row['explutype'], // 特征码组成模式 isbz: row['isbz'], // 管理保质期 iscurrday: row['iscurrday'], // 日配商品 isseason: row['isseason'], // 季节性商品 cxprecision: row['cxprecision'], // 促销优惠精度 cxcalcutype: row['cxcalcutype'], // 促销价格计算方法 open: false // 是否展开 }); } this.callView('setTreeData', treedata); } } Biz.prototype.treeSelected = function(selectValue, selectColName, treeNode) { this.dsMaster.state = { preclscode: treeNode ? treeNode.clscode : '' } this.dsMaster.search(); this.selTreeNode = treeNode; } //控制主界面按钮状态 Biz.prototype.getOpEnabled = function (opCode) { let isOk = this.super('getOpEnabled', opCode); if (!isOk) return false; let curRow = this.dsMaster.currentRow; if (opCode == 'add') { if(orgType != '1001') return false; } if (opCode == 'edit') { if(orgType != '1001') return false; if (!curRow) return false; } if (opCode == 'delete') { if(orgType != '1001') return false; if (!curRow) return false; } if (opCode == 'tolast') { if(orgType != '1001') return false; if(this.getState() == 'add' || this.getState() == 'edit') return false; if (!curRow) return false; if(TypeUtil.toString(curRow['IsLast']) == '1') return false; } if (opCode == 'nolast') { if(orgType != '1001') return false; if(this.getState() == 'add' || this.getState() == 'edit') return false; if (!curRow) return false; if(TypeUtil.toString(curRow['IsLast']) == '0') return false; } return true; }; //字段变化触发事件 Biz.prototype.fieldChanged = function (dataSrc, dr, dc) { if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) { switch (dc.fieldName) { case 'IsExPluCode': this.fieldChangedIsExPluCode(dataSrc, dr, dc); break; case 'ClsType': this.fieldChangedClsType(dataSrc, dr, dc); break; case 'SaleSeason': this.fieldChangedSaleSeason(dataSrc, dr, dc); break; } } this.super('fieldChanged'); }; //主表字段变化执行事件 Biz.prototype.fieldChangedIsExPluCode = function (dataSrc, dr, dc) { let isExPluCode = TypeUtil.toString(dr['IsExPluCode']); if(isExPluCode == '0') { dr.setColumnValue('ExPluType', '00'); } return true; }; Biz.prototype.fieldChangedClsType = function (dataSrc, dr, dc) { let clsType = TypeUtil.toString(dr['ClsType']); if(clsType == '02') { dr.setColumnValue('IsSeason', '1'); dr.setColumnValue('SaleSeason', '1111'); } return true; }; Biz.prototype.fieldChangedSaleSeason = function (dataSrc, dr, dc) { let saleSeason = TypeUtil.toString(dr['SaleSeason']); let clsType = TypeUtil.toString(dr['ClsType']); if(saleSeason == '' && clsType == '02') { dr.setColumnError('SaleSeason', '季节性品类销售季节不能为空!'); } return true; }; //增加前执行 Biz.prototype.beforeAdd = function () { if(!this.selTreeNode) { Store.messager.err('请选择父节点'); return false; } if(this.selTreeNode.islast == '1') { Store.messager.err('品类级别已是最末级,不允许增加!'); return false; } // 根据特殊选项判断是否末级 let nodeLevel = 0; if (this.selTreeNode !== null){ nodeLevel = this.selTreeNode.level; } let ret = service.GetLevelCodeTotalLen(nodeLevel+1, '1'); if (ret.result != 1) { Store.messager.err(ret.message); return false; } if(ret.data < 0) { Store.messager.err('品类级别已是最末级,不允许增加!'); return false; } this.addClsCodeLen = ret.data; return this.super('beforeAdd'); }; //增加后执行 Biz.prototype.afterAdd = function () { let masterAdapter = this.view.vm['ep_dsMaster']; // 根据特殊选项判断增加的是否是末级 let nodeLevel = 0; if (this.selTreeNode !== null){ nodeLevel = this.selTreeNode.level; } let ret = service.GetLevelCodeTotalLen(nodeLevel+2, '1'); if (ret.result != 1) { Store.messager.err(ret.message); return false; } if(ret.data < 0) { this.dsMaster.currentRow.setColumnValue('IsLast', '1'); masterAdapter.setEditorEditable('IsLast', false); masterAdapter.setEditorEditable('PluCount', true); this.isAddLast = true; }else { masterAdapter.setEditorEditable('PluCount', true); this.isAddLast = false; } this.dsMaster.currentRow.setColumnValue('ClsCode', this.selTreeNode.clscode); this.dsMaster.currentRow.setColumnValue('IsExPluCode', this.selTreeNode.isexplucode); this.dsMaster.currentRow.setColumnValue('ExPluType', this.selTreeNode.explutype); this.dsMaster.currentRow.setColumnValue('IsBz', this.selTreeNode.isbz); this.dsMaster.currentRow.setColumnValue('IsCurrDay', this.selTreeNode.iscurrday); this.dsMaster.currentRow.setColumnValue('IsSeason', this.selTreeNode.isseason); this.dsMaster.currentRow.setColumnValue('CxPrecision', this.selTreeNode.cxprecision); this.dsMaster.currentRow.setColumnValue('CxCalcuType', this.selTreeNode.cxcalcutype); return this.super('afterAdd'); }; //编辑前执行 Biz.prototype.beforeEdit = function () { // 获取当前品类级别的编码长度 let nodeLevel = 0; if (this.selTreeNode !== null){ nodeLevel = this.selTreeNode.level; } let ret = service.GetLevelCodeTotalLen(nodeLevel+1, '1'); if (ret.result != 1) { Store.messager.err(ret.message); return false; } if(ret.data < 0) { Store.messager.err('获取品类编码规则失败,请检查设置!'); return false; } this.addClsCodeLen = ret.data; return this.super('beforeEdit'); }; //编辑后执行 Biz.prototype.afterEdit = function () { let currentRow = this.dsMaster.currentRow; let clsId = TypeUtil.toString(currentRow['ClsID']); let clsCode = TypeUtil.toString(currentRow['ClsCode']); let ret = service.ClsIsUsed(clsId, clsCode); if (ret.result != 1) { Store.messager.err(ret.message); return false; } // 有下级品类或已经被商品使用,品类编码不可编辑 if(ret.data == 1) { this.isUsed = true; }else { this.isUsed = false; } let masterAdapter = this.view.vm['ep_dsMaster']; masterAdapter.setEditorEditable('ClsCode', !this.isUsed); masterAdapter.setEditorEditable('IsLast', !this.isUsed); // 根据特殊选项判断编辑的是否是末级 let nodeLevel = 0; if (this.selTreeNode !== null){ nodeLevel = this.selTreeNode.level; } ret = service.GetLevelCodeTotalLen(nodeLevel+2, '1'); if (ret.result != 1) { Store.messager.err(ret.message); return false; } if(ret.data < 0) { this.dsMaster.currentRow.setColumnValue('IsLast', '1'); masterAdapter.setEditorEditable('PluCount', true); this.isAddLast = true; }else { masterAdapter.setEditorEditable('PluCount', !this.isUsed); this.isAddLast = false; } return this.super('afterEdit'); }; //保存前执行 Biz.prototype.beforeSave = function () { let currentRow = this.dsMaster.currentRow; let clsCode = TypeUtil.toString(currentRow['ClsCode']); let clsName = TypeUtil.toString(currentRow['ClsName']); let minMlRate = TypeUtil.toFloat(currentRow['MinMlRate']); let maxMlRate = TypeUtil.toFloat(currentRow['MaxMlRate']); let isLast = TypeUtil.toString(currentRow['IsLast']); let self = this; // 品类编号需要满足特殊选项设置的长度,前缀为父级品类的编号 let selClsCode = ''; if (this.selTreeNode !== null){ selClsCode = this.selTreeNode.clscode; } let pattern=eval('/^' + selClsCode + '[0-9a-zA-Z]{' + (this.addClsCodeLen-selClsCode.length) + '}$/'); if (!pattern.test(clsCode)) { Store.messager.err('品类编号必须为数字或英文字母的组合,长度为' + this.addClsCodeLen + (selClsCode == '' ? '' : ',前缀为' + selClsCode)); return false; } pattern = /[+ -''*|=,{};]/; if(pattern.test(clsName)) { Store.messager.err('品类编号不能包含+ -\'\'*|=,{};等非法字符!'); return false; } if(minMlRate < 0 || minMlRate > 100) { Store.messager.err('最小毛利率应在0到100之间!'); return false; } if(maxMlRate < 0 || maxMlRate > 100) { Store.messager.err('最大毛利率应在0到100之间!'); return false; } if(minMlRate > maxMlRate) { Store.messager.err('最大毛利率应大于等于最小毛利率!'); return false; } if(self.getState() == 'add') { let retCls = service.ClsExists(clsCode, ''); if (retCls.result != 1) { Store.messager.err(retCls.message); return false; } if (retCls.data == 1) { Store.messager.err('品类编号已存在!'); return false; } } let ret = service.ClsExists('', clsName); if (ret.result != 1) { Store.messager.err(ret.message); return false; } if (ret.data == 1) { if (!Store.confirm("品类名称已存在,要继续吗?")) { return false; } } if(self.getState() == 'add' && !this.isAddLast && isLast == '0') { this.dsMaster.currentRow.setColumnValue('PluCount', 0); } let clsID = rhtComm.GetNextId("13001","1",Store.logOn.orgCode); this.dsMaster.currentRow.setColumnValue('ClsID', clsID); return this.super('beforeSave'); }; Biz.prototype.beforeDelete = function() { let self = this; let currentRow = self.dsMaster.currentRow; let clsId = TypeUtil.toString(currentRow['ClsID']); let clsCode = TypeUtil.toString(currentRow['ClsCode']); let clsName = TypeUtil.toString(currentRow['ClsName']); let ret = service.ClsIsUsed(clsId, ''); if (ret.result != 1) { Store.messager.err(ret.message); return false; } // 有下级品类或已经被商品使用,不可删除 if(ret.data == 1) { Store.messager.err(clsCode + '-' + clsName + ' 已经被商品使用,不能删除!'); return false; } if (!Store.confirm('将删除 ' + clsCode + '-' + clsName + ' 及其下属品类,确定吗?')) { return false; } ret = service.DeleteCls(clsCode); if (ret.result != 1) { Store.messager.err('删除失败:' + ret.message); return false; } this.initTree(); this.dsMaster.search(); //前面已经做处理,返回false,不真正删除数据 return false; } //按钮事件控制 Biz.prototype.doOp = function (opCode) { let self = this; if (opCode == 'tolast') { let ds = self.dsMaster; this.onTolast(self, ds); } if (opCode == 'nolast') { let ds = self.dsMaster; this.onNolast(self, ds); } }; Biz.prototype.onTolast = function (biz, ds) { let currentRow=ds.currentRow; let clsId = TypeUtil.toString(currentRow['ClsID']); let clsCode = TypeUtil.toString(currentRow['ClsCode']); let clsName = TypeUtil.toString(currentRow['ClsName']); let ret = service.ClsIsUsed(clsId, ''); if (ret.result != 1) { Store.messager.err(ret.message); return false; } if(ret.data == 0) { Store.messager.err(clsCode + '-' + clsName + ' 未被使用,请直接进行品类信息修改。'); return false; } if (!Store.confirm('将当前品类转为末级将删除其所有下属品类,同时更新下属末级品类对应的商品品类信息。\n您确定要将 ' + clsCode + '-' + clsName + ' 转为末级吗?')) { return false; } ret = service.ClsToLast(clsId); if (ret.result != 1) { Store.messager.err(ret.message); return false; } this.initTree(); this.dsMaster.search(); } Biz.prototype.onNolast = function (biz, ds) { let self = this; let currentRow=ds.currentRow; let clsId = TypeUtil.toString(currentRow['ClsID']); let clsCode = TypeUtil.toString(currentRow['ClsCode']); let clsName = TypeUtil.toString(currentRow['ClsName']); let ret = service.ClsIsUsed(clsId, ''); if (ret.result != 1) { Store.messager.err(ret.message); return false; } if(ret.data == 0) { Store.messager.err(clsCode + '-' + clsName + ' 未被使用,请直接进行品类信息修改。'); return false; } // 获取当前品类下一级的编码长度 let nodeLevel = 0; if (this.selTreeNode !== null){ nodeLevel = this.selTreeNode.level; } ret = service.GetLevelCodeTotalLen(nodeLevel+2, '1'); if (ret.result != 1) { Store.messager.err(ret.message); return false; } if(ret.data < 0) { Store.messager.err(clsCode + '-' + clsName + ' 已是最末级,不能转为非末级!'); return false; } let newClsCodeLen = ret.data; if (!Store.confirm('将当前品类转为非末级需要细化其下属品类,同时更新当前品类对应的商品品类信息为细化的品类。\n您确定要将 ' + clsCode + '-' + clsName + ' 转为非末级吗?')) { return false; } let clsDivide = new ClsDivide(this.dsMaster, newClsCodeLen, clsCode); clsDivide.callback = function (clsData, clsInfo) { ret = service.ClsDivide(clsId, clsData, clsInfo); if (ret.result != 1) { Store.messager.err(ret.message); return false; } self.initTree(); self.dsMaster.search(); } clsDivide.open(); } Biz.prototype.stateChanged = function(newState, oldState) { let self = this; if (newState === 'browser' && oldState === 'add') { self.initTree(); } } return Biz; });