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.

398 lines
15 KiB

define(function (require, exports, module) {
let BaseBiz = require('apps/rht/base/rhtBiz');
let Service = require('./lbl2606service');
let queryTpl = require('text!./custom-built-query.tpl')
let XWindow = require('system/views/pages/xlswindow/import-window.js')
function Biz(vm) {
//继承第一步,构造继承
BaseBiz.call(this, vm);
}
//继承第二步,方法继承
inherits(Biz, BaseBiz);
Biz.prototype.getCustomBuiltQuery = function () {
return queryTpl;
};
Biz.prototype.initCompleted = function () {
this.super('initCompleted');
let self = this;
self.$lblrule = self.getElement('.lbl-rule');
self.$lbltype = self.getElement('.lbl-type').textbox();
self.$lblclass = self.getElement('.lbl-class').textbox();
self.$lblformat = self.getElement('.lbl-format');
self.$lblcount = self.getElement('.lbl-count').textbox();
self.$lblplucode = self.getElement('.lbl-plucode').textbox();
self.$lblformat.combobox({
valueField: 'lblfrtid',
textField: 'lblfrtname',
data: []
});
initLabelRuleType(self);
initLabelClass(self);
initLabelFormat(self);
initPluInput(self);
self.getElement('.page-widget-querypanel').hide();
self.callView('resize');
};
function initLabelRuleType(self) {
let ret = Service.getSlideMenuData("actExecute", "GetLabelType", "", "", "", "", "");
if (ret.result !== 1) {
Store.messager.err(ret.message);
return false;
}
if (ret.data !== null) {
let ruledata = [{ 'enumvalueid': '<默认>', 'enumvaluename': '<默认>' }].concat(ret.data);
self.$lblrule.combobox({
valueField: 'enumvalueid',
textField: 'enumvaluename',
data: ruledata
});
self.$lblrule.combobox('setValue', '<默认>');
let typedata = [{ 'enumvalueid': '<全部>', 'enumvaluename': '<全部>' }].concat(ret.data);
self.$lbltype.combobox({
valueField: 'enumvalueid',
textField: 'enumvaluename',
data: typedata
});
self.$lbltype.combobox('setValue', '<全部>');
}
}
function initLabelClass(self) {
let ret = Service.getSlideMenuData("actExecute", "GetLabelClass", "", "", "", "", "");
if (ret.result !== 1) {
Store.messager.err(ret.message);
return false;
}
if (ret.data !== null) {
self.$lblclass.combobox({
valueField: 'lblclscode',
textField: 'lblclsname',
data: ret.data,
onChange: function () {
initLabelFormat(self);
}
});
self.$lblclass.combobox('select', ret.data[0].lblclscode);
}
}
function initLabelFormat(self) {
let lblclasscode = self.$lblclass.combobox('getValue');
let ret = Service.getSlideMenuData("actExecute", "GetLabelFormat", lblclasscode, "", "", "", "");
if (ret.result !== 1) {
Store.messager.err(ret.message);
return false;
}
if (ret.data !== null) {
self.$lblformat.combobox('loadData', ret.data);
self.$lblformat.combobox('select', ret.data[0].lblfrtid);
}
}
function initPluInput(self) {
self.$lblcount.textbox("setValue", "1");
self.$lblplucode.textbox('textbox').bind('keydown', function (e) {
if (e.keyCode === 13) {
let pluCode = self.$lblplucode.textbox('getValue');
let exists = false;
for (let element of self.dsMaster.rows) {
if (pluCode === element.PluCode || pluCode === element.BarCode) {
Store.messager.confirm("商品(" + pluCode + ")已经存在,是否继续添加?", function (go) {
if (!go) {
return;
}
beginPluCodeInput(self, pluCode);
})
exists = true;
break;
}
}
if (!exists) {
beginPluCodeInput(self, pluCode);
}
}
})
}
function beginPluCodeInput(self, pluCode) {
let orgCode = Store.logOn.orgCode;
let loopnum = Number(self.$lblcount.textbox('getValue'));
let i = 0;
while (i < loopnum) {
doPluCodeInput(pluCode, orgCode, self);
i++;
}
self.$lblplucode.textbox('textbox').select();
self.$lblplucode.textbox('textbox').focus();
}
function doPluCodeInput(inPlucode, inOrgcode, self) {
const orgCode = inOrgcode;
const pluCode = inPlucode;
let ret = Service.getSlideMenuData("actExecute", "GetPluPrice", orgCode, pluCode, "", "", "");
if (ret.result !== 1) {
Store.messager.err(ret.message);
return false;
}
if (ret.data === null) {
Store.messager.warn('商品(' + pluCode + ')不存在,请重新录入。');
self.$lblcount.textbox('textbox').focus();
}
else {
let lblRule = self.$lblrule.combobox('getValue');
if (lblRule === '<默认>') {
addPluByDefaultRule(ret.data, self);
}
else {
addPluByUsertRule(ret.data, self);
}
}
}
function addPluByDefaultRule(data, self) {
for (let element of data) {
let lblDataType = element.lbldatatype;
if (lblDataType !== '02') {
let iPrice = element.price;
let iHyPrice = element.HyPrice;
if (iPrice !== iHyPrice && iHyPrice > 0) {
lblDataType = '06';
}
let newRow = self.dsMaster.addRow();
newRow.setColumnValue('BillNo', element.billno);
newRow.setColumnText('LblDataType', lblDataType);
newRow.setColumnValue('BgnDate', element.bgndate);
newRow.setColumnValue('EndDate', element.enddate);
newRow.setColumnText('OrgCode', element.orgcode);
newRow.setColumnValue('PluID', element.pluid);
newRow.setColumnValue('PluCode', element.plucode);
newRow.setColumnValue('PluName', element.pluname);
newRow.setColumnValue('BarCode', element.barcode);
newRow.setColumnValue('Spec', element.spec);
newRow.setColumnValue('Unit', element.unit);
newRow.setColumnValue('CargoNo', element.cargono);
newRow.setColumnValue('Produce', element.produce);
newRow.setColumnValue('Grade', element.grade);
newRow.setColumnValue('Quality', element.quality);
newRow.setColumnValue('Price', element.price);
newRow.setColumnValue('HyPrice', element.hyprice);
newRow.setColumnValue('PfPrice', element.pfprice);
newRow.setColumnValue('YhPrice', element.yhprice);
newRow.setColumnValue('PluAbbrName', element.pluabbrname);
newRow.setColumnValue('BrandCode', element.brandcode);
newRow.setColumnValue('BrandName', element.brandname);
newRow.setColumnValue('PackUnit', element.packunit);
newRow.setColumnValue('PackQty', element.packqty);
newRow.setColumnValue('UDP1', element.udp1);
newRow.setColumnValue('UDP2', element.udp2);
newRow.setColumnValue('UDP3', element.udp3);
newRow.setColumnValue('UDP4', element.udp4);
newRow.setColumnValue('UDP5', element.udp5);
newRow.setColumnValue('UDP6', element.udp6);
newRow.setColumnValue('UDP7', element.udp7);
newRow.setColumnValue('UDP8', element.udp8);
newRow.setColumnValue('UDP9', element.udp9);
newRow.setColumnValue('UDP10', element.udp10);
newRow.setColumnValue('KcCount', element.kccount);
newRow.setColumnValue('EtpCode', element.etpcode);
newRow.setColumnValue('EtpName', element.etpname);
break;
}
}
}
function addPluByUsertRule(data, self) {
let lblUsrRule = self.$lblrule.combobox('getValue');
let lblFindRule = '';
let pluBarMss = self.$lblplucode.textbox('getValue');
let isFind = '0';
data.forEach(element => {
if (lblUsrRule === element.lbldatatype) {
isFind = '1';
}
});
if (isFind === '0') {
Store.message.tip('当前组织不经营该商品。');
}
if (lblUsrRule === '00' || lblUsrRule === '03' || lblUsrRule === '02' || lblUsrRule === '06' || lblUsrRule === '01') {
lblFindRule = lblUsrRule;
}
else if (lblUsrRule === '06') {
lblFindRule = '00';
}
if (lblFindRule !== '') {
data.forEach(element => {
if (lblUsrRule === element.lbldatatype) {
isFind = '1';
}
});
if (isFind === '0') {
Store.messager.confirm("商品(" + pluBarMss + ")不是[" + lblUsrRule + "]商品,是否继续添加?", function (go) {
if (!go) {
return;
}
})
}
}
else {
let curelement;
for (let element of data) {
let lblDataType = element.lbldatatype;
if ((lblDataType === '00') || (lblDataType !== '02' && lblDataType !== '03' && lblDataType !== '05')) {
curelement = element;
break;
}
}
if (lblDataType === '00') {
Store.messager.confirm("商品(" + pluBarMss + ")不是[" + lblUsrRule + "]商品,是否继续添加?", function (go) {
if (!go) {
return;
}
})
}
let newRow = self.dsMaster.addRow();
newRow.setColumnValue('BillNo', curelement.billno);
newRow.setColumnText('lbldatatype', lblRule);
newRow.setColumnValue('IsSel', '1');
newRow.setColumnValue('BgnDate', element.bgndate);
newRow.setColumnValue('EndDate', element.enddate);
newRow.setColumnText('OrgCode', element.orgcode);
newRow.setColumnValue('PluID', element.pluid);
newRow.setColumnValue('PluCode', element.plucode);
newRow.setColumnValue('PluName', element.pluname);
newRow.setColumnValue('BarCode', element.barcode);
newRow.setColumnValue('Spec', element.spec);
newRow.setColumnValue('Unit', element.unit);
newRow.setColumnValue('CargoNo', element.cargono);
newRow.setColumnValue('Produce', element.produce);
newRow.setColumnValue('Grade', element.grade);
newRow.setColumnValue('Quality', element.quality);
newRow.setColumnValue('Price', element.price);
newRow.setColumnValue('HyPrice', element.hyprice);
newRow.setColumnValue('PfPrice', element.pfprice);
newRow.setColumnValue('YhPrice', element.yhprice);
newRow.setColumnValue('PluAbbrName', element.pluabbrname);
newRow.setColumnValue('BrandCode', element.brandcode);
newRow.setColumnValue('BrandName', element.brandname);
newRow.setColumnValue('PackUnit', element.packunit);
newRow.setColumnValue('PackQty', element.packqty);
newRow.setColumnValue('UDP1', element.udp1);
newRow.setColumnValue('UDP2', element.udp2);
newRow.setColumnValue('UDP3', element.udp3);
newRow.setColumnValue('UDP4', element.udp4);
newRow.setColumnValue('UDP5', element.udp5);
newRow.setColumnValue('UDP6', element.udp6);
newRow.setColumnValue('UDP7', element.udp7);
newRow.setColumnValue('UDP8', element.udp8);
newRow.setColumnValue('UDP9', element.udp9);
newRow.setColumnValue('UDP10', element.udp10);
newRow.setColumnValue('KcCount', element.kccount);
newRow.setColumnValue('EtpCode', element.etpcode);
newRow.setColumnValue('EtpName', element.etpname);
}
}
//按钮事件控制
Biz.prototype.doOp = function (opCode) {
let self = this;
if (opCode == 'clearall') {
self.onclearall();
}
if (opCode == 'import') {
self.onimpexcel();
}
if (opCode == 'previewlabel') {
self.onpreviewlabel();
}
if (opCode == 'printlabel') {
self.onprintlabel();
}
};
//导入事件处理
Biz.prototype.onimpexcel = function () {
let self = this
let win = new XWindow({}, function (data) {
data.forEach(item => {
if (item['商品编码']) {
beginPluCodeInput(self, item['商品编码'])
}
})
});
win.open();
};
Biz.prototype.onclearall = function () {
this.dsMaster.clear();
};
Biz.prototype.onpreviewlabel = function () {
let lblFrtId = this.$lblformat.combobox('getValue');
if (this.dsMaster.rows.length!==0){
let curRow = this.dsMaster.currentRow;
if (curRow){
if (curRow.PluCode !=='' && curRow.PluName !==''){
let pd =[initPrintData(this.dsMaster)];
Store.bizDao.printLabel(lblFrtId, '1', pd, null, function (result) {
})
}
}
}
};
Biz.prototype.onprintlabel = function () {
let lblFrtId = this.$lblformat.combobox('getValue');
if (this.dsMaster.rows.length!==0){
let curRow = this.dsMaster.currentRow;
if (curRow){
if (curRow.PluCode !=='' && curRow.PluName !==''){
let pd =[initPrintData(this.dsMaster)];
Store.bizDao.printLabel(lblFrtId, '0', pd, null, function (result) {
})
}
}
}
};
function initPrintData(ds) {
let data = {
//uiObjCode: ds.uiObjCode,
//uiObjName: ds.uiObjName,
uiObjCode: 26095,
uiObjName: '标签打印数据',
isMaster: ds.isMaster,
fieldList: [],
forPrint: []
};
for (let i = 0; i < ds.columns.length; i++) {
let col = ds.columns[i];
data.fieldList.push({
fieldName: col.fieldName,
fieldDes: col.dispName,
dataType: col.dataType,
dataWidth: col.dataWidth,
dataDec: col.dataDec,
});
}
for (let k = 0; k < ds.rows.length; k++) {
let row = ds.rows[k];
data.forPrint.push(row.getPrintData());
}
return data;
};
return Biz;
});