define(function (require, exports, module) { //引入业务类基类 let BaseBiz = require('apps/rht/base/rhtBiz'); let rhtService = require('../../base/rhtService'); let rhtComm = require('apps/rht/comm/rhtComm'); let Tran = require('./Tran'); //引入业务服务 let Service = require('./etp0607service'); /** * 定义业务类对象 * @param vm 界面相关ViewModule */ function Biz(vm) { //继承第一步,构造继承 BaseBiz.call(this, vm); } //继承第二步,方法继承 inherits(Biz, BaseBiz); Biz.prototype.initCompleted = function () { this.super('initCompleted'); this.dsMaster.serverBiz = 'customerBiz' this.inOrgCode = rhtComm.GetInOrgCode(Store.logOn.orgCode).message; this.orgType = rhtComm.GetOrgType(Store.logOn.orgCode); //this.productClass = rhtComm.getRhtOptionValue('*','SYS','PRODUCT_CLASS','0'); this.isSupportFrgCurr = rhtComm.getRhtOptionValue('*','SYS','SYS_ISSUPPORTFRGCURR','0'); this.isZb = this.orgType=='1001'; this.alterMode = '0'; let ret = Service.GetAlterMode('6008'); if (ret.result == 1) { this.alterMode = ret.data; } }; //控制主界面按钮状态 Biz.prototype.getOpEnabled = function (opCode) { let self = this; let isOk = this.super('getOpEnabled', opCode); if (!isOk) return false; let curRow = this.dsMaster.currentRow; if (opCode == 'add') { if(this.orgType > '1003' && this.orgType < '1099' && this.alterMode == '1') return false; } if (opCode == 'edit') { if (!curRow) return false; if(this.orgType > '1003' && this.orgType < '1099' && this.alterMode == '1') return false; let ywStatus = TypeUtil.toString(curRow['YwStatus']); if(ywStatus > '1') return false; } if (opCode == 'delete') { if (!curRow) return false; if(this.orgType > '1003' && this.orgType < '1099' && this.alterMode == '1') return false; let ywStatus = TypeUtil.toString(curRow['YwStatus']); if(ywStatus != '0' && ywStatus != '3') return false; } if (opCode == 'act') { if (!curRow) return false; if(this.orgType > '1003' && this.orgType < '1099' && this.alterMode == '1') return false; let ywStatus = TypeUtil.toString(curRow['YwStatus']); if(ywStatus != '0') return false; } if (opCode == 'tran') { if (!curRow) return false; if(this.orgType > '1003' && this.orgType < '1099' && this.alterMode == '1') return false; let ywStatus = TypeUtil.toString(curRow['YwStatus']); let etpAttribute = TypeUtil.toString(curRow['EtpAttribute']); if(!(etpAttribute == '0' && ywStatus == '1')) return false; } if (opCode == 'stop') { if (!curRow) return false; if(this.orgType > '1003' && this.orgType < '1099' && this.alterMode == '1') return false; let ywStatus = TypeUtil.toString(curRow['YwStatus']); if(ywStatus != '1') return false; } if (opCode == 'logout') { if (!curRow) return false; if(this.orgType > '1003' && this.orgType < '1099' && this.alterMode == '1') return false; let ywStatus = TypeUtil.toString(curRow['YwStatus']); if(ywStatus != '2') return false; } if (opCode == 'revert') { if (!curRow) return false; if(this.orgType > '1003' && this.orgType < '1099' && this.alterMode == '1') return false; let ywStatus = TypeUtil.toString(curRow['YwStatus']); if(ywStatus != '2' && ywStatus != '3') return false; } return true; }; /** * @description 数据发生变化时调用 * @param dataSrc 数据集 * @param dr 数据行 * @param dc 数据列 */ Biz.prototype.fieldChanged = function (dataSrc, dr, dc) { let self = this; if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) { let currentRow = self.dsMaster.currentRow; if (currentRow === null) return false; switch (dc.fieldName) { case 'EtpCode': this.fieldChangedEtpCode(dataSrc, dr, dc); break; case 'IsQk': this.fieldChangedIsQk(dataSrc, dr, dc); break; case 'JsDay': this.fieldChangedJsDay(dataSrc, dr, dc); break; } } return this.super('fieldChanged'); }; Biz.prototype.fieldChangedEtpCode = function (dataSrc, dr, dc) { let ret = Service.GetEtpLx(dr.EtpCode); if (ret.result == 1) { dr.setColumnValue('EtpDstType', ret.data); } dr.setColumnText('JsEtpCode', dr.EtpCode); return true; }; Biz.prototype.fieldChangedIsQk = function (dataSrc, dr, dc) { let iaQk = TypeUtil.toString(dr.IsQk); let masterBdAdapter = this.view.vm['ep_dsMaster']; if (iaQk == '0') { masterBdAdapter.setEditorEditable('QkTotal', false); dr.setColumnValue('QkTotal', 0); }else { masterBdAdapter.setEditorEditable('QkTotal', true); } return true; }; Biz.prototype.fieldChangedJsDay = function (dataSrc, dr, dc) { let jsDay = TypeUtil.toFloat(dr.JsDay); if(jsDay == '') { dr.setColumnValue('JsDay', 0); } if(jsDay < '0' || jsDay > '31') { dr.setColumnError('JsDay', '客户月结日不对请重新输入!'); return false; } return true; }; //添加后执行 Biz.prototype.afterAdd = function () { let currentRow = this.dsMaster.currentRow; let masterBdAdapter = this.view.vm['ep_dsMaster']; if(this.orgType != '1001') { masterBdAdapter.setEditorEditable('OrgCode', false); } if((this.orgType != '1001' && this.orgType != '1002')) { masterBdAdapter.setEditorEditable('JsEtpCode', false); } masterBdAdapter.setEditorEditable('IsKzCredit', true); if(this.orgType != '1001' && this.orgType != '1002') { masterBdAdapter.setEditorEditable('OrgCode', false); }else { masterBdAdapter.setEditorEditable('OrgCode', true); } if(this.isSupportFrgCurr == '1') { masterBdAdapter.setEditorEditable('CurrCode', true); }else { masterBdAdapter.setEditorEditable('CurrCode', false); } //currentRow.setColumnValue('IsQk', 1); currentRow.setColumnValue('IsTh', 1); currentRow.setColumnValue('IsKzCredit', 0); currentRow.setColumnValue('LoginDate', new Date(rhtComm.GetServerDateTime(0)).format('yyyy-MM-dd')); let ret = Service.GetCurrCode(); if (ret.result == 1) { currentRow.setColumnValue('CurrCode', ret.data); } return this.super('afterAdd'); } //编辑后执行 Biz.prototype.afterEdit = function () { let currentRow = this.dsMaster.currentRow; let masterBdAdapter = this.view.vm['ep_dsMaster']; if((this.orgType != '1001' && this.orgType != '1002')) { masterBdAdapter.setEditorEditable('JsEtpCode', false); } masterBdAdapter.setEditorEditable('IsKzCredit', true); let iaQk = TypeUtil.toString(this.dsMaster.currentRow.IsQk); if (iaQk == '0') { masterBdAdapter.setEditorEditable('QkTotal', false); currentRow.setColumnValue('QkTotal', 0); }else { masterBdAdapter.setEditorEditable('QkTotal', true); } if(this.isSupportFrgCurr == '1') { masterBdAdapter.setEditorEditable('CurrCode', true); }else { masterBdAdapter.setEditorEditable('CurrCode', false); } return this.super('afterEdit'); }; //保存前校验 Biz.prototype.beforeSave = function () { let self = this; let curRow = this.dsMaster.currentRow; let etpCode = TypeUtil.toString(curRow.EtpCode); let jsEtpCode = TypeUtil.toString(curRow.JsEtpCode); let jsDay = TypeUtil.toFloat(curRow.JsDay); let yhRate = TypeUtil.toFloat(curRow.PfYhRate); let qkTotal = TypeUtil.toFloat(curRow.QkTotal); if(yhRate < 0) { Store.messager.err('优惠率必须大于零!'); return false; } if(qkTotal < 0) { Store.messager.err('允许欠款额度必须大于零!'); return false; } if(jsDay == '') { curRow.setColumnValue('JsDay', 0); } if(jsDay < '0' || jsDay > '31') { Store.messager.err('客户月结日不对请重新输入!'); return false; } let ret = Service.CheckEtpOrg(etpCode, jsEtpCode); if (ret.result != 1) { Store.messager.err(ret.message); return false; } if(etpCode == this.inOrgCode) { Store.messager.err('本组织内部组织不允许设置为客户!'); return false; } return this.super('beforeSave'); }; //删除前执行 Biz.prototype.beforeDelete = function () { let self = this; let curRow = this.dsMaster.currentRow; let ywStatus = TypeUtil.toString(curRow.YwStatus); let etpAttribute = TypeUtil.toString(curRow.EtpAttribute); let logoutDate = TypeUtil.toString(curRow.LogoutDate); let etpDstType = TypeUtil.toString(curRow.EtpDstType); if(ywStatus != '0' && etpAttribute == '1' && etpDstType == '1') { Store.messager.err('启用后的内部配送客户不允许删除!'); return false; } if(ywStatus == '3' && logoutDate != '') { let currDate = new Date(rhtComm.GetServerDateTime(0)); currDate = new Date(currDate.setFullYear(currDate.getFullYear()-1)); let oneYearBefore = currDate.format('yyyy-MM-dd'); if(logoutDate >= oneYearBefore) { Store.messager.err('客户必须注销一年以上才能删除!'); return false; } } return this.super('beforeDelete'); }; //按钮事件控制 Biz.prototype.doOp = function (opCode) { let self = this; if (opCode == 'act') { let ds = self.dsMaster; this.onAct(self, ds); } if (opCode == 'tran') { let ds = self.dsMaster; this.onTran(self, ds); } if (opCode == 'stop') { let ds = self.dsMaster; this.onStop(self, ds); } if (opCode == 'logout') { let ds = self.dsMaster; this.onLogout(self, ds); } if (opCode == 'revert') { let ds = self.dsMaster; this.onRevert(self, ds); } }; //启用 Biz.prototype.onAct = function (biz, ds) { let self = this; let currentRow = self.dsMaster.currentRow; let orgCode = TypeUtil.toString(currentRow.OrgCode); let etpCode = TypeUtil.toString(currentRow.EtpCode); if (!Store.confirm("您确定要启用该供应商吗?")) { return false; } let ret = Service.EtpAllCustToAudit(orgCode, etpCode, '0', '0', '', '客户管理'); if (ret.result != 1) { Store.messager.err(ret.message); return false; } Store.messager.tip('启用成功!'); biz.dsMaster.updateRow(); } //转化 Biz.prototype.onTran = function (biz, ds) { let self = this; let currentRow = self.dsMaster.currentRow; let orgCode = TypeUtil.toString(currentRow.OrgCode); let etpCode = TypeUtil.toString(currentRow.EtpCode); let etpAttribute = TypeUtil.toString(currentRow.EtpAttribute); tran = new Tran(orgCode, etpCode, etpAttribute); tran.callback = function () { biz.dsMaster.updateRow(); } tran.open(); } //禁用 Biz.prototype.onStop = function (biz, ds) { let self = this; let currentRow = self.dsMaster.currentRow; let orgCode = TypeUtil.toString(currentRow.OrgCode); let etpCode = TypeUtil.toString(currentRow.EtpCode); if (!Store.confirm("您确定要禁用吗?")) { return false; } let ret = Service.EtpCustomerChangeState(orgCode, etpCode, 'Forbid'); if (ret.result != 1) { Store.messager.err('禁用失败:' + ret.message); return false; } Store.messager.tip('禁用成功!'); biz.dsMaster.updateRow(); } //注销 Biz.prototype.onLogout = function (biz, ds) { let self = this; let currentRow = self.dsMaster.currentRow; let orgCode = TypeUtil.toString(currentRow.OrgCode); let etpCode = TypeUtil.toString(currentRow.EtpCode); if (!Store.confirm("您确定要注销吗?")) { return false; } let ret = Service.EtpCustomerChangeState(orgCode, etpCode, 'Cancel'); if (ret.result != 1) { Store.messager.err('注销失败:' + ret.message); return false; } Store.messager.tip('注销成功!'); biz.dsMaster.updateRow(); } //恢复 Biz.prototype.onRevert = function (biz, ds) { let self = this; let currentRow = self.dsMaster.currentRow; let orgCode = TypeUtil.toString(currentRow.OrgCode); let etpCode = TypeUtil.toString(currentRow.EtpCode); if (!Store.confirm("您确定要恢复吗?")) { return false; } let ret = Service.EtpCustomerChangeState(orgCode, etpCode, 'Recall'); if (ret.result != 1) { Store.messager.err('恢复失败:' + ret.message); return false; } Store.messager.tip('恢复成功!'); biz.dsMaster.updateRow(); } return Biz; });