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.

277 lines
12 KiB

4 years ago
define(function (require, exports, module) {
let BaseBiz = require('apps/rht/base/rhtBiz');
let Service = require('./cou190211service');
let rhtComm = require('../../comm/rhtComm');
/**
* 控制按钮的可用
* @param opCode 按钮编码
* @return [description]
*/
function Biz(vm) {
//继承第一步,构造继承
BaseBiz.call(this, vm);
vm.remark =''
}
//继承第二步,方法继承
inherits(Biz, BaseBiz);
//功能初始化完毕调用该方法
Biz.prototype.initCompleted = function() {
let orgType = rhtComm.GetOrgType(Store.logOn.orgCode);
let COU_ZmDecSpIsYkCount = rhtComm.getRhtOptionValue('*','COU','COU_ZmDecSpIsYkCount','1');
if ((orgType >= '1003') && (orgType <= '1999')){
this.dsMaster.getColumn('OrgCode').set('isEditable',false);
}
if (COU_ZmDecSpIsYkCount != "1"){
this.dsDetail.getColumn('SjCount').set('isEditable',false);
}
else{
this.dsDetail.getColumn('SjCount').set('isEditable',true);
}
return this.super('initCompleted');
};
//明细行单行提交触发的校验
Biz.prototype.dataRowValidate = function (dataSrc, dr) {
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
let masterRow = this.dsMaster.currentRow;
let sYkType = TypeUtil.toString(masterRow['YkType']);
let fYkCount = TypeUtil.toFloat(dr['YkCount']);
let fZmCount = TypeUtil.toFloat(dr['ZmCount']);
let sPluCode = dr ? TypeUtil.toString(dr['PluCode']) : '';
if (sPluCode.length > 0) {
dr.setColumnValue('HzDate', rhtComm.GetServerDateTime(0));
if (fYkCount == 0) {
return "盈亏数量不能等于0";
}
if ((fZmCount+fYkCount) < 0) {
return "盈亏数量不能大于账面数量!";
}
if (sYkType == "1") {
if (fYkCount > 0) {
return "盈亏类型为“盘亏”盈亏数量必须小于0";
}
}
if (sYkType == "2") {
if (fYkCount < 0) {
return "盈亏类型为“盘盈”盈亏数量必须大于0";
}
}
}
}
return true;
};
//校验小数精度
Biz.prototype.getPrecision = function (dataSrc, dr, dc, defaultPrecision) {
if (dataSrc.uiObjCode == this.dsDetail.uiObjCode) {
//把这里改成需要控制的字段
if (dc.fieldName == 'YkCount') {
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 'OrgCode':
this.fieldChangedOrgCode(dataSrc, dr, dc);
break;
}
}
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
switch (dc.fieldName) {
case 'PluCode':
this.fieldChangedPluCode(dataSrc, dr, dc);
break;
case 'DepCode':
this.fieldChangedDepCode(dataSrc, dr, dc);
break;
case 'YkCount':
this.fieldChangedYkCount(dataSrc, dr, dc);
break;
case 'SjCount':
this.fieldChangedSjCount(dataSrc, dr, dc);
break;
}
}
this.super('fieldChanged');
};
//OrgCode 字段变化执行事件
Biz.prototype.fieldChangedOrgCode = function (dataSrc, dr, dc) {
dr.setColumnText('CkCode', "");
dr.setColumnText('DepCode', "");
return true;
};
//PluCode 字段变化执行事件
Biz.prototype.fieldChangedPluCode = function (dataSrc, dr, dc) {
let masterRow = this.dsMaster.currentRow;
let sInOrgCode = masterRow ? TypeUtil.toString(masterRow['InOrgCode']) : '';
let sHeadDepCode = masterRow ? TypeUtil.toString(masterRow['DepCode']) : '';
let sCkCode = masterRow ? TypeUtil.toString(masterRow['CkCode']) : '';
let sPluCode = dr ? TypeUtil.toString(dr['PluCode']) : '';
let sPluID = dr ? TypeUtil.toString(dr['PluID']) : '';
if (sPluCode === '') return false;
dr.setColumnValue('ZmCount', "0");
dr.setColumnText('YkCount', "0");
let ret= Service.getSlideMenuData("DoOnDetailCalcRule","PluCode", sInOrgCode,sHeadDepCode,sCkCode,sPluCode,sPluID);
if (ret.result !== 1) {
dr.setColumnError(dc.fieldName, ret.message);
return false;
}
if (ret.data != null) {
dr.setColumnValue('Price', ret.data.price);
if (ret.data.depcode.length > 0){
dr.setColumnValue('DepID', ret.data.depid);
dr.setColumnText('DepCode', ret.data.depcode);
dr.setColumnValue('ExPluCode', ret.data.explucode);
}
}
if (dr['DepID'].length > 0){
let MRow = masterRow.getData();
let DRow = dr.getData();
let retGetPluKc= Service.getSlideMenuData("DoOnDetailCalcRule","GetPluKc", MRow,DRow,"","","");
if (retGetPluKc.result !== 1) {
dr.setColumnError(dc.fieldName, retGetPluKc.message);
return false;
}
if (retGetPluKc.data != null) {
let fZmCount = TypeUtil.toFloat(retGetPluKc.data.kccount);
let fHJPrice = TypeUtil.toFloat(retGetPluKc.data.hjprice);
let fWJPrice = TypeUtil.toFloat(retGetPluKc.data.wjprice);
dr.setColumnValue('ZmCount', retGetPluKc.data.kccount);
dr.setColumnValue('HJPrice', fHJPrice);
dr.setColumnValue('WJPrice', fWJPrice);
dr.setColumnValue('ZmHCost', (fZmCount*fHJPrice).round(2));
dr.setColumnValue('ZmWCost', (fZmCount*fWJPrice).round(2));
dr.setColumnValue('ZmSCost', (fZmCount*TypeUtil.toFloat(dr['Price'])).round(2));
}
}
return true;
};
//DepCode 字段变化执行事件
Biz.prototype.fieldChangedDepCode = function (dataSrc, dr, dc) {
let masterRow = this.dsMaster.currentRow;
let sInOrgCode = masterRow ? TypeUtil.toString(masterRow['InOrgCode']) : '';
let sPluCode = dr ? TypeUtil.toString(dr['PluCode']) : '';
let sDepCode = dr ? TypeUtil.toString(dr['DepCode']) : '';
let sPluID = dr ? TypeUtil.toString(dr['PluID']) : '';
let sDepID = dr ? TypeUtil.toString(dr['DepID']) : '';
if (sPluCode === '') return false;
if (sDepCode === '') return false;
let ret= Service.getSlideMenuData("DoOnDetailCalcRule","DepCode", sInOrgCode,sDepID,sPluID,"","");
if (ret.result !== 1) {
dr.setColumnError(dc.fieldName, ret.message);
return false;
}
dr.setColumnValue('ZmCount', "0");
dr.setColumnText('YkCount', "0");
let MRow = masterRow.getData();
let DRow = dr.getData();
let retGetPluKc= Service.getSlideMenuData("DoOnDetailCalcRule","GetPluKc", MRow,DRow,"","","");
if (retGetPluKc.result !== 1) {
dr.setColumnError(dc.fieldName, retGetPluKc.message);
return false;
}
if (retGetPluKc.data != null) {
let fZmCount = TypeUtil.toFloat(retGetPluKc.data.kccount);
let fHJPrice = TypeUtil.toFloat(retGetPluKc.data.hjprice);
let fWJPrice = TypeUtil.toFloat(retGetPluKc.data.wjprice);
dr.setColumnValue('ZmCount', retGetPluKc.data.kccount);
dr.setColumnValue('HJPrice', fHJPrice);
dr.setColumnValue('WJPrice', fWJPrice);
dr.setColumnValue('ZmHCost', (fZmCount*fHJPrice).round(2));
dr.setColumnValue('ZmWCost', (fZmCount*fWJPrice).round(2));
dr.setColumnValue('ZmSCost', (fZmCount*TypeUtil.toFloat(dr['Price'])).round(2));
}
return true;
};
//YkCount 字段变化执行事件
Biz.prototype.fieldChangedYkCount = function (dataSrc, dr, dc) {
let fYkCount = TypeUtil.toFloat(dr['YkCount']);
let fZmCount = TypeUtil.toFloat(dr['ZmCount']);
let sPluCode = dr ? TypeUtil.toString(dr['PluCode']) : '';
let fHJPrice = TypeUtil.toFloat(dr['HJPrice']);
let fWJPrice = TypeUtil.toFloat(dr['WJPrice']);
let fPrice = TypeUtil.toFloat(dr['Price']);
if (sPluCode === '') return false;
if (sPluCode.length > 0)
{
let fKyTmp= Math.abs((100*fYkCount)/fZmCount);
let fYkRate = 0.0;
if ((fZmCount == 0) || ((fZmCount != 0) && (fKyTmp > 100))){
if (fYkCount > 0){
fYkRate = 1;
}
else{
fYkRate = -1;
}
}
else{
fYkRate = fYkCount/fZmCount;
}
dr.setColumnValue('YkRate', (fYkRate*100).round(2));
let fYkHCost = (fHJPrice*fYkCount).round(2);
let fYkWCost = (fWJPrice*fYkCount).round(2);
let fYkSCost = (fPrice*fYkCount).round(2);
let fSjHCost = TypeUtil.toFloat(dr['ZmHCost'])+TypeUtil.toFloat(fYkHCost);
let fSjWCost = TypeUtil.toFloat(dr['ZmWCost'])+TypeUtil.toFloat(fYkWCost);
let fSjSCost = TypeUtil.toFloat(dr['ZmSCost'])+TypeUtil.toFloat(fYkSCost);
dr.setColumnValue('YkHCost', fYkHCost);
dr.setColumnValue('YkWCost', fYkWCost);
dr.setColumnValue('YkSCost', fYkSCost);
dr.setColumnValue('SjCount', (fZmCount+fYkCount));
dr.setColumnValue('SjHCost', fSjHCost.round(2));
dr.setColumnValue('SjWCost', fSjWCost.round(2));
dr.setColumnValue('SjSCost', fSjSCost.round(2));
}
return true;
};
//SjCount 字段变化执行事件
Biz.prototype.fieldChangedSjCount = function (dataSrc, dr, dc) {
let fSjCount = TypeUtil.toFloat(dr['SjCount']);
let fZmCount = TypeUtil.toFloat(dr['ZmCount']);
let sPluCode = dr ? TypeUtil.toString(dr['PluCode']) : '';
if (sPluCode === '') return false;
if (COU_ZmDecSpIsYkCount == "1")
{
dr.setColumnValue('YkCount', (fSjCount-fZmCount));
}
return true;
};
//按钮事件控制
Biz.prototype.doOp = function (opCode) {
if (opCode == 'acttz') {
this.opRouter('edit');
}
};
//控制主界面按钮状态
Biz.prototype.getOpEnabled = function (opCode) {
let isOk = this.super('getOpEnabled', opCode);
if (!isOk) {
return false;
}
let curRow = this.dsMaster.currentRow;
let sDataStatus = curRow ? TypeUtil.toString(curRow['DataStatus']) : '';
if (opCode == 'acttz'){
if (!curRow)
return false;
if (this.isEdit())
return false;
if ((sDataStatus == "Z") || (sDataStatus == "9"))
return false;
}
return true;
};
return Biz;
});