Browse Source

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

MaiXinRong 5 years ago
parent
commit
61fe06a4ee
3 changed files with 150 additions and 55 deletions
  1. 1 1
      app/controller/material_controller.js
  2. 2 2
      app/controller/stage_controller.js
  3. 147 52
      app/public/js/material.js

+ 1 - 1
app/controller/material_controller.js

@@ -362,7 +362,7 @@ module.exports = app => {
                             throw '请先输入编号';
                         }
                         // 判断编号为纯数字时,不能为小数
-                        if (!isNaN(data.updateData.code) && data.updateData.code.indexOf('.') !== -1) {
+                        if (!isNaN(data.updateData.code) && data.updateData.code.toString().indexOf('.') !== -1) {
                             throw '编号为纯数字时,不能为小数';
                         }
                         if (data.updateData.code.length > 15) {

+ 2 - 2
app/controller/stage_controller.js

@@ -1092,7 +1092,7 @@ module.exports = app => {
                 ctx.redirect('/tender/' + ctx.tender.id + '/measure/stage/' + ctx.params.order);
             }
         }
- 
+
         /**
          * 审核比较 页面 (Get)
          * @param ctx
@@ -1147,7 +1147,7 @@ module.exports = app => {
                 await this._getStageAuditViewData(ctx);
                 const renderData = await this._getDefaultRenderData(ctx);
                 renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.stage.bwtz);
-                await this.layout('stage/bwtz.ejs', renderData);
+                await this.layout('stage/bwtz.ejs', renderData, 'stage/audit_modal.ejs');
             } catch (err) {
                 this.log(err);
                 ctx.redirect('/tender/' + ctx.tender.id + '/measure/stage/' + ctx.params.order);

+ 147 - 52
app/public/js/material.js

@@ -242,8 +242,7 @@ $(document).ready(() => {
                 const select = SpreadJsObj.getSelectObject(info.sheet);
                 const col = info.sheet.zh_setting.cols[info.col];
                 // 未改变值则不提交
-                const validText = info.editingText ? trimInvalidChar(info.editingText) : null;
-                console.log(validText);
+                const validText = _.isNumber(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);
@@ -257,7 +256,7 @@ $(document).ready(() => {
                         return;
                     }
                     const num = parseFloat(validText);
-                    if (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num)) {
+                    if (validText !== null && (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num))) {
                         toastr.error('请输入大于0并且小于3位小数的浮点数');
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
                         return;
@@ -270,7 +269,7 @@ $(document).ready(() => {
                         return;
                     }
                     const num = parseFloat(validText);
-                    if (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num)) {
+                    if (validText !== null && (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num))) {
                         toastr.error('请输入大于0并且小于3位小数的浮点数');
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
                         return;
@@ -284,7 +283,7 @@ $(document).ready(() => {
                         return;
                     }
                     const num = parseFloat(validText);
-                    if (num < 0 || num > 100 || !/^\d+$/.test(num)) {
+                    if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
                         toastr.error('只能输入0-100的正整数');
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
                         return;
@@ -298,7 +297,7 @@ $(document).ready(() => {
                         return;
                     }
                     const num = parseFloat(validText);
-                    if (num < 0 || num > 100 || !/^\d+$/.test(num)) {
+                    if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
                         toastr.error('只能输入0-100的正整数');
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
                         return;
@@ -326,47 +325,153 @@ $(document).ready(() => {
                 });
             }
         },
-        // clipboardPasting(e, info) {
-        //     if (info.sheet.zh_setting) {
-        //         const sortData = info.sheet.zh_data;
-        //         const range = info.cellRange;
-        //         const validField = ['code', 'name', 'unit', 'spec', 'basic_price', 'basic_times', 'msg_tp', 'msg_times', 'm_up_risk', 'm_down_risk', 'remark'];
-        //         for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
-        //             const col = info.sheet.zh_setting.cols[iCol];
-        //             // if (col.type === 'Number') {
-        //             //     const num = _.toNumber(newData[col.field]);
-        //             //     if (num) {
-        //             //         newData[col.field] = num;
-        //             //     } else {
-        //             //         try {
-        //             //             newData[col.field] = math.evaluate(transExpr(newData[col.field]));
-        //             //         } catch(err) {
-        //             //             toastr.error('输入的表达式非法');
-        //             //             stagePosSpreadObj.loadCurPosData();
-        //             //             return;
-        //             //
-        //             //         }
-        //             //     }
-        //             // }
-        //             if (validField.indexOf(col.field) === -1) {
-        //                 toastr.error('不可修改此数据');
-        //                 info.cancel = true;
-        //                 return;
-        //             }
-        //         }
-        //     }
-        // },
-        // clipboardPasted(e, info) {
-        //     // console.log(e, info);
-        // },
+        deletePress: function (sheet) {
+            return;
+        },
+        clipboardPasted(e, info) {
+            // const tree = info.sheet.zh_tree;
+            // if (!tree) { return; }
+            const hint = {
+                codeEmpty: {type: 'error', msg: '请先输入编号'},
+                codeUsed: {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) {
+                SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
+                return;
+            }
+            const data = [];
+            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 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);
+                    const orgValue = sortData[curRow][colSetting.field];
+                    console.log(orgValue);
+                    if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
+                        continue;
+                    }
+                    materialData[colSetting.field] = validText;
+
+                    // if (colSetting.type === 'Number') {
+                    //     const num = _.toNumber(materialData[colSetting.field]);
+                    // }
+                }
+                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);
+            //     });
+            // }
+        },
         setReadOnly: function(readOnly) {
-            SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);
+            // SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);
         }
     };
     materialSpreadObj.refreshActn();
     materialSpread.bind(spreadNS.Events.SelectionChanged, materialSpreadObj.selectionChanged);
-    // materialSpread.bind(spreadNS.Events.ClipboardPasting, materialSpreadObj.clipboardPasting);
-    // materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
+    materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
+    SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
     // const sheet = materialSpread.getActiveSheet();
     // sheet.suspendPaint();
     // var range = sheet.getRange(-1, 8, -1, 1);
@@ -597,13 +702,3 @@ $(document).ready(() => {
         }
     });
 });
-//
-// const pasteExpr = function (e, obj) {
-//     let text = e.clipboardData.getData('text');
-//     e.preventDefault();
-//     text = trimInvalidChar(_.trim(text));
-//     const start = obj.selectionStart, end = obj.selectionEnd;
-//     obj.value = obj.value.substr(0, start) + text + obj.value.substring(end, obj.value.length);
-//     obj.selectionStart = start + text.length;
-//     obj.selectionEnd = start + text.length;
-// };