Prechádzať zdrojové kódy

调差清单复制粘贴

laiguoran 5 rokov pred
rodič
commit
c1411c9e1e

+ 5 - 0
app/controller/material_controller.js

@@ -327,6 +327,11 @@ module.exports = app => {
                     case 'notjoin':
                         responseData.data = await ctx.service.materialListNotjoin.add(data.select);
                         break;
+                    case 'paste':
+                        await ctx.service.materialList.saveDatas(data.updateData);
+                        // 取所有工料表
+                        responseData.data = await ctx.service.materialList.getMaterialData(ctx.tender.id, ctx.material.id);
+                        break;
                     default: throw '参数有误';
                 }
 

+ 9 - 1
app/public/js/material.js

@@ -362,7 +362,15 @@ $(document).ready(() => {
             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);
+                // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
+                SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
+                SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
+                return;
+            }
+            if (sortData.length > 0 && range.col + range.colCount > 18) {
+                toastMessageUniq(hint.cellError);
+                SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
+                SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
                 return;
             }
             const data = [];

+ 118 - 7
app/public/js/material_list.js

@@ -48,17 +48,31 @@ function calcOneBQJC(xmj) {
     return jiacha;
 }
 
+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(() => {
     function TipCellType()
     {
     }
     TipCellType.prototype = new GC.Spread.Sheets.CellTypes.ColumnHeader();
     TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
-        var hitInfo = { x: x, y: y, row: context.row, col: context.col, cellRect: cellRect, sheetArea: context.sheetArea, sheet: context.sheet };
-        return hitInfo;
+        return { x: x, y: y, row: context.row, col: context.col, cellRect: cellRect, sheetArea: context.sheetArea, sheet: context.sheet };
     };
     TipCellType.prototype.processMouseEnter = function (hitInfo){
-        console.log(hitInfo);
         if (!this._toolTipElement) {
             var div = document.createElement("div");
             $(div).css("position", "absolute")
@@ -124,7 +138,7 @@ $(document).ready(() => {
             // console.log(gcl.leafXmjs);
             SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gcl.leafXmjs);
             // 对清单调差工料table的单位数量进行改变
-            materialSpreadSetting.cols[materialSpreadSetting.cols.length - 1].title = '|' + gcl.unit + '数量�';
+            materialSpreadSetting.cols[materialSpreadSetting.cols.length - 1].title = '|' + gcl.unit + '数量 �';
             SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
         } else {
             SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
@@ -184,7 +198,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: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
+            {title: '|数量 �', colSpan: '1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
         ],
         emptyRows: 0,
         headRows: 2,
@@ -403,12 +417,16 @@ $(document).ready(() => {
                     SpreadJsObj.reLoadRowData(lsheet, iRow);
                 });
             },
+            deletePress: function (sheet) {
+                return;
+            },
             editEnded: function (e, info) {
                 if (info.sheet.zh_setting) {
                     const select = SpreadJsObj.getSelectObject(info.sheet);
                     const col = info.sheet.zh_setting.cols[info.col];
                     // 未改变值则不提交
-                    const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
+                    // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : 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 === '' || validText === null))) {
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
@@ -442,9 +460,102 @@ $(document).ready(() => {
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     });
                 }
-            }
+            },
+            clipboardPasted(e, info) {
+                const hint = {
+                    cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
+                    numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
+                    numberCan: {type: 'error', msg: '请粘贴大于0并且小于6位小数的浮点数'},
+                };
+                const range = info.cellRange;
+                const sortData = info.sheet.zh_data || [];
+                if (range.row + range.rowCount > sortData.length) {
+                    toastMessageUniq(hint.cellError);
+                    SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
+                    SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
+                    return;
+                }
+                if (sortData.length > 0 && range.col + range.colCount > 4) {
+                    toastMessageUniq(hint.cellError);
+                    SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
+                    SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
+                    return;
+                }
+                console.log(info);
+                // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
+                const data = [];
+                // const rowData = [];
+                for (let iRow = 0; iRow < range.rowCount; iRow++) {
+                    let bPaste = true;
+                    const curRow = range.row + iRow;
+                    // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
+                    const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_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);
+                        validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
+                        const orgValue = sortData[curRow][colSetting.field];
+                        if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
+                            sameCol++;
+                            if (range.colCount === sameCol)  {
+                                bPaste = false;
+                            }
+                            continue;
+                        }
+                        if (colSetting.field === 'quantity') {
+                            if (isNaN(validText)) {
+                                toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
+                                bPaste = false;
+                                continue;
+                            }
+                            const num = parseFloat(validText);
+                            if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
+                                toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
+                                bPaste = false;
+                                continue;
+                            }
+                        }
+                        materialData[colSetting.field] = validText;
+                    }
+                    if (bPaste) {
+                        data.push(materialData);
+                        // rowData.push(curRow);
+                    } else {
+                        SpreadJsObj.reLoadRowData(info.sheet, curRow);
+                    }
+                }
+                if (data.length === 0) {
+                    SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
+                    return;
+                }
+                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);
+                // }, function () {
+                //     SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
+                //     return;
+                // });
+                // 更新至服务器
+                postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
+                    materialListData = result;
+                    const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
+                    gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
+                    SpreadJsObj.reLoadRowData(sheet, iRow);
+                }, function () {
+                    SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
+                });
+            },
         };
         materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
+        materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
+        SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
         const sheet = materialSpread.getActiveSheet();
         sheet.suspendPaint();
         // const basic_range = sheet.getRange(1, 3);

+ 27 - 0
app/service/material_list.js

@@ -103,6 +103,33 @@ 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) {
+                    const mb_id = data.mb_id;
+                    delete data.mb_id;
+                    await transaction.update(this.tableName, data);
+                    await this.calcQuantityByML(transaction, mb_id);
+                }
+                await transaction.commit();
+                return true;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
+
+        /**
          * 应用工料清单到其它清单中
          * @return {void}
          */