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.

381 lines
16 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

define(function (require, exports, module) {
//引入业务类基类
let BaseBiz = require('apps/rht/base/rhtBiz');
let rhtComm = require('apps/rht/comm/rhtComm');
//引入业务服务
let Service = require('./pri10020202service');
/**
* 定义业务类对象
* @param vm 界面相关ViewModule
*/
function Biz(vm) {
//继承第一步,构造继承
BaseBiz.call(this, vm);
}
//继承第二步,方法继承
inherits(Biz, BaseBiz);
/**
* 全局变量
*/
let FIsTjType = "0";
let PluMlLimit = rhtComm.getRhtOptionValue("*",'CAT','PluMlLimit','0');
Biz.prototype.beforeFieldEdit = function(dataSrc, dr, dc) {
let masterRow = this.dsMaster.currentRow;
// 0-售价1-成本配送价2-加点配送价3-固定价配送价4-自由价配送价
let PriceType = TypeUtil.toString(masterRow['PriceType']);
if (dataSrc.uiObjCode == this.dsDetail.uiObjCode) {
if (dc.fieldName == 'NewPrice') {
if (PriceType !== '3') {
return false;
}
}
if (dc.fieldName == 'TzRate') {
if (PriceType !== '2') {
return false;
}
}
}
return this.super('beforeFieldEdit', dataSrc, dr, dc);
};
//保存前校验 计算主表合计数量等字段
Biz.prototype.beforeSave = function () {
let curRow = this.dsMaster.currentRow;
if(curRow){
let JgZcCode = TypeUtil.toString(curRow['JgZcCode']);
let BillType = TypeUtil.toString(curRow['BillType']);
let TzDate = TypeUtil.toString(curRow['TzDate']);
if (BillType == "1"){
if (TzDate < new Date(rhtComm.GetServerDateTime(0)).format('yyyy-MM-dd')){
curRow.setColumnError('TzDate', '输入错误,调整日期应大于当前日期!');
return false;
}
}
let retUsed= Service.getSlideMenuData("OtherProcess","UJgzcIsUsed",JgZcCode,"1",Store.logOn.orgCode,"","");
if (retUsed.result !== 0) {
curRow.setColumnError('JgZcCode', '售价政策已被使用不能再编辑!');
return false;
}
for(let i=0;i<this.dsDetail.rows.length;i++){
let row = this.dsDetail.rows[i];
let PluCode = TypeUtil.toString(row['PluCode']);
let PluName = TypeUtil.toString(row['PluName']);
let NewPrice = TypeUtil.toFloat(row['Price']);
if (PluMlLimit == "1"){
let ret= Service.getSlideMenuData("OtherProcess","ChkMlRate",PluCode,"","","","");
if (ret.result === 1) {
if (ret.data != null) {
let curMinMlRate=TypeUtil.toFloat(ret.data.MinMlRate);
let curMaxMlRate=TypeUtil.toFloat(ret.data.MaxMlRate);
let HjPrice=TypeUtil.toFloat(ret.data.HjPrice);
if ((curMinMlRate != 0) || (curMaxMlRate != 0) || (NewPrice != 0)){
let curRate = ((NewPrice - HjPrice) * 10000 / NewPrice).round(0) / 100;
if ((curMinMlRate != 0) && (curRate < curMinMlRate)){
if (!Store.confirm("商品["+PluName+"]进价为"+HjPrice+",售价为"+NewPrice+",毛利率为"+curRate+",毛利率低于品类最低毛利率"+curMinMlRate+"的限制,是否继续?")) {
return false;
}
}
if ((curMaxMlRate != 0) && (curRate > curMaxMlRate)){
if (!Store.confirm("商品["+PluName+"]进价为"+HjPrice+",售价为"+NewPrice+",毛利率为"+curRate+",毛利率低于品类最高毛利率"+curMaxMlRate+"的限制,是否继续?")) {
return false;
}
}
}
}
}
}
}
}
return this.super('beforeSave');
};
//明细行单行提交触发的校验
Biz.prototype.dataRowValidate = function (dataSrc, dr) {
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
let masterRow = this.dsMaster.currentRow;
let PluCode = TypeUtil.toString(masterRow['PluCode']);
let Price = TypeUtil.toFloat(dr['Price']);
let HyPrice = TypeUtil.toFloat(dr['HyPrice']);
let NewHyPrice = TypeUtil.toFloat(dr['NewHyPrice']);
if (PluCode.length > 0){
/*if (Price <= 0) {
return "售价应大于零!";
}*/
if (HyPrice > Price) {
return "会员价不应大于售价.";
}
if (NewHyPrice < 0) {
return "现售价不能小于零,请重新录入!";
}
}
}
return true;
};
//单据删除前处理
Biz.prototype.beforeDelete = function () {
let masterRow = this.dsMaster.currentRow;
let JgZcCode = TypeUtil.toString(masterRow['JgZcCode']);
if (masterRow){
let ret= Service.getSlideMenuData("OtherProcess","UJgzcIsUsed",JgZcCode,"1",Store.logOn.orgCode,"","");
if (ret.result !== 0) {
masterRow.setColumnError('JgZcCode', '售价政策已被使用不能被删除!');
return false;
}
}
return this.super('beforeDelete');
};
//编辑后操作
Biz.prototype.afterEdit = function () {
let masterRow = this.dsMaster.currentRow;
if (masterRow){
let BillType = TypeUtil.toString(masterRow['BillType']);
if (BillType == "0") {
masterRow.setColumnValue('TzDate', new Date(rhtComm.GetServerDateTime(0)).format('yyyy-MM-dd'));
}
}
return this.super('afterEdit');
};
/**
* @description 数据发生变化时调用
* @param dataSrc 数据集
* @param dr 数据行
* @param dc 数据列
*/
Biz.prototype.fieldChanged = function (dataSrc, dr, dc) {
let self = this;
let currentRow = self.dsMaster.currentRow;
if (currentRow === null) return false;
if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) {
switch (dc.fieldName) {
case 'BillType':
this.fieldChangedBillType(dataSrc, dr, dc);
break;
}
}
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
switch (dc.fieldName) {
case 'PluCode':
this.fieldChangedPluCode(dataSrc, dr, dc);
break;
case 'HyPrice':
this.fieldChangedHyPrice(dataSrc, dr, dc);
break;
case 'NewHyPrice':
this.fieldChangedNewHyPrice(dataSrc, dr, dc);
break;
case 'NewPrice':
this.fieldChangedNewPrice(dataSrc, dr, dc);
break;
case 'TjType':
this.fieldChangedTjType(dataSrc, dr, dc);
break;
}
}
this.super('fieldChanged');
};
//BillType 字段变化执行事件
Biz.prototype.fieldChangedBillType = function (dataSrc, dr, dc) {
let BillType = TypeUtil.toString(dr['BillType']);
if (BillType == "0") {
dr.setColumnValue('TzDate', new Date(rhtComm.GetServerDateTime(0)).format('yyyy-MM-dd'));
}
else{
dr.setColumnValue('TzDate', new Date(rhtComm.GetServerDateTime(1)).format('yyyy-MM-dd'));
}
return true;
};
//PluCode 字段变化执行事件
Biz.prototype.fieldChangedPluCode = function (dataSrc, dr, dc) {
let self = this;
let masterRow = self.dsMaster.currentRow;
let SjZcCode = TypeUtil.toString(masterRow['SjZcCode']);
let PluID = TypeUtil.toString(dr['PluID']);
let PluCode = TypeUtil.toString(dr['PluCode']);
let TjType = TypeUtil.toString(dr['TjType']);
let mPrice =0;
//let mHyPrice =0;
let mJdRate =0;
if (PluCode.length > 0){
let retJhSjTz= Service.getSlideMenuData("OtherProcess","GetJhSjTz",SjZcCode,PluID,"","","");
if (retJhSjTz.result === 1) {
if (retJhSjTz.data != null) {
dr.setColumnError('PluCode', '商品['+ retJhSjTz.data.PluCode+ '-' + retJhSjTz.data.PluName+']在计划售价调整单['+ retJhSjTz.data.BillNo +']中还未处理!');
return false;
}
}
if ((TjType == "0") || (TjType == "")){
let retPlu= Service.getSlideMenuData("DoOnDetailCalcRule","PluCode",PluID,PluCode,Store.logOn.orgCode,"","");
if (retPlu.result === 1) {
if (retPlu.data === null) {
dr.setColumnError('PluCode', '当前组织没有经营此商品!');
return false;
}
else{
mPrice = retPlu.data.HjPrice;
}
}
else{
dr.setColumnError('PluCode', '查询价格失败!'+retPlu.message);
return false;
}
}
else{
let ret= Service.getSlideMenuData("OtherProcess","GetPsJgzc",SjZcCode,PluCode,Store.logOn.orgCode,"","");
if (ret.result === 1) {
if (ret.data != null) {
mPrice = ret.data.Price;
//mHyPrice = ret.data.HyPrice;
mJdRate = ret.data.JdRate;
}
else{
dr.setColumnError('PluCode', '价格政策没有此商品!');
return false;
}
}
else{
dr.setColumnError('PluCode', '获取价格政策失败!'+ret.message);
return false;
}
}
dr.setColumnValue('Price', mPrice);
dr.setColumnValue('NewPrice', mPrice);
dr.setColumnValue('TzRate', mJdRate);
if (TjType != "2"){
let ret= Service.getSlideMenuData("OtherProcess","GetTjType",SjZcCode,PluCode,Store.logOn.orgCode,"","");
if (ret.result === 1) {
if (ret.data != null) {
FIsTjType = "1";
dr.setColumnText('TjType', ret.data.TjType);
FIsTjType = "0";
}
}
}
}
return true;
};
//HyPrice 字段变化执行事件
Biz.prototype.fieldChangedHyPrice = function (dataSrc, dr, dc) {
let self = this;
let masterRow = self.dsMaster.currentRow;
let IsTzHyPrice = TypeUtil.toString(masterRow['IsTzHyPrice']);
let HyPrice = TypeUtil.toFloat(dr['HyPrice']);
let Price = TypeUtil.toFloat(dr['Price']);
if (HyPrice < 0){
dr.setColumnError(dc.fieldName, "会员售价不能小于零,请重新录入!");
return false;
}
if ((HyPrice > Price) && (IsTzHyPrice == "1")){
dr.setColumnError(dc.fieldName, "会员价不应大于售价!");
return false;
}
return true;
};
//NewHyPrice 字段变化执行事件
Biz.prototype.fieldChangedNewHyPrice = function (dataSrc, dr, dc) {
let NewHyPrice = TypeUtil.toFloat(dr['NewHyPrice']);
let HyPrice = TypeUtil.toFloat(dr['HyPrice']);
dr.setColumnValue('CjHyPrice', (NewHyPrice-HyPrice).round(2));
return true;
};
//NewPrice 字段变化执行事件
Biz.prototype.fieldChangedNewPrice = function (dataSrc, dr, dc) {
let Price = TypeUtil.toFloat(dr['Price']);
let NewPrice = TypeUtil.toFloat(dr['NewPrice']);
dr.setColumnValue('CjPrice', (NewPrice-Price).round(2));
if (Price == 0){
dr.setColumnValue('TzRate', "0");
}
else{
dr.setColumnValue('TzRate', ((NewPrice-Price)*100/Price).round(2));
}
return true;
};
//TjType 字段变化执行事件
Biz.prototype.fieldChangedTjType = function (dataSrc, dr, dc) {
let TjType = TypeUtil.toString(dr['TjType']);
let OldTjType = TypeUtil.toString(dr.transData['TjType']);
let PluCode = TypeUtil.toString(dr['PluCode']);
if ((TjType != OldTjType) && (FIsTjType == "0")){
if ((PluCode.length > 0) && (TjType.length > 0)){
dr.setColumnValue('TjType', OldTjType);
dr.setColumnError(dc.fieldName, "调整类型不允许直接修改,若修改请直接删除!");
return false;
}
}
return true;
};
/*
//按钮事件控制
Biz.prototype.doOp = function (opCode) {
let self = this;
if (opCode == 'edit') {
let ds = self.dsMaster;
this.onreview(self, ds);
}
};
//手调按钮事件
Biz.prototype.onreview = function (biz, ds) {
let dsrow=ds.currentRow;
let BillNo = dsrow ? TypeUtil.toString(dsrow['BillNo']) : '';
let ret= Service.getSlideMenuData("actExecute","onreview",BillNo,PluID);
if (ret.result === 1) {
biz.dsMaster.updateRow();
}
else
{
Store.messager.err("记账失败!"+ret.message);
return false;
}
return true;
};
//控制主界面按钮状态
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 == 'edit') {
let OrgCode = curRow ? TypeUtil.toString(curRow['OrgCode']) : '';
let JgZcCode = curRow ? TypeUtil.toString(curRow['JgZcCode']) : '';
if (!curRow)
return false;
if (OrgCode != Store.logOn.orgCode)
return false;
let ret= Service.getSlideMenuData("OtherProcess","UJgzcIsUsed",JgZcCode,"1",Store.logOn.orgCode,"","");
if (ret.result === 1) {
return false;
}
if (ret.result === -1) {
Store.messager.err("查询价格政策组织对应失败!"+ret.message);
return false;
}
}
if (opCode == 'delete') {
let OrgCode = curRow ? TypeUtil.toString(curRow['OrgCode']) : '';
let JgZcCode = curRow ? TypeUtil.toString(curRow['JgZcCode']) : '';
if (!curRow)
return false;
if (OrgCode != Store.logOn.orgCode)
return false;
let ret= Service.getSlideMenuData("OtherProcess","UJgzcIsUsed",JgZcCode,"1",Store.logOn.orgCode,"","");
if (ret.result === 1) {
return false;
}
if (ret.result === -1) {
Store.messager.err("查询价格政策组织对应失败!"+ret.message);
return false;
}
}
return true;
};
*/
return Biz;
});