123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263 |
- 'use strict';
- /**
- * 期计量 - 本期计量台账页面 js
- *
- * @author Mai
- * @date 2018/12/7
- * @version
- */
- function checkTzMeasureType () {
- return tender.measure_type === measureType.tz.value;
- }
- /**
- * 从cookie中读取缓存的列显示设置,没有则取默认
- * @returns {*[]}
- */
- function customColDisplay () {
- const defaultSetting = [
- { title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true },
- { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
- { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
- { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
- { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
- { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
- { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp'], visible: true },
- { title: '图册号', fields: ['drawing_code'], visible: true },
- { title: '累计完成率(%)', fields: ['percent'], visible: true },
- { title: '备注', fields: ['memo'], visible: true },
- ];
- const settingStr = Cookies.get('stage-col-visible-1.0.0');
- return settingStr ? JSON.parse(settingStr) : defaultSetting;
- }
- /**
- * 根据列显示设置,调整setting中的列是否显示
- * @param setting
- * @param customDisplay
- */
- function customizeStageTreeSetting(setting, customDisplay) {
- for (const cd of customDisplay) {
- for (const c of setting.cols) {
- if (cd.fields.indexOf(c.field) !== -1) {
- c.visible = cd.visible;
- }
- }
- }
- }
- /**
- * 初始化 树结构 列事件
- * @param setting
- */
- function initTreeColSettingEvents(setting) {
- const Events = {
- readOnly: {
- measureData: function (node) {
- return node.children && node.children.length > 0;
- },
- },
- };
- const getEvent = function (eventName) {
- const names = eventName.split('.');
- let event = Events;
- for (let name of names) {
- if (event[name]) {
- event = event[name];
- } else {
- return null;
- }
- }
- if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
- return null;
- } else {
- return event;
- }
- };
- for (const col of setting.cols) {
- if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
- col.readOnly = getEvent(col.readOnly);
- }
- }
- }
- function needCheckDetail() {
- stage.check_detail = true;
- $('#check_point').show();
- }
- // 生成所有附件列表
- function getAllList(currPageNum = 1) {
- // 每页最多几个附件
- const pageCount = 11;
- // 附件总数
- const total = attData.length;
- // 总页数
- const pageNum = Math.ceil(total/pageCount);
- $('#totalPage').text(pageNum);
- $('#currentPage').text(currPageNum);
- // 当前页附件内容
- const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
- let html = '';
- for(const att of currPageAttData) {
- html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
- }
- $('#alllist-table').html(html);
- }
- // 生成当前节点列表
- function getNodeList(node) {
- let html = '';
- for(const att of attData) {
- if (parseInt(node) === att.lid) {
- html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
- }
- }
- $('#nodelist-table').html(html);
- }
- $(document).ready(() => {
- // 界面布局
- autoFlashHeight();
- // 初始化 台账树结构 数据结构
- const stageTreeSetting = {
- id: 'ledger_id',
- pid: 'ledger_pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'tender_id', 'ledger_id'],
- stageId: 'id',
- };
- // 台账树结构计算相关设置
- stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'];
- stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
- 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp'];
- stageTreeSetting.calcFun = function (node) {
- if (node.children && node.children.length === 0) {
- node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
- node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
- node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
- node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
- node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
- }
- node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
- node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
- node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
- node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
- node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
- node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), tenderInfo.decimal.up);
- };
- const stageTree = createNewPathTree('stage', stageTreeSetting);
- // 初始化 部位明细 数据结构
- const stagePosSetting = {
- id: 'id', ledgerId: 'lid',
- updateFields: ['contract_qty', 'qc_qty', 'postil'],
- };
- stagePosSetting.calcFun = function (pos) {
- pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
- pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
- pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
- pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
- pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
- };
- const stagePos = new StagePosData(stagePosSetting);
- class Changes {
- constructor(obj) {
- const self = this;
- this.obj = obj;
- // 初始化 清单编号窗口 参数
- this.spreadSetting = {
- cols: [
- {title: '已用', field: '', width: 45, formatter: '@', cellType: 'image', readOnly: true, hAlign: 1, indent: 14, img: function (data) {
- if (data.uamount && !checkZero(data.uamount)) {
- return $('#icon-ok')[0];
- } else {
- return null;
- }
- }},
- {title: '变更令号', field: 'code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
- {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
- {title: '总数量', field: 'b_amount', width: 60, formatter: '@', readOnly: true, hAlign: 2, },
- {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, },
- {title: '本期计量', field: 'uamount', width: 60, formatter: '@', hAlign: 2, type: 'Number', },
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [40],
- getColor: function (data, col, defaultColor) {
- if (col.field === 'uamount') {
- if (!data.vamount) {
- return data.uamount ? '#ff6f5c' : defaultColor;
- } else if (data.uamount) {
- return data.uamount > data.vamount ? '#ff6f5c' : defaultColor;
- } else {
- return defaultColor;
- }
- } else {
- return defaultColor;
- }
- }
- };
- this.curChangeId = '';
- this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
- this.firstView = true;
- SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
- // 初次显示,需刷新spread界面,保证界面绘制正确
- this.obj.bind('shown.bs.modal', function () {
- if (self.firstView) {
- self.firstView = false;
- self.spread.refresh();
- }
- });
- // 切换变更令,加载右侧明细数据
- this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
- const change = SpreadJsObj.getSelectObject(info.sheet);
- self._loadChangeDetail(change);
- });
- // 填写本期计量
- this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
- if (info.sheet.zh_setting) {
- const col = info.sheet.zh_setting.cols[info.col];
- const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
- const node = sortData[info.row];
- node[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
- // 刷新界面
- SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
- }
- });
- this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
- if (info.sheet.zh_setting) {
- const sortData = SpreadJsObj.getSortData(info.sheet);
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- const curRow = iRow + info.cellRange.row;
- const curCol = info.cellRange.col;
- const col = info.sheet.zh_setting.cols[info.cellRange.col];
- sortData[curRow][col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
- }
- SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
- }
- });
- SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
- if (sheet.zh_setting) {
- const sel = sheet.getSelections()[0];
- const sortData = SpreadJsObj.getSortData(sheet);
- // 仅本期计量可删除
- if (sel.col === 5 || sel.colCount === 1) {
- const col = sheet.zh_setting.cols[sel.col];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- const data = sortData[iRow];
- data[col.field] = null;
- }
- SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
- }
- }
- });
- // 过滤可变更数量为0
- $('#filterEmpty').click(function () {
- self._filterChange(!this.checked, $('#matchPos')[0].checked);
- });
- // 匹配编号
- $('#matchPos').click(function () {
- self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
- });
- // 展开收起 变更令详细信息
- $('#show-bgl-detail').bind('click', function () {
- const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
- if (detail.hasClass('col-4')) {
- detail.attr('class', 'col').hide();
- bgl.attr('class', 'col-12');
- $('a', obj).attr('title', '展开侧栏');
- $('i', obj).attr('class', 'fa fa-chevron-left');
- self.spread.refresh();
- } else {
- detail.attr('class', 'col-4').show();
- bgl.attr('class', 'col-8');
- $('a', obj).attr('title', '收起侧栏');
- $('i', obj).attr('class', 'fa fa-chevron-right');
- self.spread.refresh();
- }
- });
- // 添加调用变更令
- $('#usg-bg-ok').click(function () {
- const data = { target: self.callData, change: [] };
- for (const c of self.changes) {
- if (c.uamount) {
- if (!c.vamount || checkZero(c.vamount)) {
- toast('变更令:' + c.code + ' 当前不可使用', 'error');
- return;
- } else {
- if (c.uamount > c.vamount) {
- toast('变更令:' + c.code + ' 超计,请修改本期计量后,再提交', 'error');
- return;
- }
- }
- data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount });
- }
- }
- // 提交数据到后端
- postData(window.location.pathname + '/use-change', data, function(result) {
- if (result.pos) {
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.bills);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- stagePosSpreadObj.loadCurPosData();
- needCheckDetail();
- self.obj.modal('hide');
- });
- })
- }
- _calculateAmount() {
- for (const c of this.changes) {
- c.bamount = _.toNumber(c.b_amount);
- c.vamount = ZhCalc.sub(c.bamount, c.used_amount);
- const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid});
- if (uc) {
- c.uamount = uc.qty;
- c.vamount = ZhCalc.add(c.vamount, c.uamount);
- }
- }
- }
- _loadChangeDetail(change) {
- if (change) {
- if (change.cid === this.curChangeId) { return; }
- this.curChangeId = change.cid;
- const inputs = $('input[type!=checkbox]', this.obj);
- for (const i of inputs) {
- const field = $(i).attr('name');
- const text = (field && change[field]) ? change[field] : '';
- $(i).val(text);
- }
- const textareas = $('textarea', this.obj);
- for (const ta of textareas) {
- const field = $(ta).attr('name');
- const text = (field && change[field]) ? change[field] : '';
- ta.innerText = text;
- }
- const html = [];
- for (const a of change.attachments) {
- html.push('<tr>');
- html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
- html.push('<td>', a.u_name, '</td>');
- html.push('</tr>');
- }
- // 变更类型
- if (change.type) {
- const cType = change.type.split(',');
- $('input[name="type"]').prop("checked", false);
- for (const c of cType) {
- $('input[name="type"][value='+ c +']').prop("checked", true);
- }
- }
- // 变更类别
- $('select[name=class]').val(change.class);
- // 变更性质
- $('select[name=quality]').val(change.quality);
- // 变更单位
- $('select[name=company]').html('<option>' + change.company + '</option>');
- // 费用承担方
- $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
- // 附件
- $('#attachment').html(html.join(''));
- } else {
- const inputs = $('input', this.obj);
- for (const i of inputs) {
- $(i).val('');
- }
- const textareas = $('textarea', this.obj);
- for (const ta of textareas) {
- ta.innerText = '';
- }
- $('#attachment').html('');
- }
- }
- _viewChanges() {
- const sheet = this.spread.getActiveSheet();
- if (this.changes) {
- SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, this.changes);
- sheet.setSelection(0, 0, 1, 1);
- this._loadChangeDetail(this.changes[0]);
- this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
- } else {
- toast('查询变更令有误,请刷新页面后重试', 'warning');
- }
- }
- _filterChange(filterEmpty, matchPosName) {
- for (const c of this.changes) {
- const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
- const matchVisible = matchPosName && this.callData.pos ? c.b_detail === this.callData.pos.name : true;
- c.visible = filterVisible && matchVisible;
- }
- SpreadJsObj.refreshTreeRowVisible(this.spread.getActiveSheet());
- }
- loadChanges(data) {
- this.callData = data;
- if (this.callData.pos) {
- $('#matchPos').parent().show();
- } else {
- $('#matchPos').parent().hide();
- }
- const self = this;
- $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
- postData(window.location.pathname + '/valid-change', data, function (result) {
- self.changes = result.changes;
- self.useChanges = result.useChanges;
- self._calculateAmount();
- self._viewChanges();
- self.obj.modal('show');
- });
- }
- }
- const changesObj = new Changes($('#use-bg'));
- // 初始化 台账 spread
- const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
- customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
- // 数量变更列,添加按钮
- const col = _.find(ledgerSpreadSetting.cols, {field: 'qc_qty'});
- col.readOnly = true;
- col.cellType = 'imageBtn';
- col.hoverImg = '#ellipsis-icon';
- col.indent = 5;
- col.showImage = function (data) {
- if (!data || (data.children && data.children.length > 0)) {
- return false;
- } else {
- const nodePos = stagePos.getLedgerPos(data.id);
- return !(nodePos && nodePos.length > 0);
- }
- };
- ledgerSpreadSetting.imageClick = function (data) {
- changesObj.loadChanges({bills: data});
- };
- //
- SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
- stageTree.loadDatas(ledgerData);
- stageTree.loadCurStageData(curStageData);
- stageTree.loadPreStageData(preStageData);
- // 根据设置 计算 台账树结构
- treeCalc.calculateAll(stageTree);
- // 绘制界面
- SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
- //初始化所有附件列表
- getAllList();
- // 初始化 部位明细 Spread
- const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
- const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
- spCol.readOnly = true;
- spCol.cellType = 'imageBtn';
- spCol.hoverImg = '#ellipsis-icon';
- spCol.indent = 5;
- spCol.showImage = function (data) {
- return data;
- };
- posSpreadSetting.imageClick = function (data) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- changesObj.loadChanges({bills: node, pos: data});
- };
- SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
- const stageTreeSpreadObj = {
- refreshTreeNodes: function (sheet, nodes) {
- const tree = sheet.zh_tree;
- if (!tree) { return }
- const rows = [];
- for (const node of nodes) {
- rows.push(tree.nodes.indexOf(node));
- }
- SpreadJsObj.reLoadRowsData(sheet, rows);
- },
- editEnded: function (e, info) {
- if (info.sheet.zh_setting) {
- const col = info.sheet.zh_setting.cols[info.col];
- const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
- const node = sortData[info.row];
- if (col.field !== 'postil') {
- if (node.children && node.children.length > 0) {
- toast('清单父项不可计量', 'error');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else {
- const nodePos = stagePos.getLedgerPos(node.id);
- if (nodePos && nodePos.length > 0) {
- toast('该清单有部位明细,请在部位明细处计量', 'error');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- const billsData = {
- lid: node.id
- };
- billsData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
- postData(window.location.href + '/update', { bills: billsData }, function (data) {
- const nodes = stageTree.loadPostStageData(data);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- needCheckDetail();
- });
- }
- },
- selectionChanged: function (e, info) {
- stagePosSpreadObj.loadCurPosData();
- },
- deletePress(sheet) {
- if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
- const tree = sheet.zh_tree;
- if (!tree) { return; }
- const sel = sheet.getSelections()[0];
- const validCols = [];
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- if (!sheet.zh_setting.cols[iCol].readOnly) {
- validCols.push(iCol);
- }
- }
- if (validCols.length === 0) { return; }
- const sortData = sheet.zh_tree.nodes;
- const datas = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- const node = sortData[iRow];
- if (node) {
- const data = { lid: node.id };
- let filter = true;
- for (const iCol of validCols) {
- const colSetting = sheet.zh_setting.cols[iCol];
- if (colSetting.field !== 'postil') {
- if (node.children && node.children.length > 0) { continue; }
- const nodePos = stagePos.getLedgerPos(node.id);
- if (nodePos && nodePos.length > 0) { continue; }
- }
- data[colSetting.field] = null;
- filter = false;
- }
- if (!filter) {
- datas.push(data);
- }
- }
- }
- if (datas.length > 0) {
- postData(window.location.href + '/update', {bills: datas}, function (result) {
- const nodes = stageTree.loadPostStageData(result);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- needCheckDetail();
- });
- }
- }
- },
- clipboardPasting(e, info) {
- if (info.sheet.zh_setting) {
- const sortData = info.sheet.zh_data;
- const range = info.cellRange;
- const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'postil'];
- for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
- const col = info.sheet.zh_setting.cols[iCol];
- if (validField.indexOf(col.field) === -1) {
- toast('不可修改此数据', 'error');
- info.cancel = true;
- return;
- }
- }
- }
- },
- clipboardPasted(e, info) {
- if (info.sheet.zh_setting && info.sheet.zh_tree) {
- const sheet = info.sheet;
- const filterNodes = [], datas = [];
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- const curRow = iRow + info.cellRange.row;
- const node = sheet.zh_tree.getItemsByIndex(curRow);
- const data = {lid: node.id};
- let filter = true;
- for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
- const curCol = info.cellRange.col + iCol;
- const col = info.sheet.zh_setting.cols[curCol];
- if (col.field !== 'postil') {
- if (node.children && node.children.length > 0) {
- continue;
- }
- const nodePos = stagePos.getLedgerPos(node.id);
- if (nodePos && nodePos.length > 0) {
- continue;
- }
- }
- data[col.field] = col.type === 'Number' ? _.toNumber(info.sheet.getText(curRow, curCol)) : info.sheet.getText(curRow, curCol);
- filter = false;
- }
- if (filter) {
- filterNodes.push(node);
- } else {
- datas.push(data);
- }
- }
- if (datas.length > 0) {
- postData(window.location.href + '/update', { bills: datas }, function (data) {
- const nodes = stageTree.loadPostStageData(data);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
- needCheckDetail();
- });
- } else {
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
- }
- }
- }
- };
- slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
- slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
- slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
- slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
- SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
- const stagePosSpreadObj = {
- /**
- * 加载部位明细 根据当前台账选择节点
- */
- loadCurPosData: function () {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- if (node) {
- const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
- SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
- } else {
- SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
- }
- getNodeList(node.id);
- },
- editEnded: function (e, info) {
- if (info.sheet.zh_setting) {
- // 未改变过,则直接跳过
- const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
- const col = info.sheet.zh_setting.cols[info.col];
- const orgText = posData ? posData[col.field] : null;
- if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
- return;
- }
- // 台账模式下,不可新增
- if (checkTzMeasureType() && !posData) {
- toast('台账模式不可新增部位明细数据', 'error');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- info.cancel = true;
- return ;
- }
- // 不同节点下,部位明细检查输入
- //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const node = stagePosSpreadObj.stageTreeNode;
- if (!node) {
- toast('数据错误, 请刷新页面后再试', 'warning');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (info.editingText !== '' && node.children && node.children > 0) {
- toast('父节点不可插入部位明细', 'error');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
- toast('项目节不可插入部位明细', 'error');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- // 生成提交数据
- const data = {};
- if (col.field === 'name') {
- if (info.editingText === '' && pos) {
- toast('部位名称不可为空', 'error', 'exclamation-circle');
- info.cancel = true;
- return;
- } else if (!posData) {
- if (info.editingText !== '') {
- data.updateType = 'add';
- data.updateData = {name: info.editingText, lid: node.id, tid: tender.id};
- } else {
- return;
- }
- } else {
- data.updateType = 'update';
- data.updateData = {pid: posData.id, lid: posData.lid, name: info.editingText};
- }
- } else if (!posData) {
- toast('新增部位请先输入名称', 'warning');
- } else {
- data.updateType = 'update';
- data.updateData = {pid: posData.id, lid: posData.lid};
- data.updateData[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText;
- }
- // 提交数据到服务器
- postData(window.location.pathname + '/update', {pos: data}, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const refreshData = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
- stagePosSpreadObj.loadCurPosData();
- needCheckDetail();
- }, function () {
- stagePosSpreadObj.loadCurPosData();
- });
- }
- },
- editStarting: function (e, info) {
- stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- },
- clipboardPasting: function (e, info) {
- if (info.sheet.zh_setting) {
- const sortData = info.sheet.zh_data;
- const range = info.cellRange;
- const validField = ['contract_qty', 'qc_qty', 'postil'];
- if (!checkTzMeasureType()) {
- validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty');
- }
- for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
- const col = info.sheet.zh_setting.cols[iCol];
- if (validField.indexOf(col.field) === -1) {
- if (checkTzMeasureType()) {
- toast('不可修改此数据', 'error');
- info.cancel = true;
- return;
- } else {
- for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
- const pos = sortData(iRow);
- if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
- toast('不可修改此数据', 'error');
- info.cancel = true;
- return;
- }
- }
- }
- }
- }
- }
- },
- clipboardPasted: function (e, info) {
- const self = this;
- if (info.sheet.zh_setting) {
- const data = { updateType: '', updateData: [], };
- const sortData = info.sheet.zh_data;
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- if (sortData && (info.cellRange.row >= sortData.length)) {
- data.updateType = 'add';
- if (info.cellRange.col !== 0) {
- toast('新增部位请先输入名称', 'warning');
- self.loadCurPosData();
- return;
- }
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- const curRow = info.cellRange.row + iRow;
- const newData = {lid: 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];
- newData[colSetting.field] = info.sheet.getText(curRow, curCol);
- if (colSetting.type === 'Number') {
- newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
- }
- }
- data.updateData.push(newData);
- }
- } else {
- data.updateType = 'update';
- for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
- const curRow = info.cellRange.row + iRow;
- const curPos = sortData[curRow];
- if (curPos) {
- const newData = {pid: curPos.id, lid: curPos.lid};
- for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
- const curCol = info.cellRange.col + iCol;
- const colSetting = info.sheet.zh_setting.cols[curCol];
- newData[colSetting.field] = info.sheet.getText(curRow, curCol);
- if (colSetting.type === 'Number') {
- newData[colSetting.field] = _.toNumber(newData[colSetting.field]);
- }
- }
- data.updateData.push(newData);
- }
- }
- }
- console.log(data);
- postData(window.location.pathname + '/update', {pos: data}, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- stagePosSpreadObj.loadCurPosData();
- needCheckDetail();
- }, function () {
- stagePosSpreadObj.loadCurPosData();
- });
- }
- },
- deletePress: function (sheet) {
- if (sheet.zh_setting && sheet.zh_data) {
- const sortData = sheet.zh_data;
- if (!sortData || sortData.length === 0) { return; }
- const sel = sheet.getSelections()[0];
- const validCols = [];
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- if (!sheet.zh_setting.cols[iCol].readOnly) {
- validCols.push(iCol);
- }
- }
- if (validCols.length === 0) { return; }
- const datas = [], posSelects = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- const node = sortData[iRow];
- if (node) {
- const data = {pid: node.id, lid: node.lid};
- for (const iCol of validCols) {
- const colSetting = sheet.zh_setting.cols[iCol];
- if (colSetting.field === 'name') {
- toast('部位名称不能为空', 'error');
- return;
- }
- data[colSetting.field] = null;
- }
- datas.push(data);
- posSelects.push(node);
- }
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
- if (result.pos) {
- stagePos.updateDatas(result.pos.pos);
- stagePos.loadCurStageData(result.pos.curStageData);
- }
- const nodes = stageTree.loadPostStageData(result.ledger);
- stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
- needCheckDetail();
- // todo 只加载改变项
- stagePosSpreadObj.loadCurPosData();
- });
- }
- }
- },
- leaveCell: function (e, info) {
- console.log(1);
- },
- };
- // 加载上下窗口resizer
- $.divResizer({
- select: '#main-resize',
- callback: function () {
- slSpread.refresh();
- let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
- $(".sp-wrap").height(bcontent-40);
- spSpread.refresh();
- }
- });
- // 加载部位明细数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
- postData(window.location.pathname + '/pos', null, function (result) {
- stagePos.loadDatas(result.pos);
- if (result.curStageData) {
- stagePos.loadCurStageData(result.curStageData);
- }
- if (result.preStageData) {
- stagePos.loadPreStageData(result.preStageData);
- }
- stagePos.calculateAll();
- stagePosSpreadObj.loadCurPosData();
- });
- spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
- spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
- spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
- spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
- SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
- if (!checkTzMeasureType()) {
- }
- $('#row-view').on('show.bs.modal', function () {
- const html = [], customDisplay = customColDisplay();
- for (const cd of customDisplay) {
- html.push('<tr>');
- html.push('<td>', cd.title, '</td>');
- html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
- html.push('</tr>');
- }
- $('#row-view-list').html(html.join(''));
- });
- $('#row-view-ok').click(function () {
- const customDisplay = customColDisplay();
- const cvl = $('#row-view-list').children();
- for (const cv of cvl) {
- const title = $(cv).children()[0].innerHTML;
- const check = $('input', cv)[0].checked;
- const cd = customDisplay.find(function (c) {
- return c.title === title;
- });
- cd.visible = check;
- }
- customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
- SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
- Cookies.set('stage-col-visible', JSON.stringify(customDisplay), 7*24*60*60*1000);
- $('#row-view').modal('hide');
- });
- class SearchLedger {
- constructor(obj, mainSpread) {
- const self = this;
- this.obj = obj;
- this.mainSpread = mainSpread;
- this.spreadSetting = {
- cols: [
- {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@'},
- {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@'},
- {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
- {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
- {title: '数量', field: 'quantity', hAlign: 2, width: 50},
- {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
- ],
- emptyRows: 3,
- headRows: 1,
- headRowHeight: [40],
- defaultRowHeight: 21,
- readOnly: true
- };
- this.spread = SpreadJsObj.createNewSpread($('#search-result', this.obj)[0]);
- SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
- $('#searchLedger', this.obj).bind('click', function () {
- const keyword = $('#keyword', self.obj).val();
- if (keyword !== '') {
- $('#over', obj)[0].checked = false;
- $('#empty', obj)[0].checked = false;
- this.searchResult = [];
- const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
- for (const node of sortData) {
- if ((node.code && node.code.indexOf(keyword) > -1) ||
- node.b_code && node.b_code.indexOf(keyword) > -1 ||
- node.name && node.name.indexOf(keyword) > -1) {
- this.searchResult.push(node);
- }
- }
- SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
- }
- });
- $('#over', this.obj).bind('change', function () {
- this.searchResult = [];
- const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
- for (const node of sortData) {
- if (node.children && node.children.length > 0) continue;
- if (node.end_gather_qty) {
- if (!node.quantity || Math.abs(node.end_gather_qty) > Math.abs(node.quantity)) {
- this.searchResult.push(node);
- }
- } else if (node.end_gather_tp) {
- if (!node.total_price || Math.abs(node.end_gather_tp) > Math.abs(node.total_price)) {
- this.searchResult.push(node);
- }
- }
- }
- SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
- });
- $('#empty', this.obj).bind('change', function () {
- this.searchResult = [];
- const sortData = SpreadJsObj.getSortData(self.mainSpread.getActiveSheet());
- for (const node of sortData) {
- if (node.children && node.children.length > 0) continue;
- if (node.quantity) {
- if (!node.end_gather_qty || checkZero(node.end_gather_qty)) {
- this.searchResult.push(node);
- }
- } else if (node.total_price) {
- if (!node.end_gather_tp || checkZero(node.end_gather_tp)) {
- this.searchResult.push(node);
- }
- }
- }
- SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
- });
- this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
- const sheet = info.sheet;
- const data = sheet.zh_data;
- if (!data) { return }
- const curBills = data[info.row];
- if (!curBills) { return }
- SpreadJsObj.locateTreeNode(self.mainSpread.getActiveSheet(), curBills.ledger_id);
- });
- }
- }
- let searchLedger;
- $.divResizer({
- select: '#right-spr',
- callback: function () {
- slSpread.refresh();
- spSpread.refresh();
- if (searchLedger) {
- searchLedger.spread.refresh();
- }
- }
- });
- // 展开收起附件
- $('a', '.right-nav').bind('click', function () {
- //const main = $('#main-view'), tool = $('#tools-view');
- const tab = $(this), tabPanel = $(tab.attr('content'));
- const showTools = function (show) {
- const left = $('#main-view'), right = $('#tools-view'), parent = left.parent();
- if (show) {
- right.show();
- autoFlashHeight();
- /**
- * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
- * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
- * 故需要通过最终的parent.width再计算一次left.width
- *
- * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
- * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
- *
- */
- //left.css('width', parent.width() - right.outerWidth());
- //left.css('width', parent.width() - right.outerWidth());
- const percent = 100 - right.outerWidth() /parent.width() * 100;
- left.css('width', percent + '%');
- } else {
- right.hide();
- left.css('width', '100%');
- }
- };
- if (!tab.hasClass('active')) {
- $('a', '.side-menu').removeClass('active');
- $('.tab-content .tab-select-show').removeClass('active');
- tab.addClass('active');
- tabPanel.addClass('active');
- showTools(tab.hasClass('active'));
- if (tab.attr('content') === '#search' && !searchLedger) {
- searchLedger = new SearchLedger($('#search'), slSpread);
- searchLedger.spread.refresh();
- }
- if (tab.attr('content') === '#fujian') {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- getNodeList(node.id);
- }
- } else {
- tab.removeClass('active');
- tabPanel.removeClass('active');
- showTools(tab.hasClass('active'));
- }
- slSpread.refresh();
- spSpread.refresh();
- });
- // 切换附件里节点和所有附件
- $('#fujian .nav-link').on('click', function () {
- const tabPanel = $(this).attr('fujian-content');
- if (tabPanel !== 'syfujian') {
- $('#showPage').hide();
- } else {
- $('#showPage').show();
- }
- });
- // 上传附件
- $('#upload-file-btn').click(function () {
- const file = $('#upload-file')[0];
- if (file.files[0] === undefined) {
- toast('未选择上传文件!', 'error');
- return false;
- }
- const filesize = file.files[0].size;
- if (filesize > 10 * 1024 * 1024) {
- toast('文件大小过大!', 'error');
- return false;
- }
- const fileext = '.' + file.files[0].name.toLowerCase().split('.').splice(-1)[0];
- if (whiteList.indexOf(fileext) === -1) {
- toast('只能上传指定格式的附件!', 'error');
- return false;
- }
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const formData = new FormData();
- formData.append('lid', node.id);
- formData.append('size', filesize);
- formData.append('file', file.files[0]);
- postDataWithFile('/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/upload/file', formData, function (data) {
- $('#upload').modal('hide');
- // 插入到attData中
- console.log(data);
- attData.unshift(data);
- // 重新生成LIst
- getAllList();
- getNodeList(node.id);
- }, function () {
- toast('附件上传失败', 'error');
- });
- $('#upload-file').val('');
- });
- // 获取附件信息
- $('body').on('click', '.list-table a', function () {
- const fid = $(this).attr('file-id');
- if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
- return;
- }
- const att = attData.find(function (item) {
- return item.id === parseInt(fid);
- });
- console.log(att);
- $('#edit-att').hide();
- $('#show-att').show();
- if (att !== undefined) {
- $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
- const name = att.code !== null && att.code !== '' ? att.code : att.b_code;
- $('#show-att tr').eq(1).children('td').text(name + ' ' + att.lname);
- $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/download/file/' + att.id);
- $('#show-att tr').eq(3).children('td').eq(0).text(att.username);
- $('#show-att tr').eq(3).children('td').eq(1).text(att.in_time);
- $('#show-att tr').eq(4).children('td').text(att.remark);
- console.log(userID);
- console.log(att.uid);
- if (parseInt(userID) === att.uid) {
- $('#btn-att').show();
- $('#btn-att a').eq(1).show();
- $('#btn-att a').eq(0).hide();
- $('#btn-att a').eq(2).hide();
- $('#btn-att a').eq(3).hide();
- } else {
- $('#btn-att').hide();
- $('#btn-att a').eq(1).hide();
- $('#btn-att a').eq(0).hide();
- $('#btn-att a').eq(2).hide();
- $('#btn-att a').eq(3).hide();
- }
- $('#showAttachment').attr('file-id', fid);
- $('#showAttachment').show();
- } else {
- $('#showAttachment').hide();
- $('#showAttachment').attr('file-id', '');
- toast('附件信息获取失败', 'error');
- }
- });
- $('body').on('click', '#btn-att a', function () {
- const content = $(this).attr('content');
- const fid = $('#showAttachment').attr('file-id');
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- if (content === 'edit') {
- $('#btn-att a').eq(1).hide();
- $('#btn-att a').eq(0).show();
- $('#btn-att a').eq(2).show();
- $('#btn-att a').eq(3).show();
- $('#show-att').hide();
- $('#edit-att').show();
- const att = attData.find(function (item) {
- return item.id === parseInt(fid);
- });
- $('#edit-att .form-group').eq(0).find('input').val(att.filename);
- $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
- const name = att.code !== null && att.code !== '' ? att.code : att.b_code;
- $('#edit-att .form-group').eq(1).find('input').val(name + ' ' + att.lname);
- $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
- $('#edit-att .form-group').eq(3).find('input').val(att.remark);
- } else if (content === 'cancel') {
- $('#show-att').show();
- $('#edit-att').hide();
- $('#btn-att a').eq(1).show();
- $('#btn-att a').eq(0).hide();
- $('#btn-att a').eq(2).hide();
- $('#btn-att a').eq(3).hide();
- } else if (content === 'save') {
- const formData = new FormData();
- formData.append('id', fid);
- formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
- formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
- formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
- const file = $('#change-att-btn')[0];
- if (file.files[0] !== undefined) {
- const filesize = file.files[0].size;
- formData.append('size', filesize);
- formData.append('file', file.files[0]);
- }
- postDataWithFile('/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/save/file', formData, function (data) {
- // 替换到attData中
- const att_index = attData.findIndex(function (item) {
- return item.id === parseInt(fid);
- });
- attData.splice(att_index, 1, data);
- // 重新生成List
- getAllList(parseInt($('#currentPage').text()));
- getNodeList(node.id);
- $('#show-att').show();
- $('#edit-att').hide();
- $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
- const name = data.code !== null && data.code !== '' ? data.code : data.b_code;
- $('#show-att tr').eq(1).children('td').text(name + ' ' + data.lname);
- $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/download/file/' + data.id);
- $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
- $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
- $('#show-att tr').eq(4).children('td').text(data.remark);
- $('#btn-att a').eq(1).show();
- $('#btn-att a').eq(0).hide();
- $('#btn-att a').eq(2).hide();
- $('#btn-att a').eq(3).hide();
- }, function () {
- toast('附件上传失败', 'error');
- });
- $('#change-att-btn').val('');
- } else if (content === 'del') {
- const data = {id: fid};
- postData('/tender/' + tender.id + '/measure/stage/' + tender.ledger_times + '/delete/file', data, function (result) {
- // 删除到attData中
- const att_index = attData.findIndex(function (item) {
- return item.id === parseInt(fid);
- });
- attData.splice(att_index, 1);
- // 重新生成List
- getAllList();
- getNodeList(node.id);
- $('#showAttachment').hide();
- $('#showAttachment').attr('file-id', '');
- });
- }
- });
- // 替换附件
- $('#change-att-btn').on('change', function () {
- const file = $('#change-att-btn')[0].files[0];
- const name = file.name;
- const filename = name.substring(0, name.lastIndexOf("."));
- const fileext = name.substr(name.indexOf("."));
- const filesize = file.size;
- if (filesize > 10 * 1024 * 1024) {
- toast('文件大小过大!', 'error');
- $('#change-att-btn').val('');
- return false;
- }
- if (whiteList.indexOf(fileext) === -1) {
- toast('只能上传指定格式的附件!', 'error');
- $('#change-att-btn').val('');
- return false;
- }
- $('#edit-att .form-group').eq(0).find('input').val(filename);
- $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
- });
- // 切换页数
- $('.page-select').on('click', function () {
- const totalPageNum = $('#totalPage').text();
- const lastPageNum = $('#currentPage').text();
- const status = $(this).attr('content');
- console.log(totalPageNum,lastPageNum,status);
- if (status === 'pre' && lastPageNum > 1) {
- getAllList(parseInt(lastPageNum)-1);
- } else if (status === 'next' && lastPageNum < totalPageNum) {
- getAllList(parseInt(lastPageNum)+1);
- }
- })
- });
|