|
@@ -140,35 +140,133 @@ let componentOprObj = {
|
|
|
cacheSection = null;
|
|
|
}
|
|
|
},
|
|
|
+ //批量插入组成物
|
|
|
+ batchUpdateComponent: function () {
|
|
|
+ $.bootstrapLoading.start();
|
|
|
+ let me = componentOprObj, that = gljComponentOprObj, re = repositoryGljObj,
|
|
|
+ updateArr = [],
|
|
|
+ updateBasePrc = [],
|
|
|
+ IDMapping = {};
|
|
|
+ let formData = new FormData();
|
|
|
+ //当前工料机的工料机类型
|
|
|
+ let currentGljType = re.currentGlj.gljType;
|
|
|
+ let thisTypeGljList = _.filter(re.gljList, function (data) {
|
|
|
+ return data.gljType == currentGljType;
|
|
|
+ });
|
|
|
+ for(let glj of thisTypeGljList){
|
|
|
+ let gljComponent = glj.component ? glj.component : [];
|
|
|
+ let newComponent = [];
|
|
|
+ if(me.insertType === 'batch'){
|
|
|
+ for(let selectedComponent of me.selectedList){
|
|
|
+ let isExist = false;
|
|
|
+ for(let gljPerComponent of gljComponent){
|
|
|
+ if(selectedComponent.ID === gljPerComponent.ID){
|
|
|
+ newComponent.push({ID: selectedComponent.ID, consumeAmt: gljPerComponent.consumeAmt});
|
|
|
+ isExist = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!isExist){
|
|
|
+ newComponent.push({ID: selectedComponent.ID, consumeAmt: 0});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(me.insertType === 'batchClear'){//去除消耗量为0的组成物
|
|
|
+ for(let gljPerComponent of gljComponent){
|
|
|
+ if(gljPerComponent.consumeAmt && gljPerComponent.consumeAmt != 0){
|
|
|
+ newComponent.push({ID: gljPerComponent.ID, consumeAmt: gljPerComponent.consumeAmt});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(newComponent));
|
|
|
+ if(gljBasePrc != glj.basePrice){
|
|
|
+ updateBasePrc.push({gljId: glj.ID, gljType: currentGljType, basePrice: gljBasePrc});
|
|
|
+ }
|
|
|
+ IDMapping[glj.ID] = {component : newComponent, basePrice: gljBasePrc};
|
|
|
+ updateArr.push({ID: glj.ID, component: newComponent, basePrice: gljBasePrc});
|
|
|
+ }
|
|
|
+ formData.append('compressData', LZString.compressToUTF16(JSON.stringify(updateArr)));
|
|
|
+ $.ajax({
|
|
|
+ url: 'api/batchUpdateComponent',
|
|
|
+ type: 'POST',
|
|
|
+ data: formData,
|
|
|
+ cache: false,
|
|
|
+ contentType: false,
|
|
|
+ processData: false,
|
|
|
+ success: function(response){
|
|
|
+ if (response.err === 0) {
|
|
|
+ //更新缓存数据
|
|
|
+ for(let glj of thisTypeGljList){
|
|
|
+ if(glj.ID === re.currentGlj.ID){
|
|
|
+ re.currentComponent = re.getCurrentComponent(IDMapping[glj.ID]['component']);
|
|
|
+ sheetCommonObj.cleanData(that.workBook.getSheet(0), that.setting, -1);
|
|
|
+ sheetsOprObj.showData(that.workBook.getSheet(0), that.setting, re.currentComponent);
|
|
|
+ }
|
|
|
+ glj.component = IDMapping[glj.ID]['component'];
|
|
|
+ glj.basePrice = IDMapping[glj.ID]['basePrice'];
|
|
|
+ }
|
|
|
+ re.reSetGljBasePrc(thisTypeGljList);
|
|
|
+ if($('#component').is(':visible')){
|
|
|
+ $('#component').modal('hide');
|
|
|
+ }
|
|
|
+ $.bootstrapLoading.end();
|
|
|
+ //更新定额
|
|
|
+ if(updateBasePrc.length > 0){
|
|
|
+ re.updateRationBasePrcRq(updateBasePrc);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if($('#component').is(':visible')){
|
|
|
+ $('#component').modal('hide');
|
|
|
+ }
|
|
|
+ $.bootstrapLoading.end();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function(jqXHR){
|
|
|
+ alert(`与服务器通信发生错误${jqXHR.status} ${jqXHR.statusText}`);
|
|
|
+ $('#component').modal('hide');
|
|
|
+ $.bootstrapLoading.end();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
//组成物窗口按钮操作
|
|
|
componentsBtnOpr: function (conf) {//确定、取消、关闭按钮
|
|
|
let me = componentOprObj, that = gljComponentOprObj, re = repositoryGljObj;
|
|
|
conf.click(function () {
|
|
|
- //添加选择添加的组成物
|
|
|
- let updateArr = [];
|
|
|
- let newComponent = [];
|
|
|
- for(let i = 0, len = me.selectedList.length; i < len; i++){
|
|
|
- let isExist = false;
|
|
|
- for(let j = 0, jLen = re.currentGlj.component.length; j < jLen; j++){
|
|
|
- if(me.selectedList[i].ID === re.currentGlj.component[j].ID){
|
|
|
- newComponent.push({ID: me.selectedList[i].ID, consumeAmt: re.currentGlj.component[j].consumeAmt});
|
|
|
- isExist = true;
|
|
|
- break;
|
|
|
+ if(me.insertType === 'single'){
|
|
|
+ let updateBasePrc = [];
|
|
|
+ //添加选择添加的组成物
|
|
|
+ let updateArr = [];
|
|
|
+ let newComponent = [];
|
|
|
+ for(let i = 0, len = me.selectedList.length; i < len; i++){
|
|
|
+ let isExist = false;
|
|
|
+ for(let j = 0, jLen = re.currentGlj.component.length; j < jLen; j++){
|
|
|
+ if(me.selectedList[i].ID === re.currentGlj.component[j].ID){
|
|
|
+ newComponent.push({ID: me.selectedList[i].ID, consumeAmt: re.currentGlj.component[j].consumeAmt});
|
|
|
+ isExist = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!isExist){
|
|
|
+ newComponent.push({ID: me.selectedList[i].ID, consumeAmt: 0});
|
|
|
}
|
|
|
}
|
|
|
- if(!isExist){
|
|
|
- newComponent.push({ID: me.selectedList[i].ID, consumeAmt: 0});
|
|
|
+ re.currentGlj.component = newComponent;
|
|
|
+ let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(re.currentGlj.component));
|
|
|
+ if(gljBasePrc !== re.currentGlj.basePrice){
|
|
|
+ re.currentGlj.basePrice = gljBasePrc;
|
|
|
+ re.reshowGljBasePrc(re.currentGlj);
|
|
|
+ updateBasePrc.push({gljId: re.currentGlj.ID, gljType: re.currentGlj.gljType, basePrice: gljBasePrc});
|
|
|
+ re.updateRationBasePrcRq(updateBasePrc);
|
|
|
}
|
|
|
+ updateArr.push(re.currentGlj);
|
|
|
+ that.updateComponent(updateArr);
|
|
|
+ $('#component').modal('hide');
|
|
|
+ //$('#componentsCacnel').click();
|
|
|
}
|
|
|
- re.currentGlj.component = newComponent;
|
|
|
- let gljBasePrc = that.reCalGljBasePrc(re.getCurrentComponent(re.currentGlj.component));
|
|
|
- if(gljBasePrc !== re.currentGlj.basePrice){
|
|
|
- re.currentGlj.basePrice = gljBasePrc;
|
|
|
- re.reshowGljBasePrc(re.currentGlj);
|
|
|
+ else {
|
|
|
+ me.batchUpdateComponent();
|
|
|
}
|
|
|
- updateArr.push(re.currentGlj);
|
|
|
- that.updateComponent(updateArr);
|
|
|
- $('#componentsCacnel').click();
|
|
|
});
|
|
|
}
|
|
|
};
|