Просмотр исходного кода

指标源,全局指标参数,提交参数取值

MaiXinRong 7 лет назад
Родитель
Сommit
faaa50393b

+ 42 - 0
app/controller/lib_controller.js

@@ -12,6 +12,7 @@ const path = require('path');
 const awaitWriteStream = require('await-stream-ready').write;
 const sendToWormhole = require('stream-wormhole');
 const libConst = require('../const/lib');
+const paramConst = require('../const/template_param');
 module.exports = app => {
     class LibController extends app.BaseController {
 
@@ -128,6 +129,7 @@ module.exports = app => {
                     libInfo,
                     libConst,
                     globalParams,
+                    paramConst,
                 };
                 await this.layout('lib/global.ejs', renderData);
             } catch (error) {
@@ -263,6 +265,46 @@ module.exports = app => {
             }
 
         }
+
+        async updateParamValue (ctx) {
+            const responseData = {
+                err: 0,
+                msg: '',
+                data: {},
+            };
+            const data = JSON.parse(ctx.request.body.data);
+            try {
+                if (!data.updateType) {
+                    throw '参数修改提交类型未知';
+                }
+                if ((data.lib_id === undefined) || (data.node_id === undefined) || (data.code === undefined)) {
+                    throw '提交信息错误';
+                }
+                let result;
+                if (data.updateType === 'reset') {
+                    result = await ctx.service.tenderParam.resetCalcValue(data);
+                } else if (data.updateType === 'modify') {
+                    result = await ctx.service.tenderParam.updateCalcValue(data);
+                }
+                if (!result) {
+                    throw '提交数据失败';
+                }
+            } catch (err) {
+                console.log(err);
+                responseData.err = 1;
+                responseData.msg = err.toString();
+            }
+
+            responseData.data.param = await ctx.service.tenderParam.getDataByCondition({
+                lib_id: data.lib_id, node_id: data.node_id, code: data.code,
+            });
+            if (data.node_id !== 0) {
+                responseData.data.indexes = await ctx.service.tenderIndex.getAllDataByCondition({
+                    where: {lib_id: data.lib_id, node_id: data.node_id,}
+                });
+            }
+            ctx.body = responseData;
+        }
     }
 
     return LibController;

+ 7 - 7
app/public/js/lib_detail.js

