浏览代码

指标计算 no.2 up

laiguoran 7 年之前
父节点
当前提交
07755b5aab
共有 3 个文件被更改,包括 34 次插入11 次删除
  1. 1 1
      app/controller/lib_controller.js
  2. 32 9
      app/public/js/lib_detail.js
  3. 1 1
      app/router.js

+ 1 - 1
app/controller/lib_controller.js

@@ -313,7 +313,7 @@ module.exports = app => {
          * @param {Object} ctx -egg全局变量
          * @param {Object} ctx -egg全局变量
          * @return {void}
          * @return {void}
          */
          */
-        async getNodeAndIndex(ctx) {
+        async getParamAndIndex(ctx) {
             const responseData = {
             const responseData = {
                 err: 0,
                 err: 0,
                 msg: '',
                 msg: '',

+ 32 - 9
app/public/js/lib_detail.js

@@ -43,20 +43,26 @@ $(document).ready(function() {
     billsSheet.selectionPolicy(0);
     billsSheet.selectionPolicy(0);
     billsSheet.selectionUnit(1);
     billsSheet.selectionUnit(1);
     billsSheet.clearSelection();
     billsSheet.clearSelection();
+    billsSheet.setActiveCell(0);
+    setquotaParamIndex();
     const spreadNS = GC.Spread.Sheets;
     const spreadNS = GC.Spread.Sheets;
 
 
     //项目节选中
     //项目节选中
     billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
     billsSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
-        const billsInfo = billsTree.nodes[info.newSelections[0].row];
+        setquotaParamIndex();
+    });
+
+    function setquotaParamIndex() {
+        const billsInfo = billsTree.nodes[billsSheet.getActiveRowIndex()];
         $('#codeName').text(billsInfo.name);
         $('#codeName').text(billsInfo.name);
         $('#indexList').html('');
         $('#indexList').html('');
         $('#paramList').html('');
         $('#paramList').html('');
         if(billsInfo.match_node !== null){
         if(billsInfo.match_node !== null){
-            const postUrl = '/lib/getNodeAndIndex';
+            const postUrl = '/lib/getParamAndIndex';
             const postInfo = {
             const postInfo = {
-                lib_id:billsInfo.lib_id,
-                node_id:billsInfo.match_node,
-                bills_id:billsInfo.id
+                lib_id: billsInfo.lib_id,
+                node_id: billsInfo.match_node,
+                bills_id: billsInfo.id
             };
             };
             postData(postUrl, postInfo, function (result) {
             postData(postUrl, postInfo, function (result) {
                 let index_html = '';
                 let index_html = '';
@@ -71,12 +77,29 @@ $(document).ready(function() {
                 let param_html = '';
                 let param_html = '';
                 const param_list = result.paramList;
                 const param_list = result.paramList;
                 for(let i in param_list) {
                 for(let i in param_list) {
-                    param_html += '<tr> <td>'+ param_list[i].name +'</th><td>'+ param_list[i].code +'</td><td><input class="form-control form-control-sm" value=""></td> </tr>';
+                    param_list[i].calc_value = param_list[i].calc_value !== null ? param_list[i].calc_value : '';
+                    let subNode = param_list[i].match_type === 3 ? '(自动绑定)' : (param_list[i].match_type === 4 ? param_list[i].match_key : '');
+                    param_html += '<tr> <td>'+ param_list[i].name +'</th><td>'+ subNode +'</td><td><input type="number" class="form-control form-control-sm" value="'+ param_list[i].calc_value +'" data-old-value="'+ param_list[i].calc_value +'" data-lib-id="'+ param_list[i].lib_id +'" data-node-id="'+ param_list[i].node_id +'" data-code="'+ param_list[i].code +'"></td> </tr>';
                 }
                 }
                 $('#paramList').html(param_html);
                 $('#paramList').html(param_html);
-                console.log(param_html);
-                console.log(index_html);
             });
             });
         }
         }
-    });
+    }
+
+    $('body').on('blur', '#paramList input', function () {
+        if($(this).val() != $(this).attr('data-old-value')){
+            const postInfo = {
+                lib_id: parseInt($(this).attr('data-lib-id')),
+                node_id: parseInt($(this).attr('data-node-id')),
+                code: $(this).attr('data-code'),
+                updateType: 'modify',
+                value: parseFloat($(this).val())
+            };
+            $(this).attr('data-old-value', $(this).val());
+            const postUrl = '/lib/updateParamValue';
+            postData(postUrl, postInfo, function (result) {
+                // console.log(result);
+            });
+        }
+    })
 });
 });

+ 1 - 1
app/router.js

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