Jelajahi Sumber

Merge branch 'master' of http://192.168.1.41:3000/maixinrong/Calculation

TonyKang 5 tahun lalu
induk
melakukan
4f7a523235

+ 11 - 0
app/controller/material_controller.js

@@ -396,6 +396,17 @@ module.exports = app => {
                         };
                         responseData.data = await ctx.service.materialBills.updateFYQuantity(updateData);
                         break;
+                    case 'paste':
+                        responseData.data.m_tp = await ctx.service.materialBills.saveDatas(data.updateData);
+                        // 根据期判断需要获取的工料信息值
+                        const searchsql = { tid: ctx.tender.id };
+                        if (ctx.material.highOrder !== ctx.material.order) {
+                            const midList = await ctx.service.material.getPreMidList(ctx.tender.id, ctx.material.order);
+                            searchsql.mid = midList;
+                        }
+                        // 取所有工料表
+                        responseData.data.info = await ctx.service.materialBills.getAllDataByCondition({ where: searchsql });
+                        break;
                     default: throw '参数有误';
                 }
 

+ 117 - 109
app/public/js/material.js

@@ -86,13 +86,27 @@ function resetTpTable() {
     $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
     $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
 }
+function getPasteHint (str, row = '') {
+    let returnObj = str;
+    if (row) {
+        returnObj.msg = '工料第' + (row+1) + '行' + str.msg;
+    }
+    return returnObj;
+}
+const is_numeric = (value) => {
+    if (typeof(value) === 'object') {
+        return false;
+    } else {
+        return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
+    }
+};
 $(document).ready(() => {
     autoFlashHeight();
     const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
     const materialSpreadSetting = {
         cols: [
-            {title: '调差类型', colSpan: '1', rowSpan: '2', field: 't_type', hAlign: 1, width: 80, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'customizeCombo', comboItems: materialType.t_type, cellTypeKey: 1},
-            {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.isEdit'},
+            {title: '调差类型', colSpan: '1', rowSpan: '2', field: 't_type', hAlign: 1, width: 80, formatter: '@', readOnly: 'readOnly.isUsed', cellType: 'customizeCombo', comboItems: materialType.t_type, cellTypeKey: 1},
+            {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.isUsed'},
             {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: 'readOnly.isEdit'},
             {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit'},
             {title: '规格', colSpan: '1', rowSpan: '2', field: 'spec', hAlign: 0, width: 180, formatter: '@', readOnly: 'readOnly.isEdit'},
@@ -147,16 +161,24 @@ $(document).ready(() => {
     };
 
     const materialBase = {
-        isEdit: function (data) {
+        isUsed: function (data) {
             if (data.t_type === 2) {
                 return data.mid === materialID;
             } else {
-                const mlInfo = materialListData.find(function (item) {
-                    return item.mb_id === data.id;
-                });
+                const mlInfo = _.find(materialListData, { mb_id: data.id });
                 return data.mid === materialID && mlInfo === undefined;
             }
         },
+        isEdit: function (data) {
+            // if (data.t_type === 2) {
+            //     return data.mid === materialID;
+            // } else {
+            //     const mlInfo = _.find(materialListData, { mb_id: data.id });
+            //     return data.mid === materialID && mlInfo === undefined;
+            // }
+            return data.mid === materialID;
+        },
+
         // isStage: function (data) {
         //     return data.mid === materialID;
         // }
@@ -180,6 +202,9 @@ $(document).ready(() => {
             isEdit: function (data) {
                 return !(!readOnly && materialBase.isEdit(data));
             },
+            isUsed: function (data) {
+                return !(!readOnly && materialBase.isUsed(data));
+            },
             remark: function () {
                 return readOnly;
             },
@@ -242,7 +267,7 @@ $(document).ready(() => {
                 const select = SpreadJsObj.getSelectObject(info.sheet);
                 const col = info.sheet.zh_setting.cols[info.col];
                 // 未改变值则不提交
-                const validText = _.isNumber(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
+                const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
                 const orgValue = select[col.field];
                 if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
@@ -314,6 +339,7 @@ $(document).ready(() => {
                 select.msg_spread = materialCol.getValue.msg_spread(select);
                 select.m_spread = materialCol.getValue.m_spread(select);
                 select.m_tp = materialCol.getValue.m_tp(select);
+
                 // 更新至服务器
                 postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
                     m_tp = result.m_tp;
@@ -329,140 +355,122 @@ $(document).ready(() => {
             return;
         },
         clipboardPasted(e, info) {
-            // const tree = info.sheet.zh_tree;
-            // if (!tree) { return; }
             const hint = {
-                codeEmpty: {type: 'error', msg: '请先输入编号'},
+                cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
+                codeEmpty: {type: 'error', msg: '请先输入编号,并且不超过15个字符'},
                 codeUsed: {type: 'error', msg: '该编号已存在,请重新输入。'},
+                codeError: {type: 'error', msg: '编号为纯数字时,不能为小数'},
                 numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
                 riskCan: {type: 'error', msg: '只能粘贴0-100的正整数'},
                 numberCan: {type: 'error', msg: '请粘贴大于0并且小于3位小数的浮点数'},
             };
-            console.log(info);
             const range = info.cellRange;
             const sortData = info.sheet.zh_data || [];
             if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
+                toastMessageUniq(hint.cellError);
                 SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
                 return;
             }
             const data = [];
+            // const rowData = [];
             for (let iRow = 0; iRow < range.rowCount; iRow++) {
                 let bPaste = true;
                 const curRow = range.row + iRow;
-                const materialData = {id: sortData[curRow].id};
-                for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
+                // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
+                const materialData = { id: sortData[curRow].id };
+                const hintRow = range.rowCount > 1 ? curRow : '';
+                let sameCol = 0;
+                for (let iCol = 0; iCol < range.colCount; iCol++) {
                     const curCol = range.col + iCol;
                     const colSetting = info.sheet.zh_setting.cols[curCol];
                     if (!colSetting) continue;
 
-
                     let validText = info.sheet.getText(curRow, curCol);
-                    console.log(validText, isNaN(parseFloat(validText)));
-                    validText = _.isNumber(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
-                    console.log(validText);
+                    validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
                     const orgValue = sortData[curRow][colSetting.field];
-                    console.log(orgValue);
                     if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
+                        sameCol++;
+                        if (range.colCount === sameCol)  {
+                            bPaste = false;
+                        }
+                        continue;
+                    }
+                    if (colSetting.field === 'code' && (validText === '' || validText.length > 15)) {
+                        toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
+                        bPaste = false;
+                        continue;
+                    }
+                    if (colSetting.field === 'code' && validText.toString().indexOf('.') !== -1) {
+                        toastMessageUniq(getPasteHint(hint.codeError, hintRow));
+                        bPaste = false;
+                        continue;
+                    }
+                    if (colSetting.field === 'code' && _.find(sortData, { code: validText })) {
+                        toastMessageUniq(getPasteHint(hint.codeUsed, hintRow));
+                        bPaste = false;
+                        continue;
+                    }
+                    if (colSetting.field === 't_type' || colSetting.field === 'm_type') {
                         continue;
                     }
-                    materialData[colSetting.field] = validText;
 
-                    // if (colSetting.type === 'Number') {
-                    //     const num = _.toNumber(materialData[colSetting.field]);
-                    // }
+                    if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp'
+                        || colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk') {
+                        if (isNaN(validText)) {
+                            toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
+                            bPaste = false;
+                            continue;
+                        }
+                        const num = parseFloat(validText);
+                        if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp') {
+                            if (validText !== null && (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num))) {
+                                toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
+                                bPaste = false;
+                                continue;
+                            }
+                        } else if (colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk') {
+                            if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
+                                toastMessageUniq(getPasteHint(hint.riskCan, hintRow));
+                                bPaste = false;
+                                continue;
+                            }
+                        }
+                    }
+                    materialData[colSetting.field] = validText;
+                }
+                if (materialData.code === '' || materialData.code === null) {
+                    toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
+                    bPaste = false;
+                }
+                if (bPaste) {
+                    materialData.msg_spread = materialCol.getValue.msg_spread(sortData[curRow]);
+                    materialData.m_spread = materialCol.getValue.m_spread(sortData[curRow]);
+                    materialData.m_tp = materialCol.getValue.m_tp(sortData[curRow]);
+                    data.push(materialData);
+                    // rowData.push(curRow);
+                } else {
+                    SpreadJsObj.reLoadRowData(info.sheet, curRow);
                 }
-                console.log(materialData);
             }
             if (data.length === 0) {
                 SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
                 return;
             }
-            // if (info.sheet.zh_setting) {
-            //     const select = SpreadJsObj.getSelectObject(info.sheet);
-            //     const col = info.sheet.zh_setting.cols[info.col];
-            //     // 未改变值则不提交
-            //     const validText = info.editingText ? trimInvalidChar(info.editingText) : null;
-            //     const orgValue = select[col.field];
-            //     if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
-            //         SpreadJsObj.reLoadRowData(info.sheet, info.row);
-            //         return;
-            //     }
-            //     // 判断部分值是否输入的是数字判断和数据计算
-            //     if (col.field === 'basic_price') {
-            //         if (isNaN(validText)) {
-            //             toastr.error('不能输入其它非数字类型字符');
-            //             SpreadJsObj.reLoadRowData(info.sheet, info.row);
-            //             return;
-            //         }
-            //         const num = parseFloat(validText);
-            //         if (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num)) {
-            //             toastr.error('请输入大于0并且小于3位小数的浮点数');
-            //             SpreadJsObj.reLoadRowData(info.sheet, info.row);
-            //             return;
-            //         }
-            //     }
-            //     if (col.field === 'msg_tp') {
-            //         if (isNaN(validText)) {
-            //             toastr.error('不能输入其它非数字类型字符');
-            //             SpreadJsObj.reLoadRowData(info.sheet, info.row);
-            //             return;
-            //         }
-            //         const num = parseFloat(validText);
-            //         if (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num)) {
-            //             toastr.error('请输入大于0并且小于3位小数的浮点数');
-            //             SpreadJsObj.reLoadRowData(info.sheet, info.row);
-            //             return;
-            //         }
-            //     }
-            //     if (col.field === 'm_up_risk') {
-            //         // 只能输入正整数
-            //         if (isNaN(validText)) {
-            //             toastr.error('不能输入其它非数字类型字符');
-            //             SpreadJsObj.reLoadRowData(info.sheet, info.row);
-            //             return;
-            //         }
-            //         const num = parseFloat(validText);
-            //         if (num < 0 || num > 100 || !/^\d+$/.test(num)) {
-            //             toastr.error('只能输入0-100的正整数');
-            //             SpreadJsObj.reLoadRowData(info.sheet, info.row);
-            //             return;
-            //         }
-            //     }
-            //     if (col.field === 'm_down_risk') {
-            //         // 只能输入正整数
-            //         if (isNaN(validText)) {
-            //             toastr.error('不能输入其它非数字类型字符');
-            //             SpreadJsObj.reLoadRowData(info.sheet, info.row);
-            //             return;
-            //         }
-            //         const num = parseFloat(validText);
-            //         if (num < 0 || num > 100 || !/^\d+$/.test(num)) {
-            //             toastr.error('只能输入0-100的正整数');
-            //             SpreadJsObj.reLoadRowData(info.sheet, info.row);
-            //             return;
-            //         }
-            //     }
-            //     if (col.field === 't_type') {
-            //         if (validText === 1) {
-            //             select.quantity = null;
-            //             select.expr = null;
-            //             select.m_tp = null;
-            //         }
-            //     }
-            //     select[col.field] = validText;
-            //     select.msg_spread = materialCol.getValue.msg_spread(select);
-            //     select.m_spread = materialCol.getValue.m_spread(select);
-            //     select.m_tp = materialCol.getValue.m_tp(select);
-            //     // 更新至服务器
-            //     postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
-            //         m_tp = result.m_tp;
-            //         resetTpTable();
-            //         SpreadJsObj.reLoadRowData(info.sheet, info.row);
-            //     }, function () {
-            //         select[col.field] = orgValue;
-            //         SpreadJsObj.reLoadRowData(info.sheet, info.row);
-            //     });
-            // }
+            console.log(data);
+            // 更新至服务器
+            postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
+                materialBillsData = result.info;
+                SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
+                // for (const row in rowData) {
+                //     materialBillsData.splice(index, 1, result.info[row]);
+                //     SpreadJsObj.reLoadRowData(info.sheet, row);
+                // }
+                m_tp = result.m_tp;
+                resetTpTable();
+            }, function () {
+                SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
+                return;
+            });
         },
         setReadOnly: function(readOnly) {
             // SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);

+ 30 - 0
app/service/material_bills.js

@@ -100,6 +100,36 @@ module.exports = app => {
         }
 
         /**
+         * 修改工料信息
+         * @param {Object} data 工料内容
+         * @return {void}
+         */
+        async saveDatas(datas) {
+            if (!this.ctx.tender || !this.ctx.material) {
+                throw '数据错误';
+            }
+            // 判断是否可修改
+            // 判断t_type是否为费用
+            const transaction = await this.db.beginTransaction();
+            try {
+                for (const data of datas) {
+                    delete data.in_time;
+                    delete data.m_tp;
+                    // console.log(data);
+                    await transaction.update(this.tableName, data);
+                }
+                // console.log(datas);
+                // await transaction.update(this.tableName, datas);
+                const m_tp = await this.calcMaterialMTp(transaction);
+                await transaction.commit();
+                return m_tp;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
+        /**
          * 更新新一期的quantity和截止上期金额并返回本期总金额
          * @param transaction
          * @param tid

+ 1 - 1
app/view/material/info.ejs

@@ -71,7 +71,7 @@
 <% } %>
 <script>
     const materialType = JSON.parse('<%- materialType %>');
-    const materialBillsData = JSON.parse('<%- JSON.stringify(materialBillsData) %>');
+    let materialBillsData = JSON.parse('<%- JSON.stringify(materialBillsData) %>');
     const materialListData = JSON.parse('<%- JSON.stringify(materialListData) %>');
     const readOnly = <%- material.readOnly %>;
     const materialID = <%- material.id %>;