瀏覽代碼

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

MaiXinRong 4 年之前
父節點
當前提交
0298a4beac

+ 3 - 0
app/controller/schedule_controller.js

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

+ 6 - 6
app/public/js/schedule_plan.js

@@ -330,9 +330,6 @@ $(function () {
                 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];
@@ -365,9 +362,12 @@ $(function () {
                             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;
+                        const updateData = {
+                            lid: node.ledger_id,
+                            yearmonth,
+                            plan_gcl,
+                            plan_tp,
+                        };
                         datas.push(updateData);
                         node[yearmonth+'_gcl'] = plan_gcl;
                         node[yearmonth+'_tp'] = plan_tp;

+ 106 - 84
app/public/js/schedule_stage_gcl.js

@@ -213,7 +213,8 @@ $(function () {
             // 先判断当前修改月份与汇总sjs月份是否一致或更大,获取修改的对应台账行
             const huizongSelect = SpreadJsObj.getRowObject(huizongSpread.getActiveSheet(), row);
             if (yearmonth.split('-')[0] === curScheduleMonth.yearmonth.split('-')[0]) {
-                huizongSelect.year_sj_gcl = ZhCalc.add(ZhCalc.sub(huizongSelect.year_sj_gcl, orgValue), validText);
+                console.log(huizongSelect, row);
+                huizongSelect.year_sj_gcl = huizongSelect.year_sj_gcl ? ZhCalc.add(ZhCalc.sub(huizongSelect.year_sj_gcl, orgValue), validText) : validText;
                 huizongSelect.year_sj_tp = huizongSelect.dgn_price && huizongSelect.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(huizongSelect.year_sj_gcl, huizongSelect.dgn_price), 0) : 0;
             }
             if (yearmonth === curScheduleMonth.yearmonth) {
@@ -222,7 +223,7 @@ $(function () {
                 huizongSelect.sj_tp = huizongSelect.dgn_price && huizongSelect.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(huizongSelect.sj_gcl, huizongSelect.dgn_price), 0) : 0;
             }
             if (yearmonth <= curScheduleMonth.yearmonth) {
-                huizongSelect.end_sj_gcl = ZhCalc.add(ZhCalc.sub(huizongSelect.end_sj_gcl, orgValue), validText);
+                huizongSelect.end_sj_gcl = huizongSelect.end_sj_gcl ? ZhCalc.add(ZhCalc.sub(huizongSelect.end_sj_gcl, orgValue), validText) : validText;
                 huizongSelect.end_sj_tp = huizongSelect.dgn_price && huizongSelect.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(huizongSelect.end_sj_gcl, huizongSelect.dgn_price), 0) : 0;
             }
             const nodes = treeCalc.calculateParent(huizongSpread.getActiveSheet().zh_tree, huizongSelect);
@@ -278,44 +279,52 @@ $(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 = [], huizongNodes = [];
                 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];
+                        if(col.readOnly === true || !node.is_leaf) {
+                            continue;
+                        }
+                        const updateData = {
+                            lid: node.ledger_id,
+                            yearmonth,
+                            sj_gcl: null,
+                            sj_tp: null,
+                        };
+                        datas.push(updateData);
+                        huizongNodes.push({row: iRow, yearmonth, orgValue, nowValue: null});
+                        node[yearmonth+'_sj_gcl'] = null;
+                        node[yearmonth+'_sj_tp'] = null;
+                        bDel = true;
+                    }
+                    if (bDel) filterNodes.push(node);
                 }
-                const yearmonth = col.field.split('_')[0];
-                if(col.readOnly === true || !select.is_leaf) {
-                    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);
+                        }
+                        for (const hz of huizongNodes) {
+                            ledgerSpreadObj.reCalcHuizong(hz.row, hz.yearmonth, hz.orgValue, hz.nowValue);
+                        }
+                        SpreadJsObj.reLoadSheetData(sheet);
+                    }, function () {
+                        SpreadJsObj.reLoadSheetData(sheet);
+                    });
                 }
