Browse Source

禁止选中已存在数据

laiguoran 4 năm trước cách đây
mục cha
commit
832ce13aee

+ 17 - 1
app/controller/schedule_controller.js

@@ -49,11 +49,27 @@ module.exports = app => {
 
         async ledger(ctx) {
             const tender = ctx.tender;
+            const scheduleLedgerList = await this._getSelectedLedgerList(ctx);
+            const allSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: ctx.tender.id } });
+            const hadDataLidList = [];
+            for (const sl of scheduleLedgerList) {
+                const info = _.find(allSlmList, function(item) {
+                    return item.lid === sl && ((item.plan_tp !== null && item.plan_tp !== 0) ||
+                        (item.plan_gcl !== null && item.plan_gcl !== 0) ||
+                        (item.sj_tp !== null && item.sj_tp !== 0) ||
+                        (item.sj_gcl !== null && item.sj_gcl !== 0));
+                });
+                if (info) {
+                    hadDataLidList.push(info.lid);
+                }
+            }
+            console.log(hadDataLidList);
             const renderData = {
                 tender: tender.data,
                 tenderInfo: tender.info,
                 measureType,
-                scheduleLedgerList: await this._getSelectedLedgerList(ctx),
+                scheduleLedgerList,
+                hadDataLidList,
                 jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.ledger),
             };
             await this.layout('schedule/ledger.ejs', renderData);

+ 48 - 8
app/public/js/schedule_ledger.js

@@ -20,6 +20,7 @@ $(function () {
         level: 'level',
         rootId: -1,
         fullPath: 'full_path',
+        calcFields: ['can_select'],
         //treeCacheKey: 'ledger_bills_fold' + '_' + getTenderId(),
         // markFoldKey: 'bills-fold',
         // markFoldSubKey: window.location.pathname.split('/')[2],
@@ -28,7 +29,7 @@ $(function () {
 
     const ledgerSpreadSetting = {
         cols: [
-            {title: '', colSpan: '1', rowSpan: '2', field: 'is_select', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox'},
+            {title: '', colSpan: '1', rowSpan: '2', field: 'is_select', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox', readOnly: 'readOnly.can_select'},
             {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 185, formatter: '@', readOnly: true, cellType: 'tree'},
             {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 205, formatter: '@', readOnly: true},
             {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 100, formatter: '@', readOnly: true},
@@ -49,8 +50,17 @@ $(function () {
         }
     };
 
+    const ledgerCol = {
+        readOnly: {
+            can_select: function (data) {
+                return !data.can_select;
+            },
+        },
+    };
+
     sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
     if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
+    SpreadJsObj.initSpreadSettingEvents(ledgerSpreadSetting, ledgerCol);
     SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
     SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
 
@@ -72,10 +82,11 @@ $(function () {
         treeCalc.calculateAll(baseLedgerTree);
         for (const d of baseLedgerTree.nodes) {
             if (!d.b_code)
-                ledgerTree.addData(d, ['is_select', 'ledger_id', 'ledger_pid', 'order', 'level', 'tender_id', 'full_path',
+                ledgerTree.addData(d, ['is_select', 'can_select', 'ledger_id', 'ledger_pid', 'order', 'level', 'tender_id', 'full_path',
                     'code', 'name', 'unit', 'dgn_qty1', 'dgn_qty2', 'dgn_price', 'quantity', 'total_price']);
         }
         ledgerTree.sortTreeNode(true);
+        console.log(ledgerTree);
 
         SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, ledgerTree);
     }, null, true);
@@ -144,7 +155,7 @@ $(function () {
                 // if (materialCol.readOnly.isEdit(select)) {
                 //     return;
                 // }
-                if (col.field === 'is_select') {
+                if (col.field === 'is_select' && select.can_select) {
                     if (info.sheet.isEditing()) {
                         info.sheet.endEdit(true);
                     }
@@ -251,15 +262,37 @@ function addIsSelect(datas) {
     for (const d of datas) {
         if (!d.b_code) {
             d.is_select = selectedLedgerList.length === 0 ? 1: selectedLedgerList.indexOf(d.ledger_id) !== -1 ? 1 : 0;
-            // newDatas.push(d);
+            if (!d.is_leaf) {
+                d.can_select = hadDataLidList.length === 0 ? true : hadDataLidList.indexOf(d.ledger_id) !== -1 ? false : true;
+                // console.log(d.can_select);
+            } else if(d.can_select === undefined) {
+                d.can_select = true;
+            }
+        }
+    }
+    for (const d2 of datas) {
+        if (!d2.b_code && !d2.can_select) {
+            updateParentCanSelect(datas, d2.ledger_pid);
         }
     }
     return datas;
 }
 
+function updateParentCanSelect(datas, ledger_pid) {
+    if (ledger_pid !== 0) {
+        const info = _.find(datas, { ledger_id: ledger_pid});
+        if (info) {
+            info.can_select = false;
+            updateParentCanSelect(datas, info.ledger_pid);
+        }
+    }
+}
+
 function updateChildrenSelect(datas, is_select) {
     for (const data of datas) {
-        data.is_select = is_select;
+        if (data.can_select) {
+            data.is_select = is_select;
+        }
         if(data.children && data.children.length > 0) {
             updateChildrenSelect(data.children, is_select);
         }
@@ -271,7 +304,10 @@ function updateSiblingsSelect(tree, pid, is_select, select_msg) {
     const parent = pid !== -1 ? _.find(tree.nodes, { 'ledger_id': pid }) : tree;
     if (parent) {
         for(const d of parent.children) {
-            d.is_select = is_select;
+            if (d.can_select) {
+                d.is_select = is_select;
+            }
+            // d.is_select = is_select;
             if (select_msg.select_children || is_select === 0) {
                 updateChildrenSelect(d.children, is_select);
             }
@@ -293,7 +329,9 @@ function updateOtherSiblingsSelect(tree, pid, is_select, select_msg) {
                     let p = false;
                     if(d.children && d.children.length > 0) {
                         for (const dd of d.children) {
-                            dd.is_select = is_select;
+                            if (dd.can_select) {
+                                dd.is_select = is_select;
+                            }
                             p = true;
                             if (select_msg.select_children || is_select === 0) {
                                 updateChildrenSelect(dd.children, is_select);
@@ -302,7 +340,9 @@ function updateOtherSiblingsSelect(tree, pid, is_select, select_msg) {
                         }
                     }
                     if(p) {
-                        d.is_select = is_select;
+                        if(d.can_select) {
+                            d.is_select = is_select;
+                        }
                         selects.push(d);
                     }
                 }

+ 4 - 0
app/service/schedule_ledger_month.js

@@ -122,6 +122,10 @@ module.exports = app => {
             const result = await this.db.query(sql, sqlParam);
             return result;
         }
+
+        // async getHadDataList(tid) {
+        //     const sql = 'SELECT lid FROM ?? WHERE tid = ? '
+        // }
     }
     return ScheduleLedgerMonth;
 };

+ 1 - 0
app/view/schedule/ledger.ejs

@@ -52,4 +52,5 @@
     const thousandth = <%- ctx.tender.info.display.thousandth %>;
     const measureType = JSON.parse('<%- JSON.stringify(measureType) %>');
     const selectedLedgerList = JSON.parse('<%- JSON.stringify(scheduleLedgerList) %>');
+    const hadDataLidList = JSON.parse('<%- JSON.stringify(hadDataLidList) %>');
 </script>