Browse Source

TASK #3942 台账分解、台账修订;期望"批量插入清单-计量单元"能进行右键-竖向粘贴内容。

MaiXinRong 3 years ago
parent
commit
83f28af978

+ 28 - 20
app/public/js/ledger.js

@@ -2926,7 +2926,7 @@ $(document).ready(function() {
                             }
                             qdSheet.setSelection(sel.row, sel.col, 1, 1);
                         },
-                    },
+                    }
                 }
             });
             // 拉取签约清单数据
@@ -2938,7 +2938,7 @@ $(document).ready(function() {
                 });
             }
             // 双击签约清单,自动添加到清单编号窗口
-            this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
+            this.dealSpread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
                 const deal = info.sheet.zh_data[info.row];
                 const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
                 const sel = qdSheet.getSelections()[0];
@@ -2957,30 +2957,38 @@ $(document).ready(function() {
                 }
                 qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
             });
-            this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
-                const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
-                const count = posSheet.getColumnCount() - 2;
-                if (billsCount > count) {
-                    posSheet.setColumnCount(billsCount + 2);
-                    for (let i = count + 1; i <= billsCount; i++) {
-                        info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
+            this.qdSpread.bind(spreadNS.Events.ClipboardPasting, function (e, info) {
+                info.cancel = true;
+                const transpose = $('[name=batch-transpose]')[0].checked;
+                const pasteData = SpreadJsObj.analysisPasteText(info.pasteData.text, transpose);
+
+                const billsSheet = info.sheet, posSheet = self.posSpread.getActiveSheet();
+                const billsCount = info.sheet.getRowCount(), finalCount = info.cellRange.row + pasteData.length + 1;
+                SpreadJsObj.beginMassOperation(billsSheet);
+                if (finalCount > billsCount) {
+                    billsSheet.setRowCount(finalCount);
+                    posSheet.setColumnCount(finalCount + 2);
+                    for (let i = billsCount - 1; i <= finalCount; i++) {
+                        billsSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
                         posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
                     }
                 }
-                if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
-                    const dealBills = self.dealSpread.getActiveSheet().zh_data;
-                    if (dealBills && dealBills.length > 0) {
-                        for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
-                            const curRow = iRow + info.cellRange.row;
-                            const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
-                            if (bills) {
-                                info.sheet.getCell(curRow, 1).value(bills.name);
-                                info.sheet.getCell(curRow, 2).value(bills.unit);
-                                info.sheet.getCell(curRow, 3).value(bills.unit_price);
-                            }
+                for (let iRow = 0; iRow < pasteData.length; iRow++) {
+                    const curRow = iRow + info.cellRange.row;
+                    pasteData[iRow].forEach((value, iCol) => {
+                        billsSheet.getCell(curRow, iCol + info.cellRange.col).value(value);
+                    });
+                    if ([0, 1].indexOf(info.cellRange.col) >= 0) {
+                        const dealBills = self.dealSpread.getActiveSheet().zh_data;
+                        const bills = _.find(dealBills, {code: billsSheet.getText(curRow, 0)});
+                        if (bills) {
+                            billsSheet.getCell(curRow, 1).value(bills.name);
+                            billsSheet.getCell(curRow, 2).value(bills.unit);
+                            billsSheet.getCell(curRow, 3).value(bills.unit_price);
                         }
                     }
                 }
+                SpreadJsObj.endMassOperation(billsSheet);
             });
             this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
                 const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();

+ 27 - 18
app/public/js/revise.js

@@ -2107,30 +2107,39 @@ $(document).ready(() => {
                 qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
                 qdSheet.getParent().focus();
             });
-            this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
-                const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
-                const count = posSheet.getColumnCount() - 2;
-                if (billsCount > count) {
-                    posSheet.setColumnCount(billsCount + 2);
-                    for (let i = count + 1; i <= billsCount; i++) {
-                        info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
+            this.qdSpread.bind(spreadNS.Events.ClipboardPasting, function (e, info) {
+                info.cancel = true;
+                const transpose = $('[name=batch-transpose]')[0].checked;
+                const pasteData = SpreadJsObj.analysisPasteText(info.pasteData.text, transpose);
+
+                const billsSheet = info.sheet, posSheet = self.posSpread.getActiveSheet();
+                const billsCount = info.sheet.getRowCount(), finalCount = info.cellRange.row + pasteData.length + 1;
+                SpreadJsObj.beginMassOperation(billsSheet);
+                if (finalCount > billsCount) {
+                    billsSheet.setRowCount(finalCount);
+                    posSheet.setColumnCount(finalCount + 2);
+                    for (let i = billsCount - 1; i <= finalCount; i++) {
+                        billsSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
                         posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
                     }
                 }
-                if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
-                    const dealBills = self.dealSpread.getActiveSheet().zh_data;
-                    if (dealBills && dealBills.length > 0) {
-                        for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
-                            const curRow = iRow + info.cellRange.row;
-                            const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
-                            if (bills) {
-                                info.sheet.getCell(curRow, 1).value(bills.name);
-                                info.sheet.getCell(curRow, 2).value(bills.unit);
-                                info.sheet.getCell(curRow, 3).value(bills.unit_price);
-                            }
+                SpreadJsObj.beginMassOperation(billsSheet);
+                for (let iRow = 0; iRow < pasteData.length; iRow++) {
+                    const curRow = iRow + info.cellRange.row;
+                    pasteData[iRow].forEach((value, iCol) => {
+                        billsSheet.getCell(curRow, iCol + info.cellRange.col).value(value);
+                    });
+                    if ([0, 1].indexOf(info.cellRange.col) >= 0) {
+                        const dealBills = self.dealSpread.getActiveSheet().zh_data;
+                        const bills = _.find(dealBills, {code: billsSheet.getText(curRow, 0)});
+                        if (bills) {
+                            billsSheet.getCell(curRow, 1).value(bills.name);
+                            billsSheet.getCell(curRow, 2).value(bills.unit);
+                            billsSheet.getCell(curRow, 3).value(bills.unit_price);
                         }
                     }
                 }
+                SpreadJsObj.endMassOperation(billsSheet);
             });
             this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
                 const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();

+ 19 - 4
app/public/js/spreadjs_rela/spreadjs_zh.js

@@ -952,23 +952,38 @@ const SpreadJsObj = {
             }
             copyData.push(rowText.join('\t'));
         }
-        return copyData.join('\n');
+        return copyData.join('\r\n');
     },
-    analysisPasteText: function (text) {
+    analysisPasteText: function (text, transpose = false) {
+        console.log(text);
         const result = [];
         if (text === '') return result;
 
-        const rows = text.split('\n');
+        const rows = text.split('\r\n');
+        if (rows[rows.length - 1] === '') rows.splice(rows.length - 1, 1);
         for (const r of rows) {
             const cols = r.split('\t');
             result.push(cols);
         }
-        return result;
+        return transpose ? SpreadJsObj.transposePasteData(result) : result;
     },
     analysisPasteHtml: function (html) {
         const result = [];
         if (!html || html === '') return result;
     },
+    transposePasteData: function (data) {
+        console.log(data);
+        const result = [];
+        const rowCount = data.length, colCount = data.reduce((r, x) => { return r ? Math.max(r, x.length) : x.length; });
+        for (let c = 0; c < colCount; c++) {
+            const newRow = [];
+            for (let r = 0; r < rowCount; r++) {
+                newRow.push(data[r][c]);
+            }
+            result.push(newRow)
+        }
+        return result;
+    },
     /**
      * 树表结构,定位至指定的节点
      * @param {GC.Spread.Sheets.Worksheet} sheet - 需要定位的sheet

+ 7 - 1
app/view/ledger/explode_modal.ejs

@@ -63,12 +63,18 @@
                 <h5 class="modal-title">批量插入清单-计量单元</h5>
             </div>
             <div class="modal-body">
-                <div class="custom-control custom-checkbox mb-2">
+                <div class="custom-control custom-checkbox mb-2 d-inline-block">
                     <label class="form-check-label">
                         <input class="form-check-input" type="checkbox" name="batch-filter">
                         过滤无计量单元的清单
                     </label>
                 </div>
+                <div class="custom-control custom-checkbox mb-2 d-inline-block">
+                    <label class="form-check-label">
+                        <input class="form-check-input" type="checkbox" name="batch-transpose">
+                        竖向粘贴
+                    </label>
+                </div>
                 <div class="row">
                     <div class="col-6">
                         <h6>清单信息</h6>

+ 7 - 1
app/view/revise/info_modal.ejs

@@ -6,12 +6,18 @@
                 <h5 class="modal-title">批量插入清单-计量单元</h5>
             </div>
             <div class="modal-body">
-                <div class="custom-control custom-checkbox mb-2">
+                <div class="custom-control custom-checkbox mb-2 d-inline-block">
                     <label class="form-check-label">
                         <input class="form-check-input" type="checkbox" name="batch-filter">
                         过滤无计量单元的清单
                     </label>
                 </div>
+                <div class="custom-control custom-checkbox mb-2 d-inline-block">
+                    <label class="form-check-label">
+                        <input class="form-check-input" type="checkbox" name="batch-transpose">
+                        竖向粘贴
+                    </label>
+                </div>
                 <div class="row">
                     <div class="col-6">
                         <h6>清单信息</h6>