|
|
define(function (require, exports, module) {
|
|
|
let BaseBiz = require('apps/rht/base/rhtBiz');
|
|
|
let rhtComm = require('apps/rht/comm/rhtComm');
|
|
|
let Service = require('./sku080204service');
|
|
|
let XWindow = require('system/views/pages/xlswindow/import-window');
|
|
|
let IsdsMasterChg = false;
|
|
|
let IsdsDetailChg = false;
|
|
|
|
|
|
/**
|
|
|
* 控制按钮的可用
|
|
|
* @param opCode 按钮编码
|
|
|
* @return [description]
|
|
|
*/
|
|
|
|
|
|
function Biz(vm) {
|
|
|
//继承第一步,构造继承
|
|
|
BaseBiz.call(this, vm);
|
|
|
}
|
|
|
|
|
|
//继承第二步,方法继承
|
|
|
inherits(Biz, BaseBiz);
|
|
|
|
|
|
let SKU_IsCheckPluBar = rhtComm.getRhtOptionValue('*','SKU','SKU_IsCheckPluBar','0');
|
|
|
let Sku_IsVerifyBarCode = rhtComm.getRhtOptionValue('*','SKU','Sku_IsVerifyBarCode','0');
|
|
|
|
|
|
let MaxSerialNo = 1;
|
|
|
//保存前记录日志
|
|
|
Biz.prototype.afterEdit = function () {
|
|
|
return this.super('afterEdit');
|
|
|
};
|
|
|
//保存后记录日志
|
|
|
Biz.prototype.beforeSave = function () {
|
|
|
let masterRow = this.dsMaster.currentRow;
|
|
|
let BarCode = TypeUtil.toString(masterRow['BarCode']);
|
|
|
let PluName = TypeUtil.toString(masterRow['PluName']);
|
|
|
let PluAbbrName = TypeUtil.toString(masterRow['PluAbbrName']);
|
|
|
let PluMN = TypeUtil.toString(masterRow['PluMN']);
|
|
|
let BarType = TypeUtil.toString(masterRow['BarType']);
|
|
|
let TableName="";
|
|
|
|
|
|
if ((PluName.indexOf(";") != -1) || (PluName.indexOf("''") != -1)){
|
|
|
masterRow.setColumnError("PluName", "商品名称含有非法字符;或者''!");
|
|
|
return false;
|
|
|
}
|
|
|
if ((PluAbbrName.indexOf(";") != -1) || (PluAbbrName.indexOf("''") != -1)){
|
|
|
masterRow.setColumnError("PluAbbrName", "商品简称含有非法字符;或者''!");
|
|
|
return false;
|
|
|
}
|
|
|
if ((PluMN.indexOf(";") != -1) || (PluMN.indexOf("''") != -1)){
|
|
|
masterRow.setColumnError("PluMN", "商品助记符含有非法字符;或者''!");
|
|
|
return false;
|
|
|
}
|
|
|
if (BarCode.indexOf(";") != -1){
|
|
|
masterRow.setColumnError("BarCode", "商品条码含有非法字符;!"+OldID);
|
|
|
return false;
|
|
|
}
|
|
|
if (this._state == "add") {
|
|
|
if (BarType == "0"){
|
|
|
TableName="tSkuMulBar";
|
|
|
}
|
|
|
else {
|
|
|
TableName="TSKUPLUPACKAGEHEAD";
|
|
|
}
|
|
|
let ret= Service.getSlideMenuData("OnBeforeSave","BarCodeRepeat",TableName,BarCode,"","");
|
|
|
if (ret.result !== 1) {
|
|
|
masterRow.setColumnError("BarCode", ret.message);
|
|
|
return false;
|
|
|
}
|
|
|
if (ret.data.IsExist == "1") {
|
|
|
masterRow.setColumnError("BarCode", ret.message);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return this.super('beforeSave');
|
|
|
};
|
|
|
//字段变化触发事件
|
|
|
Biz.prototype.fieldChanged = function (dataSrc, dr, dc) {
|
|
|
if (dataSrc.uiObjCode === this.dsMaster.uiObjCode) {
|
|
|
switch (dc.fieldName) {
|
|
|
case 'BarCode':
|
|
|
this.fieldChangedBarCode(dataSrc, dr, dc);
|
|
|
break;
|
|
|
case 'PluCode':
|
|
|
this.fieldChangedPluCode(dataSrc, dr, dc);
|
|
|
break;
|
|
|
case 'BarType':
|
|
|
this.fieldChangedBarType(dataSrc, dr, dc);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
this.super('fieldChanged');
|
|
|
};
|
|
|
//主表 BarCode 字段变化执行事件
|
|
|
Biz.prototype.fieldChangedBarCode = function (dataSrc, dr, dc) {
|
|
|
let barCode = TypeUtil.toString(dr['BarCode']);
|
|
|
let pluCode = TypeUtil.toString(dr['PluCode']);
|
|
|
let pluId = TypeUtil.toString(dr['PluID']);
|
|
|
if (pluCode.length > 0){
|
|
|
//用正则表达式校验输入内容必须是0-9的数字
|
|
|
let re=/^[0-9]+$/;
|
|
|
if (SKU_IsCheckPluBar == "0"){
|
|
|
re=/^[A-Za-z0-9]+$/;
|
|
|
}
|
|
|
if (!re.test(barCode)) {
|
|
|
dr.setColumnError('BarCode',"条码只能是数字、英版文字母!");
|
|
|
return false;
|
|
|
}
|
|
|
if (barCode !== "") {
|
|
|
let ret= Service.getSlideMenuData("DoOnMasterCalcRule","BarCode",barCode,pluCode,pluId,"","");
|
|
|
if (ret.result !== 1) {
|
|
|
dr.setColumnError(dc.fieldName, ret.message);
|
|
|
return false;
|
|
|
}
|
|
|
};
|
|
|
};
|
|
|
return true;
|
|
|
};
|
|
|
//主表 PluCode 字段变化执行事件
|
|
|
Biz.prototype.fieldChangedPluCode = function (dataSrc, dr, dc) {
|
|
|
let PluCode = dr['PluCode'];
|
|
|
let OldPluCode = TypeUtil.toString(dr.transData['PluCode']);
|
|
|
if ((this._state == "edit") && (OldPluCode !=PluCode)) {
|
|
|
dr.setColumnError('PluCode',"已保存数据不允许变更商品编码!");
|
|
|
dr.setColumnText(dc.fieldName, OldPluCode);
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
};
|
|
|
//主表 BarType 字段变化执行事件
|
|
|
Biz.prototype.fieldChangedBarType = function (dataSrc, dr, dc) {
|
|
|
let BarType = dr['BarType'];
|
|
|
let OldBarType = TypeUtil.toString(dr.transData['BarType']);
|
|
|
if ((this._state == "edit") && (BarType !=OldBarType)) {
|
|
|
dr.setColumnError('PluCode',"已保存数据不允许变更条码类型!");
|
|
|
dr.setColumnText(dc.fieldName, OldBarType);
|
|
|
return false;
|
|
|
}
|
|
|
else {
|
|
|
if (BarType !=OldBarType){
|
|
|
dr.setColumnText("PluCode", "");
|
|
|
dr.setColumnText("PluName", "");
|
|
|
dr.setColumnText("PluMN", "");
|
|
|
dr.setColumnText("PluAbbrName", "");
|
|
|
dr.setColumnText("Spec", "");
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
};
|
|
|
//定义按钮事件
|
|
|
Biz.prototype.doOp = function (opCode) {
|
|
|
let self = this;
|
|
|
if (opCode == 'actimport') {
|
|
|
let dhead = self.dsMaster;
|
|
|
this.onimportexcelpl(self, dhead);
|
|
|
}
|
|
|
};
|
|
|
//控制主界面按钮状态(预制信息不允许修改和删除)
|
|
|
Biz.prototype.getOpEnabled = function (opCode) {
|
|
|
let isOk = this.super('getOpEnabled', opCode);
|
|
|
if (!isOk) {
|
|
|
return false;
|
|
|
}
|
|
|
let curRow = this.dsMaster.currentRow;
|
|
|
|
|
|
if (opCode == 'edit') {
|
|
|
let PatternType = curRow ? TypeUtil.toString(curRow['PatternType']) : '';
|
|
|
if ((PatternType == "0"))
|
|
|
return false;
|
|
|
}
|
|
|
if (opCode == 'delete') {
|
|
|
let PatternType = curRow ? TypeUtil.toString(curRow['PatternType']) : '';
|
|
|
if ((PatternType == "0"))
|
|
|
return false;
|
|
|
}
|
|
|
if (opCode == 'actimport') {
|
|
|
if (this.isEdit())
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
};
|
|
|
//导入按钮事件(暂时先不做 后期需要再加)
|
|
|
Biz.prototype.onimportexcelpl= function () {
|
|
|
let masterRow = this.dsMaster.currentRow;
|
|
|
let ds = this.dsDetail;
|
|
|
//执行导入
|
|
|
let win = new XWindow({}, function (data) {
|
|
|
(new ExcelHelper(this.biz, data,masterRow)).import(); // 处理返回的excel data数据,这里的数据已经是数组,包含了读取的所有数据.
|
|
|
});
|
|
|
win.open();
|
|
|
}
|
|
|
|
|
|
//Excel导入处理 增加到当前界面明细表中
|
|
|
function ExcelHelper(biz, data,masterRow) {
|
|
|
let curIndex = 0;
|
|
|
let excelCols = [];
|
|
|
let PluCode="";
|
|
|
let BarCode="";
|
|
|
let BarType="";
|
|
|
this.import = function () {
|
|
|
if (data != null) {
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
tmp = data[i];
|
|
|
PluCode = tmp['商品编码'];
|
|
|
BarCode = tmp['条码'];
|
|
|
BarType = tmp['条码类型'];
|
|
|
//用正则表达式校验输入内容必须是0-9的数字
|
|
|
let re=/^[0-9]+$/;
|
|
|
if (SKU_IsCheckPluBar == "0"){
|
|
|
re=/^[A-Za-z0-9]+$/;
|
|
|
}
|
|
|
if (!re.test(BarCode)) {
|
|
|
Store.messager.tip( "条码只能是数字、英版文字母!");
|
|
|
return false;
|
|
|
}
|
|
|
if (BarCode !== "") {
|
|
|
let ret= Service.getSlideMenuData("ImportExecute","UCheckBarCode",BarCode,PluCode,"","");
|
|
|
if (ret.result !== 1) {
|
|
|
Store.messager.tip(ret.message);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
dr.setColumnError('BarCode',"条码不能为空!");
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
Store.messager.tip( PluCode);
|
|
|
}
|
|
|
};
|
|
|
let ret= Service.getSlideMenuData("ImportExecute","InExcel",data,"","","","");
|
|
|
if (ret.result !== 1) {
|
|
|
masterRow.setColumnError('BarCode', ret.message);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return Biz;
|
|
|
}); |