define(function (require, exports, module) { let BaseBiz = require('apps/rht/base/rhtBiz'); let Service = require('./cou190201service'); let rhtComm = require('../../comm/rhtComm'); let showErrorInfo = require('system/views/pages/messager/showerrorinfo'); let multiWindow = require("system/views/pages/multiwindow/multiwindow"); let PdWindow = require("system/views/pages/batch-pd-window/batch-pd-window"); let queryWindow = require("system/views/pages/querywindow/querywindow"); var ScDateWindow = require('system/views/pages/scdatewindow/scdatewindow'); /** * 控制按钮的可用 * @param opCode 按钮编码 * @return [description] */ function Biz(vm) { //继承第一步,构造继承 BaseBiz.call(this, vm); vm.remark ='' } //继承第二步,方法继承 inherits(Biz, BaseBiz); //取部门核算级别 let accLength = rhtComm.getOptionOrgAccLevel(); let Cou_LsYdPdType = rhtComm.getRhtOptionValue('*','COU','Cou_LsYdPdType','1'); //let Cou_LsJzShowFields = rhtComm.getRhtOptionValue('*','COU','Cou_LsJzShowFields','0'); let IsMdKwMng = rhtComm.getRhtOptionValue('*','STK','IsMdKwMng','1'); let COU_ISPDBILLNEEDSH = rhtComm.getRhtOptionValue('*','COU','COU_ISPDBILLNEEDSH','0'); let IsMulScDate = rhtComm.getRhtOptionValue("*",'SYS','SYS_IsMulScDate','0'); /* //功能初始化完毕调用该方法 Biz.prototype.initCompleted = function() { if (Cou_LsJzShowFields == "1"){ this.dsMaster.getColumn('ZmWCost').set('dispPosition','3'); } return this.super('initCompleted'); }; */ //编辑后 Biz.prototype.afterEdit = function() { let masterRow = this.dsMaster.currentRow; let sJzDate = masterRow ? TypeUtil.toString(masterRow['JzDate']) : ''; let sCouStatus = masterRow ? TypeUtil.toString(masterRow['CouStatus']) : ''; if (sJzDate != "") { this.dsDetail.getColumn('YkReason').set('isEditable',false); this.dsDetail.getColumn('PluCode').set('isEditable',false); this.dsDetail.getColumn('DepCode').set('isEditable',false); } else{ if (sCouStatus == "0"){ this.dsDetail.getColumn('YkReason').set('isEditable',false); this.dsDetail.getColumn('PluCode').set('isEditable',true); this.dsDetail.getColumn('DepCode').set('isEditable',true); } else if (sCouStatus == "2"){ this.dsDetail.getColumn('YkReason').set('isEditable',true); this.dsDetail.getColumn('PluCode').set('isEditable',false); this.dsDetail.getColumn('DepCode').set('isEditable',false); } else{ this.dsDetail.getColumn('YkReason').set('isEditable',false); this.dsDetail.getColumn('PluCode').set('isEditable',false); this.dsDetail.getColumn('DepCode').set('isEditable',false); } } return this.super('afterEdit'); }; // 列校验,列赋值时调用,发生异常表示校验失败 Biz.prototype.dataColumnValidate = function (dataSrc, dr, dc, value) { let self = this; if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) { let masterRow = self.dsMaster.currentRow; let sBillType = masterRow ? TypeUtil.toString(masterRow['BillType']) : ''; let DepCodeHead = masterRow ? TypeUtil.toString(masterRow['DepCode']) : ''; if (this.dsDetail.rows.length == 0){ if ((accLength > 0) && (DepCodeHead.length == 0)){ return "核算到部门,必须录入主表部门!"; } if (sBillType == "1"){ return "循环盘点单无需录入表体,请直接保存,单据会自动生成。"; } else if ((sBillType == "0") && (Cou_LsYdPdType != "1")){ return "月度盘点单无需录入表体,请直接保存,单据会自动生成。"; } } } return this.super('dataColumnValidate'); }; //保存前校验 Biz.prototype.beforeSave = function () { let masterRow = this.dsMaster.currentRow; if(masterRow){ let sOrgCode = masterRow ? TypeUtil.toString(masterRow['OrgCode']) : ''; let sCkCode = masterRow ? TypeUtil.toString(masterRow['CkCode']) : ''; let sBillType = masterRow ? TypeUtil.toString(masterRow['BillType']) : ''; let sDepId = masterRow ? TypeUtil.toString(masterRow['DeptId']) : ''; let sDepCode = masterRow ? TypeUtil.toString(masterRow['DepCode']) : ''; let sIsHc = masterRow ? TypeUtil.toString(masterRow['IsHc']) : ''; if (((sBillType == "1") || ((sBillType == "0") && (Cou_LsYdPdType != "1"))) && (this.dsDetail.rows.length == 0)){ let newBillNo=''; if (sBillType == "1"){ //循环盘点 let ret= Service.getSlideMenuData("BeforeSave","GenXhPdBill","1902",sOrgCode,sCkCode,sDepId,""); if (ret.result !== 1) { Store.messager.err(ret.message); return false; } newBillNo = ret.data.billno; } else if (sBillType == "0"){ //月度盘点 if (sDepCode == ''){ sDepCode = '%'; } let ret= Service.getSlideMenuData("BeforeSave","GenMonthPdBill","1902",sOrgCode,sCkCode,sDepCode,sIsHc); if (ret.result !== 1) { Store.messager.err(ret.message); return false; } newBillNo = ret.data.billno; } if (newBillNo != ''){ // 产生新单后需要删除当前单据 this.dsMaster.deleteRow(masterRow); this.callView('toList'); this.opRouter('refresh'); Store.messager.tip('已经产生新的盘点单:'+newBillNo+',请在查询页面进行操作!'); return true; } } } return this.super('beforeSave'); }; //字段变化触发事件 Biz.prototype.fieldChanged = function (dataSrc, dr, dc) { if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) { switch (dc.fieldName) { case 'OrgCode': this.fieldChangedOrgCode(dataSrc, dr, dc); break; } } if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) { switch (dc.fieldName) { case 'PluCode': this.fieldChangedPluCode(dataSrc, dr, dc); break; case 'DepCode': this.fieldChangedDepCode(dataSrc, dr, dc); break; } } this.super('fieldChanged'); }; //OrgCode 字段变化执行事件 Biz.prototype.fieldChangedOrgCode = function (dataSrc, dr, dc) { let sOrgCode = TypeUtil.toString(dr['OrgCode']); let sOldOrgCode = TypeUtil.toString(dr.transData['OrgCode']); if (sOldOrgCode != sOrgCode){ dr.setColumnText('CkCode', ""); dr.setColumnText('DepCode', ""); } return true; }; //PluCode 字段变化执行事件 Biz.prototype.fieldChangedPluCode = function (dataSrc, dr, dc) { let masterRow = this.dsMaster.currentRow; let sInOrgCode = TypeUtil.toString(masterRow['InOrgCode']); let sHeadDepCode = masterRow ? TypeUtil.toString(masterRow['DepCode']) : ''; let sCkCode = masterRow ? TypeUtil.toString(masterRow['CkCode']) : ''; let sPluCode = dr ? TypeUtil.toString(dr['PluCode']) : ''; let sDepCode = dr ? TypeUtil.toString(dr['DepCode']) : ''; if (sPluCode === '') return false; if (sDepCode.length > 0){ let ret= Service.getSlideMenuData("DoOnDetailCalcRule","UCheckInPlut", sOrgCode,sDepCode,sCkCode,sPluCode,""); if (ret.result !== 1) { dr.setColumnError(dc.fieldName, ret.message); return false; } } else{ let ret= Service.getSlideMenuData("DoOnDetailCalcRule","PluCode", sInOrgCode,sHeadDepCode,sCkCode,sPluCode,""); if (ret.result !== 1) { dr.setColumnError(dc.fieldName, ret.message); return false; } if (ret.data != null) { dr.setColumnValue('Price', ret.data.price); if (sDepCode.length <= 0){ dr.setColumnValue('DepID', ret.data.depid); dr.setColumnValue('DepCode', ret.data.depcode); dr.setColumnValue('DepName', ret.data.depname); dr.setColumnValue('ExPluCode', ret.data.explucode); dr.setColumnValue('ExPluName', ret.data.expluname); } } } if (IsMdKwMng == "1"){ let sOrgCode = TypeUtil.toString(masterRow['OrgCode']); let sPluID = dr ? TypeUtil.toString(dr['PluID']) : ''; let JSONObject={CurInOrgCode:sOrgCode,CkCode:sCkCode,PluID:sPluID}; let retKwCode = Service.getSlideMenuData("pubsysBaseBL","GetPluKw",JSONObject,"","","",""); if (retKwCode.result === 1) { if (retKwCode.data != null) { dr.setColumnValue('KwCode', retKwCode.data.KwCode); } } else{ dr.setColumnError('BillNo', retKwCode.message); return false; } } return true; }; //DepCode 字段变化执行事件 Biz.prototype.fieldChangedDepCode = function (dataSrc, dr, dc) { let sPluCode = dr ? TypeUtil.toString(dr['PluCode']) : ''; if (sPluCode === '') return false; let masterRow = this.dsMaster.currentRow; let sOrgCode = masterRow ? TypeUtil.toString(masterRow['InOrgCode']) : ''; let sCkCode = masterRow ? TypeUtil.toString(masterRow['CkCode']) : ''; let sDepCode = dr ? TypeUtil.toString(dr['DepCode']) : ''; let ret= Service.getSlideMenuData("DoOnDetailCalcRule","UCheckInPlut", sOrgCode,sDepCode,sCkCode,sPluCode,""); if (ret.result !== 1) { dr.setColumnError(dc.fieldName, ret.message); return false; } return true; }; //增加右键菜单按钮并控制按钮状态 Biz.prototype.getContextMenus = function (ds, source) { let menus = this.super("getContextMenus", ds, source) let edit = ds.getEditable(); let curRow = this.dsMaster.currentRow; let sCouStatus = curRow ? TypeUtil.toString(curRow['CouStatus']) : ''; menus.push({ text: '漏盘数据', opCode: 'coulose', disabled: edit || (sCouStatus =="0") }); menus.push({ text: '复盘数据', opCode: 'courepeat', disabled: edit || (sCouStatus !="2") }); menus.push({ text: '批量选择盘点商品', opCode: 'multiplu', disabled: !edit }); return menus; }; //增加右键菜单按钮并控制按钮状态 Biz.prototype.getContextMenus = function (ds, source) { let menus = this.super("getContextMenus", ds, source); if (ds.uiObjCode === this.dsDetail.uiObjCode) { let edit = ds.getEditable(); if ((!edit) && (IsMulScDate =='1')){ let curBodyRow = this.dsDetail.currentRow; let PluCode = curBodyRow ? TypeUtil.toString(curBodyRow['PluCode']) : ''; if (PluCode != ''){ menus.push({ text: '生产日期管理', opCode: 'scdate', disabled: false }); } } } return menus; }; //按钮事件控制 Biz.prototype.doOp = function (opCode) { let self = this; if (opCode == 'pladd') { this.onpladd(); } if (opCode == 'start') { this.onstartcollect("start"); } if (opCode == 'collect') { this.onstartcollect("collect"); } if (opCode == 'abort') { this.onabort(); } if (opCode == 'myacc') { this.onmyacc(); } if (opCode == 'pass') { this.onpass("1"); } if (opCode == 'nopass') { this.onpass("2"); } if (opCode == 'multiplu') { this.onmultiplu("2"); } if (opCode == 'coulose') { this.oncoulose(); } if (opCode == 'courepeat') { this.oncourepeat(); } if (opCode == 'scdate') { let dhead = self.dsMaster; let dbodyrow = self.dsDetail.currentRow; this.onscdate(self, dhead,dbodyrow); } }; //控制主界面按钮状态 Biz.prototype.getOpEnabled = function (opCode) { let isOk = this.super('getOpEnabled', opCode); if (!isOk) { return false; } let curRow = this.dsMaster.currentRow; let sJzDate = curRow ? TypeUtil.toString(curRow['JzDate']) : ''; let sCouStatus = curRow ? TypeUtil.toString(curRow['CouStatus']) : ''; let sShDate = curRow ? TypeUtil.toString(curRow['ShDate']) : ''; if (opCode == 'pladd'){ if (this.isEdit()) return false; } if (opCode == 'edit'){ if (!curRow) return false; if ((sJzDate != "") || (sCouStatus == "3")) return false; } if (opCode == 'delete'){ if (!curRow) return false; if ((sJzDate != "") || (sCouStatus != "0")) return false; } if (opCode == 'start'){ if (!curRow) return false; if (this.isEdit()) return false; if ((sJzDate != "") || (sCouStatus != "0")) return false; } if (opCode == 'collect'){ if (!curRow) return false; if (this.isEdit()) return false; if (sJzDate != "") return false; if ((sCouStatus != "1") && (sCouStatus != "2")) return false; } if (opCode == 'abort'){ if (!curRow) return false; if (this.isEdit()) return false; if (sJzDate != "") return false; if ((sCouStatus != "1") && (sCouStatus != "2")) return false; } if (opCode == 'myacc'){ if (!curRow) return false; if (this.isEdit()) return false; if ((sJzDate != "") || (sCouStatus != "2")) return false; } if ((opCode == 'pass') || (opCode == 'nopass')) { if (!curRow) return false; if (COU_ISPDBILLNEEDSH != "1") return false; if (this.isEdit()) return false; if ((sJzDate != "") || (sCouStatus != "2")) return false; if ((opCode == 'pass') && (sShDate != "")) return false; if ((opCode == 'nopass') && (sShDate == "")) return false; } return true; }; //审核公共事件处理 Biz.prototype.onpass = function (sType) { let sTypeName ="审核"; if (sType == "2"){ sTypeName ="反审核"; } //弹出是否确认提交对话框 if (!Store.confirm("确认要对选中数据进行"+sTypeName+"处理吗?")) { return false; } let curHRow = this.dsMaster.currentRow; let sBillNo = curHRow ? TypeUtil.toString(curHRow['BillNo']) : ''; let arrBillNo = new Array(); let iPass = 0; if (this.dsMaster.getSelectedRows().length <= 0){ if (sBillNo.length > 0){ arrBillNo[0] = sBillNo; iPass = iPass +1; } } else{ //只处理符合条件的单据 for (let i=0;i 0){ arrBillNo[0] = sBillNo; iPass = iPass +1; } } else{ //只处理符合条件的单据 for (let i=0;i 0){ arrBillNo[0] = sBillNo; iPass = iPass +1; } } else{ //只处理符合条件的单据 for (let i=0;i 0){ arrBillNo[0] = sBillNo; iPass = iPass +1; } } else{ //只处理符合条件的单据 for (let i=0;i 0){ if (!Store.confirm("经过检查,发现本盘点单存在以下问题:
"+retcheck.message+"
是否忽略这些信息,依旧执行入账操作?")) { return false; } } let retAcc= Service.getSlideMenuData("actExecute","onaccone", arrBillNo,"","","",""); if (retAcc.result !== 1) { Store.messager.err(retAcc.message); this.opRouter('refresh'); return false; } } else{ let retAcc= Service.getSlideMenuData("actExecute","onacc", arrBillNo,"","","",""); if (retAcc.result !== 1) { Store.messager.err(retAcc.message); this.opRouter('refresh'); return false; } } this.opRouter('refresh'); Store.messager.tip("记账盘点单成功!"); return true; }; //批量多选商品事件处理 Biz.prototype.onmultiplu = function () { let self = this; let curHRow = this.dsMaster.currentRow; let sCkCode= curHRow ? TypeUtil.toString(curHRow['CkCode']) : ''; let sDepCode= curHRow ? TypeUtil.toString(curHRow['DepCode']) : ''; let sInOrgCode= curHRow ? TypeUtil.toString(curHRow['InOrgCode']) : ''; //定义多选窗口界面 let exists = new Array(); for (let j = 0; j < self.dsDetail.rows.length; j++) { exists.push({ 'DepID': self.dsDetail.rows[j].DepID, 'PluID': self.dsDetail.rows[j].PluID, 'ExPluCode': self.dsDetail.rows[j].ExPluCode }); } let param={ exists: exists, uiObjCode: '19103', serverBiz: 'cn.qdhezheng.rht.app.cou.cou190201.SavePlugin', biz: self, pk: "DepID,PluID,ExPluCode", fixQuery: { 'DepCode': sDepCode, 'CkCode': sCkCode, 'OrgCode': sInOrgCode }, showCheckColumn: true, funcCode: self.FuncCode, ds: self.dsDetail, itreator: function (row) { let isOK = self.pladdrows(row); if (isOK != true) { Store.messager.tip("批量导入商品失败!"); return false; } return true; } }; //new多选窗体 并打开 let myWindow = new multiWindow(param); myWindow.open(); }; //批量增加每行后触发操作 Biz.prototype.pladdrows = function (row) { let ds = this.dsDetail; if (row != null) { let dr = ds.addRow(); dr.setColumnValue('PluID', row['PluID']); dr.setColumnValue('PluCode', row['PluCode']); dr.setColumnValue('PluName', row['PluName']); dr.setColumnValue('DepID', row['DepID']); dr.setColumnValue('DepCode', row['DepCode']); dr.setColumnValue('DepName', row['DepName']); dr.setColumnValue('ExPluCode', row['ExPluCode']); dr.setColumnValue('ExPluName', row['ExPluName']); dr.setColumnValue('Spec', row['Spec']); dr.setColumnValue('Unit', row['Unit']); dr.setColumnValue('BarCode', row['BarCode']); if (IsMdKwMng == "1"){ let curHRow = this.dsMaster.currentRow; let sCkCode= curHRow ? TypeUtil.toString(curHRow['CkCode']) : ''; let sOrgCode= curHRow ? TypeUtil.toString(curHRow['OrgCode']) : ''; let sPluID = row['PluID']; let JSONObject={CurInOrgCode:sOrgCode,CkCode:sCkCode,PluID:sPluID}; let retKwCode = Service.getSlideMenuData("pubsysBaseBL","GetPluKw",JSONObject,"","","",""); if (retKwCode.result === 1) { if (retKwCode.data != null) { dr.setColumnValue('KwCode', retKwCode.data.KwCode); } } else{ Store.messager.tip(retKwCode.message); return false; } } } return true; }; //展示漏盘数据事件处理 Biz.prototype.oncoulose = function () { let self = this; let curHRow = this.dsMaster.currentRow; let sBillNo= curHRow ? TypeUtil.toString(curHRow['BillNo']) : ''; //定义多选窗口界面 let param={ uiObjCode: '19105', biz: self, fixQuery: { 'BillNo': sBillNo }, funcCode: self.FuncCode, ds: self.dsDetail }; //new窗体 并打开 let myWindow = new queryWindow(param); myWindow.open(); }; //展示复盘数据事件处理 Biz.prototype.oncourepeat = function () { let self = this; let curHRow = this.dsMaster.currentRow; let sBillNo= curHRow ? TypeUtil.toString(curHRow['BillNo']) : ''; //定义多选窗口界面 let param={ uiObjCode: '19107', biz: self, fixQuery: { 'BillNo': sBillNo }, funcCode: self.FuncCode, ds: self.dsDetail }; //new窗体 并打开 let myWindow = new queryWindow(param); myWindow.open(); }; //批量增加事件处理 Biz.prototype.onpladd = function () { let self = this; //定义多选窗口界面 let param = { uiObjCode: '19112', serverBiz: 'cn.qdhezheng.rht.app.cou.cou190201.AddSavePlugin', biz: self, pk: "OrgCode,DepCode", showCheckColumn: true, enablePager: false, funcCode: self.FuncCode, ds: self.dsMaster, callback: function (rows) { if (rows.length == 0){ Store.messager.tip("请先选择数据再执行本操作!"); return false; } let addDataList = new Array(); for (let j = 0; j < rows.length; j++) { addDataList.push({ 'OrgCode': rows[j].OrgCode, 'DepCode': rows[j].DepCode }); } let ret = Service.getSlideMenuData("actExecute", "onpladd", addDataList, "", "", "", ""); if (ret.result !== 1){ let ushowErrorInfo = new showErrorInfo(800,500,"处理失败信息如下:",ret.message); ushowErrorInfo.open(); return false; } else{ Store.messager.tip("生成成功!"); return true; } } }; //new多选窗体 并打开 let myWindow = new PdWindow(param); myWindow.open(); }; //生产日期信息按钮事件处理 Biz.prototype.onscdate = function (self, dhead, dbodyrow) { let curRow = self.dsMaster.currentRow; let YwType = curRow ? TypeUtil.toString(curRow['YwType']) : '*'; let CouStatus = curRow ? TypeUtil.toString(curRow['CouStatus']) : '0'; if (IsMulScDate !=='1'){ Store.messager.err("系统没有开启多生产日期管理,请先开启后再执行本操作!"); return false; } //定义窗口界面 let param = { uiObjCode: self.dsMaster.funcCode, billNo: dbodyrow.BillNo, ywType: YwType, toSerialNo: dbodyrow.SerialNo, pluInf: dbodyrow.PluCode+'-'+dbodyrow.PluName, recCount: dbodyrow.SjCount, biz: self, pk: "BillNo,YwType,ToSerialNo,SerialNo", fixQuery: { 'ToSerialNo': dbodyrow.SerialNo, 'BillNo': dbodyrow.BillNo, 'YwType': YwType }, showCheckColumn: true, isToEdit: (CouStatus ==='2'), enablePager: false, funcCode: self.FuncCode, ds: dbodyrow }; //new多选窗体 并打开 let myWindow = new ScDateWindow(param); myWindow.open(); }; return Biz; });