You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

413 lines
14 KiB

4 years ago
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('./etp0606service');
/**
* 定义业务类对象
* @param vm 界面相关ViewModule
*/
function Biz(vm) {
//继承第一步,构造继承
BaseBiz.call(this, vm);
}
//继承第二步,方法继承
inherits(Biz, BaseBiz);
Biz.prototype.initCompleted = function () {
this.super('initCompleted');
this.dsMaster.serverBiz = 'supBiz'
this.orgType = rhtComm.GetOrgType(Store.logOn.orgCode);
this.productClass = rhtComm.getRhtOptionValue('*','SYS','PRODUCT_CLASS','0');
this.isEtpCodeRule = rhtComm.getRhtOptionValue('*','SUPP','IS_ETP_CODE_RULE','0');
this.supplierCodeLength = rhtComm.getRhtOptionValue("*",'SUPP','SupplierCodeLength','0');
this.isZb = this.orgType=='1001';
this.alterMode = '0';
let ret = Service.GetAlterMode('6006');
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(!this.isBrowser()){
return false;
}
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 == 'convert') {
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 == 'preabandon') {
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 == 'abandon') {
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' || ywStatus == '4')))
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' && ywStatus != '4')
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;
}
}
return this.super('fieldChanged');
};
Biz.prototype.fieldChangedEtpCode = function (dataSrc, dr, dc) {
dr.setColumnValue('JsEtpCode', dr.EtpCode);
return true;
};
//新增行后处理,默认值已经处理
Biz.prototype.afterNewRow = function (dataSrc, newRow) {
if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) {
//dataSrc.currentRow.setColumnValue('Months', new Date(Store.bizDao.getSysDate()).format('yyyyMM'));
}
return this.super('afterNewRow', dataSrc, newRow);
};
Biz.prototype.beforeAdd = function () {
this.dsMaster.getColumn('OrgCode').set('isEditable',true);
this.dsMaster.getColumn('EtpCode').set('isEditable',true);
this.dsMaster.getColumn('EtpAttribute').set('isEditable',true);
return this.super('beforeAdd');
};
//添加后执行
Biz.prototype.afterAdd = function () {
let masterBdAdapter = this.view.vm['ep_dsMaster'];
if(this.orgType != '1001') {
masterBdAdapter.setEditorEditable('OrgCode', false);
}
if(this.productClass == '1' && (this.orgType != '1001' && this.orgType != '1002')) {
masterBdAdapter.setEditorEditable('JsEtpCode', false);
}
return this.super('afterAdd');
}
//编辑后执行
Biz.prototype.afterEdit = function () {
if(this.productClass == '1' && (this.orgType != '1001' && this.orgType != '1002')) {
let masterBdAdapter = this.view.vm['ep_dsMaster'];
masterBdAdapter.setEditorEditable('JsEtpCode', false);
}
return this.super('afterEdit');
};
//保存前校验
Biz.prototype.beforeSave = function () {
let self = this;
let curRow = this.dsMaster.currentRow;
let qkTotal = TypeUtil.toFloat(curRow.QkTotal);
let pdTotal = TypeUtil.toFloat(curRow.PdTotal);
let orgCode = TypeUtil.toString(curRow.OrgCode);
let etpCode = TypeUtil.toString(curRow.EtpCode);
let jsEtpCode = TypeUtil.toString(curRow.JsEtpCode);
if(qkTotal < 0) {
Store.messager.err('欠款数量应该是正值。');
return false;
}
if(pdTotal < 0) {
Store.messager.err('铺底数量应该是正值。');
return false;
}
if (self.getState() === 'add') {
let res = Service.CheckEtpExist(orgCode, etpCode);
if (res.result != 1) {
Store.messager.err(res.message);
return false;
}
}
let ret = Service.CheckEtpOrg(etpCode, jsEtpCode);
if (ret.result != 1) {
Store.messager.err(ret.message);
return false;
}
curRow.setColumnValue('LoginDate', new Date(rhtComm.GetServerDateTime(0)).format('yyyy-MM-dd'));
return this.super('beforeSave');
};
Biz.prototype.beforeEdit = function () {
this.dsMaster.getColumn('OrgCode').set('isEditable',false);
this.dsMaster.getColumn('EtpCode').set('isEditable',false);
this.dsMaster.getColumn('EtpAttribute').set('isEditable',false);
return this.super('beforeEdit');
};
//删除前执行
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);
if(ywStatus != '0' && etpAttribute == '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 == 'convert') {
let ds = self.dsMaster;
this.onTypeUtil(self, ds);
}
if (opCode == 'preabandon') {
let ds = self.dsMaster;
this.onPreabandon(self, ds);
}
if (opCode == 'abandon') {
let ds = self.dsMaster;
this.onAbandon(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.EtpAllSupToAudit(orgCode, etpCode, '0', '0', '', '供应商管理');
if (ret.result != 1) {
Store.messager.err(ret.message);
return false;
}
Store.messager.tip('启用成功!');
biz.dsMaster.updateRow();
}
//转化
Biz.prototype.onTypeUtil = 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.onPreabandon = 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.EtpSupplierChangeState(orgCode, etpCode, 'PrePass');
if (ret.result != 1) {
Store.messager.err('预淘汰失败:' + ret.message);
return false;
}
Store.messager.tip('预淘汰成功!');
biz.dsMaster.updateRow();
}
//淘汰
Biz.prototype.onAbandon = 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.EtpSupplierChangeState(orgCode, etpCode, 'Pass');
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.EtpSupplierChangeState(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.EtpSupplierChangeState(orgCode, etpCode, 'Recall');
if (ret.result != 1) {
Store.messager.err('恢复失败:' + ret.message);
return false;
}
Store.messager.tip('恢复成功!');
biz.dsMaster.updateRow();
}
return Biz;
});