Browse Source

进度台账勾选

laiguoran 4 years ago
parent
commit
d183726fd3

+ 4 - 1
app/controller/schedule_controller.js

@@ -11,6 +11,7 @@
 const moment = require('moment');
 const measureType = require('../const/tender').measureType;
 const billsPosConvert = require('../lib/bills_pos_convert');
+const _ = require('lodash');
 
 module.exports = app => {
     class ScheduleController extends app.BaseController {
@@ -30,10 +31,12 @@ module.exports = app => {
 
         async ledger(ctx) {
             const tender = ctx.tender;
+            const scheduleLedgerList = await ctx.service.scheduleLedger.getAllDataByCondition({ where: { tid: tender.id } });
             const renderData = {
                 tender: tender.data,
                 tenderInfo: tender.info,
                 measureType,
+                scheduleLedgerList: _.map(scheduleLedgerList, 'ledger_id'),
                 jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.ledger),
             };
             await this.layout('schedule/ledger.ejs', renderData, 'schedule/ledger_modal.ejs');
@@ -48,7 +51,7 @@ module.exports = app => {
         async loadLedgerData(ctx) {
             try {
                 const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
-                const posData = this.ctx.tender.data.measure_type === measureType.tz.value
+                const posData = ctx.tender.data.measure_type === measureType.tz.value
                     ? await ctx.service.pos.getPosData({ tid: ctx.tender.id }) : [];
                 const convert = new billsPosConvert(ctx);
                 convert.loadData(ledgerData, posData, []);

+ 110 - 1
app/public/js/schedule_ledger.js

@@ -8,6 +8,7 @@
 function getTenderId() {
     return window.location.pathname.split('/')[2];
 }
+const selects = [];
 $(function () {
     autoFlashHeight();
     // 初始化台账
@@ -45,7 +46,7 @@ $(function () {
         defaultRowHeight: 21,
         headerFont: '12px 微软雅黑',
         font: '12px 微软雅黑',
-        readOnly: true,
+        // readOnly: true,
         localCache: {
             key: 'ledger-bills',
             colWidth: true,
@@ -58,11 +59,91 @@ $(function () {
     SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
 
     postData(window.location.pathname + '/load', {}, function (data) {
+        data = addIsSelect(data);
         ledgerTree.loadDatas(data);
         treeCalc.calculateAll(ledgerTree);
+        // console.log(ledgerTree);
         SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, ledgerTree);
     }, null, true);
 
+    const ledgerSpreadObj = {
+        refreshTree: function (sheet, data) {
+            SpreadJsObj.massOperationSheet(sheet, function () {
+                const tree = sheet.zh_tree;
+                // 处理删除
+                if (data.delete) {
+                    data.delete.sort(function (x, y) {
+                        return y.deleteIndex - x.deleteIndex;
+                    });
+                    for (const d of data.delete) {
+                        sheet.deleteRows(d.deleteIndex, 1);
+                    }
+                }
+                // 处理新增
+                if (data.create) {
+                    const newNodes = data.create;
+                    if (newNodes) {
+                        newNodes.sort(function (a, b) {
+                            return a.index - b.index;
+                        });
+
+                        for (const node of newNodes) {
+                            sheet.addRows(node.index, 1);
+                            SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
+                        }
+                    }
+                }
+                // 处理更新
+                if (data.update) {
+                    const rows = [];
+                    for (const u of data.update) {
+                        rows.push(tree.nodes.indexOf(u));
+                    }
+                    SpreadJsObj.reLoadRowsData(sheet, rows);
+                }
+                // 处理展开
+                if (data.expand) {
+                    const expanded = [];
+                    for (const e of data.expand) {
+                        if (expanded.indexOf(e) === -1) {
+                            const posterity = tree.getPosterity(e);
+                            for (const p of posterity) {
+                                sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
+                                expanded.push(p);
+                            }
+                        }
+                    }
+                }
+            });
+        },
+        buttonClicked: function (e, info) {
+            if (info.sheet.zh_setting) {
+                const select = SpreadJsObj.getSelectObject(info.sheet);
+                const col = info.sheet.zh_setting.cols[info.col];
+                // if (materialCol.readOnly.isEdit(select)) {
+                //     return;
+                // }
+                if (col.field === 'is_select') {
+                    if (info.sheet.isEditing()) {
+                        info.sheet.endEdit(true);
+                    }
+                    // 选中和去除关联
+                    select.is_select = info.sheet.getValue(info.row, info.col) ? 1 : 0;
+                    selects.splice(0, selects.length);
+                    selects.push(select);
+                    updateChildrenSelect(select.children, select.is_select);
+                    updateParentSelect(info.sheet.zh_tree, select.ledger_pid, select.is_select);
+                    // console.log(selects);
+                    const refreshNode = ledgerTree.loadPostData({update: selects});
+                    ledgerSpreadObj.refreshTree(info.sheet, refreshNode);
+                }
+            }
+        },
+    };
+
+    ledgerSpread.bind(spreadNS.Events.ButtonClicked, ledgerSpreadObj.buttonClicked);
+
+
     // // 显示层次
     // (function (select, sheet) {
     //     $(select).click(function () {
@@ -90,3 +171,31 @@ $(function () {
     //     });
     // })('a[name=showLevel]', ledgerSpread.getActiveSheet());
 });
+function addIsSelect(datas) {
+    for (const d of datas) {
+        d.is_select = selectedLedgerList.length === 0 ? 1: selectedLedgerList.indexOf(d.ledger_id) !== -1 ? 1 : 0;
+    }
+    return datas;
+}
+
+function updateChildrenSelect(datas, is_select) {
+    for (const data of datas) {
+        data.is_select = is_select;
+        if(data.children && data.children.length > 0) {
+            updateChildrenSelect(data.children, is_select);
+        }
+        selects.push(data);
+    }
+}
+
+function updateParentSelect(tree, pid, is_select) {
+    if (pid !== -1) {
+        const parent = _.find(tree.nodes, { 'ledger_id': pid });
+        if (parent) {
+            const hadselectInfo = is_select === 0 ? _.findIndex(parent.children, { 'is_select': 1 }) : 1;
+            parent.is_select = (hadselectInfo !== -1 && is_select === 0) || is_select === 1 ? 1 : 0;
+            selects.push(parent);
+            updateParentSelect(tree, parent.ledger_pid, is_select);
+        }
+    }
+}

+ 11 - 0
app/service/schedule_ledger.js

@@ -0,0 +1,11 @@
+'use strict';
+
+module.exports = app => {
+    class ScheduleLedger extends app.BaseService {
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'schedule_ledger';
+        }
+    }
+    return ScheduleLedger;
+};

+ 5 - 4
app/view/schedule/ledger.ejs

@@ -7,16 +7,16 @@
                 <div class="d-inline-block">
                     <a class="btn btn-sm btn-light">
                         <div class="custom-control custom-checkbox">
-                            <input type="checkbox" class="custom-control-input" id="customCheckDisabled" checked="">
-                            <label class="custom-control-label text-primary" for="customCheckDisabled">自动选择同级项</label>
+                            <input type="checkbox" class="custom-control-input" id="save_siblings">
+                            <label class="custom-control-label text-primary" for="save_siblings">自动选择同级项</label>
                         </div>
                     </a>
                 </div>
                 <div class="d-inline-block">
                     <a class="btn btn-sm btn-light">
                         <div class="custom-control custom-checkbox">
-                            <input type="checkbox" class="custom-control-input" id="customCheckDisabled2">
-                            <label class="custom-control-label text-primary" for="customCheckDisabled2">跨级选择同级项</label>
+                            <input type="checkbox" class="custom-control-input" id="save_other_siblings">
+                            <label class="custom-control-label text-primary" for="save_other_siblings">跨级选择同级项</label>
                         </div>
                     </a>
                 </div>
@@ -42,6 +42,7 @@
     const tenderInfo = JSON.parse(unescape('<%- escape(JSON.stringify(tenderInfo)) %>'));
     const thousandth = <%- ctx.tender.info.display.thousandth %>;
     const measureType = JSON.parse('<%- JSON.stringify(measureType) %>');
+    const selectedLedgerList = JSON.parse('<%- JSON.stringify(scheduleLedgerList) %>');
 </script>
 <script>
     $.subMenu({