瀏覽代碼

修复变更令bug

ellisran 1 年之前
父節點
當前提交
c8eeedc048
共有 1 個文件被更改,包括 55 次插入33 次删除
  1. 55 33
      app/public/js/change_information_set.js

+ 55 - 33
app/public/js/change_information_set.js

@@ -2094,6 +2094,7 @@ function tableDataRemake(changeListData) {
                         changeList[index].lid = newlistinfo.leafXmjs[0].gcl_id;
                     }
                 }
+                let lidIsNumber = false;
                 if (listinfo === undefined) {
                     // 针对旧数据获取清单信息
                     listinfo = changeListData[clinfo.lid - 1];
@@ -2106,8 +2107,9 @@ function tableDataRemake(changeListData) {
                         }
                         continue;
                     }
+                    lidIsNumber = true;
                 }
-                const info = makePushBwmx(clinfo, listinfo, removeList, updateList);
+                const info = makePushBwmx(clinfo, listinfo, removeList, updateList, lidIsNumber);
                 if (info && _.findIndex(changeLedgerList, { id: clinfo.gcl_id }) !== -1) {
                     // 可能因为升降级关系:细目,分部分项等会发生变化,更新清单
                     const updateInfo = {};
@@ -2140,7 +2142,7 @@ function tableDataRemake(changeListData) {
             }
         }
         if(updateList.length > 0) {
-            // console.log(updateList);
+            console.log(updateList);
             postData(window.location.pathname + '/save', { type:'update_list', updateData: updateList }, function (result) {
             }, function () {
             });
@@ -2154,9 +2156,10 @@ function tableDataRemake(changeListData) {
     }
 }
 
-function makePushBwmx(clinfo, listinfo, removeList, updateList) {
+function makePushBwmx(clinfo, listinfo, removeList, updateList, lidIsNumber) {
     let info = '';
-    const checkKey = ['name', 'unit', 'unit_price', 'oamount'];
+    const checkKey = ['name', 'code', 'unit', 'unit_price'];
+    const checkLeafKey = ['oamount', 'code', 'dwgc', 'fbgc', 'fxgc', 'jldy'];
     let pushbwmx = '0*;*0';
     if (listinfo.leafXmjs !== undefined) {
         const leafInfo = listinfo.leafXmjs.find(function (item) {
@@ -2168,45 +2171,52 @@ function makePushBwmx(clinfo, listinfo, removeList, updateList) {
             return flag;
         });
         if (leafInfo) {
+            const oneUpdate = { id: clinfo.id };
+            let needUpdate = false;
             // 判断要不要更新名称,单位,原数量,单价
             checkKey.forEach(function (key) {
-                const oneUpdate = { id: clinfo.id };
-                let needUpdate = false;
+                if (listinfo[key] !== clinfo[key]) {
+                    oneUpdate[key] = listinfo[key];
+                    clinfo[key] = listinfo[key];
+                    if (key === 'unit') {
+                        const oamount = ZhCalc.round(clinfo.oamount, findDecimal(listinfo[key]));
+                        if (oamount !== clinfo.oamount) {
+                            oneUpdate.oamount = oamount;
+                            clinfo.oamount = oamount;
+                        }
+                        const camount = ZhCalc.round(clinfo.camount, findDecimal(listinfo[key]));
+                        if (camount !== clinfo.camount) {
+                            oneUpdate.camount = camount;
+                            clinfo.camount = camount;
+                        }
+                    }
+                    // else if (key === 'unit_price') {
+                    //     // 可能要更新总金额了
+                    //     oneUpdate[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
+                    //     clinfo[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
+                    // }
+                    needUpdate = true;
+                }
+            });
+            checkLeafKey.forEach(function (key) {
                 // 只有数量是对比leafInfo,其它对比listinfo,且有些值需要重新计算
                 if (key === 'oamount') {
                     if (leafInfo.quantity !== clinfo[key]) {
-                        oneUpdate[key] = leafInfo[key];
+                        oneUpdate[key] = leafInfo.quantity;
                         clinfo[key] = leafInfo.quantity;
                         needUpdate = true;
                     }
                 } else {
-                    if (listinfo[key] !== clinfo[key]) {
-                        oneUpdate[key] = listinfo[key];
-                        clinfo[key] = listinfo[key];
-                        if (key === 'unit') {
-                            const oamount = ZhCalc.round(clinfo.oamount, findDecimal(listinfo[key]));
-                            if (oamount !== clinfo.oamount) {
-                                oneUpdate.oamount = oamount;
-                                clinfo.oamount = oamount;
-                            }
-                            const camount = ZhCalc.round(clinfo.camount, findDecimal(listinfo[key]));
-                            if (camount !== clinfo.camount) {
-                                oneUpdate.camount = camount;
-                                clinfo.camount = camount;
-                            }
-                        }
-                        // else if (key === 'unit_price') {
-                        //     // 可能要更新总金额了
-                        //     oneUpdate[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
-                        //     clinfo[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
-                        // }
+                    if (leafInfo[key] !== clinfo['xmj_' + key]) {
+                        oneUpdate['xmj_' + key] = leafInfo[key];
+                        clinfo['xmj_' + key] = leafInfo[key];
                         needUpdate = true;
                     }
                 }
-                if (needUpdate) {
-                    updateList.push(oneUpdate);
-                }
             });
+            if (needUpdate) {
+                updateList.push(oneUpdate);
+            }
             info = leafInfo;
             pushbwmx = leafInfo.code + '!_!' + (leafInfo.jldy !== undefined ? leafInfo.jldy : '') + '!_!' +
                 (leafInfo.dwgc ? leafInfo.dwgc : '') + '!_!' +
@@ -2231,11 +2241,23 @@ function makePushBwmx(clinfo, listinfo, removeList, updateList) {
     if (bwmx) {
         const bwmxArray = bwmx.split('$#$');
         bwmxArray.push(pushbwmx);
-        $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
+        if (lidIsNumber) {
+            $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
+        } else {
+            $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', bwmxArray.join('$#$'));
+        }
+    } else {
+        if (lidIsNumber) {
+            $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
+        } else {
+            $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
+        }
+    }
+    if (lidIsNumber) {
+        $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').addClass('table-success');
     } else {
-        $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').attr('data-bwmx', pushbwmx);
+        $('#table-list-select tr[data-lid="'+ clinfo.lid +'"]').addClass('table-success');
     }
-    $('#table-list-select tr[data-index="'+ clinfo.lid +'"]').addClass('table-success');
     return info;
 }