|
|
@@ -0,0 +1,782 @@
|
|
|
+function getTenderId() {
|
|
|
+ return window.location.pathname.split('/')[2];
|
|
|
+}
|
|
|
+const invalidFields = {
|
|
|
+ parent: ['cur_qty', 'cur_tp', 'unit_price'],
|
|
|
+};
|
|
|
+function transExpr(expr) {
|
|
|
+ return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
|
|
|
+}
|
|
|
+
|
|
|
+$(document).ready(function() {
|
|
|
+ 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', 'stage_id', 'tree_id'],
|
|
|
+ };
|
|
|
+ this.tree = createNewPathTree('ledger', this.treeSetting);
|
|
|
+ this.spreadSetting = {
|
|
|
+ cols: [
|
|
|
+ {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 230, formatter: '@', cellType: 'tree', readOnly: true},
|
|
|
+ {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 185, formatter: '@', cellType: 'autoTip', readOnly: true},
|
|
|
+ {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'unit', readOnly: true},
|
|
|
+ {title: '税率(%)', colSpan: '1', rowSpan: '1', field: 'tax', hAlign: 2, width: 80, type: 'Number', readOnly: true},
|
|
|
+ {title: '入账金额', colSpan: '1', rowSpan: '1', field: 'in_tp', hAlign: 2, width: 80, type: 'Number'},
|
|
|
+ {title: '入账金额(不含税)', colSpan: '1', rowSpan: '1', field: 'in_excl_tax_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
|
|
|
+ {title: '本期批注', colSpan: '1', rowSpan: '1', field: 'postil', hAlign: 0, width: 100, formatter: '@'},
|
|
|
+ {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 120, formatter: '@', cellType: 'ellipsisAutoTip'},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [32],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ readOnly: readOnly,
|
|
|
+ localCache: {
|
|
|
+ key: 'cost_book',
|
|
|
+ colWidth: true,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.phasePay);
|
|
|
+
|
|
|
+ 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;
|
|
|
+ $('#bills-spread').focusin(this.focusIn);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && !nodeUsed);
|
|
|
+ setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && preNode);
|
|
|
+ setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && !tree.isLastSibling(last));
|
|
|
+ setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed && first.tree_level > 1);
|
|
|
+ setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent && preNode && !this.checkNodeUsed(tree, preNode));
|
|
|
+ }
|
|
|
+ loadRelaData(loadAtt = true) {
|
|
|
+ this.refreshOperationValid();
|
|
|
+ SpreadJsObj.saveTopAndSelect(this.sheet, this.ckBillsSpread);
|
|
|
+ const select = SpreadJsObj.getSelectObject(this.sheet);
|
|
|
+ detailObj.loadDetailData(select);
|
|
|
+ if (loadAtt) costFile.getCurAttHtml(select);
|
|
|
+ }
|
|
|
+ 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 = this.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) {
|
|
|
+ if (node.pre_pay_tp || node.pre_cut_tp || node.pre_yf_tp || node.pre_sf_tp) return true;
|
|
|
+ const posterity = tree.getPosterity(node);
|
|
|
+ for (const p of posterity) {
|
|
|
+ if (p.pre_pay_tp || p.pre_cut_tp || p.pre_yf_tp || p.pre_sf_tp) return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 事件
|
|
|
+ focusIn() {
|
|
|
+ const select = SpreadJsObj.getSelectObject(billsObj.sheet);
|
|
|
+ costFile.getCurAttHtml(select);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ 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 'in_tp':
|
|
|
+ info.cancel = (node.children && node.children.length > 0) || node.had_detail;
|
|
|
+ if (!info.cancel) {
|
|
|
+ const detailRange = detailObj.data.getPartData(node.id);
|
|
|
+ if (detailRange && detailRange.length > 0) info.cancel = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ editEnded(e, info) {
|
|
|
+ if (!info.sheet.zh_setting) return;
|
|
|
+
|
|
|
+ const node = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
+ const data = { book_id: node.book_id, ledger_id: node.id, cost_id: node.cost_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 (col.type === 'Number') {
|
|
|
+ const num = _.toNumber(text);
|
|
|
+ if (_.isFinite(num)) {
|
|
|
+ data[col.field] = num;
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ data[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
|
|
|
+ } catch(err) {
|
|
|
+ toastr.error('输入的表达式非法');
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ data[col.field] = text;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ data[col.field] = col.type === 'Number' ? 0 : '';
|
|
|
+ }
|
|
|
+ // 更新至服务器
|
|
|
+ postData('update', {target: 'ledger', update: data}, function (result) {
|
|
|
+ const refreshNode = billsObj.tree.loadPostData(result);
|
|
|
+ billsObj.refreshTree(refreshNode);
|
|
|
+ }, function () {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ 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 = { book_id: node.book_id, ledger_id: node.id, cost_id: node.cost_id };;
|
|
|
+ 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;
|
|
|
+
|
|
|
+ data[col.field] = col.type === 'Number' ? 0 : '';
|
|
|
+ bDel = true;
|
|
|
+ }
|
|
|
+ if (bDel) datas.push(data);
|
|
|
+ }
|
|
|
+ if (datas.length > 0) {
|
|
|
+ postData('update', {target: 'ledger', update: datas}, function (result) {
|
|
|
+ const refreshNode = sheet.zh_tree.loadPostData(result);
|
|
|
+ billsObj.refreshTree(refreshNode);
|
|
|
+ }, function () {
|
|
|
+ SpreadJsObj.reLoadRowData(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 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 = { book_id: node.book_id, ledger_id: node.id, cost_id: node.cost_id };
|
|
|
+ for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
|
|
|
+ const curCol = info.cellRange.col + iCol;
|
|
|
+ const colSetting = info.sheet.zh_setting.cols[curCol];
|
|
|
+ data[colSetting.field] = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
|
|
|
+ bPaste = true;
|
|
|
+ }
|
|
|
+ if (bPaste) {
|
|
|
+ datas.push(data);
|
|
|
+ } else {
|
|
|
+ filterNodes.push(node);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (datas.length > 0) {
|
|
|
+ postData('update', {target: 'ledger', update: 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();
|
|
|
+ class DetailObj {
|
|
|
+ constructor() {
|
|
|
+ this.spread = SpreadJsObj.createNewSpread($('#detail-spread')[0]);
|
|
|
+ this.sheet = this.spread.getActiveSheet();
|
|
|
+ this.data = createAncillaryGcl({ id: 'id', masterId: 'ledger_id', sort: [['d_order', 'asc']] });
|
|
|
+ this.dealSpreadSetting = {
|
|
|
+ cols: [
|
|
|
+ {title: '合同编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 160, formatter: '@', readOnly: true},
|
|
|
+ {title: '合同名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 160, formatter: '@', readOnly: true},
|
|
|
+ {title: '乙方', colSpan: '1', rowSpan: '1', field: 'party_b', hAlign: 0, width: 150, formatter: '@', readOnly: true},
|
|
|
+ {title: '合同金额', colSpan: '1', rowSpan: '1', field: 'deal_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true},
|
|
|
+ {title: '税率(%)', colSpan: '1', rowSpan: '1', field: 'tax', hAlign: 2, width: 80, type: 'Number', readOnly: true},
|
|
|
+ {title: '实付金额', colSpan: '1', rowSpan: '1', field: 'sf_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true},
|
|
|
+ {title: '入账金额', colSpan: '1', rowSpan: '1', field: 'in_tp', hAlign: 2, width: 80, type: 'Number'},
|
|
|
+ {title: '入账金额(不含税)', colSpan: '1', rowSpan: '1', field: 'in_excl_tax_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
|
|
|
+ {title: '本期批注', colSpan: '1', rowSpan: '1', field: 'postil', hAlign: 0, width: 100, formatter: '@'},
|
|
|
+ {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 120, formatter: '@', cellType: 'ellipsisAutoTip'},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [32],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ readOnly: readOnly,
|
|
|
+ localCache: {
|
|
|
+ key: 'cost_book_deal',
|
|
|
+ colWidth: true,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ this.commonSpreadSetting = {
|
|
|
+ cols: [
|
|
|
+ {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 160, formatter: '@', readOnly: true},
|
|
|
+ {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 160, formatter: '@', readOnly: true},
|
|
|
+ {title: '税率(%)', colSpan: '1', rowSpan: '1', field: 'tax', hAlign: 2, width: 80, type: 'Number', readOnly: true},
|
|
|
+ {title: '实付金额', colSpan: '1', rowSpan: '1', field: 'sf_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true},
|
|
|
+ {title: '入账金额', colSpan: '1', rowSpan: '1', field: 'in_tp', hAlign: 2, width: 80, type: 'Number'},
|
|
|
+ {title: '入账金额(不含税)', colSpan: '1', rowSpan: '1', field: 'in_excl_tax_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
|
|
|
+ {title: '本期批注', colSpan: '1', rowSpan: '1', field: 'postil', hAlign: 0, width: 100, formatter: '@'},
|
|
|
+ {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 120, formatter: '@', cellType: 'ellipsisAutoTip'},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [32],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ readOnly: readOnly,
|
|
|
+ localCache: {
|
|
|
+ key: 'cost_book_detail',
|
|
|
+ colWidth: true,
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ this.initSpread();
|
|
|
+ this.initOtherEvent();
|
|
|
+ }
|
|
|
+ initSpread() {
|
|
|
+ SpreadJsObj.initSheet(this.sheet, this.commonSpreadSetting);
|
|
|
+ this.spread.bind(spreadNS.Events.SelectionChanged, this.selectionChanged);
|
|
|
+ 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.ClipboardPasting, this.clipboardPasting);
|
|
|
+ SpreadJsObj.addDeleteBind(this.spread, this.deletePress);
|
|
|
+ }
|
|
|
+ initOtherEvent() {
|
|
|
+ const self = this;
|
|
|
+ $('#detail-spread').focusin(this.focusIn);
|
|
|
+ }
|
|
|
+ loadData(datas) {
|
|
|
+ this.data.loadDatas(datas);
|
|
|
+ this.loadDetailData(SpreadJsObj.getSelectObject(billsObj.sheet));
|
|
|
+ }
|
|
|
+ refreshSheet() {
|
|
|
+ if (this.sheet.zh_data.length === 0) {
|
|
|
+ this.reloadDetailData();
|
|
|
+ } else {
|
|
|
+ SpreadJsObj.reLoadSheetData(this.sheet);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reloadDetailData() {
|
|
|
+ const data = this.billsNode ? this.data.getPartData(this.billsNode.id) || [] : [];
|
|
|
+ SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, data);
|
|
|
+ }
|
|
|
+ loadDetailData(bills) {
|
|
|
+ detailObj.billsNode = bills;
|
|
|
+ const spreadSetting = bills && bills.is_deal ? this.dealSpreadSetting : this.commonSpreadSetting;
|
|
|
+ if (!bills || (bills.children && bills.children.length > 0)) {
|
|
|
+ spreadSetting.readOnly = true;
|
|
|
+ } else {
|
|
|
+ spreadSetting.readOnly = readOnly;
|
|
|
+ }
|
|
|
+ SpreadJsObj.initSheet(this.sheet, spreadSetting);
|
|
|
+ this.reloadDetailData();
|
|
|
+ }
|
|
|
+ loadRelaData() {
|
|
|
+ const select = SpreadJsObj.getSelectObject(this.sheet);
|
|
|
+ if (select) costFile.getCurAttHtml(this.billsNode, select);
|
|
|
+ }
|
|
|
+ // 事件
|
|
|
+ focusIn() {
|
|
|
+ detailObj.loadRelaData();
|
|
|
+ }
|
|
|
+ selectionChanged(e, info) {
|
|
|
+ if (info.newSelections) {
|
|
|
+ if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row) {
|
|
|
+ detailObj.loadRelaData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ editEnded(e, info) {
|
|
|
+ const setting = info.sheet.zh_setting;
|
|
|
+ if (!setting) return;
|
|
|
+ const detailData = SpreadJsObj.getSelectObject(info.sheet);
|
|
|
+
|
|
|
+ const col = setting.cols[info.col];
|
|
|
+ const orgText = detailData ? detailData[col.field] : '', newText = trimInvalidChar(info.editingText);
|
|
|
+ if (orgText === newText || (!orgText && !newText)) return;
|
|
|
+
|
|
|
+ const relaBills = detailObj.billsNode;
|
|
|
+ if (!relaBills) {
|
|
|
+ toastr.error('数据错误,请选择台账节点后再试');
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const data = { target: 'detail' };
|
|
|
+ if (detailData) {
|
|
|
+ const updateData = { book_id: detailData.book_id, detail_id: detailData.id };
|
|
|
+ if (col.type === 'Number') {
|
|
|
+ const num = _.toNumber(newText);
|
|
|
+ if (!_.isFinite(num)) {
|
|
|
+ toastr.error('输入的数字非法');
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ updateData[col.field] = num;
|
|
|
+ } else {
|
|
|
+ updateData[col.field] = newText;
|
|
|
+ }
|
|
|
+ data.update = [ updateData ];
|
|
|
+ }
|
|
|
+ // 更新至服务器
|
|
|
+ postData('update', data, function (result) {
|
|
|
+ detailObj.data.updateDatas(result.detail);
|
|
|
+ detailObj.refreshSheet();
|
|
|
+ result.ledger.tree_id = relaBills.tree_id;
|
|
|
+ const refreshNode = billsObj.tree.loadPostData({ update: result.ledger });
|
|
|
+ billsObj.refreshTree(refreshNode);
|
|
|
+ }, function () {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ 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 = { book_id: node.book_id, detail_id: node.id };
|
|
|
+ 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;
|
|
|
+
|
|
|
+ data[col.field] = col.type === 'Number' ? 0 : '';
|
|
|
+ bDel = true;
|
|
|
+ }
|
|
|
+ if (bDel) datas.push(data);
|
|
|
+ }
|
|
|
+ if (datas.length > 0) {
|
|
|
+ postData('update', {target: 'detail', update: 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 pasteData = info.pasteData.html
|
|
|
+ ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
|
|
|
+ : (info.pasteData.text === ''
|
|
|
+ ? SpreadJsObj.Clipboard.getAnalysisPasteText()
|
|
|
+ : SpreadJsObj.analysisPasteText(info.pasteData.text));
|
|
|
+ const hint = {
|
|
|
+ invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
|
|
|
+ };
|
|
|
+ const datas = [], filterNodes = [];
|
|
|
+
|
|
|
+ // todo
|
|
|
+ let 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;
|
|
|
+
|
|
|
+ let bPaste = false;
|
|
|
+ const data = { book_id: node.book_id, detail_id: node.id };
|
|
|
+ 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 (colSetting.type === 'Number') {
|
|
|
+ const num = _.toNumber(value);
|
|
|
+ if (num) {
|
|
|
+ data[colSetting.field] = num;
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
|
|
|
+ bPaste = true;
|
|
|
+ } catch (err) {
|
|
|
+ toastMessageUniq(hint.invalidExpr);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ data[colSetting.field] = value;
|
|
|
+ }
|
|
|
+ bPaste = true;
|
|
|
+ }
|
|
|
+ if (bPaste) {
|
|
|
+ datas.push(data);
|
|
|
+ } else {
|
|
|
+ filterNodes.push(node);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (datas.length > 0) {
|
|
|
+ postData('update', {target: 'detail', update: datas}, function (result) {
|
|
|
+ detailObj.data.updateDatas(result.detail);
|
|
|
+ detailObj.refreshSheet();
|
|
|
+ }, function () {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const detailObj = new DetailObj();
|
|
|
+
|
|
|
+ const costFile = $.ledger_att({
|
|
|
+ selector: '#fujian',
|
|
|
+ key: 'id',
|
|
|
+ subKey: 'id',
|
|
|
+ masterKey: 'rela_id',
|
|
|
+ subMasterKey: 'rela_sub_id',
|
|
|
+ uploadUrl: 'file/upload',
|
|
|
+ deleteUrl: 'file/delete',
|
|
|
+ checked: false,
|
|
|
+ zipName: `附件.zip`,
|
|
|
+ readOnly: false,
|
|
|
+ fileIdType: 'string',
|
|
|
+ fileInfo: {
|
|
|
+ user_name: 'user_name',
|
|
|
+ user_id: 'user_id',
|
|
|
+ create_time: 'create_time',
|
|
|
+ },
|
|
|
+ getCurHint: function(node) {
|
|
|
+ return`${node.name || ''}`;
|
|
|
+ },
|
|
|
+ locate: function (att) {
|
|
|
+ if (!att) return;
|
|
|
+ SpreadJsObj.locateTreeNode(billsObj.sheet, att.node.tree_id, true);
|
|
|
+ detailObj.loadDetailData(att.node);
|
|
|
+ if (att.sub_node) SpreadJsObj.locateDataBy(detailObj.sheet, n => { return n.id === att.sub_node.id; });
|
|
|
+ costFile.getCurAttHtml(att.node, att.sub_node);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const searchObj = $.ledgerSearch({
|
|
|
+ selector: '#search',
|
|
|
+ searchRangeStr: '编号/名称',
|
|
|
+ ledger: {
|
|
|
+ billsTree: billsObj.tree,
|
|
|
+ getLedgerPos: function(node) { return detailObj.data.getPartData(node.id); },
|
|
|
+ posId: 'id',
|
|
|
+ },
|
|
|
+ resultSpreadSetting: {
|
|
|
+ cols: [
|
|
|
+ {title: '编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
|
|
|
+ {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
|
|
|
+ {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
|
|
|
+ ],
|
|
|
+ emptyRows: 0,
|
|
|
+ headRows: 1,
|
|
|
+ headRowHeight: [32],
|
|
|
+ headColWidth: [30],
|
|
|
+ defaultRowHeight: 21,
|
|
|
+ headerFont: '12px 微软雅黑',
|
|
|
+ font: '12px 微软雅黑',
|
|
|
+ selectedBackColor: '#fffacd',
|
|
|
+ readOnly: true,
|
|
|
+ },
|
|
|
+ locate: function(cur) {
|
|
|
+ if (!cur.lid) return;
|
|
|
+
|
|
|
+ SpreadJsObj.locateTreeNode(billsObj.sheet, cur.lid, true);
|
|
|
+ billsObj.loadRelaData();
|
|
|
+ if (cur.pid) {
|
|
|
+ const pIndex = detailObj.sheet.zh_data.findIndex(x => { return x.id === cur.pid; });
|
|
|
+ SpreadJsObj.locateRow(detailObj.sheet, pIndex);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+ // 加载数据
|
|
|
+ postData('load', { filter: 'bills;detail;att' }, function(result) {
|
|
|
+ billsObj.loadData(result.bills);
|
|
|
+ detailObj.loadData(result.detail);
|
|
|
+
|
|
|
+ for (const f of result.att) {
|
|
|
+ f.node = billsObj.tree.datas.find(x => { return x.id === f.rela_id; });
|
|
|
+ f.sub_node = f.rela_sub_id ? detailObj.data.getItem(f.rela_sub_id) : null;
|
|
|
+ }
|
|
|
+ costFile.loadDatas(result.att);
|
|
|
+ costFile.getCurAttHtml(SpreadJsObj.getSelectObject(billsObj.sheet));
|
|
|
+ });
|
|
|
+
|
|
|
+ // 展开收起标准清单
|
|
|
+ $('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') === '#search') {
|
|
|
+ searchObj.spread.refresh();
|
|
|
+ }
|
|
|
+ } else { // 收起工具栏
|
|
|
+ tab.removeClass('active');
|
|
|
+ tabPanel.removeClass('active');
|
|
|
+ showSideTools(tab.hasClass('active'));
|
|
|
+ }
|
|
|
+ billsObj.spread.refresh();
|
|
|
+ detailObj.spread.refresh();
|
|
|
+ });
|
|
|
+
|
|
|
+ $.divResizer({
|
|
|
+ select: '#detail-spr',
|
|
|
+ callback: function () {
|
|
|
+ billsObj.spread.refresh();
|
|
|
+ detailObj.spread.refresh();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 工具栏spr
|
|
|
+ $.divResizer({
|
|
|
+ select: '#right-spr',
|
|
|
+ callback: function () {
|
|
|
+ billsObj.spread.refresh();
|
|
|
+ detailObj.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();
|
|
|
+ detailObj.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);
|
|
|
+});
|