123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- $(document).ready(() => {
- autoFlashHeight();
- class QtyObj {
- constructor(setting) {
- this.spread = SpreadJsObj.createNewSpread(setting.obj);
- this.sheet = this.spread.getActiveSheet();
- SpreadJsObj.initSheet(this.sheet, setting.spreadSetting);
- if (setting.treeSetting) {
- this.tree = createNewPathTree('base', setting.treeSetting);
- this.tree.loadDatas(setting.data);
- } else {
- this.data = setting.data;
- }
- this.type = setting.type;
- if (setting.treeSetting) {
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.tree);
- } else {
- 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) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const node = SpreadJsObj.getRowObject(info.sheet, info.row);
- if (!node || (self.tree && node.children && node.children.length > 0)) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- 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;
- }
- if (col.type === 'Number') {
- const num = _.toNumber(newValue);
- if (num) {
- data[col.field] = num;
- }
- } else {
- 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) {
- info.cancel = true;
- const setting = info.sheet.zh_setting;
- if (!setting) 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 = SpreadJsObj.getRowObject(info.sheet, curRow);
- if (self.tree && node.children && node.children.length > 0) continue;
- 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;
- }
- } else {
- data[colSetting.field] = value;
- 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) return;
- 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 = SpreadJsObj.getRowObject(info.sheet, 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] = colSetting.type === 'Number' ? 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.tree
- ? this.tree.getItems(d.id)
- : 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 mainQtyObj = new QtyObj({
- obj: $('#main_qty_spread')[0],
- 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 微软雅黑',
- },
- data: mainQty,
- isTree: false,
- type: 'main_quantity',
- });
- const gclQtyObj = new QtyObj({
- obj: $('#gcl_qty_spread')[0],
- spreadSetting: {
- cols: [
- {title: '工程名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@', readOnly: true, cellType: 'tree'},
- {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 微软雅黑',
- },
- data: gclQty,
- type: 'gcl_quantity',
- isTree: true,
- treeSetting: {
- id: 'id',
- pid: 'pid',
- order: 'order',
- level: 'level',
- fullPath: 'full_path',
- rootId: -1,
- }
- })
- });
|