12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004 |
- 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: '@', cellType: 'autoTip'},
- {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: 80, type: 'Number'},
- {title: '本期|数量', colSpan: '2|1', rowSpan: '1|1', field: 'cur_qty', hAlign: 2, width: 80, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'cur_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true},
- {title: '截止本期|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_qty', hAlign: 2, width: 80, type: 'Number'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true},
- {title: '发票号', colSpan: '1', rowSpan: '2', field: 'invoice_code', hAlign: 0, width: 100, formatter: '@'},
- {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 120, formatter: '@', cellType: 'ellipsisAutoTip'},
- ],
- emptyRows: 3,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: readOnly,
- localCache: {
- key: 'payment-safe-bills',
- colWidth: true,
- },
- };
- 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);
- 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);
- attObj.setSafeBills();
- }
- 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_qty || node.pre_tp) return true;
- const posterity = tree.getPosterity(node);
- for (const p of posterity) {
- if (p.pre_qty || p.pre_tp) return true;
- }
- 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);
- 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);
- }
- };
- }
- class AttObj {
- constructor() {
- this.atts = [];
- this.billsIndexes = {};
- this.pageCount = 15;
- this.activeTab = 'cur';
- this.curPageIndex = 1;
- this.curTotalPage = 1;
- this.allPageIndex = 1;
- this.allTotalPage = 1;
- }
- refreshShowPage() {
- const prefix = this.activeTab;
- $('#totalPage').html(this[prefix + 'TotalPage']);
- $('#currentPage').html(this[prefix + 'PageIndex']);
- if (this[prefix + 'TotalPage'] > 1) {
- $('#showPage').show();
- } else {
- $('#showPage').hide();
- }
- }
- reCalcPage() {
- this.allTotalPage = Math.ceil(this.atts.length / this.pageCount);
- const curNode = SpreadJsObj.getSelectObject(billsObj.sheet);
- const curAttIndex = curNode ? this.billsIndexes[curNode.safe_id] || [] : [];
- this.curTotalPage = Math.ceil(curAttIndex.length / this.pageCount);
- this.refreshShowPage();
- }
- loadDatas(datas) {
- for (const d of datas) {
- this.atts.push(d);
- if (!this.billsIndexes[d.safe_id]) {
- this.billsIndexes[d.safe_id] = [];
- }
- this.billsIndexes[d.safe_id].push(d);
- }
- this.refreshTable();
- }
- loadUpdateAtt(files) {
- for (const d of files) {
- this.atts.unshift(d);
- if (!this.billsIndexes[d.safe_id]) {
- this.billsIndexes[d.safe_id] = [];
- }
- this.billsIndexes[d.safe_id].unshift(d);
- }
- }
- loadDeleteAtt(file) {
- let fileIndex = this.atts.findIndex(x => { return x.id === file.id; });
- this.atts.splice(fileIndex, 1);
- if (this.billsIndexes[file.safe_id]) {
- fileIndex = this.billsIndexes[file.safe_id].findIndex(x => { return x.id === file.id; });
- this.billsIndexes[file.safe_id].splice(fileIndex, 1);
- }
- }
- getFileHtml(file) {
- const html = [];
- const downHtml = `<a href="javascript: void(0);" onclick="AliOss.downloadFile('${file.filepath}', '${file.filename + file.fileext}')" class="mr-1"><i class="fa fa-download fa-fw"></i></a>`;
- const delHtml = file.uid === userID ? `<a href="javascript: void(0);" class="mr-1 text-danger" name="del-file" file_id="${file.id}"><i class="fa fa-trash-o fa-fw"></i></a>` : '';
- const locateHtml = `<a href="javascript: void(0);" name="locate-bills" file_id="${file.id}" class="mr-1"><i data-toggle="tooltip" data-placement="left" data-original-title="定位" class="fa fa-crosshairs"></i></a>`;
- html.push('<tr>');
- html.push(`<td><input type="checkbox" name="check-att" file_id="${file.id}"></td>`);
- html.push(`<td><div class="d-flex justify-content-between align-items-center table-file"><a href="javascript: void(0);" file_id="${file.id}" name="view-file">${file.filename}${file.fileext}</a><div class="btn-group-table" style="display: none;">${locateHtml}${downHtml}${delHtml}</div></div></td>`);
- html.push(`<td>${file.u_name}</td>`);
- html.push('</tr>');
- return html.join('');
- }
- refreshCurTable() {
- const curNode = SpreadJsObj.getSelectObject(billsObj.sheet);
- const html = [];
- if (curNode) {
- const attIndex = this.billsIndexes[curNode.safe_id] || [];
- const beginIndex = (this.curPageIndex - 1) * this.pageCount;
- const endIndex = (this.curPageIndex) * this.pageCount - 1;
- for (const [i, ai] of attIndex.entries()) {
- if (i < beginIndex) continue;
- if (i > endIndex) continue;
- html.push(this.getFileHtml(ai));
- }
- }
- $('#cur-att-list').html(html.join(''));
- }
- refreshAllTable() {
- const html = [];
- const attIndex = this.atts;
- const beginIndex = (this.allPageIndex - 1) * this.pageCount;
- const endIndex = (this.allPageIndex) * this.pageCount - 1;
- for (const [i, ai] of attIndex.entries()) {
- if (i < beginIndex) continue;
- if (i > endIndex) continue;
- html.push(this.getFileHtml(ai));
- }
- $('#all-att-list').html(html.join(''));
- }
- prePage(){
- const pageIndex = this.activeTab + 'PageIndex';
- if (this[pageIndex] <= 1) return;
- this[pageIndex] = this[pageIndex] - 1;
- this.refreshShowTable();
- this.refreshShowPage();
- }
- nextPage() {
- const pageIndex = this.activeTab + 'PageIndex';
- if (this[pageIndex] >= this[this.activeTab + 'TotalPage']) return;
- this[pageIndex] = this[pageIndex] + 1;
- this.refreshShowTable();
- this.refreshShowPage();
- }
- refreshTable() {
- this.reCalcPage();
- this.refreshCurTable();
- this.refreshAllTable();
- }
- refreshShowTable() {
- if (this.activeTab === 'cur') {
- this.refreshCurTable();
- } else {
- this.refreshAllTable();
- }
- }
- batchDownload() {
- const checkes = $('[name=check-att]:checked');
- if (checkes.length === 0) {
- toastr.warning('请选择需要批量下载的文件');
- return;
- }
- const files = [], fileIds = [];
- for (const c of checkes) {
- const file = this.atts.find(x => { return x.id === parseInt(c.getAttribute('file_id'))});
- if (file && fileIds.indexOf(file.id) < 0) {
- fileIds.push(file.id);
- files.push({ filename: file.filename, fileext: file.fileext, filepath: c.viewpath || file.filepath});
- }
- }
- AliOss.zipFiles(files, '安全生产费-附件.zip', (fails) => {
- $(self).removeAttr('disabled');
- if (fails.length === 0) {
- toastr.success('下载成功');
- } else {
- toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
- }
- }, () => {
- $(self).removeAttr('disabled');
- toastr.error('批量下载失败');
- });
- }
- uploadAtt(files, callback) {
- const curNode = SpreadJsObj.getSelectObject(billsObj.sheet);
- const formData = new FormData();
- if (curNode) formData.append('safe_id', curNode.safe_id);
- for (const file of files) {
- if (file === undefined) {
- toastr.error('未选择上传文件。');
- return false;
- }
- if (file.size > 30 * 1024 * 1024) {
- toastr.error('上传文件大小超过30MB。');
- return false;
- }
- const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
- if (whiteList.indexOf(fileext) === -1) {
- toastr.error('仅支持office文档、图片、压缩包格式,请勿上传' + fileext + '格式文件。');
- return false;
- }
- formData.append('size', file.size);
- formData.append('file[]', file);
- }
- postDataWithFile('file/upload', formData, function (files) {
- attObj.loadUpdateAtt(files);
- attObj.refreshTable();
- if (callback) callback();
- });
- }
- deleteAtt(file_id) {
- const file = this.atts.find(x => { return x.id === file_id; });
- if (!file) return;
- postData('file/delete', {id: file_id}, function() {
- attObj.loadDeleteAtt(file);
- attObj.refreshTable();
- })
- }
- locateBills(file_id) {
- const file = this.atts.find(x => { return x.id === file_id; });
- if (!file || !file.safe_id) return;
- const safeBills = billsObj.tree.nodes.find(x => { return x.safe_id === file.safe_id; });
- SpreadJsObj.locateTreeNode(billsObj.sheet, safeBills.tree_id, true);
- this.refreshCurTable();
- }
- setTab(tab) {
- this.activeTab = tab;
- this.refreshShowPage();
- }
- setSafeBills() {
- this.curPageIndex = 1;
- this.reCalcPage();
- this.refreshCurTable();
- }
- }
- const attObj = new AttObj();
- $('#upload-ok').click(function() {
- const input = $('#upload-file');
- attObj.uploadAtt(input[0].files, function() {
- $(input).val('');
- $('#upload').modal('hide');
- });
- });
- $('#batch-download-att').click(() => {
- attObj.batchDownload();
- });
- $('body').on('mouseenter', ".table-file", function(){
- $(this).children(".btn-group-table").css("display","block");
- });
- $('body').on('mouseleave', ".table-file", function(){
- $(this).children(".btn-group-table").css("display","none");
- });
- $('body').on('click', '[name=del-file]', function() {
- attObj.deleteAtt(parseInt(this.getAttribute('file_id')));
- });
- $('body').on('click', 'a[name=view-file]', function() {
- const file_id = parseInt(this.getAttribute('file_id'));
- const file = attObj.atts.find(x => { return x.id === file_id; });
- if (!file) return;
- if (file.viewpath) {
- window.open(file.viewpath, '_blank');
- } else {
- AliOss.downloadFile(file.filepath, `${file.filename}${file.fileext}`)
- }
- });
- $('body').on('click', 'a[name=locate-bills]', function() {
- attObj.locateBills(parseInt(this.getAttribute('file_id')));
- });
- $('.page-select').click(function() {
- const content = this.getAttribute('content');
- if (content === 'pre') {
- attObj.prePage();
- } else if (content === 'next') {
- attObj.nextPage();
- }
- });
- $('[fujian-content]').click(function() {
- const content = this.getAttribute('fujian-content');
- attObj.setTab(content.replace('-att', ''));
- });
- $('.check-all-file').change(function() {
- const checked = this.checked;
- const table = $(this).parent().parent().parent().parent();
- const checkes = $('[name=check-att]', table);
- checkes.each(function(){
- this.checked = checked;
- })
- });
- // 加载安全生产费数据
- postData('load', { filter: 'bills;att' }, function(result) {
- billsObj.loadData(result.bills);
- attObj.loadDatas(result.att);
- });
- 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 sel = mainSheet.getSelections()[0];
- 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 : [];
- }
- }
- if (stdData.length > 0) {
- 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, { b_code: stdNode.b_code, name: stdNode.name });
- if (node) {
- mainSheet.setSelection(billsObj.tree.nodes.indexOf(node), sel.col, 1, sel.colCount);
- SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, billsObj.tree.nodes.indexOf(node)]);
- }
- billsObj.refreshOperationValid();
- billsObj.spread.focus();
- });
- } else {
- const node = _.find(billsObj.tree.nodes, { b_code: stdNode.b_code, name: stdNode.name });
- mainSheet.setSelection(billsObj.tree.nodes.indexOf(node), sel.col, 1, sel.colCount);
- 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 { // 收起工具栏
- tab.removeClass('active');
- tabPanel.removeClass('active');
- showSideTools(tab.hasClass('active'));
- }
- billsObj.spread.refresh();
- });
- // 工具栏spr
- $.divResizer({
- select: '#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);
- });
|