$(document).ready(() => { autoFlashHeight(); class QtyObj { constructor(setting) { this.spread = SpreadJsObj.createNewSpread(setting.obj); this.sheet = this.spread.getActiveSheet(); SpreadJsObj.initSheet(this.sheet, setting.spreadSetting); this.data = setting.data; this.type = setting.type; SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.data); const self = this; this.sheet.bind(spreadNS.Events.EditEnded, function(e, info) { if (!info.sheet.zh_setting || !info.sheet.zh_data) return; const node = info.sheet.zh_data[info.row]; if (!node) return; const col = info.sheet.zh_setting.cols[info.col]; const data = {}; data.id = node.id; const oldValue = node ? node[col.field] : null; const newValue = trimInvalidChar(info.editingText); if (oldValue == info.editingText || ((!oldValue || oldValue === '') && (newValue === ''))) { SpreadJsObj.reLoadRowData(info.sheet, info.row); return; } data[col.field] = newValue; postData('info/save', { type: self.type, updateData: [data]}, function (result) { self.loadUpdateData(result); SpreadJsObj.reLoadSheetData(info.sheet); }, function () { SpreadJsObj.reLoadRowData(info.sheet, info.row); }); }); this.sheet.bind(spreadNS.Events.ClipboardPasting, function(e, info) { const setting = info.sheet.zh_setting, sortData = info.sheet.zh_data; info.cancel = true; if (!setting || !sortData) return; const pasteData = info.pasteData.html ? SpreadJsObj.analysisPasteHtml(info.pasteData.html) : (info.pasteData.text === '' ? SpreadJsObj.Clipboard.getAnalysisPasteText() : SpreadJsObj.analysisPasteText(info.pasteData.text)); const uDatas = []; for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) { const curRow = info.cellRange.row + iRow; const node = sortData[curRow]; let bPaste = false; const data = {}; for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) { const curCol = info.cellRange.col + iCol; const colSetting = setting.cols[curCol]; const value = trimInvalidChar(pasteData[iRow][iCol]); if (colSetting.type === 'Number') { const num = _.toNumber(value); if (num) { data[colSetting.field] = num; bPaste = true; } } } if (bPaste) { if (node) { data.id = node.id; uDatas.push(data); } } } if (uDatas.length > 0) { postData('info/save', { type: self.type, updateData: uDatas}, function (result) { self.loadUpdateData(result); SpreadJsObj.reLoadSheetData(info.sheet); }); } else { SpreadJsObj.reLoadSheetData(info.sheet); } }); SpreadJsObj.addDeleteBind(this.spread, function(sheet) { if (!sheet.zh_setting || !sheet.zh_data) return; const sortData = sheet.zh_data; const datas = []; const sels = sheet.getSelections(); if (!sels || !sels[0]) return; for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) { let bDel = false; const node = sortData[iRow]; if (node) { const data = { id: node.id }; for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) { const style = sheet.getStyle(iRow, iCol); if (!style.locked) { const colSetting = sheet.zh_setting.cols[iCol]; data[colSetting.field] = 0; bDel = true; } } if (bDel) { datas.push(data); } } } if (datas.length === 0) return; postData('info/save', { type: self.type, updateData: datas}, function (result) { self.loadUpdateData(result); SpreadJsObj.reLoadSheetData(sheet); }, function () { SpreadJsObj.reLoadSheetData(sheet); }); }); } loadUpdateData(data) { for (const d of data) { const source = this.data.find(x => { return x.id === d.id }); if (!source) continue; source.dgn_qty = d.dgn_qty; source.final_qty = d.final_qty; } } } const spreadSetting = { cols: [ {title: '工程名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@', readOnly: true}, {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}, {title: '设计', colSpan: '1', rowSpan: '1', field: 'dgn_qty', hAlign: 2, width: 100, type: 'Number'}, {title: '竣工', colSpan: '1', rowSpan: '1', field: 'final_qty', hAlign: 2, width: 100, type: 'Number'}, ], emptyRows: 0, headRows: 1, headRowHeight: [32], defaultRowHeight: 21, headerFont: '12px 微软雅黑', font: '12px 微软雅黑', }; const mainQtyObj = new QtyObj({ obj: $('#main_qty_spread')[0], spreadSetting, data: mainQty, type: 'main_quantity', }); const gclQtyObj = new QtyObj({ obj: $('#gcl_qty_spread')[0], spreadSetting, data: gclQty, type: 'gcl_quantity', }) });