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.

268 lines
9.5 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 Service = require('./cnt070104service');
/**
* 定义业务类对象
* @param vm 界面相关ViewModule
*/
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.dsMaster.serverBiz = 'cntLxPeriodBiz'
// }
//拼装查询条件
Biz.prototype.beforeDataSrcSearch = function (dataSrc, params) {
let self = this;
self.setServerBiz('cn.qdhezheng.rht.app.cnt.cnt070104.PreProcess');
};
//控制主界面按钮状态
Biz.prototype.getOpEnabled = function (opCode) {
let self = this;
let isOk = this.super('getOpEnabled', opCode);
if (!isOk) return false;
let curRow = this.dsMaster.currentRow;
let orgCode = curRow ? TypeUtil.toString(curRow.OrgCode) : '';
if (opCode == 'edit') {
if (!curRow)
return false;
if(orgType == '9999')
return true;
if (orgCode != Store.logOn.orgCode)
return false;
}
if (opCode == 'delete') {
if (!curRow)
return false;
if(orgType == '9999')
return true;
if (orgCode != Store.logOn.orgCode)
return false;
}
if (opCode == 'auto') {
if (!curRow)
return false;
if(self.getState() === 'edit') {
return false
}
if(orgType == '9999')
return true;
if (orgCode != Store.logOn.orgCode)
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) {
}
}else if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
let currentRow = self.dsMaster.currentRow;
if (currentRow === null) return false;
this.fieldChangedMx(dataSrc, dr, dc);
}
return this.super('fieldChanged');
};
Biz.prototype.fieldChangedMx = function (dataSrc, dr, dc) {
let isJs = TypeUtil.toString(dr.IsJs);
if(isJs == '1') {
dr.setColumnError('PeriodCode', '此结算期已对账不能修改!');
return false;
}
return true;
};
//按钮事件控制
Biz.prototype.doOp = function (opCode) {
let self = this;
if (opCode == 'auto') {
let ds = self.dsMaster;
this.onAuto(self, ds);
}
};
Biz.prototype.onAuto = function (biz, ds) {
let dsrow=ds.currentRow;
let cntId = dsrow ? TypeUtil.toString(dsrow['CntID']) : '';
let htCode = dsrow ? TypeUtil.toString(dsrow['HtCode']) : '';
let htName = dsrow ? TypeUtil.toString(dsrow['HtName']) : '';
if (!Store.confirm('您确认要生成合同' + htCode + '-' + htName + '的联销结算期吗?')) {
return false;
}else {
let actRes= Service.AutoGenLxPeriod(cntId);
if (actRes.result !== 1) {
Store.messager.err('生成失败!' + actRes.message);
return false;
}else {
Store.messager.tip('生成成功!');
}
}
return true;
};
Biz.prototype.beforeEdit = function () {
this.dsMaster.columns.forEach(v => {
v.set('isEditable',false);
})
return this.super('beforeEdit');
};
//保存前校验
Biz.prototype.beforeSave = function () {
if(!this.ChkCntLxTcJsPeriod(false)) {
return false;
}
return this.super('beforeSave');
};
Biz.prototype.ChkCntLxTcJsPeriod = function (onlyChkCurrentRow) {
if(this.dsDetail.rows.length < 1) {
return true;
}
let cntStartDate = TypeUtil.toString(this.dsMaster.currentRow.StartDate);
let cntEndDate = TypeUtil.toString(this.dsMaster.currentRow.EndDate);
let bdDate = TypeUtil.toString(this.dsMaster.currentRow.BdDate);
if(bdDate == '') {
bdDate = cntStartDate;
}
if(onlyChkCurrentRow) {
if(!this.ChkJsPeriodInput(cntStartDate, cntEndDate, this.dsDetail.currentRow)) {
return false;
}
}else {
let minStartDate = TypeUtil.toString(this.dsDetail.rows[0].BgnDate);
for(let i = 1; i < this.dsDetail.rows.length; i++) {
let bgnDate = TypeUtil.toString(this.dsDetail.rows[i].BgnDate);
if(minStartDate > bgnDate) {
minStartDate = bgnDate;
}
if(!this.ChkJsPeriodInput(cntStartDate, cntEndDate, this.dsDetail.rows[i])) {
return false;
}
}
if(minStartDate != bdDate) {
Store.messager.err('结算期最小开始日期' + minStartDate + '应该与保底开始日期' + bdDate + '一致!');
return false;
}
this.dsDetail.rows.sort(this.SortJsPeriod);
let rowBgnDate;
let rowEndDate;
let nextDate = '';
for(let i = 0; i < this.dsDetail.rows.length; i++) {
if(TypeUtil.toString(this.dsDetail.rows[i].PeriodType) == '1') {
continue;
}
rowBgnDate = TypeUtil.toString(this.dsDetail.rows[i].BgnDate);
rowEndDate = TypeUtil.toString(this.dsDetail.rows[i].EndDate);
if(nextDate != '' && nextDate != rowBgnDate) {
Store.messager.err('结算期' + TypeUtil.toString(this.dsDetail.rows[i].PeriodCode) + '日期不连续');
return false;
}
nextDate = rhtComm.DateChangeDays(1, rowEndDate);
}
// 判断多月通算期是否符合要求
for(let i = 0; i < this.dsDetail.rows.length; i++) {
if(TypeUtil.toString(this.dsDetail.rows[i].PeriodType) != '1') {
continue;
}
rowBgnDate = TypeUtil.toString(this.dsDetail.rows[i].BgnDate);
rowEndDate = TypeUtil.toString(this.dsDetail.rows[i].EndDate);
let isBgnDateValid = false;
let isEndDateValid = false;
for(let j = 0; j < this.dsDetail.rows.length; j++) {
if(TypeUtil.toString(this.dsDetail.rows[j].PeriodType) == '1') {
continue;
}
if(TypeUtil.toString(this.dsDetail.rows[j].BgnDate) == rowBgnDate) {
isBgnDateValid = true;
break;
}
}
if(!isBgnDateValid) {
Store.messager.err('结算期' + TypeUtil.toString(this.dsDetail.rows[i].PeriodCode) + '开始日期输入错误(多月结算期的开始日期应该是某个子结算期的开始日期)');
return false;
}
for(let j = 0; j < this.dsDetail.rows.length; j++) {
if(TypeUtil.toString(this.dsDetail.rows[j].PeriodType) == '1') {
continue;
}
if(TypeUtil.toString(this.dsDetail.rows[j].EndDate) == rowEndDate) {
isEndDateValid = true;
break;
}
}
if(!isEndDateValid) {
Store.messager.err('结算期' + TypeUtil.toString(this.dsDetail.rows[i].PeriodCode) + '结束日期输入错误(多月结算期的结束日期应该是某个子结算期的结束日期)');
return false;
}
}
}
return true;
};
Biz.prototype.SortJsPeriod = function (a, b) {
return a.BgnDate - b.BgnDate;
};
Biz.prototype.ChkJsPeriodInput = function (cntStartDate, cntEndDate, jsPeriodRow) {
let jsBgnDate = TypeUtil.toString(jsPeriodRow.BgnDate);
let jsEndDate = TypeUtil.toString(jsPeriodRow.EndDate);
if(jsBgnDate > jsEndDate) {
Store.messager.err('联销结算期结束日期必须大于等于开始日期!');
return false;
}
if(jsBgnDate < cntStartDate || jsBgnDate > cntEndDate) {
Store.messager.err('联销结算期的开始日期应在合同有效期内!');
return false;
}
if(jsEndDate < cntStartDate || jsEndDate > cntEndDate) {
Store.messager.err('联销结算期的结束日期应在合同有效期内!');
return false;
}
return true;
};
return Biz;
});