-                let sj_gcl = 0;
-                let sj_tp = 0;
-                select[col.field] = 0;
-                const updateData = {
-                    lid: select.ledger_id,
-                    yearmonth,
-                    sj_gcl,
-                    sj_tp,
-                };
-                postData(window.location.pathname + '/save', {type: 'ledger_edit', postData: updateData}, function (result) {
-                    select[yearmonth + '_sj_tp'] = sj_tp;
-                    const nodes = treeCalc.calculateParent(sheet.zh_tree, select);
-                    const refreshNode = ledgerTree.loadPostData({update: nodes});
-                    ledgerSpreadObj.refreshTree(sheet, refreshNode);
-                    ledgerSpreadObj.reCalcHuizong(info.row, yearmonth, orgValue, validText);
-                },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) {
@@ -323,57 +332,70 @@ $(function () {
                 cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
                 numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
             };
-            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;
+            const tree = info.sheet.zh_tree;
+            if (!tree) { return; }
+            const sortData = info.sheet.zh_tree.nodes;
+            const datas = [], filterNodes = [], huizongNodes = [];
+
+            for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
+                let bPaste = false;
+                const curRow = info.cellRange.row + iRow;
+                const node = sortData[curRow];
+                if (node) {
+                    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 reg = new RegExp('^([-]?)\\d+$');
+                        if (validText !== null && (!reg.test(validText))) {
+                            validText = ZhCalc.round(validText, 3);
+                        }
+                        const sj_gcl = validText;
+                        const sj_tp = node.dgn_price && node.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, node.dgn_price), 0) : 0;
+                        const updateData = {
+                            lid: node.ledger_id,
+                            yearmonth,
+                            sj_gcl,
+                            sj_tp,
+                        };
+                        datas.push(updateData);
+                        huizongNodes.push({row: info.cellRange.row + iRow, yearmonth, orgValue, nowValue: validText});
+                        node[yearmonth+'_sj_gcl'] = sj_gcl;
+                        node[yearmonth+'_sj_tp'] = sj_tp;
+                        bPaste = true;
+                    }
+                    if (bPaste) {
+                        filterNodes.push(node);
+                    }
+                }
             }
-            if (isNaN(validText)) {
-                toastr.error('不能粘贴其它非数字类型字符');
+            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);
+                    }
+                    for (const hz of huizongNodes) {
+                        ledgerSpreadObj.reCalcHuizong(hz.row, hz.yearmonth, hz.orgValue, hz.nowValue);
+                    }
+                    SpreadJsObj.reLoadSheetData(info.sheet);
+                }, function () {
+                    SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
+                });
+            } else {
                 SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
-                return;
             }
-            const yearmonth = col.field.split('_')[0];
-            // 判断输入位数,提示
-            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);
-            }
-            const sj_gcl = validText;
-            const sj_tp = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, select.dgn_price), 0) : 0;
-            select[col.field] = validText;
-            const updateData = {
-                lid: select.ledger_id,
-                yearmonth,
-                sj_gcl,
-                sj_tp,
-            };
-            console.log(updateData);
-            postData(window.location.pathname + '/save', {type: 'ledger_edit', postData: updateData}, function (result) {
-                select[yearmonth + '_sj_tp'] = sj_tp;
-                const nodes = treeCalc.calculateParent(info.sheet.zh_tree, select);
-                const refreshNode = ledgerTree.loadPostData({update: nodes});
-                ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
-                ledgerSpreadObj.reCalcHuizong(info.row, yearmonth, orgValue, validText);
-            },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);
-            })
         },
     };
 

+ 45 - 0
app/service/schedule_ledger_month.js

@@ -126,6 +126,51 @@ module.exports = app => {
             }
         }
 
+        async saveSjDatas(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.sj_gcl === null && data.sj_tp === null && info.plan_gcl === null && info.plan_tp === null) {
+                            await transaction.delete(this.tableName, { id: info.id });
+                        } else {
+                            const updateData = {
+                                id: info.id,
+                                sj_gcl: data.sj_gcl,
+                                sj_tp: data.sj_tp,
+                            };
+                            await transaction.update(this.tableName, updateData);
+                        }
+                    } else {
+                        const insertData = {
+                            tid: this.ctx.tender.id,
+                            lid: data.lid,
+                            yearmonth: data.yearmonth,
+                            sj_gcl: data.sj_gcl,
+                            sj_tp: data.sj_tp,
+                        };
+                        await transaction.insert(this.tableName, insertData);
+                    }
+                }
+                // 重新计算本月、总 计划金额和计划工程量
+                for (const ym of ymArray) {
+                    await this.calcMonthSj(transaction, this.ctx.tender.id, ym);
+                }
+                await this.ctx.service.scheduleMonth.calcSj(transaction, this.ctx.tender.id);
+                await transaction.commit();
+                return true;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
         async calcMonthSj(transaction, tid, yearmonth) {
             const sql = 'SELECT SUM(`sj_gcl`) as total_sj_gcl, SUM(`sj_tp`) as total_sj_tp FROM ?? WHERE tid = ? and yearmonth = ?';
             const sqlParam = [this.tableName, tid, yearmonth];