Browse Source

材料调差,不参与调差清单功能

laiguoran 5 years ago
parent
commit
ab15600e27

+ 6 - 0
app/controller/material_controller.js

@@ -293,6 +293,12 @@ module.exports = app => {
                     case 'useOther':
                         responseData.data = await ctx.service.materialList.addOther(data.postData);
                         break;
+                    case 'join':
+                        await ctx.service.materialListNotjoin.del(data.select.id);
+                        break;
+                    case 'notjoin':
+                        responseData.data = await ctx.service.materialListNotjoin.add(data.select);
+                        break;
                     default: throw '参数有误';
                 }
 

+ 121 - 46
app/public/js/material_list.js

@@ -8,6 +8,17 @@
  * @version
  */
 
+function findNotJoinLeafXmj(x, type = '') {
+    if (type === 'index') {
+        return notJoinList.findIndex(function (item) {
+            return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
+        });
+    }
+    return notJoinList.find(function (item) {
+        return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
+    });
+}
+
 $(document).ready(() => {
     autoFlashHeight();
     // 清单table
@@ -33,7 +44,7 @@ $(document).ready(() => {
     // 解析清单汇总数据
     gclGatherModel.loadLedgerData(ledger, curLedgerData);
     gclGatherModel.loadPosData(pos, curPosData);
-    const gclGatherData = gclGatherModel.gatherGclData();
+    let gclGatherData = gclGatherModel.gatherGclData();
     console.log(gclGatherData);
     // 获取项目节数据
     function loadLeafXmjData(iGclRow) {
@@ -89,7 +100,7 @@ $(document).ready(() => {
             {title: '清单调差工料|编号', colSpan: '4|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
             {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
             {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
-            {title: '|数量', colSpan: '1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', readOnly: readOnly.quantity},
+            {title: '|数量', colSpan: '1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number', readOnly: true},
         ],
         emptyRows: 0,
         headRows: 2,
@@ -99,22 +110,6 @@ $(document).ready(() => {
         font: '10pt 微软雅黑',
     };
 
-    const materialCol = {
-        readOnly: {
-            quantity: function () {
-                const sheet = leafXmjSpread.getActiveSheet();
-                const select = SpreadJsObj.getSelectObject(sheet);
-                const notx = notJoinList.find(function (item) {
-                    return item.gcl_id === select.gcl_id && item.xmj_id === select.id && (select.mx_id === undefined || (select.mx_id !== undefined && select.mx_id === item.mx_id));
-                });
-                console.log(notx);
-                return readOnly || notx === undefined;
-            },
-        },
-    };
-    SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
-    // SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
-    // 获取第一个调差工料数据
     // 获取项目节数据
     let materialList = [];
     function loadMaterialData(iGclRow, iLXmjRow) {
@@ -127,7 +122,10 @@ $(document).ready(() => {
                     materialList.push(m);
                 }
             }
-            console.log(materialList);
+            // console.log(materialList);
+            const notx = findNotJoinLeafXmj(xmj);
+            materialSpreadSetting.cols[materialSpreadSetting.cols.length - 1].readOnly = !(readOnly || notx === undefined);
+            SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
             SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialList);
         } else {
             SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
@@ -145,9 +143,7 @@ $(document).ready(() => {
             const xmj = gclGatherData[index].leafXmjs;
             const leafXmjSheet = leafXmjSpread.getActiveSheet();
             for (const [iRow,x] of xmj.entries()) {
-                const notx = notJoinList.find(function (item) {
-                    return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
-                });
+                const notx = findNotJoinLeafXmj(x);
                 const color = notx === undefined ? '' : '#d6d8db';
                 leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color);
             }
@@ -209,6 +205,36 @@ $(document).ready(() => {
         $('#materialBills').find('input:disabled').prop('checked', true);
     });
     if (!readOnly) {
+        const leafXmjSpreadObj = {
+            getSelect : function () {
+                const sheet = ledgerSpread.getActiveSheet();
+                const select = SpreadJsObj.getSelectObject(sheet);
+                const index = gclGatherData.indexOf(select);
+                const leafXmjSheet = leafXmjSpread.getActiveSheet();
+                const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
+                const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
+                return [index, iRow, leafXmjSheet, leafXmjSelect];
+            },
+            checkJoinMaterial: function (type) {
+                const [iGclRow, iRow, sheet, select] = leafXmjSpreadObj.getSelect();
+                const color = type === 'join' ? '' : '#d6d8db';
+                const data = {
+                    type: type,
+                    select: type === 'join' ? findNotJoinLeafXmj(select) : select,
+                }
+                // 添加到
+                postData(window.location.pathname + '/save', data, function (result) {
+                    if (type === 'join') {
+                        const index = findNotJoinLeafXmj(select, 'index');
+                        notJoinList.splice(index, 1);
+                    } else {
+                        notJoinList.push(result);
+                    }
+                    sheet.getRange(iRow, -1, 1, -1).backColor(color);
+                    loadMaterialData(iGclRow, iRow);
+                });
+            },
+        }
         // leafXmj右键功能
         $.contextMenu({
             selector: '#leaf-xmj-spread',
@@ -221,34 +247,43 @@ $(document).ready(() => {
                     name: '不参与调差',
                     icon: 'fa-remove',
                     callback: function (key, opt) {
-                        const sheet = ledgerSpread.getActiveSheet();
+                        leafXmjSpreadObj.checkJoinMaterial('notjoin');
+                    },
+                    visible: function (key, opt) {
+                        const sheet = leafXmjSpread.getActiveSheet();
                         const select = SpreadJsObj.getSelectObject(sheet);
-                        const index = gclGatherData.indexOf(select);
-                        const leafXmjSheet = leafXmjSpread.getActiveSheet();
-                        const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
-                        const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
-                        leafXmjSheet.getRange(iRow, -1, 1, -1).backColor('#d6d8db');
+                        const notx = findNotJoinLeafXmj(select);
+                        if (!readOnly && select && notx === undefined) {
+                            return true;
+                        } else {
+                            return false;
+                        }
+                    }
+                },
+                'start': {
+                    name: '参与调差',
+                    icon: 'fa-sign-in',
+                    callback: function (key, opt) {
+                        leafXmjSpreadObj.checkJoinMaterial('join');
                     },
-                    disabled: function (key, opt) {
+                    visible: function (key, opt) {
                         const sheet = leafXmjSpread.getActiveSheet();
                         const select = SpreadJsObj.getSelectObject(sheet);
-                        const notx = notJoinList.find(function (item) {
-                            return item.gcl_id === select.gcl_id && item.xmj_id === select.id && (select.mx_id === undefined || (select.mx_id !== undefined && select.mx_id === item.mx_id));
-                        });
+                        const notx = findNotJoinLeafXmj(select);
                         if (!readOnly && select && notx === undefined) {
                             return false;
                         } else {
                             return true;
                         }
-                    }
-                },
+                    },
+
+                }
             }
         });
         const materialBase = {
             isEdit: function (data) {
-                return materialListData.find(function (item) {
-                    return item.mbid === data.id;
-                });
+                // 是否本期添加的工料
+                return data.mid === materialID;
             }
         };
         // material-spread右键功能
@@ -275,7 +310,7 @@ $(document).ready(() => {
                     // 未改变值则不提交
                     const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
                     const orgValue = select[col.field];
-                    if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
+                    if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
                         return;
                     }
@@ -291,9 +326,6 @@ $(document).ready(() => {
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     });
                 }
-            },
-            setReadOnly: function(readOnly) {
-                SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'quantity', readOnly);
             }
         };
         materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
@@ -305,6 +337,13 @@ $(document).ready(() => {
                 toastr.warning('请选中需要应用到其他清单明细的调差工料');
                 return false;
             }
+            const leafXmjSheet = leafXmjSpread.getActiveSheet();
+            const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
+            const notl = findNotJoinLeafXmj(leafXmjSelect);
+            if (notl !== undefined) {
+                toastr.error('该清单不参与调差,调差工料无法应用到其它清单中');
+                return false;
+            }
             const ledgerSheet = ledgerSpread.getActiveSheet();
             const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
             if (ledgerSelect.leafXmjs.length < 2) {
@@ -315,11 +354,16 @@ $(document).ready(() => {
             const needAddList = [];
             for (const xmj of ledgerSelect.leafXmjs) {
                 if (xmj.mx_id !== undefined) {
-                    const ml = materialListData.find(function (item) {
-                        return xmj.mx_id === item.mx_id && select.mb_id === item.mb_id;
+                    const notx = notJoinList.find(function (item) {
+                        return item.gcl_id === xmj.gcl_id && item.xmj_id === xmj.id && (xmj.mx_id === undefined || (xmj.mx_id !== undefined && xmj.mx_id === item.mx_id));
                     });
-                    if (ml === undefined) {
-                        needAddList.push(xmj.mx_id);
+                    if (notx === undefined) {
+                        const ml = materialListData.find(function (item) {
+                            return xmj.mx_id === item.mx_id && select.mb_id === item.mb_id;
+                        });
+                        if (ml === undefined) {
+                            needAddList.push(xmj.mx_id);
+                        }
                     }
                 }
             }
@@ -370,7 +414,7 @@ $(document).ready(() => {
                     disabled: function (key, opt) {
                         const sheet = materialSpread.getActiveSheet();
                         const select = SpreadJsObj.getSelectObject(sheet);
-                        if (!readOnly && select && materialBase.isEdit(select) === undefined) {
+                        if (!readOnly && select && materialBase.isEdit(select)) {
                             return false;
                         } else {
                             return true;
@@ -408,6 +452,37 @@ $(document).ready(() => {
         }
     });
 
+    // 显示有调差工料清单
+    $('#show_material_gcl').click(function () {
+        if ($(this).is(':checked')) {
+            const hadMaterialGclGatherData = [];
+            const hadGclIdList = [];
+            for (const ml of materialListData) {
+                if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
+                    hadGclIdList.push(ml.gcl_id);
+                }
+            }
+            for (const gcl of gclGatherData) {
+                const gcl_id = gcl.leafXmjs[0].gcl_id;
+                if (hadGclIdList.indexOf(gcl_id) !== -1) {
+                    hadMaterialGclGatherData.push(gcl);
+                }
+            }
+            gclGatherData = hadMaterialGclGatherData;
+        } else {
+            gclGatherModel.loadLedgerData(ledger, curLedgerData);
+            gclGatherModel.loadPosData(pos, curPosData);
+            gclGatherData = gclGatherModel.gatherGclData();
+        }
+        SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
+        loadLeafXmjData(0);
+        loadMaterialData(0, 0);
+        SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
+        SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
+        SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
+
+    });
+
     $.subMenu({
         menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
         toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',

+ 9 - 1
app/service/material.js

@@ -132,12 +132,17 @@ module.exports = app => {
                 } else {
                     throw '新增期数据失败';
                 }
-                // 存在上一期时,复制上一期审批流程
+                // 存在上一期时,复制上一期审批流程、不参与调差的清单
                 if (preMaterial) {
                     const auditResult = await this.ctx.service.materialAudit.copyPreMaterialAuditors(transaction, preMaterial, newMaterial);
                     if (!auditResult) {
                         throw '复制上一期审批流程失败';
                     }
+                    const preNotJoinList = await this.ctx.service.materialListNotjoin.getAllDataByCondition({ where: { tid: this.ctx.tender.id, mid: preMaterial.id } });
+                    const materialResult = await this.ctx.service.materialListNotjoin.copyNewStageNotJoinList(transaction, preNotJoinList, newMaterial.id);
+                    if (materialResult.affectedRows === 0) {
+                        throw '新增不参与调差清单数据失败';
+                    }
                 }
 
                 await transaction.commit();
@@ -159,6 +164,9 @@ module.exports = app => {
             try {
                 await transaction.delete(this.tableName, { id });
                 await transaction.delete(this.ctx.service.materialAudit.tableName, { mid: id });
+                await transaction.delete(this.ctx.service.materialBills.tableName, { mid: id });
+                await transaction.delete(this.ctx.service.materialList.tableName, { mid: id });
+                await transaction.delete(this.ctx.service.materialListNotjoin.tableName, { mid: id });
                 await transaction.commit();
                 return true;
             } catch (err) {

+ 1 - 1
app/service/material_list.js

@@ -117,7 +117,7 @@ module.exports = app => {
          * @return {void}
          */
         async getMaterialData(tid) {
-            const sql = 'SELECT ml.`id`, mb.`code`, mb.`name`, mb.`unit`, ml.`quantity`, ml.`mb_id`, ml.`gcl_id`, ml.`xmj_id`, ml.`mx_id`, ml.`tid`' +
+            const sql = 'SELECT ml.`id`, mb.`code`, mb.`name`, mb.`unit`, ml.`quantity`, ml.`mb_id`, ml.`gcl_id`, ml.`xmj_id`, ml.`mx_id`, ml.`tid`, ml.`mid`' +
                 ' FROM ' + this.tableName + ' as ml' +
                 ' LEFT JOIN ' + this.ctx.service.materialBills.tableName + ' as mb' +
                 ' ON ml.`mb_id` = mb.`id`' +

+ 66 - 0
app/service/material_list_notjoin.js

@@ -21,6 +21,72 @@ module.exports = app => {
             super(ctx);
             this.tableName = 'material_list_notjoin';
         }
+
+        /**
+         * 添加不参与调差的清单
+         * @return {void}
+         */
+        async add(data) {
+            if (!this.ctx.tender || !this.ctx.material) {
+                throw '数据错误';
+            }
+            const newListNotJoin = {
+                tid: this.ctx.tender.id,
+                mid: this.ctx.material.id,
+                gcl_id: data.gcl_id,
+                xmj_id: data.id,
+                mx_id: data.mx_id !== undefined ? data.mx_id : '',
+                in_time: new Date(),
+            };
+
+            // 新增不参与调差清单
+            const result = await this.db.insert(this.tableName, newListNotJoin);
+            if (result.affectedRows === 0) {
+                throw '新增不参与调差清单数据失败';
+            }
+            return await this.getDataById(result.insertId);
+        }
+
+        /**
+         * 删除不参与调差的清单
+         * @param {int} id 工料id
+         * @return {void}
+         */
+        async del(id) {
+            if (!this.ctx.tender || !this.ctx.material) {
+                throw '数据错误';
+            }
+            // 判断是否可删
+            return await this.deleteById(id);
+        }
+
+        /**
+         * 复制上一期不参与调差的清单到下一期中
+         * @param {Object} transaction - 新增一期的事务
+         * @param {Object} list 上期清单
+         * @param {int} mid 工料id
+         * @return {void}
+         */
+        async copyNewStageNotJoinList(transaction, list, mid) {
+            if (!this.ctx.tender) {
+                throw '数据错误';
+            }
+            const notJoinlist = [];
+            for (const mb of list) {
+                const newLists = {
+                    tid: list.id,
+                    mid,
+                    mb_id: list.mb_id,
+                    gcl_id: list.gcl_id,
+                    xmj_id: list.xmj_id,
+                    mx_id: list.mx_id,
+                    in_time: new Date(),
+                };
+                notJoinlist.push(newLists);
+            }
+            // 复制上一期不参与调差的清单
+            return await transaction.insert(this.tableName, notJoinlist);
+        }
     }
     return MaterialListNotJoin;
 };

+ 3 - 2
app/view/material/list.ejs

@@ -10,8 +10,8 @@
                 <div class="d-inline-block ml-2">
                     <a class="btn btn-sm btn-light">
                         <div class="custom-control custom-checkbox">
-                            <input type="checkbox" class="custom-control-input" id="customCheckDisabled">
-                            <label class="custom-control-label text-primary" for="customCheckDisabled">显示有调差工料清单</label>
+                            <input type="checkbox" class="custom-control-input" id="show_material_gcl">
+                            <label class="custom-control-label text-primary" for="show_material_gcl">显示有调差工料清单</label>
                         </div>
                     </a>
                 </div>
@@ -76,4 +76,5 @@
     const pos = JSON.parse('<%- JSON.stringify(pos) %>');
     const curPosData = JSON.parse('<%- JSON.stringify(curPosData) %>');
     const readOnly = <%- material.readOnly %>;
+    const materialID = <%- material.id %>;
 </script>