define(function (require, exports, module) { let BaseBiz = require('apps/rht/base/rhtBiz'); let rhtComm = require('apps/rht/comm/rhtComm'); let service = require('./sys010104service'); var BgnDate = require('./BgnDate'); /** * 控制按钮的可用 * @param opCode 按钮编码 * @return [description] */ function Biz(vm) { //继承第一步,构造继承 BaseBiz.call(this, vm); vm.remark = '' } //继承第二步,方法继承 inherits(Biz, BaseBiz); Biz.prototype.initCompleted = function () { this.super('initCompleted'); this.dsMaster.serverBiz = 'acctMonthBiz' this.currDate = rhtComm.GetServerDate(0); this.isNewYear = false; this.isFirstYrea = false; this.lastAcctYear = ''; this.lastAcctMonth = ''; this.lastBgnDate = ''; this.lastEndDate = ''; this.dtBgnDate = ''; this.dtLastDay = ''; this.newAcctYear = ''; this.nextAcctMonth = ''; this.getMaxAcctData(); }; //控制主界面按钮状态 Biz.prototype.getOpEnabled = function (opCode) { var self = this; var isOk = this.super('getOpEnabled', opCode); if (!isOk) return false; // var curRow = this.dsMaster.currentRow; // var currYear = curRow ? TypeUtil.toString(curRow['AcctYear']) : ''; // var currMonth = curRow ? TypeUtil.toString(curRow['AcctMonth']) : ''; // if (opCode == 'add') { // } // if (opCode == 'edit') { // if(currYear !== this.lastAcctYear || currMonth !== this.lastAcctMonth) { // return false; // } // } // if (opCode == 'delete') { // if(currYear !== this.lastAcctYear || currMonth !== this.lastAcctMonth) { // return false; // } // } return true; } Biz.prototype.beforeAdd = function () { let self = this; let bgnDate = ''; if(this.isFirstYrea || this.lastAcctMonth === '12') { if (Store.confirm("要增加" + this.newAcctYear + "整年的会计月吗?")) { if(this.isFirstYrea) { let dialogBgnDate = new BgnDate(); dialogBgnDate.callback = function (date) { bgnDate = date; let ret = service.genAcctData(self.newAcctYear, bgnDate); if(ret.result !== 1) { Store.messager.error(ret.message) return false; } Store.messager.tip('增加成功'); self.getMaxAcctData(); } dialogBgnDate.open(); }else { bgnDate = rhtComm.DateChangeDays(1, this.dtLastDay); let ret = service.genAcctData(self.newAcctYear, bgnDate); if(ret.result !== 1) { Store.messager.error(ret.message) return false; } Store.messager.tip('增加成功'); this.getMaxAcctData(); } // 不走常规的增加 return false; }else { this.isNewYear = true; } }else { this.isNewYear = false; this.nextAcctMonth = TypeUtil.toString(TypeUtil.toInt(this.lastAcctMonth) + 1); if(TypeUtil.toInt(this.nextAcctMonth) < 10) { this.nextAcctMonth = '0' + this.nextAcctMonth; } if(this.nextAcctMonth > '12') { Store.messager.tip(lastAcctYear + '年度会计月已满12个月不能再增加!'); return false; } } this.dsMaster.getColumn('AcctYear').set('isEditable',false); this.dsMaster.getColumn('AcctYear').set('isEditable',false); if(this.isFirstYrea) { this.dsMaster.getColumn('BgnDate').set('isEditable',true); }else { this.dsMaster.getColumn('BgnDate').set('isEditable',false); } return this.super('beforeAdd'); }; Biz.prototype.afterAdd = function () { let dr = this.dsMaster.currentRow; if(this.isNewYear) { dr.setColumnValue('AcctYear', this.newAcctYear); dr.setColumnValue('AcctMonth', '01'); }else { dr.setColumnValue('AcctYear', this.lastAcctYear); dr.setColumnValue('AcctMonth', this.nextAcctMonth); } const newBgnDate = rhtComm.DateChangeDays(1, this.dtLastDay); dr.setColumnValue('BgnDate', newBgnDate); dr.setColumnValue('EndDate', this.nextAcctMonth); return this.super('afterAdd'); }; Biz.prototype.beforeSave = function () { let dr = this.dsMaster.currentRow; if(dr.EndDate < dr.BgnDate) { dr.setColumnError('EndDate', '结束日期不能早于开始日期!'); return false; } if(this.getState() === 'edit' && dr.EndDate < this.currDate) { dr.setColumnError('EndDate', '结束日期不能早于当前日期!'); return false; } return this.super('beforeSave'); }; Biz.prototype.afterSave = function () { this.getMaxAcctData(); return this.super('afterSave'); }; Biz.prototype.beforeEdit = function () { if(this.dsMaster.currentRow.EndDate < this.currDate) { Store.messager.tip('当前月份已经结束,不可修改'); return false; } var currYear = this.dsMaster.currentRow['AcctYear']; var currMonth = this.dsMaster.currentRow['AcctMonth']; if(currYear !== this.lastAcctYear || currMonth !== this.lastAcctMonth) { Store.messager.tip('不是最后一个会计月,不可修改'); return false; } this.dsMaster.getColumn('AcctYear').set('isEditable',false); this.dsMaster.getColumn('AcctYear').set('isEditable',false); this.dsMaster.getColumn('BgnDate').set('isEditable',false); return this.super('beforeEdit'); }; Biz.prototype.beforeDelete = function () { if(this.dsMaster.currentRow.EndDate < this.currDate) { Store.messager.tip('当前月份已经结束,不可删除'); return false; } if(this.dsMaster.currentRow.BgnDate < this.currDate) { Store.messager.tip('当前月份已经开始,不可删除'); return false; } var currYear = this.dsMaster.currentRow['AcctYear']; var currMonth = this.dsMaster.currentRow['AcctMonth']; if(currYear !== this.lastAcctYear || currMonth !== this.lastAcctMonth) { Store.messager.tip('不是最后一个会计月,不可修改'); return false; } return this.super('beforeDelete'); }; Biz.prototype.afterDelete = function () { this.getMaxAcctData(); return this.super('afterDelete'); }; /** * @description 数据发生变化时调用 * @param dataSrc 数据集 * @param dr 数据行 * @param dc 数据列 */ Biz.prototype.fieldChanged = function (dataSrc, dr, dc) { var self = this; if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) { var currentRow = self.dsMaster.currentRow; if (currentRow === null) return false; switch (dc.fieldName) { case 'EndDate': this.fieldChangedEndDate(dataSrc, dr, dc); break; } } return this.super('fieldChanged'); }; // 字段变化执行事件 Biz.prototype.fieldChangedEndDate = function (dataSrc, dr, dc) { if(dr.EndDate < dr.BgnDate) { dr.setColumnError('EndDate', '结束日期不能早于开始日期!'); return false; } if(this.getState() === 'edit' && dr.EndDate < this.currDate) { dr.setColumnError('EndDate', '结束日期不能早于当前日期!'); return false; } return true; }; Biz.prototype.getMaxAcctData = function () { var ret = service.getMaxAcctData(); if(ret.result !== 1) { Store.messager.error(ret.message) return false; }else { if(ret.data.length > 0) { this.isFirstYrea = false; this.lastAcctYear = TypeUtil.toString(ret.data[0].acctyear); this.lastAcctMonth = TypeUtil.toString(ret.data[0].acctmonth); this.lastBgnDate = TypeUtil.toString(ret.data[0].bgndate); this.lastEndDate = TypeUtil.toString(ret.data[0].enddate); this.dtBgnDate = TypeUtil.toString(ret.data[0].bgndate); this.dtLastDay = TypeUtil.toString(ret.data[0].enddate); this.newAcctYear = TypeUtil.toString(TypeUtil.toInt(this.lastAcctYear) + 1); }else { this.isFirstYrea = true; this.dtBgnDate = this.currDate; this.dtLastDay = this.currDate; this.newAcctYear = TypeUtil.toString(TypeUtil.toInt(this.currDate.substring(0, 4))); } } }; return Biz; });