浏览代码

复制粘贴

laiguoran 4 年之前
父节点
当前提交
c3afc648cb
共有 3 个文件被更改,包括 159 次插入110 次删除
  1. 3 0
      app/controller/schedule_controller.js
  2. 111 110
      app/public/js/schedule_plan.js
  3. 45 0
      app/service/schedule_ledger_month.js

+ 3 - 0
app/controller/schedule_controller.js

@@ -441,6 +441,9 @@ module.exports = app => {
                     case 'ledger_edit':
                         responseData.data = await ctx.service.scheduleLedgerMonth.save(data.postData);
                         break;
+                    case 'ledger_paste':
+                        responseData.data = await ctx.service.scheduleLedgerMonth.saveDatas(data.postData);
+                        break;
                     default: throw '参数有误';
                 }
                 ctx.body = responseData;

+ 111 - 110
app/public/js/schedule_plan.js

@@ -137,7 +137,6 @@ $(function () {
         const newLedgerList = setMonthToLedger(data.bills, data.slm);
         baseLedgerTree.loadDatas(newLedgerList);
         treeCalc.calculateAll(baseLedgerTree);
-        console.log(baseLedgerTree);
         for (const d of baseLedgerTree.nodes) {
             if (!d.b_code) {
                 const one = _.find(selectedLedgerList, function (item) {
@@ -148,7 +147,6 @@ $(function () {
                 }
             }
         }
-        // console.log(ledgerTree);
         ledgerTree.sortTreeNode(true);
         treeCalc.calculateAll(ledgerTree);
         console.log(ledgerTree);
@@ -253,7 +251,6 @@ $(function () {
                     plan_gcl,
                     plan_tp,
                 };
-                console.log(updateData);
                 postData(window.location.pathname + '/save', {type: 'ledger_edit', postData: updateData}, function (result) {
                     if (mode === 'tp') {
                         select[yearmonth + '_gcl'] = plan_gcl;
@@ -272,48 +269,49 @@ $(function () {
             }
         },
         deletePress: function (sheet) {
-            if (!sheet.zh_setting || sheet.zh_setting.readOnly) return;
+            if (!sheet.zh_setting) return;
             if (sheet.zh_setting && sheet.zh_tree) {
-                const sel = sheet.getSelections()[0];
+                const sel = sheet.getSelections()[0], datas = [], filterNodes = [];
                 if (!sel) return;
-                if(sel.rowCount > 1 || sel.colCount > 1) {
-                    return;
-                }
-                const select = SpreadJsObj.getSelectObject(sheet);
-                const col = sheet.zh_setting.cols[sel.col];
-                const orgValue = select[col.field];
-                if (!orgValue) {
-                    return;
+                for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
+                    let bDel = false;
+                    const node = sheet.zh_tree.nodes[iRow];
+                    for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
+                        const col = sheet.zh_setting.cols[iCol];
+                        const orgValue = node[col.field];
+                        if (!orgValue) {
+                            continue;
+                        }
+                        const yearmonth = col.field.split('_')[0];
+                        const modes = col.field.split('_')[1];
+                        if(col.readOnly === true || !node.is_leaf || mode[modes] !== schedule.mode) {
+                            continue;
+                        }
+                        const updateData = {
+                            lid: node.ledger_id,
+                            yearmonth,
+                            plan_gcl: null,
+                            plan_tp: null,
+                        };
+                        datas.push(updateData);
+                        node[yearmonth+'_gcl'] = null;
+                        node[yearmonth+'_tp'] = null;
+                        bDel = true;
+                    }
+                    if (bDel) filterNodes.push(node);
                 }
-                const yearmonth = col.field.split('_')[0];
-                const modes = col.field.split('_')[1];
-                if(col.readOnly === true || !select.is_leaf || mode[modes] !== schedule.mode) {
-                    return;
+                if (datas.length > 0) {
+                    postData(window.location.pathname + '/save', {type: 'ledger_paste', postData: datas}, function (result) {
+                        for (const uul of filterNodes) {
+                            const nodes = treeCalc.calculateParent(sheet.zh_tree, uul);
+                            const refreshNode = ledgerTree.loadPostData({update: nodes});
+                            ledgerSpreadObj.refreshTree(sheet, refreshNode);
+                        }
+                        SpreadJsObj.reLoadSheetData(sheet);
+                    }, function () {
+                        SpreadJsObj.reLoadSheetData(sheet);
+                    });
                 }
-                let plan_gcl = 0;
-                let plan_tp = 0;
-                select[col.field] = 0;
-                const updateData = {
-                    lid: select.ledger_id,
-                    yearmonth,
-                    plan_gcl,
-                    plan_tp,
-                };
-                postData(window.location.pathname + '/save', {type: 'ledger_edit', postData: updateData}, function (result) {
-                    if (modes === 'tp') {
-                        select[yearmonth + '_gcl'] = plan_gcl;
-                    } else {
-                        select[yearmonth + '_tp'] = plan_tp;
-                    }
-                    const nodes = treeCalc.calculateParent(sheet.zh_tree, select);
-                    const refreshNode = ledgerTree.loadPostData({update: nodes});
-                    ledgerSpreadObj.refreshTree(sheet, refreshNode);
-                },function () {
-                    select[col.field] = orgValue;
-                    const nodes = treeCalc.calculateParent(sheet.zh_tree, select);
-                    const refreshNode = ledgerTree.loadPostData({update: nodes});
-                    ledgerSpreadObj.refreshTree(sheet, refreshNode);
-                })
             }
         },
         clipboardPasted(e, info) {
@@ -321,76 +319,79 @@ $(function () {
                 cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
                 numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
             };
-            console.log(info);
-            const range = info.cellRange;
-            if (range.rowCount > 1 || range.colCount > 1) {
-                toastMessageUniq(hint.cellError);
-                SpreadJsObj.reLoadSheetHeader(ledgerSpread.getActiveSheet());
-                SpreadJsObj.reLoadSheetData(ledgerSpread.getActiveSheet());
-                return;
-            }
-            const select = SpreadJsObj.getSelectObject(info.sheet);
-            const col = info.sheet.zh_setting.cols[range.col];
-            let validText = is_numeric(info.pasteData.text) ? parseFloat(info.pasteData.text) : (info.pasteData.text ? trimInvalidChar(info.pasteData.text) : null);
-            const orgValue = select[col.field];
-            if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
-                SpreadJsObj.reLoadRowData(info.sheet, info.row);
-                return;
-            }
-            if (isNaN(validText)) {
-                toastr.error('不能粘贴其它非数字类型字符');
-                SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
-                return;
-            }
-            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+$');
-                if (validText !== null && (!reg.test(validText))) {
-                    // toastr.error('粘贴的金额小数位数不能大于0位');
-                    // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
-                    // return;
-                    validText = ZhCalc.round(validText, 0);
+            const tree = info.sheet.zh_tree;
+            if (!tree) { return; }
+
+            const sortData = info.sheet.zh_tree.nodes;
+            const datas = [], filterNodes = [];
+
+            for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
+                let bPaste = false;
+                const curRow = info.cellRange.row + iRow;
+                const node = sortData[curRow];
+                if (node) {
+                    const updateData = {
+                        lid: node.ledger_id,
+                    };
+                    for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
+                        const curCol = info.cellRange.col + iCol;
+                        const colSetting = info.sheet.zh_setting.cols[curCol];
+                        let validText = is_numeric(info.sheet.getText(curRow, curCol)) ? parseFloat(info.sheet.getText(curRow, curCol)) : (info.sheet.getText(curRow, curCol) ? trimInvalidChar(info.sheet.getText(curRow, curCol)) : null);
+                        const orgValue = node[colSetting.field];
+                        if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
+                            continue;
+                        }
+                        if (isNaN(validText)) {
+                            toastMessageUniq(hint.numberExpr);
+                            continue;
+                        }
+                        const yearmonth = colSetting.field.split('_')[0];
+                        const mode = colSetting.field.split('_')[1];
+                        let plan_gcl = 0;
+                        let plan_tp = 0;
+                        // 判断输入位数,提示
+                        if (mode === 'tp') {
+                            const reg = new RegExp('^([-]?)\\d+$');
+                            if (validText !== null && (!reg.test(validText))) {
+                                validText = ZhCalc.round(validText, 0);
+                            }
+                            plan_gcl = node.dgn_price && node.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(validText, node.dgn_price), 3) : 0;
+                            plan_tp = validText;
+                        } else {
+                            const reg = new RegExp('^([-]?)\\d+$');
+                            if (validText !== null && (!reg.test(validText))) {
+                                validText = ZhCalc.round(validText, 3);
+                            }
+                            plan_gcl = validText;
+                            plan_tp = node.dgn_price && node.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, node.dgn_price), 0) : 0;
+                        }
+                        updateData.yearmonth = yearmonth;
+                        updateData.plan_gcl = plan_gcl;
+                        updateData.plan_tp = plan_tp;
+                        datas.push(updateData);
+                        node[yearmonth+'_gcl'] = plan_gcl;
+                        node[yearmonth+'_tp'] = plan_tp;
+                        bPaste = true;
+                    }
+                    if (bPaste) {
+                        filterNodes.push(node);
+                    }
                 }
-                plan_gcl = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(validText, select.dgn_price), 3) : 0;
-                plan_tp = validText;
+            }
+            if (datas.length > 0) {
+                postData(window.location.pathname + '/save', {type: 'ledger_paste', postData: datas}, function (result) {
+                    for (const uul of filterNodes) {
+                        const nodes = treeCalc.calculateParent(info.sheet.zh_tree, uul);
+                        const refreshNode = ledgerTree.loadPostData({update: nodes});
+                        ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
+                    }
+                    SpreadJsObj.reLoadSheetData(info.sheet);
+                }, function () {
+                    SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
+                });
             } else {
-                // const reg = new RegExp('^([-]?)\\d+(\\.\\d{0,3})?$');
-                const reg = new RegExp('^([-]?)\\d+$');
-                if (validText !== null && (!reg.test(validText))) {
-                    // toastr.error('粘贴的工程量小数位数不能大于3位');
-                    // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
-                    // return;
-                    validText = ZhCalc.round(validText, 3);
-                }
-                plan_gcl = validText;
-                plan_tp = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, select.dgn_price), 0) : 0;
+                SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
             }
-            select[col.field] = validText;
-            const updateData = {
-                lid: select.ledger_id,
-                yearmonth,
-                plan_gcl,
-                plan_tp,
-            };
-            postData(window.location.pathname + '/save', {type: 'ledger_edit', postData: updateData}, function (result) {
-                if (mode === 'tp') {
-                    select[yearmonth + '_gcl'] = plan_gcl;
-                } else {
-                    select[yearmonth + '_tp'] = plan_tp;
-                }
-                const nodes = treeCalc.calculateParent(info.sheet.zh_tree, select);
-                const refreshNode = ledgerTree.loadPostData({update: nodes});
-                ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
-            },function () {
-                select[col.field] = orgValue;
-                const nodes = treeCalc.calculateParent(info.sheet.zh_tree, select);
-                const refreshNode = ledgerTree.loadPostData({update: nodes});
-                ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
-            })
         },
     };
 
