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.

347 lines
16 KiB

define(function (require, exports, module) {
let BaseBiz = require('apps/rht/base/rhtBiz');
let Service = require('./dst200109service');
let rhtComm = require('../../comm/rhtComm');
/**
* 控制按钮的可用
* @param opCode 按钮编码
* @return [description]
*/
function Biz(vm) {
//继承第一步,构造继承
BaseBiz.call(this, vm);
vm.remark =''
}
//继承第二步,方法继承
inherits(Biz, BaseBiz);
let gbCheck = "1";
let Dst_PsCyDefCk = rhtComm.getRhtOptionValue('*','DST','Dst_PsCyDefCk','0');
//编辑后
Biz.prototype.afterEdit = function () {
let masterRow = this.dsMaster.currentRow;
let sBillType = TypeUtil.toString(masterRow['BillType']);
let fOriCyCount = TypeUtil.toFloat(masterRow['OriCyCount']);
if (sBillType == "1"){
this.dsDetail.allowDel = false;
this.dsDetail.allowEdit = false;
this.dsDetail.allowInsert = false;
}
else{
this.dsDetail.allowDel = true;
this.dsDetail.allowEdit = true;
this.dsDetail.allowInsert = true;
}
if (fOriCyCount != 0){
this.dsMaster.getColumn('CyYy').set('isEditable',false);
this.dsDetail.getColumn('CyYy').set('isEditable',false);
}
else{
this.dsMaster.getColumn('CyYy').set('isEditable',true);
this.dsDetail.getColumn('CyYy').set('isEditable',true);
}
return this.super('afterEdit');
};
//保存前校验
Biz.prototype.beforeSave = function () {
let masterRow = this.dsMaster.currentRow;
if(masterRow){
let iErrCount = 0;
for (let i=0;i<this.dsDetail.rows.length;i++){
let row = this.dsDetail.rows[i];
let fCyCount = TypeUtil.toFloat(row['CyCount']);
if (fCyCount == 0) {
iErrCount = iErrCount + 1;
}
}
if (iErrCount > 0){
if (!Store.confirm("此单据存在商品差异数量等于零的数据,是否继续保存?")) {
return false;
}
}
}
return this.super('beforeSave');
};
//新增行后处理,默认值已经处理
Biz.prototype.afterNewRow = function (dataSrc, newRow) {
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
let masterRow = this.dsMaster.currentRow;
let sCyYy = masterRow ? TypeUtil.toString(masterRow['CyYy']) : '';
let sCkCode = masterRow ? TypeUtil.toString(masterRow['CkCode']) : '';
if (sCyYy.length > 0){
newRow.setColumnText('CyYy', sCyYy);
}
newRow.setColumnText('CkCode', sCkCode);
}
this.super('afterNewRow', dataSrc, newRow);
};
//明细行单行提交触发的校验
Biz.prototype.dataRowValidate = function (dataSrc, dr) {
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
let sPluCode = TypeUtil.toString(dr['PluCode']);
if (gbCheck == "1"){
if (sPluCode.length > 0) {
let masterRow = this.dsMaster.currentRow;
let ret= Service.getSlideMenuData("DoOnDetailCalcRule","dataRowValidate", masterRow.getData(), dr.getData(), "","","");
if (ret.result !== 1) {
return ret.message;
}
}
else{
return '商品编码不能为空!';
}
}
}
return true;
};
//校验小数精度
Biz.prototype.getPrecision = function (dataSrc, dr, dc, defaultPrecision) {
if (dataSrc.uiObjCode == this.dsDetail.uiObjCode) {
if (gbCheck == "1"){
//把这里改成需要控制的字段
if ((dc.fieldName == 'CyCount') || (dc.fieldName == 'CsCount')) {
return TypeUtil.toInt(dr['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 'RefBillNo':
this.fieldChangedRefBillNo(dataSrc, dr, dc);
break;
case 'CyYy':
this.fieldChangedCyYy(dataSrc, dr, dc);
break;
}
}
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
switch (dc.fieldName) {
case 'PluCode':
this.fieldChangedPluCode(dataSrc, dr, dc);
break;
case 'PluType':
this.fieldChangedPluType(dataSrc, dr, dc);
break;
case 'CyCount':
this.fieldChangedCyCsCount(dataSrc, dr, dc);
break;
case 'CsCount':
this.fieldChangedCyCsCount(dataSrc, dr, dc);
break;
case 'CyYy':
this.fieldChangedBodyCyYy(dataSrc, dr, dc);
break;
}
}
this.super('fieldChanged');
};
//RefBillNo 字段变化执行事件
Biz.prototype.fieldChangedRefBillNo = function (dataSrc, dr, dc) {
let sRefBillNo = dr ? TypeUtil.toString(dr['RefBillNo']) : '';
if (sRefBillNo.length > 0) {
let sZrr = TypeUtil.toString(dr['Zrr']);
if (sZrr.length <= 0){
dr.setColumnError('BillNo','请先输入责任人!');
dr.setColumnText('RefBillNo', '');
return false;
}
let sCyYy = dr ? TypeUtil.toString(dr['CyYy']) : '';
let sShOrgCode = dr ? TypeUtil.toString(dr['ShOrgCode']) : '';
let sBillType = dr ? TypeUtil.toString(dr['BillType']) : '';
//调取服务端插件获取参照主表表数据
let retHead= Service.getSlideMenuData("getRefBill","Head",sRefBillNo,"","","","");
//如果没有结果报错并结束
if (retHead.result !== 1){
dr.setColumnError('BillNo',retHead.message);
dr.setColumnText('RefBillNo', '');
return false;
}
else{
dr.setColumnValue('ShOrgCode', retHead.data[0].shorgcode);
dr.setColumnValue('ShOrgName', retHead.data[0].shorgname);
if (Dst_PsCyDefCk == "1"){
dr.setColumnValue('CkCode', retHead.data[0].ckcode);
dr.setColumnValue('CkName', retHead.data[0].ckname);
}
else if (Dst_PsCyDefCk == "2"){
let ret= Service.getSlideMenuData("DoOnMasterCalcRule","UQueryCkCode", sRefBillNo, sShOrgCode, "0",sCyYy,"");
if (ret.result === 1) {
dr.setColumnText('CkCode', ret.message);
}
}
let sCkCode = dr ? TypeUtil.toString(dr['CkCode']) : '';
if (sCkCode.length <= 0){
dr.setColumnError('BillNo','主表仓库不能为空!');
dr.setColumnText('RefBillNo', '');
return false;
}
//调取服务端插件获取明细表数据
let retBody= Service.getSlideMenuData("getRefBill","Body",sRefBillNo,"","","","");
//如果没有结果报错并结束
if (retBody.result !== 1){
dr.setColumnError('BillNo',retBody.message);
dr.setColumnText('RefBillNo', '');
return false;
}
else{
if (sBillType == "1"){
gbCheck = "0";
//首先清空明细表
this.dsDetail.deleteAll();
//循环插入记录
for(let i = 0; i <= retBody.data.length - 1; i++){
let drdetail = this.dsDetail.addRow();
drdetail.setColumnValue('SerialNo', retBody.data[i].serialno)
drdetail.setColumnValue('PluID', retBody.data[i].pluid);
drdetail.setColumnText('PluCode', retBody.data[i].plucode);
drdetail.setColumnValue('PluName', retBody.data[i].pluname);
drdetail.setColumnValue('ExPluCode',retBody.data[i].explucode);
drdetail.setColumnValue('ExPluName',retBody.data[i].expluname);
drdetail.setColumnValue('PsPrice',parseFloat(retBody.data[i].psprice).round(4));
drdetail.setColumnValue('PsTotal',parseFloat(retBody.data[i].pstotal).round(2));
if (sCyYy.length > 0){
drdetail.setColumnText('CyYy',sCyYy);
}
drdetail.setColumnText('PluType',retBody.data[i].plutype);
drdetail.setColumnValue('CyCount',parseFloat(retBody.data[i].pscount).round(4));
drdetail.setColumnValue('CsCount',"0");
drdetail.setColumnValue('DotDecimal',retBody.data[i].dotdecimal);
}
gbCheck = "1";
}
}
}
}
return true;
};
//CyYy 字段变化执行事件
Biz.prototype.fieldChangedCyYy = function (dataSrc, dr, dc) {
let sCyYy = dr ? TypeUtil.toString(dr['CyYy']) : '';
let sRefBillNo = dr ? TypeUtil.toString(dr['RefBillNo']) : '';
let sShOrgCode = dr ? TypeUtil.toString(dr['ShOrgCode']) : '';
if (Dst_PsCyDefCk == "2"){
if (sRefBillNo.length > 0){
let ret= Service.getSlideMenuData("DoOnMasterCalcRule","UQueryCkCode", sRefBillNo, sShOrgCode, "0",sCyYy,"");
if (ret.result === 1) {
dr.setColumnText('CkCode', ret.message);
}
}
}
return true;
};
//PluCode 字段变化执行事件
Biz.prototype.fieldChangedPluCode = function (dataSrc, dr, dc) {
let masterRow = this.dsMaster.currentRow;
let sPluCode = dr ? TypeUtil.toString(dr['PluCode']) : '';
let sPluID = dr ? TypeUtil.toString(dr['PluID']) : '';
if (sPluCode === '') return false;
let JSONObject={PluCode:sPluCode,PluID:sPluID,FieldNameGrp:"DotDecimal",FieldCount:1};
let retPlu = Service.getSlideMenuData("pubsysBaseBL","USkuGetPluPropInfo",JSONObject,"","","","");
if (retPlu.result === 1) {
if (retPlu.data != null) {
dr.setColumnValue('DotDecimal', retPlu.data.DotDecimal);
}
}
else{
dr.setColumnError('BillNo', retPlu.message);
dr.setColumnValue('PluCode', "");
dr.setColumnValue('PluName', "");
dr.setColumnValue('PsPrice', "0");
return false;
}
if (Dst_PsCyDefCk == "2"){
let sCyYy = dr ? TypeUtil.toString(dr['CyYy']) : '';
let sRefBillNo = masterRow ? TypeUtil.toString(masterRow['RefBillNo']) : '';
let sShOrgCode = masterRow ? TypeUtil.toString(masterRow['ShOrgCode']) : '';
if (sRefBillNo.length > 0){
let ret= Service.getSlideMenuData("DoOnMasterCalcRule","UQueryCkCode", sRefBillNo, sShOrgCode, sPluID,sCyYy,"");
if (ret.result === 1) {
dr.setColumnText('CkCode', ret.message);
}
}
}
dr.setColumnText('PluType', "0");
let fPsPrice = TypeUtil.toFloat(dr['PsPrice']);
let fCyCount = TypeUtil.toFloat(dr['CyCount']);
dr.setColumnValue('PsTotal', (fPsPrice*fCyCount).round(2));
return true;
};
//PluType 字段变化执行事件
Biz.prototype.fieldChangedPluType = function (dataSrc, dr, dc) {
let sPluCode = dr ? TypeUtil.toString(dr['PluCode']) : '';
if (sPluCode === '') return false;
if (gbCheck == "1"){
let masterRow = this.dsMaster.currentRow;
let sRefBillNo = masterRow ? TypeUtil.toString(masterRow['RefBillNo']) : '';
let sPluType = dr ? TypeUtil.toString(dr['PluType']) : '';
let fCyCount = TypeUtil.toFloat(dr['CyCount']);
let ret= Service.getSlideMenuData("DoOnDetailCalcRule","PluType", sRefBillNo, sPluCode, sPluType,"","");
if (ret.result !== 1) {
dr.setColumnError('BillNo',ret.message);
return false;
}
else{
if (ret.data != null){
let fPsPrice = TypeUtil.toFloat(ret.data.psprice);
dr.setColumnValue('PsPrice', fPsPrice);
dr.setColumnValue('PsTotal', (fCyCount*fPsPrice).round(2));
}
}
}
return true;
};
//CyCsCount 字段变化执行事件
Biz.prototype.fieldChangedCyCsCount = function (dataSrc, dr, dc) {
let sPluCode = dr ? TypeUtil.toString(dr['PluCode']) : '';
let sPluID = dr ? TypeUtil.toString(dr['PluID']) : '';
if (gbCheck == "1"){
if (sPluCode === ''){
dr.setColumnError(dc.fieldName, "请先录入商品!");
return false;
}
let JSONObject={PluCode:sPluCode,PluID:sPluID,FieldNameGrp:"DotDecimal",FieldCount:1};
let retPlu = Service.getSlideMenuData("pubsysBaseBL","USkuGetPluPropInfo",JSONObject,"","","","");
if (retPlu.result === 1) {
if (retPlu.data != null) {
dr.setColumnValue('DotDecimal', retPlu.data.DotDecimal);
}
}
else{
dr.setColumnError('BillNo', retPlu.message);
dr.setColumnValue('PluCode', "");
dr.setColumnValue('PluName', "");
dr.setColumnValue('PsPrice', "0");
return false;
}
}
let fPsPrice = TypeUtil.toFloat(dr['PsPrice']);
let fPrice = TypeUtil.toFloat(dr['Price']);
let fCyCount = TypeUtil.toFloat(dr['CyCount']);
dr.setColumnValue('PsTotal', (fPsPrice*fCyCount).round(2));
dr.setColumnValue('STotal', (fPrice*fCyCount).round(2));
return true;
};
//CyYy 字段变化执行事件
Biz.prototype.fieldChangedBodyCyYy = function (dataSrc, dr, dc) {
let sCyYy = dr ? TypeUtil.toString(dr['CyYy']) : '';
if ((sCyYy == "0") || (sCyYy == "3") || (sCyYy == "7")){
dr.setColumnValue('IsPk', "1");
}
else{
dr.setColumnValue('IsPk', "0");
}
return true;
};
return Biz;
});