Browse Source

1. 计量台账,编辑、复制粘贴、删除,合同/变更--设计数量
2. 计量台账,经济指标计算

MaiXinRong 5 years ago
parent
commit
dfa4a6b276

+ 11 - 1
app/controller/stage_controller.js

@@ -142,6 +142,11 @@ module.exports = app => {
                 [renderData.ledgerSpread, renderData.posSpread] = this._getSpreadSetting();
                 renderData.changeConst = changeConst;
                 renderData.ledgerData = await ctx.service.ledger.getDataByTenderId(ctx.tender.id, -1);
+                const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
+                for (const d of dgnData) {
+                    const l = ctx.app._.find(renderData.ledgerData, {id: d.id});
+                    ctx.app._.assignIn(l, d);
+                }
                 let curStageData, preStageData;
                 // 当前操作人查看最新数据,其他人查看历史数据
                 if (ctx.stage.readOnly) {
@@ -237,7 +242,12 @@ module.exports = app => {
                 if (data.pos) {
                     responseData.data = await ctx.service.stagePos.updateStageData(data.pos);
                 } else if (data.bills) {
-                    responseData.data.curStageData = await ctx.service.stageBills.updateStageData(data.bills);
+                    if (data.bills.dgn) {
+                        responseData.data.dgn = await ctx.service.stageBillsDgn.saveDgnData(data.bills.dgn);
+                    }
+                    if (data.bills.stage) {
+                        responseData.data.curStageData = await ctx.service.stageBills.updateStageData(data.bills.stage);
+                    }
                 }
                 await this.ctx.service.stage.updateCheckDetailFlag(ctx.stage.id, true);
                 ctx.body = responseData;

+ 3 - 0
app/public/js/global.js

@@ -257,6 +257,9 @@ const zeroRange = 0.00000001;
 function checkZero(value) {
     return _.isNumber(value) && Math.abs(value) < zeroRange;
 }
+function checkFieldChange(o, n) {
+    return o == n || ((!o || o === '') && (n === ''));
+}
 
 /**
  * 设置本地缓存

+ 21 - 0
app/public/js/path_tree.js

@@ -1170,6 +1170,23 @@ const createNewPathTree = function (type, setting) {
             }
         }
 
+        _updateDgnData(datas) {
+            datas = datas instanceof Array ? datas : [datas];
+            let loadedData = [];
+            for (const data of datas) {
+                let node = this.getStageItems(data.id);
+                if (node) {
+                    for (const prop in node) {
+                        if (data[prop] !== undefined && data[prop] !== node[prop]) {
+                            node[prop] = data[prop];
+                        }
+                    }
+                    loadedData.push(node);
+                }
+            }
+            return loadedData;
+        }
+
         /**
          * 提交数据至后端,返回的前端树结构应刷新的部分
          * StageTree仅有更新CurStage部分,不需要增删
@@ -1187,6 +1204,10 @@ const createNewPathTree = function (type, setting) {
                 result = this._updateStageData(data.curStageData);
                 this._getNodesParents(parents, result);
             }
+            if (data.dgn) {
+                const dgnResult = this._updateDgnData(data.dgn);
+                result = result ? result.concat(dgnResult) : dgnResult;
+            }
             result = result ? result.concat(parents) : parents;
             result.sort((a, b) => {
                 return b.level - a.level;

+ 78 - 40
app/public/js/stage.js

@@ -165,7 +165,7 @@ $(document).ready(() => {
         node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
         node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
         node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
-        node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), tenderInfo.decimal.up);
+        node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
     };
     const stageTree = createNewPathTree('stage', stageTreeSetting);
     // 初始化 部位明细 数据结构
@@ -458,6 +458,7 @@ $(document).ready(() => {
     ledgerSpreadSetting.imageClick = function (data) {
         changesObj.loadChanges({bills: data});
     };
+    ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
     SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
 
     stageTree.loadDatas(ledgerData);
@@ -502,9 +503,20 @@ $(document).ready(() => {
             if (info.sheet.zh_setting) {
                 const col = info.sheet.zh_setting.cols[info.col];
                 const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
-                const node = sortData[info.row];
+                const node = sortData[info.row], updateData = {};
 
-                if (col.field !== 'postil') {
+                const orgValue = node[col.field];
+                const newValue =  col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
+                if (orgValue == newValue || ((!orgValue || orgValue === '') && (newValue === ''))) {
+                    return;
+                }
+                if (col.field.indexOf('_dgn_') > 0) {
+                    if (node.b_code && node.b_code !== '') {
+                        toast('仅项目节可输入设计数量');
+                        SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                        return;
+                    }
+                } else if (col.field !== 'postil') {
                     if (node.children && node.children.length > 0) {
                         toast('清单父项不可计量', 'error');
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
@@ -518,12 +530,20 @@ $(document).ready(() => {
                         }
                     }
                 }
-                const billsData = {
-                    lid: node.id
-                };
-                billsData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
 
-                postData(window.location.href + '/update', { bills: billsData }, function (data) {
+                if (col.field.indexOf('_dgn_') > 0) {
+                    updateData.dgn = {
+                        id: node.id
+                    };
+                    updateData.dgn[col.field] = newValue;
+                } else {
+                    updateData.stage = {
+                        lid: node.id
+                    };
+                    updateData.stage[col.field] = newValue;
+                }
+
+                postData(window.location.href + '/update', {bills: updateData}, function (data) {
                     const nodes = stageTree.loadPostStageData(data);
                     stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
                     needCheckDetail();
@@ -550,29 +570,41 @@ $(document).ready(() => {
                 if (validCols.length === 0) { return; }
 
                 const sortData = sheet.zh_tree.nodes;
-                const datas = [];
+                const datas = [], dgnDatas = [];
                 for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
                     const node = sortData[iRow];
                     if (node) {
-                        const data = { lid: node.id };
-                        let filter = true;
+                        const data = { lid: node.id }, dgnData = { id: node.id };
+                        let filter = true, filterDgn = true;
                         for (const iCol of validCols) {
                             const colSetting = sheet.zh_setting.cols[iCol];
-                            if (colSetting.field !== 'postil') {
+                            if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
+                                if (node.b_code && node.b_code !== '') continue;
+                            } else if (colSetting.field !== 'postil') {
                                 if (node.children && node.children.length > 0) { continue; }
                                 const nodePos = stagePos.getLedgerPos(node.id);
                                 if (nodePos && nodePos.length > 0) { continue; }
                             }
-                            data[colSetting.field] = null;
-                            filter = false;
-                        }
-                        if (!filter) {
-                            datas.push(data);
+
+                            if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
+                                if (node[colSetting.field] && node[colSetting.field] !== 0) {
+                                    dgnData[colSetting.field] = 0;
+                                    filterDgn = false;
+                                }
+                            } else {
+                                data[colSetting.field] = null;
+                                filter = false;
+                            }
                         }
+                        if (!filter) datas.push(data);
+                        if (!filterDgn) dgnDatas.push(dgnData);
                     }
                 }
-                if (datas.length > 0) {
-                    postData(window.location.href + '/update', {bills: datas}, function (result) {
+                if (datas.length > 0 || dgnDatas.length > 0) {
+                    const bills = {};
+                    if (datas.length > 0) bills.stage = datas;
+                    if (dgnDatas.length > 0) bills.dgn = dgnDatas;
+                    postData(window.location.href + '/update', {bills: bills}, function (result) {
                         const nodes = stageTree.loadPostStageData(result);
                         stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
                         needCheckDetail();
@@ -582,12 +614,12 @@ $(document).ready(() => {
         },
         clipboardPasting(e, info) {
             if (info.sheet.zh_setting) {
-                const sortData = info.sheet.zh_data;
+                const setting = info.sheet.zh_setting;
                 const range = info.cellRange;
-                const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
+                const stageField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
                 for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
                     const col = info.sheet.zh_setting.cols[iCol];
-                    if (validField.indexOf(col.field) === -1) {
+                    if ((stageField.indexOf(col.field) === -1) && setting.dgnUpFields.indexOf(col.field) === -1) {
                         toast('不可修改此数据', 'error');
                         info.cancel = true;
                         return;
@@ -597,41 +629,47 @@ $(document).ready(() => {
         },
         clipboardPasted(e, info) {
             if (info.sheet.zh_setting && info.sheet.zh_tree) {
-                const sheet = info.sheet;
-                const filterNodes = [], datas = [];
+                const sheet = info.sheet, setting = info.sheet.zh_setting;
+                const filterNodes = [], datas = [], dgnDatas = [];
 
                 for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
                     const curRow = iRow + info.cellRange.row;
                     const node = sheet.zh_tree.getItemsByIndex(curRow);
 
-                    const data = {lid: node.id};
-                    let filter = true;
+                    const data = {lid: node.id}, dgnData = {id: node.id};
+                    let filter = true, filterDgn = true;
                     for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
                         const curCol = info.cellRange.col + iCol;
                         const col = info.sheet.zh_setting.cols[curCol];
 
-                        if (col.field !== 'postil') {
-                            if (node.children && node.children.length > 0) {
-                                continue;
-                            }
-
+                        if (setting.dgnUpFields.indexOf(col.field) !== -1) {
+                            if (node.b_code && node.b_code !== '') continue;
+                        } else if (col.field !== 'postil') {
+                            if (node.children && node.children.length > 0) continue;
                             const nodePos = stagePos.getLedgerPos(node.id);
-                            if (nodePos && nodePos.length > 0) {
-                                continue;
-                            }
+                            if (nodePos && nodePos.length > 0) continue;
                         }
 
-                        data[col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
-                        filter = false;
+                        if (setting.dgnUpFields.indexOf(col.field) !== -1) {
+                            dgnData[col.field] = _.toNumber(sheet.getText(curRow, curCol));
+                            filterDgn = false;
+                        } else {
+                            data[col.field] = col.type === 'Number' ? _.toNumber(sheet.getText(curRow, curCol)) : sheet.getText(curRow, curCol);
+                            filter = false;
+                        }
                     }
-                    if (filter) {
+                    if (filter && filterDgn) {
                         filterNodes.push(node);
                     } else {
-                        datas.push(data);
+                        if (!filter) datas.push(data);
+                        if (!filterDgn) dgnDatas.push(dgnData);
                     }
                 }
-                if (datas.length > 0) {
-                    postData(window.location.href + '/update', { bills: datas }, function (data) {
+                if (datas.length > 0 || dgnDatas.length > 0) {
+                    const updateData = {};
+                    if (datas.length > 0) updateData.stage = datas;
+                    if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
+                    postData(window.location.href + '/update', {bills: updateData}, function (data) {
                         const nodes = stageTree.loadPostStageData(data);
                         stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
                         needCheckDetail();

+ 137 - 0
app/service/stage_bills_dgn.js

@@ -0,0 +1,137 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const validField = ['id', 'tid', 'deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
+
+module.exports = app => {
+
+    class StageBillsDgn extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'stage_bills_dgn';
+        }
+
+        /**
+         * 获取截止本期数据
+         * @param {Number} tid - 标段id
+         * @returns {Promise<void>}
+         */
+        async getDgnData(tid) {
+            return await this.db.select(this.tableName, {
+                where: {tid: tid},
+                columns: ['id', 'deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'],
+            });
+        }
+
+        /**
+         * 过滤无效字段,容错
+         * @param data
+         * @private
+         */
+        _filterInvalidField(data) {
+            for (const prop in data) {
+                if (validField.indexOf(prop) === -1) {
+                    delete data[prop];
+                }
+            }
+        }
+
+        /**
+         * 保存设计数量 - 提交单条数据
+         * @param data
+         * @returns {Promise<*>}
+         * @private
+         */
+        async _saveDgnData(data) {
+            if (!data.id) {
+                throw '数据错误';
+            }
+            const orgData = await this.getDataById(data.id);
+            this._filterInvalidField(data);
+            if (orgData) {
+                await this.db.update(this.tableName, data);
+            } else {
+                data.tid = this.ctx.tender.id;
+                await this.db.insert(this.tableName, data);
+            }
+            return await this.getDataById(data.id);
+        }
+
+        /**
+         * 保存设计数量 - 提交多条数据(事务)
+         * @param datas
+         * @returns {Promise<void>}
+         * @private
+         */
+        async _saveDgnDatas(datas) {
+            const orgDatas = await this.db.select(this.tableName, {
+                where: {
+                    id: this._.map(datas, 'id'),
+                }
+            });
+            const updateDatas = [], newDatas = [];
+            for(const d of datas) {
+                this._filterInvalidField(d);
+                const orgD = this._.find(orgDatas, {id: d.id});
+                if (orgD) {
+                    updateDatas.push(d);
+                } else {
+                    d.tid = this.ctx.tender.id;
+                    newDatas.push(d);
+                }
+            }
+            const transaction = await this.db.beginTransaction();
+            try {
+                if (newDatas.length > 0) {
+                    await transaction.insert(this.tableName, newDatas);
+                }
+                if (updateDatas.length > 0) {
+                    for (const u of updateDatas) {
+                        await transaction.update(this.tableName, u);
+                    }
+                }
+                await transaction.commit();
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+            await this.db.select(this.tableName, {
+                where: {
+                    id: this._.map(datas, 'id')
+                }
+            });
+        }
+
+        /**
+         * 保存设计数量 - 外部调用
+         * @param data
+         * @returns {Promise<*>}
+         */
+        async saveDgnData(data) {
+            if (data instanceof Array) {
+                if (data.length > 1) {
+                    return await this._saveDgnDatas(data);
+                } else if (data.length === 1) {
+                    return await this._saveDgnData(data[0]);
+                }
+            } else {
+                return await this._saveDgnData(data);
+            }
+        }
+    }
+
+    return StageBillsDgn;
+};

+ 1 - 1
app/service/stage_bills_final.js

@@ -87,4 +87,4 @@ module.exports = app => {
     }
 
     return StageBillsFinal;
-}
+};