123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734 |
- function getTenderId() {
- return window.location.pathname.split('/')[2];
- }
- const invalidFields = {
- parent: ['cur_qty', 'cur_tp', 'unit_price'],
- };
- $(document).ready(function() {
- let stdGcl;
- autoFlashHeight();
- class BillsObj {
- constructor() {
- this.spread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
- this.sheet = this.spread.getActiveSheet();
- this.treeSetting = {
- id: 'tree_id',
- pid: 'tree_pid',
- order: 'tree_order',
- level: 'tree_level',
- isLeaf: 'tree_is_leaf',
- fullPath: 'tree_full_path',
- rootId: -1,
- calcFields: ['cur_tp', 'pre_tp', 'end_tp'],
- keys: ['id', 'detail_id', 'tree_id'],
- };
- this.tree = createNewPathTree('ledger', this.treeSetting);
- this.spreadSetting = {
- cols: [
- {title: '编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 230, formatter: '@', cellType: 'tree'},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
- {title: '规格', colSpan: '1', rowSpan: '2', field: 'spec', hAlign: 0, width: 150, formatter: '@'},
- {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'unit'},
- {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
- {title: '本期|数量', colSpan: '2|1', rowSpan: '1|1', field: 'cur_qty', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'cur_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
- {title: '截止本期|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_qty', hAlign: 2, width: 60, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},
- {title: '发票号', colSpan: '1', rowSpan: '2', field: 'invoice_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
- ],
- emptyRows: 3,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: readOnly,
- };
- this.ckBillsSpread = window.location.pathname + '-billsSelect';
- this.initSpread();
- this.initOtherEvent();
- }
- initSpread() {
- SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
- this.spread.bind(spreadNS.Events.SelectionChanged, this.selectionChanged);
- this.spread.bind(spreadNS.Events.topRowChanged, this.topRowChanged);
- this.spread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
- const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
- SpreadJsObj.Clipboard.setCopyData(copyText);
- });
- if (readOnly) return;
- this.spread.bind(spreadNS.Events.EditEnded, this.editEnded);
- this.spread.bind(spreadNS.Events.EditStarting, this.editStarting);
- this.spread.bind(spreadNS.Events.ClipboardPasting, this.clipboardPasting);
- SpreadJsObj.addDeleteBind(this.spread, this.deletePress);
- }
- initOtherEvent() {
- const self = this;
- // 增删上下移升降级
- $('a[name="base-opr"]').click(function () {
- self.baseOpr(this.getAttribute('type'));
- });
- }
- refreshOperationValid() {
- const setObjEnable = function (obj, enable) {
- if (enable) {
- obj.removeClass('disabled');
- } else {
- obj.addClass('disabled');
- }
- };
- const invalidAll = function () {
- setObjEnable($('a[name=base-opr][type=add]'), false);
- setObjEnable($('a[name=base-opr][type=delete]'), false);
- setObjEnable($('a[name=base-opr][type=up-move]'), false);
- setObjEnable($('a[name=base-opr][type=down-move]'), false);
- setObjEnable($('a[name=base-opr][type=up-level]'), false);
- setObjEnable($('a[name=base-opr][type=down-level]'), false);
- };
- const sel = this.sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = this.sheet.zh_tree;
- if (!tree) {
- invalidAll();
- return;
- }
- const first = tree.nodes[row];
- if (!first) {
- invalidAll();
- return;
- }
- let last = first, sameParent = true, nodeUsed = this.checkNodeUsed(tree, first);
- if (sel.rowCount > 1 && first) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = tree.nodes[sel.row + r];
- if (!rNode) {
- sameParent = false;
- break;
- }
- nodeUsed = nodeUsed || this.checkNodeUsed(tree, rNode);
- if (rNode.tree_level > first.tree_level) continue;
- if ((rNode.tree_level < first.tree_level) || (rNode.tree_level === first.tree_level && rNode.tree_pid !== first.tree_pid)) {
- sameParent = false;
- break;
- }
- last = rNode;
- }
- }
- const preNode = tree.getPreSiblingNode(first);
- const valid = !this.sheet.zh_setting.readOnly;
- setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.tree_level > 1);
- setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.tree_level > 1 && !nodeUsed);
- setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.tree_level > 1 && preNode);
- setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.tree_level > 1 && !tree.isLastSibling(last));
- setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
- && first.tree_level > 2 && !tree.isLastSibling(last));
- setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
- && first.tree_level > 1 && preNode && !this.checkNodeUsed(tree, preNode));
- }
- loadRelaData() {
- this.refreshOperationValid();
- SpreadJsObj.saveTopAndSelect(this.sheet, this.ckBillsSpread);
- }
- refreshTree(data) {
- const sheet = this.sheet;
- SpreadJsObj.massOperationSheet(sheet, function () {
- const tree = sheet.zh_tree;
- // 处理删除
- if (data.delete) {
- data.delete.sort(function (a, b) {
- return b.deleteIndex - a.deleteIndex;
- });
- for (const d of data.delete) {
- sheet.deleteRows(d.deleteIndex, 1);
- }
- }
- // 处理新增
- if (data.create) {
- const newNodes = data.create;
- if (newNodes) {
- newNodes.sort(function (a, b) {
- return a.index - b.index;
- });
- for (const node of newNodes) {
- sheet.addRows(node.index, 1);
- SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
- }
- }
- }
- // 处理更新
- if (data.update) {
- const rows = [];
- for (const u of data.update) {
- rows.push(tree.nodes.indexOf(u));
- }
- SpreadJsObj.reLoadRowsData(sheet, rows);
- }
- // 处理展开
- if (data.expand) {
- const expanded = [];
- for (const e of data.expand) {
- if (expanded.indexOf(e) === -1) {
- const posterity = tree.getPosterity(e);
- for (const p of posterity) {
- sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
- expanded.push(p);
- }
- }
- }
- }
- });
- }
- loadData(datas) {
- this.tree.loadDatas(datas);
- treeCalc.calculateAll(this.tree);
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Tree, this.tree);
- SpreadJsObj.loadTopAndSelect(this.sheet, this.ckBillsSpread);
- this.refreshOperationValid();
- }
- getDefaultSelectInfo() {
- if (!this.tree) return;
- const sel = this.sheet.getSelections()[0];
- const node = this.sheet.zh_tree.nodes[sel.row];
- if (!node) return;
- let count = 1;
- if (sel.rowCount > 1) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = sheet.zh_tree.nodes[sel.row + r];
- if (rNode.tree_level > node.tree_level) continue;
- if ((rNode.tree_level < node.tree_level) || (rNode.tree_level === node.tree_level && rNode.tree_pid !== node.tree_pid)) {
- toastr.warning('请选择同一节点下的节点,进行该操作');
- return;
- }
- count += 1;
- }
- }
- return [this.tree, node, count];
- }
- checkNodeUsed(tree, node) {
- // todo 检查节点是否已使用
- return false;
- }
- baseOpr(type, addCount = 1) {
- const self = this;
- const sheet = self.sheet;
- const sel = sheet.getSelections()[0];
- const [tree, node, count] = this.getDefaultSelectInfo();
- if (!tree || !node || !count) return;
- if (type === 'delete') {
- const parent = tree.getParent(node);
- const children = parent ? parent.children : tree.children;
- const index = children.indexOf(node);
- for (let i = 0; i < count; i++) {
- const child = children[i+index];
- if (this.checkNodeUsed(tree, child)) {
- toastr.warning('选中的节点已计量,不可删除');
- return;
- }
- }
- } else if (type === 'up-level') {
- const parent = tree.getParent(node);
- const children = parent ? parent.children : tree.children;
- const index = children.indexOf(node);
- for (let i = index; i < children.length; i++) {
- const child = children[index];
- if (this.checkNodeUsed(tree, child)) {
- if (i >= index + count) {
- toastr.warning('其后节点已计量,选中的节点不可升级');
- } else {
- toastr.warning('选中的节点已计量,不可升级');
- }
- return;
- }
- }
- } else if (type === 'down-level') {
- const parent = tree.getParent(node);
- const children = parent ? parent.children : tree.children;
- const index = children.indexOf(node);
- if (index > 0 && this.checkNodeUsed(tree, children[index-1])) {
- toastr.warning('其前节点已计量,选中的节点不可降级');
- return;
- }
- for (let i = index; i < count; i++) {
- const child = children[i+index];
- if (this.checkNodeUsed(tree, child)) {
- toastr.warning('选中的节点已计量,不可降级');
- return;
- }
- }
- }
- const updateData = {
- postType: type,
- postData: {
- id: node.tree_id,
- count: type === 'add' ? addCount : count,
- }
- };
- if (type === 'delete') {
- deleteAfterHint(function () {
- postData('update', updateData, function (result) {
- const refreshData = tree.loadPostData(result);
- self.refreshTree(refreshData);
- if (sel) {
- sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
- }
- self.refreshOperationValid();
- });
- });
- } else {
- postData('update', updateData, function (result) {
- const refreshData = tree.loadPostData(result);
- self.refreshTree(refreshData);
- if (['up-move', 'down-move'].indexOf(type) > -1) {
- if (sel) {
- sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
- // SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
- }
- } else if (type === 'add') {
- const sel = sheet.getSelections()[0];
- if (sel) {
- sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
- // SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
- }
- }
- self.refreshOperationValid();
- });
- }
- }
- // 事件
- selectionChanged(e, info) {
- if (info.newSelections) {
- if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row) {
- billsObj.loadRelaData();
- }
- }
- }
- topRowChanged(e, info) {
- SpreadJsObj.saveTopAndSelect(info.sheet, billsObj.ckBillsSpread);
- }
- editEnded(e, info) {
- if (!info.sheet.zh_setting) return;
- const tree = info.sheet.zh_tree;
- const node = SpreadJsObj.getSelectObject(info.sheet);
- const data = { id: node.id, detail_id: node.detail_id, tree_id: node.tree_id };
- // 未改变值则不提交
- const col = info.sheet.zh_setting.cols[info.col];
- const orgValue = node[col.field];
- const newValue = trimInvalidChar(info.editingText);
- if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) return;
- if (info.editingText) {
- const text = newValue;
- if (billsObj.checkNodeUsed(tree, node) && col.field ==='b_code' && orgValue !== '' && text === '') {
- toastr.error('节点已计量,请勿删除编号');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (col.type === 'Number') {
- const num = _.toNumber(text);
- if (_.isFinite(num)) {
- data[col.field] = num;
- } else {
- try {
- data[col.field] = math.evaluate(transExpr(text));
- } catch(err) {
- toastr.error('输入的表达式非法');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- } else {
- data[col.field] = text;
- }
- } else {
- if (billsObj.checkNodeUsed(tree, node) && (col.field ==='b_code') && orgValue !== '') {
- toastr.error('节点已计量,请勿删除编号');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- data[col.field] = col.type === 'Number' ? 0 : '';
- }
- // 更新至服务器
- postData('update', {postType: 'update', postData: data}, function (result) {
- const refreshNode = billsObj.tree.loadPostData(result);
- billsObj.refreshTree(refreshNode);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
- });
- }
- editStarting(e, info) {
- if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
- const tree = info.sheet.zh_tree;
- const col = info.sheet.zh_setting.cols[info.col];
- const node = info.sheet.zh_tree.nodes[info.row];
- if (!node) {
- info.cancel = true;
- return;
- }
- switch (col.field) {
- case 'b_code':
- info.cancel = readOnly || billsObj.checkNodeUsed(tree, node);
- break;
- case 'unit_price':
- info.cancel = readOnly || (node.children && node.children.length > 0) || billsObj.checkNodeUsed(tree, node);
- break;
- case 'cur_qty':
- case 'cur_tp':
- info.cancel = (node.children && node.children.length > 0);
- break;
- }
- }
- deletePress (sheet) {
- if (!sheet.zh_setting) return;
- const sel = sheet.getSelections()[0], datas = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- let bDel = false;
- const node = sheet.zh_tree.nodes[iRow];
- const data = sheet.zh_tree.getNodeKeyData(node);
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const col = sheet.zh_setting.cols[iCol];
- const style = sheet.getStyle(iRow, iCol);
- if (style.locked) continue;
- if (col.field === 'b_code' && sheet.zh_tree.checkNodeUsed(node, pos)) {
- toastr.warning(`"${node.b_code || ''} ${node.name}"已计量,请勿修改`);
- return;
- }
- data[col.field] = col.type === 'Number' ? 0 : '';
- bDel = true;
- }
- if (bDel) datas.push(data);
- }
- if (datas.length > 0) {
- postData('update', {postType: 'update', postData: datas}, function (result) {
- const refreshNode = sheet.zh_tree.loadPostData(result);
- billsObj.refreshTree(refreshNode);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, sel.row, sel.rowCount);
- });
- }
- }
- clipboardPasting(e, info) {
- info.cancel = true;
- const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
- if (!setting || !tree) return;
- const pasteData = info.pasteData.html
- ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
- : (info.pasteData.text === ''
- ? SpreadJsObj.Clipboard.getAnalysisPasteText()
- : SpreadJsObj.analysisPasteText(info.pasteData.text));
- const hint = {
- usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
- usedCode: {type: 'warning', msg: '节点已计量,编号不可修改'},
- invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
- parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
- };
- const datas = [], filterNodes = [];
- let level, filterRow = 0;
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
- const curRow = info.cellRange.row + iRow;
- const node = tree.nodes[curRow];
- if (!node) continue;
- if (!level) level = node.level;
- if (node.level < level) break;
- let bPaste = false;
- const data = info.sheet.zh_tree.getNodeKeyData(node);
- for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
- const curCol = info.cellRange.col + iCol;
- const colSetting = info.sheet.zh_setting.cols[curCol];
- const value = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
- if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
- toastMessageUniq(hint.parent);
- continue;
- }
- if (billsObj.checkNodeUsed(tree, node) && colSetting.field === 'unit_price') {
- toastMessageUniq (hint.usedUp);
- continue;
- }
- if (colSetting.type === 'Number') {
- const num = _.toNumber(value);
- if (num) {
- data[colSetting.field] = num;
- } else {
- try {
- data[colSetting.field] = math.evaluate(transExpr(value));
- bPaste = true;
- } catch (err) {
- toastMessageUniq(hint.invalidExpr);
- continue;
- }
- }
- } else {
- if (node.used && (colSetting.field ==='b_code') && data[colSetting.field] !== '' && value === '') {
- toastMessageUniq(hint.usedCode);
- continue;
- }
- data[colSetting.field] = value;
- }
- bPaste = true;
- }
- if (bPaste) {
- datas.push(data);
- } else {
- filterNodes.push(node);
- }
- }
- if (datas.length > 0) {
- postData('update', {postType: 'update', postData: datas}, function (result) {
- const refreshNode = tree.loadPostData(result);
- if (refreshNode.update) refreshNode.update = refreshNode.update.concat(filterNodes);
- billsObj.refreshTree(refreshNode);
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- });
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- }
- }
- }
- const billsObj = new BillsObj();
- // 清单右键菜单
- const billsContextMenuOptions = {
- selector: '#bills-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
- billsObj.loadRelaData();
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {}
- };
- if (!readOnly) {
- billsContextMenuOptions.items.create = {
- name: '新增',
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- billsObj.baseOpr('add');
- },
- disabled: function (key, opt) {
- const sheet = billsObj.sheet;
- const selection = sheet.getSelections();
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = sheet.zh_tree;
- if (!tree) return true;
- const first = sheet.zh_tree.nodes[row];
- const valid = !sheet.zh_setting.readOnly;
- return !(valid && first && first.tree_level > 1);
- }
- };
- billsContextMenuOptions.items.delete = {
- name: '删除',
- icon: 'fa-remove',
- callback: function (key, opt) {
- billsObj.baseOpr('delete');
- },
- disabled: function (key, opt) {
- const sheet = billsObj.sheet;
- const selection = sheet.getSelections();
- const sel = selection ? selection[0] : sheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = sheet.zh_tree;
- if (!tree) return true;
- const first = sheet.zh_tree.nodes[row];
- let last = first, sameParent = true, nodeUsed = billsObj.checkNodeUsed(tree, first);
- if (sel.rowCount > 1 && first) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = tree.nodes[sel.row + r];
- if (!rNode) {
- sameParent = false;
- break;
- }
- nodeUsed = nodeUsed || billsObj.checkNodeUsed(tree, rNode);
- if (rNode.tree_level > first.tree_level) continue;
- if ((rNode.tree_level < first.tree_level) || (rNode.tree_level === first.tree_level && rNode.tree_pid !== first.tree_pid)) {
- sameParent = false;
- break;
- }
- last = rNode;
- }
- }
- const valid = !sheet.zh_setting.readOnly;
- return !(valid && first && sameParent && !(first.tree_level === 1) && !nodeUsed);
- }
- };
- }
- // 加载安全生产费数据
- postData('load', { filter: 'bills' }, function(result) {
- billsObj.loadData(result.bills);
- });
- const stdGclSetting = {
- selector: '#std-gcl',
- stdType: 'gcl',
- libs: stdBills,
- treeSetting: {
- id: 'bill_id',
- pid: 'pid',
- order: 'order',
- level: 'level',
- isLeaf: 'is_leaf',
- fullPath: 'full_path',
- rootId: -1,
- keys: ['id', 'list_id', 'bill_id']
- },
- spreadSetting: {
- cols: [
- {title: '清单编号', field: 'b_code', hAlign: 0, width: 170, formatter: '@', cellType: 'tree'},
- {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
- {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'}
- ],
- treeCol: 0,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- headColWidth: [30],
- selectedBackColor: '#fffacd',
- readOnly: true,
- },
- page: 'paymentSafe',
- tid: getTenderId(),
- cellDoubleClick: function (e, info) {
- const stdSheet = info.sheet;
- const stdTree = stdSheet.zh_tree;
- const stdNode = stdTree.nodes[info.row];
- if (!stdNode || !stdNode.b_code) return;
- const mainSheet = billsObj.sheet;
- if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) return;
- const mainTree = mainSheet.zh_tree;
- const nodes = [stdNode, ...stdTree.getAllParents(stdNode)];
- nodes.sort((a, b) => { return a.level - b.level; });
- const stdData = [];
- let mainChildren = mainTree.children, mainCur, checkNode;
- for (const sd of nodes) {
- const field = sd.b_code ? 'b_code' : 'name';
- checkNode = mainChildren.find(x => { return x[field] === sd[field]; });
- if (!checkNode) {
- stdData.push({ b_code: sd.b_code, name: sd.name, unit: sd.unit });
- } else {
- mainCur = checkNode;
- mainChildren = mainCur ? mainCur.children : [];
- }
- }
- postData('update', { postType: 'add-std',
- postData: {
- id: mainCur ? mainCur.tree_id : mainTree.setting.rootId,
- stdData
- }
- }, function (result) {
- const refreshNode = mainTree.loadPostData(result);
- billsObj.refreshTree(refreshNode);
- const node = _.find(billsObj.tree.nodes, { code: stdNode.code, name: stdNode.name });
- if (node) {
- mainSheet.setSelection(billsObj.tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
- SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, billsObj.tree.nodes.indexOf(node)]);
- }
- billsObj.refreshOperationValid;
- billsObj.spread.focus();
- });
- },
- };
- // 展开收起标准清单
- $('a', '#side-menu').bind('click', function (e) {
- e.preventDefault();
- const tab = $(this), tabPanel = $(tab.attr('content'));
- // 展开工具栏、切换标签
- if (!tab.hasClass('active')) {
- // const close = $('.active', '#side-menu').length === 0;
- $('a', '#side-menu').removeClass('active');
- $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
- tab.addClass('active');
- tabPanel.addClass('active');
- // $('.tab-content .tab-pane').removeClass('active');
- showSideTools(tab.hasClass('active'));
- if (tab.attr('content') === '#std-gcl') {
- if (!stdGcl) stdGcl = $.stdLib(stdGclSetting);
- stdGcl.spread.refresh();
- } else if (tab.attr('content') === '#fujian') {
- // todo 附件
- }
- } else { // 收起工具栏
- tab.removeClass('active');
- tabPanel.removeClass('active');
- showSideTools(tab.hasClass('active'));
- }
- billsObj.spread.refresh();
- });
- // 工具栏spr
- $.divResizer({
- select: '#revise-right-spr',
- callback: function () {
- billsObj.spread.refresh();
- if (stdGcl) stdGcl.spread.refresh();
- }
- });
- // 导航Menu
- $.subMenu({
- menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
- toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
- key: 'menu.1.0.0',
- miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
- callback: function (info) {
- if (info.mini) {
- $('.panel-title').addClass('fluid');
- $('#sub-menu').removeClass('panel-sidebar');
- } else {
- $('.panel-title').removeClass('fluid');
- $('#sub-menu').addClass('panel-sidebar');
- }
- autoFlashHeight();
- billsObj.spread.refresh();
- if (stdGcl) stdGcl.spread.refresh();
- }
- });
- // 显示层次
- (function (select, sheet) {
- $(select).click(function () {
- if (!sheet.zh_tree) return;
- const tag = $(this).attr('tag');
- const tree = sheet.zh_tree;
- setTimeout(() => {
- showWaitingView();
- switch (tag) {
- case "1":
- case "2":
- case "3":
- case "4":
- tree.expandByLevel(parseInt(tag));
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "last":
- tree.expandByCustom(() => { return true; });
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- }
- closeWaitingView();
- }, 100);
- });
- })('a[name=showLevel]', billsObj.sheet);
- });
|