瀏覽代碼

调整批量录入

ellisran 2 周之前
父節點
當前提交
d269e570bf
共有 2 個文件被更改,包括 50 次插入36 次删除
  1. 47 33
      app/public/js/change_revise.js
  2. 3 3
      app/view/change/revise_modal.ejs

+ 47 - 33
app/public/js/change_revise.js

@@ -5510,14 +5510,18 @@ $(document).ready(() => {
                 }
                 SpreadJsObj.reLoadSheetData(bpObj.bpSheet);
             },
+            genId: function (prefix) {
+                const id = prefix + '-' + Date.now().toString(36) + '-' + Math.floor(Math.random() * 0x100000).toString(36);
+                // 若要绝对确保在 DOM 中唯一,可检查并重试:
+                return id;
+            },
             bpClipboardPasted: function (e, info) {
                 if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
                     info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
                 }
                 const node = SpreadJsObj.getSelectObject(billsSheet);
-                const data = [];
-                const rows = [];
-                const updateData = [], insertData = [];
+                const updateDatas = [];
+                const insertDatas = [];
                 const sortData = info.sheet.zh_data || [];
                 const hint = {
                     expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
@@ -5557,35 +5561,34 @@ $(document).ready(() => {
                         posData[colSetting.field] = validText;
                     }
                     if (bPaste && posData.name) {
-                        posData.id = curRow;
                         delete posData.waitingLoading;
                         if (curRow >= sortData.length) {
+                            posData.id = batchPosSpreadObj.genId(curRow);
                             bpObj.bpData.push(posData);
-                            insertData.push(posData);
+                            insertDatas.push(posData);
                         } else {
                             // 更改bpObj.bpData同行数据用posData替换
                             bpObj.bpData[curRow] = posData;
-                            updateData.push(posData);
+                            updateDatas.push(posData);
                         }
-                        data.push(posData);
-                        rows.push(curRow);
                     }
                 }
-                if (data.length > 0) {
-                    for (const [i,d] of data.entries()) {
+                if (insertDatas.length > 0) {
+                    for (const d of insertDatas) {
                         const pos = _.find(bpObj.posData, { name: d.name });
                         const bpPoss = _.filter(bpObj.bpData, { name: d.name });
                         const spPos = _.find(bpObj.spData, { name: d.name });
                         if (pos && bpPoss.length > 0) {
-                            // 其它bpPoss add为false
-                            for (const b of bpPoss) {
-                                b.add = false;
-                            }
                             const cInfo = _.find(changeList, { gcl_id: pos.lid, mx_id: pos.id });
                             if (cInfo) {
                                 continue;
                             }
-                            bpObj.bpData[rows[i]].add = true;
+                            // 其它bpPoss add为false
+                            for (const b of bpPoss) {
+                                b.add = false;
+                            }
+                            const bp = _.find(bpObj.bpData, { id: d.id });
+                            bp.add = true;
                             if (spPos) {
                                 spPos.id = d.id;
                                 spPos.camount = d.camount;
@@ -5604,6 +5607,20 @@ $(document).ready(() => {
                         }
                     }
                 }
+                if (updateDatas.length > 0) {
+                    for (const d of updateDatas) {
+                        const pos = _.find(bpObj.posData, { name: d.name });
+                        const spPos = _.find(bpObj.spData, { id: d.id });
+                        if (pos && spPos) {
+                            const cInfo = _.find(changeList, { gcl_id: pos.lid, mx_id: pos.id });
+                            if (cInfo) {
+                                continue;
+                            }
+                            spPos.camount = d.camount || 0;
+                            spPos.camount_expr = d.camount_expr || '';
+                        }
+                    }
+                }
                 SpreadJsObj.loadSheetData(bpObj.bpSheet, SpreadJsObj.DataType.Data, bpObj.bpData);
                 SpreadJsObj.loadSheetData(bpObj.spSheet, SpreadJsObj.DataType.Data, bpObj.spData);
             },
@@ -5612,7 +5629,7 @@ $(document).ready(() => {
                 if (!sel || !sel[0]) return;
                 const col = info.sheet.zh_setting.cols[sel[0].col];
                 const node = SpreadJsObj.getSelectObject(info.sheet);
-                if (!node || node.id === undefined) return;
+                if (!node || !node.id) return;
                 if (col.field === 'camount') {
                     if (node.camount_expr && node.camount_expr !== '') {
                         info.sheet.getCell(info.row, info.col).text(node.camount_expr);
@@ -5627,7 +5644,7 @@ $(document).ready(() => {
                 const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
                 const node = SpreadJsObj.getSelectObject(billsSheet);
                 const col = info.sheet.zh_setting.cols[info.col];
-                if (!posData || posData.id === undefined || !col) {
+                if (!posData || !posData.id || !col) {
                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
                 }
@@ -5688,7 +5705,7 @@ $(document).ready(() => {
                     let bPaste = true;
                     const curRow = info.cellRange.row + iRow;
                     const posData = sortData[curRow];
-                    if (!posData || posData.id === undefined) continue;
+                    if (!posData || !posData.id) continue;
                     for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
                         const curCol = info.cellRange.col + iCol;
                         const colSetting = info.sheet.zh_setting.cols[curCol];
@@ -5745,7 +5762,7 @@ $(document).ready(() => {
                 if (!sel || !sel[0]) return;
                 const col = info.sheet.zh_setting.cols[sel[0].col];
                 const node = SpreadJsObj.getSelectObject(info.sheet);
-                if (!node || node.id === undefined) return;
+                if (!node || !node.id) return;
                 if (col.field === 'camount') {
                     if (node.camount_expr && node.camount_expr !== '') {
                         info.sheet.getCell(info.row, info.col).text(node.camount_expr);
@@ -5760,7 +5777,7 @@ $(document).ready(() => {
                 const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
                 const node = SpreadJsObj.getSelectObject(billsSheet);
                 const col = info.sheet.zh_setting.cols[info.col];
-                if (!posData || posData.id === undefined || !col) {
+                if (!posData || !posData.id || !col) {
                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
                 }
@@ -5828,6 +5845,9 @@ $(document).ready(() => {
                 for (let r = 0; r < sel.rowCount; r++) {
                     const select = bpObj.bpData[row + r];
                     delList.push(select);
+                    const spRow = _.findIndex(bpObj.spData, { id: select.id });
+                    bpObj.spData.splice(spRow, 1);
+                    bpObj.spSheet.deleteRows(spRow, 1);
                 }
                 _.pullAll(bpObj.bpData, delList);
                 bpObj.bpSheet.deleteRows(row, sel.rowCount);
@@ -5890,15 +5910,7 @@ $(document).ready(() => {
                 $('#batch-ledger-name').text('');
                 SpreadJsObj.loadSheetData(bpObj.opSheet, SpreadJsObj.DataType.Data, []);
             }
-            bpObj.bpData = [];
-            bpObj.spData = [];
-            SpreadJsObj.loadSheetData(bpObj.bpSheet, SpreadJsObj.DataType.Data, []);
-            SpreadJsObj.loadSheetData(bpObj.spSheet, SpreadJsObj.DataType.Data, []);
-            // if (datas.length === 0) {
-            //     $('#show-project-0').show();
-            // } else {
-            //     $('#show-project-0').hide();
-            // }
+            $('#clear-bp-btn').click();
         }
 
         const initBatchPos = function () {
@@ -6054,7 +6066,7 @@ $(document).ready(() => {
                     },
                 }
             };
-            $.contextMenu(spContextMenuOptions);
+            // $.contextMenu(spContextMenuOptions);
 
             $('#batch-pos').bind('shown.bs.modal', function () {
                 if (opSpread) opSpread.refresh();
@@ -6065,13 +6077,15 @@ $(document).ready(() => {
             $('#clear-bp-btn').click(function () {
                 bpObj.bpData = [];
                 batchPosSpreadObj.clearBpSheet(bpObj.bpSheet);
-            });
-
-            $('#clear-op-btn').click(function () {
                 bpObj.spData = [];
                 batchPosSpreadObj.clearSpSheet(bpObj.spSheet);
             });
 
+            // $('#clear-op-btn').click(function () {
+            //     bpObj.spData = [];
+            //     batchPosSpreadObj.clearSpSheet(bpObj.spSheet);
+            // });
+
             $('#add-changelist-btn').click(function () {
                 if (bpObj.spData.length === 0) {
                     toastr.warning('录入区计量单元为空');

+ 3 - 3
app/view/change/revise_modal.ejs

@@ -149,6 +149,9 @@
                             <div class="d-inline-block ml-3">
                                 <button class="btn btn-sm btn-outline-primary" id="clear-bp-btn">清空</button>
                             </div>
+                            <div class="d-inline-block ml-3">
+                                <p class="text-warning">计量单元仅支持粘贴;绿色行表示已存在录入区的计量单元。</p>
+                            </div>
                             <div class="modal-height-300" id="batch-pos-spread">
                             </div>
                         </div>
@@ -156,9 +159,6 @@
                             <div class="d-inline-block">
                                 <h5 class="pl-2" style="line-height: 28px;">录入区 </h5>
                             </div>
-                            <div class="d-inline-block ml-3">
-                                <button class="btn btn-sm btn-outline-primary" id="clear-op-btn">清空</button>
-                            </div>
                             <div class="modal-height-300" id="save-pos-spread">
                             </div>
                         </div>