Jelajahi Sumber

计划进度台账数据调整

laiguoran 4 tahun lalu
induk
melakukan
86a5ed2c54
2 mengubah file dengan 130 tambahan dan 16 penghapusan
  1. 130 15
      app/public/js/schedule_plan.js
  2. 0 1
      app/view/schedule/plan.ejs

+ 130 - 15
app/public/js/schedule_plan.js

@@ -22,15 +22,11 @@ $(function () {
         level: 'level',
         rootId: -1,
         fullPath: 'full_path',
-        calcFields: ['total_price']
         //treeCacheKey: 'ledger_bills_fold' + '_' + getTenderId(),
         // markFoldKey: 'bills-fold',
         // markFoldSubKey: window.location.pathname.split('/')[2],
     };
-    treeSetting.calcFun = function (node) {
-        node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
-    };
-    const ledgerTree = createNewPathTree('base', treeSetting);
+    const ledgerTree = createNewPathTree('filter', treeSetting);
 
     const static_cols = [
         {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', readOnly: true, cellType: 'tree'},
@@ -94,15 +90,41 @@ $(function () {
     SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
 
     postData('/tender/' + getTenderId() + '/schedule/ledger/load', {}, function (data) {
-        let treeData = [];
-        for(const sl of selectedLedgerList) {
-            const one = _.find(data, { 'ledger_id' : sl });
-            treeData.push(one);
+        // let treeData = [];
+        // for(const sl of selectedLedgerList) {
+        //     const one = _.find(data, { 'ledger_id' : sl });
+        //     treeData.push(one);
+        // }
+        // treeData = setLeafData(treeData);
+        // console.log(treeData);
+        // let treeData = data;
+        const baseLedgerTree = createNewPathTree('base', {
+            id: 'ledger_id',
+            pid: 'ledger_pid',
+            order: 'order',
+            level: 'level',
+            rootId: -1,
+            fullPath: 'full_path',
+            calcFields: ['total_price'],
+            calcFun: function (node) {
+                node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
+            }
+        });
+        baseLedgerTree.loadDatas(data);
+        treeCalc.calculateAll(baseLedgerTree);
+        for (const d of baseLedgerTree.nodes) {
+            if (!d.b_code) {
+                const one = _.find(selectedLedgerList, function (item) {
+                    return item === d.ledger_id;
+                });
+                if(one) {
+                    ledgerTree.addData(d, ['ledger_id', 'ledger_pid', 'order', 'level', 'tender_id', 'full_path',
+                        'code', 'name', 'unit', 'dgn_qty1', 'dgn_qty2', 'dgn_price', 'quantity', 'total_price']);
+                }
+            }
         }
-        treeData = setLeafData(treeData);
-        ledgerTree.loadDatas(treeData);
-        treeCalc.calculateAll(ledgerTree);
-        console.log(ledgerTree);
+        ledgerTree.sortTreeNode(true);
+        // console.log(ledgerTree);
         SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, ledgerTree);
     }, null, true);
 
@@ -171,20 +193,35 @@ $(function () {
                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
                 }
-                select[col.field] = validText;
                 const yearmonth = col.field.split('_')[0];
                 const mode = col.field.split('_')[1];
                 let plan_gcl = 0;
                 let plan_tp = 0;
+                // 判断输入位数,提示
                 if (mode === 'tp') {
+                    const reg = new RegExp('^([-]?)\\d+(\\.\\d{0,'+ parseInt(tenderInfo.decimal.tp) +'})?$');
+                    console.log(reg);
+                    console.log(reg.test(validText));
+                    if (validText !== null && (!reg.test(validText))) {
+                        toastr.error('输入金额小数位数不能大于' + tenderInfo.decimal.tp + '位');
+                        SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                        return;
+                    }
                     plan_gcl = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(validText, select.dgn_price), tenderInfo.decimal.up) : 0;
                     plan_tp = validText;
                     select[yearmonth + '_gcl'] = plan_gcl;
                 } else {
+                    const reg = new RegExp('^([-]?)\\d+(\\.\\d{0,'+ parseInt(tenderInfo.decimal.up) +'})?$');
+                    if (validText !== null && (!reg.test(validText))) {
+                        toastr.error('输入工程量小数位数不能大于' + tenderInfo.decimal.up + '位');
+                        SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                        return;
+                    }
                     plan_gcl = validText;
                     plan_tp = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, select.dgn_price), tenderInfo.decimal.tp) : 0;
                     select[yearmonth + '_tp'] = plan_tp;
                 }
+                select[col.field] = validText;
                 const updateData = {
                     lid: select.ledger_id,
                     yearmonth,
@@ -193,13 +230,91 @@ $(function () {
                 };
                 console.log(updateData);
                 // postData(window.location.pathname + '/save', {type: 'mode', postData: updateData}, function (result) {
-                //     SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
                 // })
             }
         },
         deletePress: function (sheet) {
             return;
         },
+        clipboardPasted(e, info) {
+            const hint = {
+                cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
+                numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
+                numberCan: {type: 'error', msg: '请粘贴大于0并且小于3位小数的浮点数'},
+            };
+            const range = info.cellRange;
+            const sortData = info.sheet.zh_data || [];
+            if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
+                toastMessageUniq(hint.cellError);
+                SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
+                SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
+                return;
+            }
+            if (sortData.length > 0 && range.col + range.colCount > 4 + months.length) {
+                toastMessageUniq(hint.cellError);
+                SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
+                SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
+                return;
+            }
+            const data = [];
+            for (let iRow = 0; iRow < range.rowCount; iRow++) {
+                let bPaste = true;
+                const curRow = range.row + iRow;
+                const materialMonthData = sortData[curRow];
+                const hintRow = range.rowCount > 1 ? curRow : '';
+                let sameCol = 0;
+                for (let iCol = 0; iCol < range.colCount; iCol++) {
+                    const curCol = range.col + iCol;
+                    const colSetting = info.sheet.zh_setting.cols[curCol];
+                    if (!colSetting) continue;
+
+                    let validText = info.sheet.getText(curRow, curCol);
+                    validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
+                    const orgValue = sortData[curRow][colSetting.field];
+                    if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
+                        sameCol++;
+                        if (range.colCount === sameCol)  {
+                            bPaste = false;
+                        }
+                        continue;
+                    }
+                    const num = parseFloat(validText);
+                    if (isNaN(validText)) {
+                        toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
+                        bPaste = false;
+                        continue;
+                    }
+                    if (validText !== null && (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num))) {
+                        toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
+                        bPaste = false;
+                        continue;
+                    }
+                    materialMonthData[colSetting.field] = validText;
+                    sortData[curRow][colSetting.field] = validText;
+                }
+                if (bPaste) {
+                    data.push(materialMonthData);
+                } else {
+                    SpreadJsObj.reLoadRowData(info.sheet, curRow);
+                }
+            }
+            if (data.length === 0) {
+                SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
+                return;
+            }
+            // // 更新至服务器
+            // postData(window.location.pathname + '/month/save', { type:'paste', updateData: data }, function (result) {
+            //     SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
+            //     materialBillsData = result.materialBillsData;
+            //     SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
+            //     m_tp = result.m_tp;
+            //     resetTpTable();
+            // }, function () {
+            //     SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
+            //     return;
+            // });
+        },
     };
 
     ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerSpreadObj.editEnded);

+ 0 - 1
app/view/schedule/plan.ejs

@@ -28,6 +28,5 @@
     const schedule = JSON.parse('<%- JSON.stringify(schedule) %>');
     const scheduleMonth = JSON.parse('<%- JSON.stringify(scheduleMonth) %>');
     const monthList = _.map(scheduleMonth, 'yearmonth');
-    console.log(monthList);
     const mode = JSON.parse('<%- JSON.stringify(mode) %>');
 </script>