|
@@ -40,6 +40,14 @@ $(document).ready(function() {
|
|
|
SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
|
|
|
|
|
|
const treeOperationObj = {
|
|
|
+ getSelectNode: function (sheet) {
|
|
|
+ if (!sheet || !sheet.zh_tree) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ const sel = sheet.getSelections()[0];
|
|
|
+ return sheet.zh_tree.nodes[sel.row];
|
|
|
+ }
|
|
|
+ },
|
|
|
/**
|
|
|
* 刷新顶部按钮是否可用
|
|
|
* @param sheet
|
|
@@ -355,6 +363,23 @@ $(document).ready(function() {
|
|
|
self.refreshTree(sheet, result);
|
|
|
self.refreshOperationValid(sheet, sheet.getSelections());
|
|
|
});
|
|
|
+ },
|
|
|
+ batchInsertData: function (spread, data, fun) {
|
|
|
+ const self = this;
|
|
|
+ const sheet = spread.getActiveSheet();
|
|
|
+ const row = sheet.getSelections()[0].row;
|
|
|
+
|
|
|
+ const tree = sheet.zh_tree;
|
|
|
+ if (!tree) { return; }
|
|
|
+
|
|
|
+ const node = tree.nodes[row];
|
|
|
+ if (!node) { return; }
|
|
|
+
|
|
|
+ tree.batchInsert('batch-insert', node, data, function (result) {
|
|
|
+ self.refreshTree(sheet, result);
|
|
|
+ self.refreshOperationValid(sheet, sheet.getSelections());
|
|
|
+ fun();
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -391,6 +416,7 @@ $(document).ready(function() {
|
|
|
});
|
|
|
treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet(), ledgerSpread.getActiveSheet().getSelections());
|
|
|
|
|
|
+ let batchInsertObj;
|
|
|
// 右键菜单
|
|
|
$.contextMenu({
|
|
|
selector: '#ledger-spread',
|
|
@@ -475,7 +501,39 @@ $(document).ready(function() {
|
|
|
document.execCommand('paste');
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ 'batchInsertChild': {
|
|
|
+ name: '批量插入子项',
|
|
|
+ icon: 'fa-sign-in',
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ callback: function(key, opt) {
|
|
|
+ $('h5', $('#batch')).text('批量插入子项');
|
|
|
+ if (!batchInsertObj) {
|
|
|
+ batchInsertObj = new BatchInsertObj($('#batch'), key);
|
|
|
+ } else {
|
|
|
+ batchInsertObj.batchType = key;
|
|
|
+ }
|
|
|
+ $('#batch').modal('show');
|
|
|
+ },
|
|
|
+ },
|
|
|
+ 'batchInsertNext': {
|
|
|
+ name: '批量插入后项',
|
|
|
+ icon: 'fa-sign-in',
|
|
|
+ disabled: function (key, opt) {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ callback: function (key, opt) {
|
|
|
+ $('h5', $('#batch')).text('批量插入后项');
|
|
|
+ if (!batchInsertObj) {
|
|
|
+ batchInsertObj = new BatchInsertObj($('#batch'), key);
|
|
|
+ } else {
|
|
|
+ batchInsertObj.batchType = key;
|
|
|
+ }
|
|
|
+ $('#batch').modal('show');
|
|
|
+ },
|
|
|
+ },
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -537,7 +595,7 @@ $(document).ready(function() {
|
|
|
} else if (tab.attr('content') === '#deal-bills' && !dealBills) {
|
|
|
dealBills = new DealBills($('#deal-bills-spread')[0], {
|
|
|
cols: [
|
|
|
- {title: '清单编号', field: 'code', width: 120, readOnly: true, cellType: 'tree'},
|
|
|
+ {title: '清单编号', field: 'code', width: 120, readOnly: true},
|
|
|
{title: '名称', field: 'name', width: 230, readOnly: true},
|
|
|
{title: '单位', field: 'unit', width: 50, readOnly: true},
|
|
|
{title: '单价', field: 'unit_price', width: 50, readOnly: true},
|
|
@@ -595,7 +653,7 @@ $(document).ready(function() {
|
|
|
SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'tree', self.pathTree);
|
|
|
});
|
|
|
}
|
|
|
- };
|
|
|
+ }
|
|
|
class DealBills {
|
|
|
constructor (obj, spreadSetting) {
|
|
|
const self = this;
|
|
@@ -623,5 +681,124 @@ $(document).ready(function() {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+ class BatchInsertObj {
|
|
|
+ constructor (obj, batchType) {
|
|
|
+ const self = this;
|
|
|
+ this.obj = obj;
|
|
|
+ this.batchType = batchType;
|
|
|
+
|
|
|
+ this.xmSpreadSetting = {
|
|
|
+ cols: [
|
|
|
+ {title: '部位', field: 'bw', width: 80, readOnly: true},
|
|
|
+ {title: '图册号', field: 'drawingCode', width: 60, readOnly: true},
|
|
|
+ {title: '数量1', field: 'bills1', width: 50, readOnly: true},
|
|
|
+ {title: '数量2', field: 'bills2', width: 50, readOnly: true},
|
|
|
+ ],
|
|
|
+ emptyRows: 6,
|
|
|
+ };
|
|
|
+ this.xmSpread = SpreadJsObj.createNewSpread($('.batch-l-t')[0]);
|
|
|
+ SpreadJsObj.initSheet(this.xmSpread.getActiveSheet(), this.xmSpreadSetting);
|
|
|
+
|
|
|
+ this.gclSpreadSetting = {
|
|
|
+ cols: [
|
|
|
+ {title: '编号', field: 'code', width: 80, readOnly: true},
|
|
|
+ {title: '名称', field: 'name', width: 120, readOnly: true},
|
|
|
+ {title: '单位', field: 'unit', width: 50, readOnly: true},
|
|
|
+ {title: '单价', field: 'unit_price', width: 50, readOnly: true},
|
|
|
+ {title: '图册号', field: 'name', width: 60, readOnly: true},
|
|
|
+ ],
|
|
|
+ emptyRows: 2,
|
|
|
+ };
|
|
|
+ this.gclSpread = SpreadJsObj.createNewSpread($('.batch-l-b')[0]);
|
|
|
+ SpreadJsObj.initSheet(this.gclSpread.getActiveSheet(), this.gclSpreadSetting);
|
|
|
+ this.gclSpread.getActiveSheet().setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
|
|
|
+ this.gclSpread.getActiveSheet().getCell(0, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单1');
|
|
|
+ this.gclSpread.getActiveSheet().getCell(1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单2');
|
|
|
+
|
|
|
+ this.dealSpreadSetting = {
|
|
|
+ cols: [
|
|
|
+ {title: '清单编号', field: 'code', width: 80, readOnly: true},
|
|
|
+ {title: '名称', field: 'name', width: 120, readOnly: true},
|
|
|
+ {title: '单位', field: 'unit', width: 50, readOnly: true},
|
|
|
+ {title: '单价', field: 'unit_price', width: 50, readOnly: true},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ };
|
|
|
+ this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r')[0]);
|
|
|
+ SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
|
|
|
+ postData('/deal/get-data', {}, function (data) {
|
|
|
+ SpreadJsObj.loadSheetData(self.dealSpread.getActiveSheet(), 'data', data);
|
|
|
+
|
|
|
+ self.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
|
|
|
+ const deal = info.sheet.zh_data[info.row];
|
|
|
+ const sel = self.gclSpread.getActiveSheet().getSelections()[0];
|
|
|
+ self.gclSpread.getActiveSheet().getCell(sel.row, 0).value(deal.code);
|
|
|
+ self.gclSpread.getActiveSheet().getCell(sel.row, 1).value(deal.name);
|
|
|
+ self.gclSpread.getActiveSheet().getCell(sel.row, 2).value(deal.unit);
|
|
|
+ self.gclSpread.getActiveSheet().getCell(sel.row, 3).value(deal.unit_price);
|
|
|
+ if (sel.row + 1 === self.gclSpread.getActiveSheet().getRowCount()) {
|
|
|
+ const count = sel.row + 2;
|
|
|
+ self.gclSpread.getActiveSheet().setRowCount(count);
|
|
|
+ self.gclSpread.getActiveSheet().getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
|
|
|
+
|
|
|
+ const colCount = self.xmSpread.getActiveSheet().getColumnCount() + 1
|
|
|
+ self.xmSpread.getActiveSheet().setColumnCount(colCount);
|
|
|
+ self.xmSpread.getActiveSheet().getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('数量' + count);
|
|
|
+ }
|
|
|
+ self.gclSpread.getActiveSheet().setSelection(sel.row + 1, sel.col, 1, 1);
|
|
|
+ })
|
|
|
+ });
|
|
|
+
|
|
|
+ this.obj.bind('shown.bs.modal', function () {
|
|
|
+ self.xmSpread.refresh();
|
|
|
+ self.gclSpread.refresh();
|
|
|
+ self.dealSpread.refresh();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#batch-ok').click(function () {
|
|
|
+ treeOperationObj.batchInsertData(ledgerSpread, {
|
|
|
+ batchData: self.getBatchData(),
|
|
|
+ batchType: self.batchType,
|
|
|
+ }, function () {
|
|
|
+ self.obj.modal('hide');
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ getBatchData () {
|
|
|
+ const result = [];
|
|
|
+ const xmSheet = this.xmSpread.getActiveSheet(), gclSheet = this.gclSpread.getActiveSheet();
|
|
|
+ for (let iRow = 0; iRow < xmSheet.getRowCount(); iRow++) {
|
|
|
+ if (xmSheet.getText(iRow, 0) === '') { continue; }
|
|
|
+ const xmj = {
|
|
|
+ name: xmSheet.getText(iRow, 0),
|
|
|
+ children: [],
|
|
|
+ };
|
|
|
+ result.push(xmj);
|
|
|
+ for (let iCol = 2; iCol < xmSheet.getColumnCount(); iCol++) {
|
|
|
+ let value;
|
|
|
+ try {
|
|
|
+ value = parseFloat(xmSheet.getText(iRow, iCol));
|
|
|
+ if (value !== 0 && !isNaN(value)) {
|
|
|
+ const gcl = {
|
|
|
+ b_code: gclSheet.getText(iCol - 2, 0),
|
|
|
+ name: gclSheet.getText(iCol - 2, 1),
|
|
|
+ unit: gclSheet.getText(iCol - 2, 2),
|
|
|
+ quantity: value,
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ gcl.unit_price = parseFloat(gclSheet.getText(iCol - 2, 3));
|
|
|
+ } catch (err) {
|
|
|
+ }
|
|
|
+ if (gcl.b_code !== '' || gcl.name !== '') {
|
|
|
+ xmj.children.push(gcl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|
|
|
|