@@ -436,7 +437,7 @@ $(function () {
                 }
             }
         }
-        console.log(update_under_ledger);
+
         postData(window.location.pathname + '/save', {type: 'mode', postData: {mode: this_mode, update_under_ledger}}, function (result) {
             _self.addClass('disabled').attr('disabled', true);
             _self.text('当前');
@@ -496,7 +497,7 @@ $(function () {
             const hadmonth = [];
             for (const m of addMonthList) {
                 const one = _.find(scheduleMonth, { yearmonth: m });
-                console.log(one, m);
+
                 if (one) {
                     hadmonth.push(m);
                 }

+ 45 - 0
app/service/schedule_ledger_month.js

@@ -44,6 +44,51 @@ module.exports = app => {
             }
         }
 
+        async saveDatas(datas) {
+            // 判断是添加,删除,还是修改
+            const transaction = await this.db.beginTransaction();
+            try {
+                const ymArray = [];
+                for (const data of datas) {
+                    const info = await this.getDataByCondition({ tid: this.ctx.tender.id, lid: data.lid, yearmonth: data.yearmonth });
+                    if (!this._.includes(ymArray, data.yearmonth)) {
+                        ymArray.push(data.yearmonth);
+                    }
+                    if (info) {
+                        if (data.plan_gcl === null && data.plan_tp === null && info.sj_gcl === null && info.sj_tp === null) {
+                            await transaction.delete(this.tableName, { id: info.id });
+                        } else {
+                            const updateData = {
+                                id: info.id,
+                                plan_gcl: data.plan_gcl,
+                                plan_tp: data.plan_tp,
+                            };
+                            await transaction.update(this.tableName, updateData);
+                        }
+                    } else {
+                        const insertData = {
+                            tid: this.ctx.tender.id,
+                            lid: data.lid,
+                            yearmonth: data.yearmonth,
+                            plan_gcl: data.plan_gcl,
+                            plan_tp: data.plan_tp,
+                        };
+                        await transaction.insert(this.tableName, insertData);
+                    }
+                }
+                // 重新计算本月、总 计划金额和计划工程量
+                for (const ym of ymArray) {
+                    await this.calcMonthPlan(transaction, this.ctx.tender.id, ym);
+                }
+                await this.ctx.service.scheduleMonth.calcPlan(transaction, this.ctx.tender.id);
+                await transaction.commit();
+                return true;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
         async saveSj(data) {
             // 判断是添加,删除,还是修改
             const transaction = await this.db.beginTransaction();