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.

394 lines
17 KiB

define(function (require, exports, module) {
//引入业务类基类
let BaseBiz = require('apps/rht/base/rhtBiz');
let rhtComm = require('apps/rht/comm/rhtComm');
//引入业务服务
let Service = require('./pri100102service');
/**
* 定义业务类对象
* @param vm 界面相关ViewModule
*/
function Biz(vm) {
//继承第一步,构造继承
BaseBiz.call(this, vm);
}
//继承第二步,方法继承
inherits(Biz, BaseBiz);
/**
* 全局变量
*/
let IsProAdjustPrice = rhtComm.getRhtOptionValue('*','PRC','IsProAdjustPrice','1');
let Prc_IsChgCmp = rhtComm.getRhtOptionValue(Store.logOn.orgCode,'PRC','Prc_IsChgCmp','0');
let PluMlLimit = rhtComm.getRhtOptionValue(Store.logOn.orgCode,'CAT','PluMlLimit','0');
let OrgType = rhtComm.GetOrgType(Store.logOn.orgCode);
let FbCatMlLimit = false;
if (OrgType != "1001"){
if (PluMlLimit=="1"){
FbCatMlLimit = true;
}
}
Biz.prototype.beforeFieldEdit = function(dataSrc, dr, dc) {
let masterRow = this.dsMaster.currentRow;
var IsTzPrice = TypeUtil.toString(masterRow['IsTzPrice']);
var IsTzHyPrice = TypeUtil.toString(masterRow['IsTzHyPrice']);
var IsTzPfPrice = TypeUtil.toString(masterRow['IsTzPfPrice']);
if (dataSrc.uiObjCode == this.dsDetail.uiObjCode) {
if (dc.fieldName == 'NewPrice') {
if (IsTzPrice === '0') {
return false;
}
}
if (dc.fieldName == 'NewHyPrice') {
if (IsTzHyPrice === '0') {
return false;
}
}
if (dc.fieldName == 'NewPfPrice') {
if (IsTzPfPrice === '0') {
return false;
}
}
}
return this.super('beforeFieldEdit', dataSrc, dr, dc);
};
//保存前校验 计算主表合计数量等字段
Biz.prototype.beforeSave = function () {
let curRow = this.dsMaster.currentRow;
let IsTzPrice = curRow['IsTzPrice'];
let IsTzHyPrice = curRow['IsTzHyPrice'];
let IsTzPfPrice = curRow['IsTzPfPrice'];
let TzDate = curRow['TzDate'];
let BillType = curRow['BillType'];
let sdate=new Date(Store.bizDao.getSysDate()).format('yyyy-MM-dd');
if (OrgType != "1001"){
if ((IsTzPrice =="0") && (IsTzHyPrice =="0") && (IsTzPfPrice =="0")){
curRow.setColumnError('IsTzPrice', "没有设置调整范围,请设置后再进行保存!" );
return false;
}
for (let i =0; i < this.dsDetail.rows.length; i++) {
let row = this.dsDetail.rows[i];
let PluID = row['PluID'];
let PluCode = row['PluCode'];
let PluName = row['PluName'];
let HjPrice = TypeUtil.toFloat(row['HJPrice']);
let NewPrice = TypeUtil.toFloat(row['NewPrice']);
if ((row['NewHyPrice'] > row['NewPrice']) && (IsTzHyPrice == "1")) {
curRow.setColumnError('NewHyPrice', "会员价不应大于售价!" );
return false;
}
if (FbCatMlLimit){
let ret= Service.getSlideMenuData("OnBeforeSave","GetMlRate",PluCode,"","","","");
if (ret.result === 1) {
if (ret.data != null) {
let curMinMlRate=TypeUtil.toFloat(ret.data.MinMlRate);
let curMaxMlRate=TypeUtil.toFloat(ret.data.MaxMlRate);
if ((curMinMlRate != 0) || (curMaxMlRate != 0) || (NewPrice != 0)) {
let curRate = Math.round(0);
if (NewPrice !== 0){
curRate = Math.round((NewPrice-HjPrice)*10000/NewPrice)/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;
}
}
}
}
}
ret= Service.getSlideMenuData("OnBeforeSave","GetPluPackage",PluID,"","","","");
if (ret.result === 1) {
if (ret.data != null) {
if (ret.data.PackageName != "*"){
if (!Store.confirm("商品["+PluName+"]已被商品包["+ret.data.PackageName+"]引用,是否继续?")) {
return false;
}
}
}
}
}
}
}
if (BillType=="1"){
if (TzDate <= sdate){
curRow.setColumnError('TzDate', "输入错误,计划调价日期应大于当前日期!" );
return false;
}
}
for (let i =0; i < this.dsDetail.rows.length; i++) {
let row = this.dsDetail.rows[i];
let PluCode = row['PluCode'];
let PluName = row['PluName'];
let NewPrice = TypeUtil.toFloat(row['NewPrice']);
let NewHyPrice = TypeUtil.toFloat(row['NewHyPrice']);
let NewPfPrice = TypeUtil.toFloat(row['NewPfPrice']);
if ((IsTzPrice =="1") && (NewPrice == 0)){
if (!Store.confirm("确认将商品"+PluCode+"-"+PluName+"现售价置为零吗?")) {
return false;
}
}
if ((IsTzHyPrice =="1") && (NewHyPrice == 0)){
if (!Store.confirm("确认将商品"+PluCode+"-"+PluName+"现售价置为零吗?")) {
return false;
}
}
if ((IsTzPfPrice =="1") && (NewPfPrice == 0)){
if (!Store.confirm("确认将商品"+PluCode+"-"+PluName+"现售价置为零吗?")) {
return false;
}
}
}
return this.super('beforeSave');
}
//新增行后处理,默认值已经处理
Biz.prototype.afterNewRow = function (dataSrc, newRow) {
if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) {
newRow.setColumnValue('YwType',"1002");
let sdate=new Date(Store.bizDao.getSysDate()).format('yyyy-MM-dd');
newRow.setColumnValue('TzDate', sdate);
}
};
//明细行单行提交触发的校验
Biz.prototype.dataRowValidate = function (dataSrc, dr) {
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
let PluCode = TypeUtil.toString(dr['PluCode']);
let NewPrice = TypeUtil.toFloat(dr['NewPrice']);
let Price = TypeUtil.toFloat(dr['Price']);
if ((IsProAdjustPrice != "1") && (PluCode != "") && (NewPrice != Price)) {
let ret= Service.getSlideMenuData("OnDetailBeforePost","CheckCX", PluCode, Store.logOn.orgCode,"","","");
if (ret.result == 1) {
if (ret.data != null){
if (TypeUtil.toFloat(ret.data.con) > 0) {
if (IsProAdjustPrice == "0") {
return "本商品正在促销,不允许调整售价!";
}
if (IsProAdjustPrice == "2") {
if (!Store.confirm("本商品正在促销,是否要调整售价? \r\n 如要对商品进行售价调整注意以下两点 \r\n 1.请注意打印价签,以备促销期结束后使用!\r\n 2.请注意该售价调整会影响按比例促销商品的促销价格!")) {
return "请重新修改!";
}
}
}
}
}
}
}
return true;
}
/**
* @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 'IsTzPrice':
case 'IsTzHyPrice':
case 'IsTzPfPrice':
this.fieldChangedIsTzPrice(dataSrc, dr, dc);
break;
}
}*/
if (dataSrc.uiObjCode === this.dsDetail.uiObjCode) {
switch (dc.fieldName) {
case 'PluCode':
this.fieldChangedPluCode(dataSrc, dr, dc);
break;
case 'NewPrice':
this.fieldChangedNewPrice(dataSrc, dr, dc);
break;
case 'NewHyPrice':
this.fieldChangedNewHyPrice(dataSrc, dr, dc);
break;
case 'NewPfPrice':
this.fieldChangedNewPfPrice(dataSrc, dr, dc);
break;
}
}
this.super('fieldChanged');
};
//PluCode 字段变化执行事件
Biz.prototype.fieldChangedPluCode = function (dataSrc, dr, dc) {
let self = this;
let currentRow = self.dsMaster.currentRow;
let PluCode = dr['PluCode'];
let PluType = currentRow['PluType'];
let ret= Service.getSlideMenuData("DoOnDetailCalcRule","PluCode","",Store.logOn.orgCode,PluCode,PluType,"Price,HyPrice,PfPrice");
if (ret.result === 1) {
if (ret.data != null) {
dr.setColumnValue('HJPrice', ret.data.HjPrice);
dr.setColumnValue('Price', ret.data.Price);
dr.setColumnValue('HyPrice', ret.data.HyPrice);
dr.setColumnValue('PfPrice', ret.data.PfPrice);
dr.setColumnValue('NewPrice', ret.data.Price);
dr.setColumnValue('NewHyPrice', ret.data.HyPrice);
dr.setColumnValue('NewPfPrice', ret.data.PfPrice);
}
}
return true;
};
//NewPrice 字段变化执行事件
Biz.prototype.fieldChangedNewPrice = function (dataSrc, dr, dc) {
let self = this;
let NewPrice = TypeUtil.toFloat(dr['NewPrice']);
let Price = TypeUtil.toFloat(dr['Price']);
let currentRow = self.dsMaster.currentRow;
let PluType = TypeUtil.toString(currentRow['PluType']);
let PluID = TypeUtil.toString(dr['PluID']);
let PluCode = TypeUtil.toString(dr['PluCode']);
if (NewPrice < 0){
dr.setColumnError(dc.fieldName, "现售价不能小于零,请重新录入!");
return false;
}
if ((PluType == "0") && (PluID != "")){
let ret= Service.getSlideMenuData("DoOnDetailCalcRule","NewPrice",PluID,PluCode,Store.logOn.orgCode,"","");
if (ret.result === 1) {
if (ret.data != null) {
if (TypeUtil.toFloat(ret.data.HjPrice) > NewPrice) {
if (Prc_IsChgCmp =="1"){
if (!Store.confirm("商品售价小于商品最新进价,是否继续?")) {
return false;
}
}
else{
dr.setColumnError(dc.fieldName, "商品售价不允许小于商品最新进价:" + ret.data.HjPrice + ",请重新录入!");
return false;
}
}
}
}
else
{
dr.setColumnError(dc.fieldName, ret.message);
return false;
}
ret= Service.getSlideMenuData("DoOnDetailCalcRule","NewPricePluEx",PluID,PluCode,Store.logOn.orgCode,NewPrice,"");
if (ret.result === 2) {
dr.setColumnError(dc.fieldName, ret.message);
}
else if (ret.result !== 1)
{
dr.setColumnError(dc.fieldName, ret.message);
return false;
}
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;
};
//NewHyPrice 字段变化执行事件
Biz.prototype.fieldChangedNewHyPrice = function (dataSrc, dr, dc) {
let self = this;
let NewPrice = TypeUtil.toFloat(dr['NewPrice']);
let NewHyPrice = TypeUtil.toFloat(dr['NewHyPrice']);
let HyPrice = TypeUtil.toFloat(dr['HyPrice']);
let currentRow = self.dsMaster.currentRow;
let PluType = TypeUtil.toString(currentRow['PluType']);
let PluID = TypeUtil.toString(dr['PluID']);
let IsTzHyPrice = currentRow['IsTzHyPrice'];
if (NewHyPrice < 0){
dr.setColumnError(dc.fieldName, "现会员价不能小于零,请重新录入!");
return false;
}
if ((PluType == "0") && (PluID != "")){
if ((OrgType != "1001") && (IsTzHyPrice == "1")){
if (NewHyPrice > NewPrice){
dr.setColumnError(dc.fieldName, "会员价不应大于售价!");
return false;
}
}
dr.setColumnValue('CjHyPrice', (NewHyPrice-HyPrice).round(2));
}
return true;
};
//NewPfPrice 字段变化执行事件
Biz.prototype.fieldChangedNewPfPrice = function (dataSrc, dr, dc) {
let self = this;
let currentRow = self.dsMaster.currentRow;
let PluType = TypeUtil.toString(currentRow['PluType']);
let NewPfPrice = TypeUtil.toFloat(dr['NewPfPrice']);
let PfPrice = TypeUtil.toFloat(dr['PfPrice']);
let PluID = TypeUtil.toString(dr['PluID']);
let PluCode = TypeUtil.toString(dr['PluCode']);
if (NewPfPrice < 0){
dr.setColumnError(dc.fieldName, "批发价不能小于零,请重新录入!");
return false;
}
if ((PluType == "0") && (PluID != "")){
let ret= Service.getSlideMenuData("DoOnDetailCalcRule","NewPfPrice",PluID,PluCode,Store.logOn.orgCode,NewPfPrice,"");
if (ret.result !== 1) {
dr.setColumnError(dc.fieldName, ret.message);
return false;
}
dr.setColumnValue('CjPfPrice', (NewPfPrice-PfPrice).round(2));
}
return true;
};
//按钮事件控制
Biz.prototype.doOp = function (opCode) {
let self = this;
if (opCode == 'shoutiao') {
let ds = self.dsMaster;
this.onshoutiao(self, ds);
}
};
//手调按钮事件
Biz.prototype.onshoutiao = function (biz, ds) {
let dsrow=ds.currentRow;
let BillNo = dsrow ? TypeUtil.toString(dsrow['BillNo']) : '';
let ret= Service.getSlideMenuData("doAccount","doAccount",BillNo,"1002-1");
if (ret.result === 1) {
biz.dsMaster.updateRow();
}
else
{
Store.messager.err("记账失败!"+ret.message);
return false;
}
return true;
};
//控制主界面按钮状态
Biz.prototype.getOpEnabled = function (opCode) {
let isOk = this.super('getOpEnabled', opCode);
if (!isOk) {
return false;
}
let curRow = this.dsMaster.currentRow;
if (opCode == 'shoutiao') {
let IsEnabled = curRow ? TypeUtil.toString(curRow['IsEnabled']) : '';
let DataStatus = curRow ? TypeUtil.toString(curRow['DataStatus']) : '';
if (!curRow)
return false;
if ((IsEnabled !="1") && (DataStatus == "9"))
return false;
}
return true;
};
return Biz;
});