Explorar o código

变更清单排序和去重

laiguoran %!s(int64=6) %!d(string=hai) anos
pai
achega
ae42033a82
Modificáronse 1 ficheiros con 65 adicións e 19 borrados
  1. 65 19
      app/public/js/change_set.js

+ 65 - 19
app/public/js/change_set.js

@@ -9,20 +9,66 @@
  */
 
 $(document).ready(() => {
+    // 编号排序,多重判断
+    function sortByCode(a, b) {
+        let code1 = a.code.split('-');
+        let code2 = b.code.split('-');
+        let code1length = code1.length;
+        let code2length = code2.length;
+        for (let i = 0; i < code1length; i ++) {
+            if (i+1 <= code2length) {
+                if (code1[i] != code2[i]) {
+                    if (!/^\d+$/.test(code1[i])) {
+                        return code1[i].charCodeAt() - code2[i].charCodeAt();
+                    } else {
+                        return parseInt(code1[i]) - parseInt(code2[i]);
+                    }
+                } else if (i+1 == code1length && code1[i] == code2[i]) {
+                    if (code1length == code2length) {
+                        return 0;
+                    } else {
+                        return code1length - code2length;
+                    }
+                }
+            } else {
+                if (i+1 >= code1length) {
+                    return 1;
+                } else {
+                    return -1;
+                }
+            }
+        }
+    }
 
     gclGatherModel.loadLedgerData(ledger);
     gclGatherModel.loadPosData(pos);
     const gclGatherData = gclGatherModel.gatherGclData();
+    for (const ggd in gclGatherData) {
+        gclGatherData[ggd].code = gclGatherData[ggd].b_code;
+    }
+    // 数组去重
+    for (const db of gclGatherData) {
+        const exist_index = dealBillList.findIndex(function (item) {
+            return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
+        });
+        if (exist_index !== -1) {
+            dealBillList.splice(exist_index, 1);
+        }
+    }
+    const changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
     // 先加载台账数据
     let listHtml = '';
     let list_index = 1;
-    for (const gcl of gclGatherData) {
+    let gcl_index = 0;
+    for (const gcl of changeListData) {
         const unit = gcl.unit !== undefined && gcl.unit !== null ? gcl.unit : '';
         const quantity = gcl.quantity !== null && gcl.quantity !== undefined ? (unit !== '' ? roundnum(gcl.quantity, findDecimal(gcl.unit)) : gcl.quantity) : 0;
         const unit_price = gcl.unit_price !== null && gcl.unit_price !== undefined ? gcl.unit_price : 0;
-        listHtml += '<tr data-lid="' + list_index + '" data-gcl="' + (list_index-1) + '" data-index="' + list_index + '" data-bwmx="">' +
+        let gclhtml = gcl.leafXmjs !== undefined ? ' data-gcl="' + gcl_index + '"': '';
+        gcl_index = gclhtml !== '' ? gcl_index++ : gcl_index;
+        listHtml += '<tr data-lid="' + list_index + '"'+ gclhtml +' data-index="' + list_index + '" data-bwmx="">' +
             '<td>' + list_index + '</td>' +
-            '<td>' + gcl.b_code + '</td>' +
+            '<td>' + gcl.code + '</td>' +
             '<td>' + gcl.name + '</td>' +
             '<td>' + unit + '</td>' +
             '<td>' + roundnum(unit_price, unitPriceUnit) + '</td>' +
@@ -31,22 +77,22 @@ $(document).ready(() => {
             '</tr>';
         list_index++;
     }
-    // 再加载签约清单
-    for (const db of dealBillList) {
-        const unit = db.unit !== undefined && db.unit !== null ? db.unit : '';
-        const quantity = db.quantity !== null && db.quantity !== undefined ? (unit !== '' ? roundnum(db.quantity, findDecimal(db.unit)) : db.quantity) : 0;
-        const unit_price = db.unit_price !== null && db.unit_price !== undefined ? db.unit_price : 0;
-        listHtml += '<tr data-lid="' + db.id + '" data-index="' + list_index + '" data-bwmx="">' +
-            '<td>' + list_index + '</td>' +
-            '<td>' + db.code + '</td>' +
-            '<td>' + db.name + '</td>' +
-            '<td>' + unit + '</td>' +
-            '<td>' + roundnum(unit_price, unitPriceUnit) + '</td>' +
-            '<td>' + quantity + '</td>' +
-            // '<td>' + roundnum(parseFloat(db.unit_price).mul(parseFloat(db.quantity)), totalPriceUnit) + '</td>' +
-            '</tr>';
-        list_index++;
-    }
+    // // 再加载签约清单
+    // for (const db of dealBillList) {
+    //     const unit = db.unit !== undefined && db.unit !== null ? db.unit : '';
+    //     const quantity = db.quantity !== null && db.quantity !== undefined ? (unit !== '' ? roundnum(db.quantity, findDecimal(db.unit)) : db.quantity) : 0;
+    //     const unit_price = db.unit_price !== null && db.unit_price !== undefined ? db.unit_price : 0;
+    //     listHtml += '<tr data-lid="' + db.id + '" data-index="' + list_index + '" data-bwmx="">' +
+    //         '<td>' + list_index + '</td>' +
+    //         '<td>' + db.code + '</td>' +
+    //         '<td>' + db.name + '</td>' +
+    //         '<td>' + unit + '</td>' +
+    //         '<td>' + roundnum(unit_price, unitPriceUnit) + '</td>' +
+    //         '<td>' + quantity + '</td>' +
+    //         // '<td>' + roundnum(parseFloat(db.unit_price).mul(parseFloat(db.quantity)), totalPriceUnit) + '</td>' +
+    //         '</tr>';
+    //     list_index++;
+    // }
     $('#table-list-select').html(listHtml);
 
     // 上报时按钮点击