|
@@ -0,0 +1,209 @@
|
|
|
+const BatchImportStageGcl = function (setting) {
|
|
|
+ const biObj = {
|
|
|
+ setting,
|
|
|
+ spread: null,
|
|
|
+ sheet: null,
|
|
|
+ tenderSourceTree: null,
|
|
|
+ history: [],
|
|
|
+ batchTree: null,
|
|
|
+ rebuildStageSelect: function () {
|
|
|
+ const getItems = function (data) {
|
|
|
+ const items = [];
|
|
|
+ if (data) {
|
|
|
+ for (let i = 1; i <= data.stageCount; i++) {
|
|
|
+ items.push({value: i, text: `第${i}期`});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return items;
|
|
|
+ };
|
|
|
+ for (let i = 0; i < biObj.sheet.getRowCount(); i++) {
|
|
|
+ const data = biObj.batchTree.nodes[i];
|
|
|
+ if (!data.tid) continue;
|
|
|
+
|
|
|
+ const items = getItems(data);
|
|
|
+ const cellType = new spreadNS.CellTypes.ComboBox().itemHeight(10).editorValueType(spreadNS.CellTypes.EditorValueType.value).items(items);
|
|
|
+ biObj.sheet.getCell(i, 2).cellType(cellType);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ trEditEnded: function (e, info) {
|
|
|
+ const data = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
+ const col = info.sheet.zh_setting.cols[info.col];
|
|
|
+ data[col.field] = info.sheet.getValue(info.row, info.col);
|
|
|
+ },
|
|
|
+ reloadBatchTree() {
|
|
|
+ this.batchTree.clearDatas();
|
|
|
+ for (const h of this.history) {
|
|
|
+ if (!h.ledger_node) continue;
|
|
|
+
|
|
|
+ const ledgerData = { lid: h.lid, ledger_id: h.ledger_node.ledger_id, code: h.ledger_node.code, name: h.ledger_node.name, ledger_node: h.ledger_node };
|
|
|
+ const batchNode = this.batchTree.addNode(ledgerData, null);
|
|
|
+ for (const t of h.tenders) {
|
|
|
+ const tenderData = JSON.parse(JSON.stringify(t));
|
|
|
+ const tender = this.tenderSourceTree.nodes.find(y => { return y.tid === t.tid });
|
|
|
+ tenderData.stageCount = tender.stageCount;
|
|
|
+ this.batchTree.addNode(tenderData, batchNode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.batchTree.sortTreeNode(true);
|
|
|
+ },
|
|
|
+ loadHistory: function () {
|
|
|
+ if (biObj.batching) return;
|
|
|
+
|
|
|
+ biObj.tender_id = biObj.setting.stageTree.nodes[0].tender_id;
|
|
|
+ postData('/list/load', {type: 'stageBatch', tid: biObj.tender_id}, data => {
|
|
|
+ biObj.history = data.history || [];
|
|
|
+ // 屏蔽自己
|
|
|
+ const curIndex = data.tenders.findIndex(x => { return x.id === biObj.tender_id });
|
|
|
+ if (curIndex >= 0) data.tenders.splice(curIndex, 1);
|
|
|
+ biObj.tenderSourceTree = Tender2Tree.convert(data.category, data.tenders, data.ledgerAuditConst, data.stageAuditConst);
|
|
|
+ for (const h of biObj.history) {
|
|
|
+ h.ledger_order = biObj.setting.stageTree.nodes.findIndex(x => { return x.id === h.lid; });
|
|
|
+ h.ledger_node = h.ledger_order >= 0 ? biObj.setting.stageTree.nodes[h.ledger_order] : null;
|
|
|
+ if (h.tenders) h.tenders = h.tenders.filter(x => { return biObj.tenderSourceTree.nodes.find(y => { return x.tid === y.tid; })});
|
|
|
+ }
|
|
|
+ biObj.history.sort((x, y) => { return x.ledger_order - y.ledger_order; });
|
|
|
+ biObj.reloadBatchTree();
|
|
|
+ SpreadJsObj.loadSheetData(biObj.sheet, SpreadJsObj.DataType.Tree, biObj.batchTree);
|
|
|
+ biObj.rebuildStageSelect();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ initBatchImport: function () {
|
|
|
+ if (this.spread) return;
|
|
|
+
|
|
|
+ this.spread = SpreadJsObj.createNewSpread($('#bi-spread')[0]);
|
|
|
+ this.sheet = this.spread.getActiveSheet();
|
|
|
+ SpreadJsObj.initSheet(this.sheet, {
|
|
|
+ cols: [
|
|
|
+ // {title: '选择', field: 'selected', hAlign: 1, width: 40, formatter: '@', cellType: 'checkbox'},
|
|
|
+ {title: '编号', field: 'code', hAlign: 0, width: 180, formatter: '@', cellType: 'tree'},
|
|
|
+ {title: '名称/引用标段', field: 'name', hAlign: 0, width: 180, formatter: '@'},
|
|
|
+ {title: '可选期', field: 'stage', hAlign: 1, width: 60, formatter: '@'},
|
|
|
+ // {title: '覆盖数据', field: 'is_cover', hAlign: 1, width: 60, cellType: 'checkbox'},
|
|
|
+ {title: '状态', field: 'status', hAlign: 1, width: 60, formatter: '@'},
|
|
|
+ {title: '错误信息', field: 'error', hAlign: 1, width: 60, formatter: '@'},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [32],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ selectedBackColor: '#fffacd',
|
|
|
+ });
|
|
|
+ this.spread.bind(spreadNS.Events.EditEnded, biObj.trEditEnded);
|
|
|
+
|
|
|
+ this.batchTree = createNewPathTree('gather', {
|
|
|
+ id: 'id',
|
|
|
+ pid: 'pid',
|
|
|
+ order: 'order',
|
|
|
+ level: 'level',
|
|
|
+ rootId: -1,
|
|
|
+ fullPath: 'full_path',
|
|
|
+ });
|
|
|
+ },
|
|
|
+ checkErrors: function () {
|
|
|
+ const hasError = this.batchTree.children.findIndex(x => { return x.error > 0; }) >= 0;
|
|
|
+ if (hasError) {
|
|
|
+ $('#bi-download-error').show();
|
|
|
+ } else {
|
|
|
+ $('#bi-download-error').hide();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ importStageGcl: async function (node, cover) {
|
|
|
+ const updateData = { lid: node.lid, type: 'stage', cover, tenders: [] };
|
|
|
+ for (const tender of node.children) {
|
|
|
+ updateData.tenders.push({ tid: tender.tid, name: tender.name, stageCount: tender.stageCount, stage: tender.stage });
|
|
|
+ }
|
|
|
+
|
|
|
+ const result = await postDataAsync(window.location.pathname + '/sumLoad', updateData);
|
|
|
+ biObj.setting.afterLoad(result, node.ledger_node);
|
|
|
+ node.errors = result.sumLoadHis.errors;
|
|
|
+ node.error = node.errors ? node.errors.length : 0;
|
|
|
+ },
|
|
|
+ batchImport: async function () {
|
|
|
+ $('#bi-start')[0].disabled = true;
|
|
|
+ biObj.batching = true;
|
|
|
+ const cover = $('#bi-cover')[0].checked;
|
|
|
+ for (const node of this.batchTree.children) {
|
|
|
+ if (!node.children || node.children.length === 0) continue;
|
|
|
+ const row = this.batchTree.getNodeIndex(node);
|
|
|
+ try {
|
|
|
+ node.status = '开始导入';
|
|
|
+ SpreadJsObj.reLoadRowData(biObj.sheet, row);
|
|
|
+ await biObj.importStageGcl(node, cover);
|
|
|
+ node.status = '导入完成';
|
|
|
+ SpreadJsObj.reLoadRowData(biObj.sheet, row);
|
|
|
+ } catch(err) {
|
|
|
+ console.log(err);
|
|
|
+ node.status = '导入失败';
|
|
|
+ SpreadJsObj.reLoadRowData(biObj.sheet, row);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ biObj.batching = false;
|
|
|
+ $('#bi-start')[0].disabled = false;
|
|
|
+ biObj.checkErrors();
|
|
|
+ },
|
|
|
+ downloadErrors: function () {
|
|
|
+ const errorType = {
|
|
|
+ less: '数量变少',
|
|
|
+ miss: '找不到清单',
|
|
|
+ 'qc-conflict': '变更冲突(已调用变更令)'
|
|
|
+ };
|
|
|
+ // const setting = {
|
|
|
+ // header: ['清单编号', '清单名称','单位', '合同数量', '变更数量', '错误类型'],
|
|
|
+ // width: [80, 200, 60, 80, 80, 180],
|
|
|
+ // hAlign: ['left', 'left', 'center', 'right', 'right', 'left'],
|
|
|
+ // };
|
|
|
+ // const sheets = [];
|
|
|
+ // for (const node of this.batchTree.children) {
|
|
|
+ // if (node.error > 0) {
|
|
|
+ // sheets.push({ name: node.code, setting, data: node.errors.map(x => {
|
|
|
+ // return [x.b_code, x.name, x.unit, x.qty, x.qc_qty, errorType[x.type]]; })
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // XLSXObj.exportXlsxSheets(sheets, '批量导入错误.xlsx');
|
|
|
+ const setting = {
|
|
|
+ cols: [
|
|
|
+ {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
|
|
|
+ {title: '清单名称', field: 'name', hAlign: 0, width: 180, formatter: '@'},
|
|
|
+ {title: '单位', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
|
|
|
+ {title: '合同数量', field: 'qty', hAlign: 2, width: 80, formatter: '@'},
|
|
|
+ {title: '变更数量', field: 'qc_qty', hAlign: 2, width: 80, formatter: '@'},
|
|
|
+ {title: '错误类型', field: 'type', hAlign: 0, width: 150, formatter: '@', getValue(data) { return errorType[data.type]; }},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [32],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ };
|
|
|
+ const sheets = [];
|
|
|
+ for (const node of this.batchTree.children) {
|
|
|
+ if (node.error > 0) {
|
|
|
+ sheets.push({ name: node.code, setting, data: node.errors });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SpreadExcelObj.exportSimpleXlsxSheets(sheets, '批量导入错误.xlsx');
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ $('#batch-import').on('shown.bs.modal', () => {
|
|
|
+ biObj.initBatchImport();
|
|
|
+ biObj.loadHistory();
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#bi-start').click(function () {
|
|
|
+ biObj.batchImport();
|
|
|
+ });
|
|
|
+ $('#bi-download-error').click(function () {
|
|
|
+ biObj.downloadErrors();
|
|
|
+ });
|
|
|
+
|
|
|
+ const show = function () {
|
|
|
+ $('#batch-import').modal('show');
|
|
|
+ };
|
|
|
+
|
|
|
+ return { show }
|
|
|
+};
|