@@ -24,13 +24,13 @@ $(document).ready(function() {
     billsTree.loadDatas(bills);
     SpreadJsObj.initSheet(billsSpread.getActiveSheet(), {
         cols: [
-            {title: '项目节编号', field: 'code', width: 120, cellType: 'tree', vAlign: 1,},
-            {title: '清单编号', field: 'b_code', width: 80, vAlign: 1,},
-            {title: '名称', field: 'name', width: 200, vAlign: 1,},
-            {title: '单位', field: 'unit', width: 50, vAlign: 1,},
-            {title: '数量1', field: 'dgn_quantity1', width: 60, type: 'Number', vAlign: 1,},
-            {title: '数量2', field: 'dgn_quantity2', width: 60, type: 'Number', vAlign: 1,},
-            {title: '金额', field: 'total_price', width: 60, type: 'Number', vAlign: 1,},
+            {title: '项目节编号', field: 'code', width: 120, cellType: 'tree', vAlign: 1, readOnly: true,},
+            {title: '清单编号', field: 'b_code', width: 80, vAlign: 1, readOnly: true,},
+            {title: '名称', field: 'name', width: 200, vAlign: 1, readOnly: true,},
+            {title: '单位', field: 'unit', width: 50, vAlign: 1, readOnly: true,},
+            {title: '数量1', field: 'dgn_quantity1', width: 60, type: 'Number', vAlign: 1, readOnly: true,},
+            {title: '数量2', field: 'dgn_quantity2', width: 60, type: 'Number', vAlign: 1, readOnly: true,},
+            {title: '金额', field: 'total_price', width: 60, type: 'Number', vAlign: 1, readOnly: true,},
         ],
         treeCol: 0,
         emptyRows: 3,

+ 1 - 0
app/router.js

@@ -20,6 +20,7 @@ module.exports = app => {
     app.get('/lib/detail/:id', sessionAuth, 'libController.detail');
     app.post('/lib/detail/get-children', sessionAuth, 'libController.getChildren');
     app.get('/lib/global/:id', sessionAuth, 'libController.global');
+    app.post('/lib/updateParamValue', sessionAuth, 'libController.updateParamValue');
     app.post('/lib/delete', sessionAuth, 'libController.delete');
     app.post('/lib/enter', sessionAuth, 'libController.enter');
 

+ 9 - 3
app/service/quota_lib.js

@@ -159,9 +159,15 @@ module.exports = app => {
                 }
                 await this.ctx.service.match.matchBills(billsData);
                 const billsResult = await conn.insert('is_quota_bills',billsData);
-                const nodeResult = await this.ctx.service.tenderNode.insertData(this.ctx.service.match.nodes, conn);
-                const indexResult = await this.ctx.service.tenderIndex.insertData(this.ctx.service.match.indexes, conn);
-                const paramResult = await this.ctx.service.tenderParam.insertData(this.ctx.service.match.params, conn);
+                if (this.ctx.service.match.nodes.length > 0) {
+                    const nodeResult = await this.ctx.service.tenderNode.insertData(this.ctx.service.match.nodes, conn);
+                }
+                if (this.ctx.service.match.indexes.length > 0) {
+                    const indexResult = await this.ctx.service.tenderIndex.insertData(this.ctx.service.match.indexes, conn);
+                }
+                if (this.ctx.service.match.params.length > 0) {
+                    const paramResult = await this.ctx.service.tenderParam.insertData(this.ctx.service.match.params, conn);
+                }
                 await conn.commit(); // 提交事务
                 return true;
             } catch (err) {

+ 3 - 1
app/service/template_node.js

@@ -193,6 +193,8 @@ module.exports = app => {
             const transaction = await this.db.beginTransaction();
             try {
                 const nodes = [], indexes = [], params = [];
+                this._loadDefaultParam(params, paramConst.defaultGlobalParams, 0);
+                console.log(params);
                 for (const sheet of excelSheets) {
                     this._parseSheetData(sheet, nodes, indexes, params);
                 }
@@ -204,7 +206,7 @@ module.exports = app => {
                         throw '导入指标节点错误';
                     }
                     await this.ctx.service.templateIndex.importData(indexes, transaction);
-                    await this.ctx.service.templateParam.importData(params.concat(paramConst.defaultGlobalParams), transaction);
+                    await this.ctx.service.templateParam.importData(params, transaction);
                 } else {
                     throw 'Excel文件中无标准的指标数据';
                 }

+ 44 - 0
app/service/tender_param.js

@@ -20,6 +20,50 @@ module.exports = app => {
             super(ctx);
             this.tableName = 'tender_param';
         }
+
+        async updateCalcValue(data) {
+            const transaction = await this.db.beginTransaction();
+            try {
+                const condition = {
+                    lib_id: parseInt(data.lib_id),
+                    node_id: data.node_id,
+                    code: data.code
+                };
+                if (condition.lib_id < 0 || condition.node_id < 0) {
+                    throw '提交数据错误';
+                }
+                const updateData = {
+                    calc_value: parseFloat(data.value),
+                };
+                await transaction.update(this.tableName, updateData, {where: condition});
+                // to do 计算
+                await transaction.commit();
+                return true;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
+        async resetCalcValue(data) {
+            try {
+                const condition = {
+                    lib_id: parseInt(data.lib_id),
+                    node_id: data.node_id,
+                    code: data.code,
+                };
+                if (condition.lib_id < 0 || condition.node_id < 0) {
+                    throw '提交数据错误';
+                }
+                const param = await this.getDataByCondition(condition);
+                data.value = param.match_value;
+                await this.updateCalcValue(data);
+                return true;
+            } catch (err) {
+                throw err;
+            }
+
+        }
     };
 
     return TenderParam;

+ 31 - 5
app/view/lib/global.ejs

@@ -30,10 +30,16 @@
                                 <th>参数名称</th><th>绑定分项节点</th><th>参数数值</th>
                             </tr>
                             <% for (const p of globalParams) { %>
-                            <tr>
-                                <td code="<%= p.code %>"><%= p.name %></td>
-                                <td><%- p.match_key %></td>
-                                <td><input class="form-control form-control-sm" value="<%- p.calc_value %>"></td>
+                            <tr code="<%= p.code %>">
+                                <td><%= p.name %></td>
+                                <td>
+                                    <% if (p.match_type === paramConst.matchType.fixed_id) { %>
+                                    <small class="text-muted">(自动绑定)</small>
+                                    <% } else { %>
+                                    <%- p.match_key %>
+                                    <% } %>
+                                </td>
+                                <td><input name="param-value" class="form-control form-control-sm" value="<%- p.calc_value %>" org-value="<%- p.calc_value %>"></td>
                             </tr>
                             <% } %>
                         </table>
@@ -43,4 +49,24 @@
         </div>
     </div>
 </div>
-</div>
+<script>
+    $(document).ready(function () {
+        // 全局参数,修改参数数值
+        $('input[name=param-value]').blur(function () {
+            const self = $(this);
+            if (self.val() === self.attr('org-value')) { return; }
+            const data = {
+                lib_id: window.location.pathname.split('/')[3],
+                node_id: 0,
+                code: self.parent().parent().attr('code'),
+                value: self.val(),
+                updateType: 'modify',
+            }
+            postData('/lib/updateParamValue', data, function (data) {
+                self.attr('org-value', data.param.calc_value);
+            }, function () {
+                self.val(self.attr('org-value'));
+            });
+        });
+    });
+</script>