define(function (require, exports, module) { let BaseBiz = require('apps/rht/base/rhtBiz'); let Service = require('./dst200102service'); let rhtComm = require('../../comm/rhtComm'); let PdWindow = require("system/views/pages/batch-pd-window/batch-pd-window"); /** * 控制按钮的可用 * @param opCode 按钮编码 * @return [description] */ function Biz(vm) { //继承第一步,构造继承 BaseBiz.call(this, vm); vm.remark ='' } //继承第二步,方法继承 inherits(Biz, BaseBiz); //新增行后处理,默认值已经处理 Biz.prototype.afterNewRow = function (dataSrc, newRow) { if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) { let Ord_YhDays = rhtComm.getRhtOptionValue('*','ORD','Ord_YhDays','1'); let iYhDays = TypeUtil.toFloat(Ord_YhDays); newRow.setColumnValue('SdDate',rhtComm.GetServerDate(iYhDays)); } }; //行删除前的校验 Biz.prototype.beforeDeleteRow=function(dataSrc, dataRow){ if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) { let sAskType = TypeUtil.toString(dataRow['AskType']); if ( (sAskType == "3") || (sAskType == "4") || (sAskType == "5") ) { masterRow.setColumnError("BillNo", '组合类要货不允许对要货记录进行删除!'); return false; } } return true; }; //明细行单行提交触发的校验 Biz.prototype.dataRowValidate = function (dataSrc, dr) { if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) { let sPackUnit = TypeUtil.toString(dr['PackUnit']); let fPsCount = TypeUtil.toFloat(dr['PsCount']); if (fPsCount <= 0) { return "配送数量不能小于或等于零!"; } if (sPackUnit == "") { dr.setColumnText('PackCount',"0"); } } return true; }; //校验小数精度 Biz.prototype.getPrecision = function (dataSrc, dr, dc, defaultPrecision) { if (dataSrc.uiObjCode == this.dsDetail.uiObjCode) { //把这里改成需要控制的字段 if ((dc.fieldName == 'PackCount') ||(dc.fieldName == 'SglCount')) { return TypeUtil.toInt(dr['R_DotDecimal']); } } return this.super('getPrecision', dataSrc, dr, dc, defaultPrecision); }; //字段变化触发事件 Biz.prototype.fieldChanged = function (dataSrc, dr, dc) { if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) { switch (dc.fieldName) { case 'Remark': this.fieldChangedRemark(dataSrc, dr, dc); break; } } if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) { switch (dc.fieldName) { case 'ShOrgCode': this.fieldChangedShOrgCode(dataSrc, dr, dc); break; case 'PluCode': this.fieldChangedPluCode(dataSrc, dr, dc); break; case 'PackUnit': this.fieldChangedPackUnit(dataSrc, dr, dc); break; case 'PackCount': this.fieldChangedPackCount(dataSrc, dr, dc); break; case 'SglCount': this.fieldChangedSglCount(dataSrc, dr, dc); break; } } this.super('fieldChanged'); }; //Remark 字段变化执行事件 Biz.prototype.fieldChangedRemark = function (dataSrc, dr, dc) { let sRemarkBillNo = dr ? TypeUtil.toString(dr['RemarkBillNo']) : ''; if (sRemarkBillNo.length > 0){ dr.setColumnError(dc.fieldName, "备注信息已写入配送单,不能修改!"); return false; } return true; }; //ShOrgCode 字段变化执行事件 Biz.prototype.fieldChangedShOrgCode = function (dataSrc, dr, dc) { let sShOrgCode = dr ? TypeUtil.toString(dr['ShOrgCode']) : ''; if (sShOrgCode === '') return false; if (dc.getRefValue('etpdsttype') == "0") { dr.setColumnValue('OrgType',"0") } else{ dr.setColumnValue('OrgType',"1") } let dBodyRow = dr.getData(); let ret= Service.getSlideMenuData("DoOnDetailCalcRule","ShOrgCode", dBodyRow,"","","",""); if (ret.result !== 1) { dr.setColumnError(dc.fieldName, ret.message); return false; } if (ret.data != null) { let fPsCount = TypeUtil.toFloat(dr['PsCount']); let fPsPrice = TypeUtil.toFloat(ret.data.price); dr.setColumnValue('PsPrice', ret.data.price); dr.setColumnValue('PsTotal', (fPsPrice*fPsCount).round(2)); dr.setColumnValue('ShAddr', ret.data.address); } return true; }; //PluCode 字段变化执行事件 Biz.prototype.fieldChangedPluCode = function (dataSrc, dr, dc) { let sPluCode = TypeUtil.toString(dr['PluCode']); let fPsCount = TypeUtil.toFloat(dr['PsCount']); if (sPluCode === '') return false; //获取包装信息 let JSONObject={psPluCode:sPluCode,psYwType:"2002"}; let retPacket= Service.getSlideMenuData("pubsysBaseBL","GetDefaultPluPackUnitByYwType",JSONObject,sPluCode,"","",""); if (retPacket.result === 1) { if (retPacket.data != null) { dr.setColumnValue('PackUnit', retPacket.data.Unit); dr.setColumnValue('PackQty', retPacket.data.Qty); } } dr.setColumnValue('PackCount', "0"); dr.setColumnText('SglCount', "0"); //明细相关字段赋值 let dBodyRow = dr.getData(); let ret= Service.getSlideMenuData("DoOnDetailCalcRule","PluCode", dBodyRow,"","","",""); if (ret.result !== 1) { dr.setColumnError(dc.fieldName, ret.message); return false; } if (ret.data != null) { let fPsPrice = TypeUtil.toFloat(ret.data.price); dr.setColumnValue('PsPrice', ret.data.price); dr.setColumnValue('PsTotal', (fPsPrice*fPsCount).round(2)); dr.setColumnValue('NewPcJPrice', ret.data.newpcjprice); } return true; }; //PackUnit 字段变化执行事件 Biz.prototype.fieldChangedPackUnit = function (dataSrc, dr, dc) { let sPackUnit = TypeUtil.toString(dr['PackUnit']); let sAskType = TypeUtil.toString(dr['AskType']); if ((sAskType == "3") || (sAskType == "4") || (sAskType == "5")){ dr.setColumnError(dc.fieldName, '组合类要货不允许对要货包装进行修改!'); return false; } if (sPackUnit == "") { dr.setColumnValue('PackQty', "0"); } dr.setColumnText('PackCount', "0"); return true; }; //PackCount 字段变化执行事件 Biz.prototype.fieldChangedPackCount = function (dataSrc, dr, dc) { let fPackCount = TypeUtil.toFloat(dr['PackCount']); let fPackQty = TypeUtil.toFloat(dr['PackQty']); let fSglCount = TypeUtil.toFloat(dr['SglCount']); let fPsPrice = TypeUtil.toFloat(dr['PsPrice']); let fPsCount = fPackCount*fPackQty+fSglCount; let fPsCost = (fPsCount*fPsPrice).round(2); let sPluCode = dr ? TypeUtil.toString(dr['PluCode']) : ''; if (sPluCode === '') return false; let sAskType = TypeUtil.toString(dr['AskType']); if ((sAskType == "3") || (sAskType == "4") || (sAskType == "5")){ dr.setColumnError(dc.fieldName, '组合类要货不允许对要货包装进行修改!'); return false; } if (fPackCount < 0) { dr.setColumnError(dc.fieldName, '包装数量不允许为负数!'); return false; } dr.setColumnValue('PsCount', fPsCount); dr.setColumnValue('PsTotal', fPsCost); return true; }; //SglCount 字段变化执行事件 Biz.prototype.fieldChangedSglCount = function (dataSrc, dr, dc) { let fPackCount = TypeUtil.toFloat(dr['PackCount']); let fPackQty = TypeUtil.toFloat(dr['PackQty']); let fSglCount = TypeUtil.toFloat(dr['SglCount']); let fPsPrice = TypeUtil.toFloat(dr['PsPrice']); let fPsCount = fPackCount*fPackQty+fSglCount; let fPsCost = (fPsCount*fPsPrice).round(2); let sPluCode = dr ? TypeUtil.toString(dr['PluCode']) : ''; if (sPluCode === '') return false; let sAskType = TypeUtil.toString(dr['AskType']); if ((sAskType == "3") || (sAskType == "4") || (sAskType == "5")){ dr.setColumnError(dc.fieldName, '组合类要货不允许对要货包装进行修改!'); return false; } if (fSglCount < 0) { dr.setColumnError(dc.fieldName, '单件件数不允许为负数!'); return false; } dr.setColumnValue('PsCount', fPsCount); dr.setColumnValue('PsTotal', fPsCost); return true; }; //按钮事件控制 Biz.prototype.doOp = function (opCode) { if (opCode == 'pass') { this.onpass(); } if (opCode == 'pladd') { this.onpladd(); } }; //控制主界面按钮状态 Biz.prototype.getOpEnabled = function (opCode) { let isOk = this.super('getOpEnabled', opCode); if (!isOk) { return false; } let curRow = this.dsMaster.currentRow; let sYwStatus = curRow ? TypeUtil.toString(curRow['YwStatus']) : ''; if (opCode == 'pladd'){ // 暂时不用 后期再支持 return false; } if ((opCode == 'pass') || (opCode == 'edit') || (opCode == 'delete')){ if (!curRow) return false; if (this.isEdit()) return false; if (sYwStatus != "0") return false; } return true; }; //确认事件处理 Biz.prototype.onpass = function () { //弹出是否确认提交对话框 if (!Store.confirm("确认要对选中数据进行处理吗?")) { return false; } let curHRow = this.dsMaster.currentRow; let sBillNo = curHRow ? TypeUtil.toString(curHRow['BillNo']) : ''; let sYwStatus = curHRow ? TypeUtil.toString(curHRow['YwStatus']) : ''; if (sYwStatus == "1") { Store.messager.err("此主动配送单已经经过确认!"); return false; } if ((sBillNo.length == 0) || (sBillNo == "*")){ Store.messager.err("请选择有效单据!"); return false; } let Dst_ZdPs_SendBld = rhtComm.getRhtOptionValue('*','DST','Dst_ZdPs_SendBld','0'); if (Dst_ZdPs_SendBld == "0"){ let retchk = Service.getSlideMenuData("actExecute","chkpass", sBillNo,"","","",""); if (retchk.result !== 1) { Store.messager.err(retchk.message); return false; } if ((retchk.data !== null) && (retchk.data.length !== 0)){ //展示不合法数据 let mainGrid = { opts: {}, data: { columns: [ {field: 'PluCode',name: '商品编码'}, {field: 'PluName',name: '商品名称'}, {field: 'YhCount',name: '配送数量'}, {field: 'QrCount',name: '确认数量'}, {field: 'Remark',name: '备注信息'} ], rows:retchk.data /*rows: [ {PluCode: '111111'}, {PluCode: '22222'} ],*/ }, actions: {} }; this.view.register('grid','grid_main',mainGrid); //确认是否继续 if (!Store.confirm("该主动配送单存在生不成待配送数据的商品,您是否还要继续生成待配送数据?")) { return false; } else{ if (!Store.confirm("您确认要将此主动配送单生成待配送数据吗?")) { return false; } } } } if (Dst_ZdPs_SendBld == "1"){ if (!Store.confirm("主动配送单确认后会将数据发送到便利店,确认继续吗?")) { return false; } } let ret= Service.getSlideMenuData("actExecute","onpass", sBillNo,"","","",""); if (ret.result !== 1) { Store.messager.err("确认失败:"+ret.message); return false; } Store.messager.tip(sBillNo+"处理成功!"); this.dsMaster.updateRow(); return true; }; //批量增加事件处理 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 }); }; */ //首先清空明细表 //this.dsDetail.deleteAll(); //循环插入记录 for(let i = 0; i <= rows.length - 1; i++){ let newRow = self.dsDetail.addRow(); newRow.setColumnValue('SerialNo', i+1) newRow.setColumnText('OrgType',"0"); newRow.setColumnText('ShOrgCode',rows[i].shorgcode); newRow.setColumnText('PluCode', rows[i].plucode); newRow.setColumnValue('PackUnit',rows[i].packunit); newRow.setColumnValue('PackQty',rows[i].packqty); newRow.setColumnText('PackCount',rows[i].packcount); newRow.setColumnText('SglCount',rows[i].sglcount); } } }; //new多选窗体 并打开 let myWindow = new PdWindow(param); myWindow.open(); }; return Biz; });