12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346 |
- 'use strict';
- /**
- * 期计量 - 本期计量台账页面 js
- *
- * @author Mai
- * @date 2018/12/7
- * @version
- */
- const ckBillsSpread = window.location.pathname + '-billsSelect';
- function checkTzMeasureType () {
- return relaTender.measure_type === measureType.tz.value;
- }
- function transExpr(expr) {
- return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
- }
- function getExprInfo (field) {
- const exprField = [
- {qty: 'sgfh_qty', expr: 'sgfh_expr'},
- {qty: 'sjcl_qty', expr: 'sjcl_expr'},
- {qty: 'qtcl_qty', expr: 'qtcl_expr'},
- {qty: 'contract_qty', expr: 'contract_expr'},
- ];
- return _.find(exprField, {qty: field});
- }
- /**
- * 从cookie中读取缓存的列显示设置,没有则取默认
- * @returns {*[]}
- */
- function customColDisplay () {
- const defaultSetting = [
- { 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', 'end_gather_percent', 'end_final_1_percent'], visible: true },
- { title: '本期批注', fields: ['postil'], visible: true },
- { title: '图册号', fields: ['drawing_code'], visible: true },
- { title: '备注', fields: ['memo'], visible: true },
- { title: '总额计量', fields: ['is_tp'], visible: true},
- ];
- if (!checkTzMeasureType()) {
- defaultSetting.unshift({ title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true }, { title: '台账', fields: ['quantity', 'total_price'], visible: true});
- }
- const settingStr = Cookies.get(ckColSetting);
- if (settingStr) {
- const customSetting = JSON.parse(settingStr);
- for (const ds of defaultSetting) {
- const cs = customSetting.find(x => {return x.title === ds.title});
- if (cs) ds.visible = cs.visible;
- }
- }
- return 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;
- }
- }
- }
- }
- // 生成所有附件列表
- function getAllList(currPageNum = 1) {
- // 每页最多几个附件
- const pageCount = 20;
- // 附件总数
- const total = attData.length;
- // 总页数
- const pageNum = Math.ceil(total/pageCount);
- $('#totalPage').text(pageNum);
- $('#currentPage').text(total === 0 ? 0 : currPageNum);
- // 当前页附件内容
- const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
- currPageFileData = currPageAttData;
- let html = '';
- for(const att of currPageAttData) {
- html += `<tr>
- <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
- <td>
- <div class="d-flex">
- <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
- <a href="/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
- </div>
- </td><td>${att.username}</td></tr>`
- }
- $('#alllist-table').html(html);
- $('#alllist-table').on('click', 'tr', function() {
- $('#alllist-table tr').removeClass('bg-light')
- $(this).addClass('bg-light')
- })
- }
- // 生成当前节点列表
- function getNodeList(node) {
- let html = '';
- for(const att of attData) {
- if (node === att.lid) {
- html += `<tr>
- <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
- <td>
- <div class="d-flex">
- <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
- <a href="/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
- </div>
- </td><td>${att.username}</td></tr>`
- }
- }
- $('#nodelist-table').html(html);
- $('#nodelist-table').on('click', 'tr', function() {
- $('#nodelist-table tr').removeClass('bg-light');
- $(this).addClass('bg-light');
- })
- }
- function getGxbyText(data) {
- const def = thirdParty.gxby.find(function (x) {
- return x.value === data.gxby_status;
- });
- return def ? def.name : '';
- }
- function getDaglText(data) {
- const def = thirdParty.dagl.find(function (x) {
- return x.value === data.dagl_status;
- });
- return def ? def.name : '';
- }
- function getHintMsg () {
- return {
- invalidExpr: {type: 'warning', msg: '粘贴了非法表达式,已过滤'},
- disableChange: {type: 'error', msg: '不可修改此数据'},
- }
- }
- let currPageFileData = [];
- $(document).ready(() => {
- let detail, searchLedger;
- // 界面布局
- autoFlashHeight();
- // 初始化 台账树结构 数据结构
- removeLocalCache('bills-fold');
- const stageTreeSetting = {
- id: 'ledger_id',
- pid: 'ledger_pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'tender_id', 'ledger_id'],
- stageId: 'id',
- autoExpand: 3,
- // markFoldKey: 'bills-fold',
- // markFoldSubKey: window.location.pathname.split('/')[2],
- markExpandKey: 'stage-bills-expand',
- markExpandSubKey: window.location.pathname.split('/')[2],
- };
- // 台账树结构计算相关设置
- stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty', 'postil', 'used', 'contract_expr'];
- stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
- 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp', 'final_1_tp', 'end_final_1_tp'];
- stageTreeSetting.calcFun = function (node) {
- if (!node.children || node.children.length === 0) {
- node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
- node.end_gather_qty = ZhCalc.add(node.end_contract_qty, node.end_qc_qty);
- node.end_qc_minus_qty = ZhCalc.add(node.pre_qc_minus_qty, node.qc_minus_qty);
- node.final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.quantity);
- node.final_1_tp = ZhCalc.mul(node.final_1_qty, node.unit_price, tenderInfo.decimal.tp);
- node.deal_final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.deal_qty);
- node.end_final_1_qty = ZhCalc.add(node.end_qc_qty, node.final_1_qty);
- }
- node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
- node.end_gather_tp = ZhCalc.add(node.end_contract_tp, node.end_qc_tp);
- node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
- node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.final_1_tp);
- if (!node.children || node.children.length === 0) {
- if (node.end_contract_qty) {
- node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
- } else {
- node.end_correct_tp = node.end_gather_tp;
- }
- }
- node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
- node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
- node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
- node.end_final_1_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_1_tp), 100, 2);
- node.end_correct_1_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_1_tp), 100, 2);
- };
- const stageTree = createNewPathTree('stage', stageTreeSetting);
- // 初始化 计量单元 数据结构
- const stagePosSetting = { id: 'id', ledgerId: 'lid' };
- stagePosSetting.calcFun = function (pos) {
- pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
- pos.end_gather_qty = ZhCalc.add(pos.end_contract_qty, pos.end_qc_qty);
- pos.end_qc_minus_qty = ZhCalc.add(pos.pre_qc_minus_qty, pos.qc_minus_qty);
- pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
- pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
- pos.estimate_qty = !checkZero(pos.real_qty)
- ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
- : null;
- pos.final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.quantity);
- pos.deal_final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.deal_qty);
- pos.end_final_1_qty = ZhCalc.add(pos.end_qc_qty, pos.final_1_qty);
- };
- const stagePos = new StagePosData(stagePosSetting);
- // 初始化 台账 spread
- const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
- customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
- const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_final_1_percent' || x.field === 'end_correct_1_percent'});
- if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent';
- ledgerSpreadSetting.imageClick = function (data, hitinfo) {
- const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
- if (col.field === 'dagl') data.dagl_url && window.open(data.dagl_url);
- if (col.field === 'gxby') data.gxby_url && window.open(data.gxby_url);
- };
- ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
- ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
- if (data) {
- if (col.field === 'gxby') {
- const def = thirdParty.gxby.find(function (x) {
- return x.value === data.gxby_status;
- });
- if (def && def.color) return def.color;
- } else if (col.field === 'dagl') {
- const def = thirdParty.dagl.find(function (x) {
- return x.value === data.dagl_status;
- });
- if (def && def.color) return def.color;
- }
- return checkUtils.billsOver(data, checkTzMeasureType(), stagePos) ? '#f8d7da' : defaultColor;
- } else {
- return defaultColor;
- }
- };
- sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
- sjsSettingObj.set3FCols(ledgerSpreadSetting.cols, [
- {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
- {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
- ]);
- if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
- ledgerSpreadSetting.headColWidth = [50];
- ledgerSpreadSetting.rowHeader = [
- {
- rowHeaderType: 'tag',
- setting: {
- indent: 14,
- tagSize: 0.8,
- tagFont: '8px 微软雅黑',
- getColor: function (index, data) {
- if (!data) return;
- return billsTag.getBillsTagsColor(data.id);
- },
- getTagHtml: function (index, data) {
- if (!data) return;
- const getHtml = function (list) {
- if (!list || list.length === 0) return '';
- const html = [];
- for (const l of list) {
- html.push('<div class="row mr-1">');
- html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
- html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
- html.push('</div>');
- }
- return html.join('');
- };
- return getHtml(billsTag.getBillsTagsInfo(data.id));
- }
- },
- },
- ];
- SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
- slSpread.getActiveSheet().frozenColumnCount(5);
- slSpread.getActiveSheet().options.frozenlineColor = '#93b5e4';
- //初始化所有附件列表
- getAllList();
- // 初始化 计量单元 Spread
- const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
- const spCol = _.find(posSpreadSetting.cols, {field: 'qc_qty'});
- spCol.cellType = 'activeImageBtn';
- spCol.normalImg = '#ellipsis-icon';
- spCol.indent = 5;
- spCol.showImage = function (data) {
- return data !== undefined && data !== null;
- };
- posSpreadSetting.imageClick = function (data, hitinfo) {
- const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
- if (col.field === 'dagl') data.dagl_url && window.open(data.dagl_url);
- if (col.field === 'gxby') data.gxby_url && window.open(data.gxby_url);
- };
- posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
- if (data) {
- if (col.field === 'gxby') {
- const def = thirdParty.gxby.find(function (x) {
- return x.value === data.gxby_status;
- });
- if (def && def.color) return def.color;
- } else if (col.field === 'dagl') {
- const def = thirdParty.dagl.find(function (x) {
- return x.value === data.dagl_status;
- });
- if (def && def.color) return def.color;
- }
- }
- if (checkTzMeasureType()) {
- return checkUtils.posOver(data) ? '#f8d7da' : defaultColor;
- }
- };
- sjsSettingObj.setGridSelectStyle(posSpreadSetting);
- if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
- sjsSettingObj.set3FCols(posSpreadSetting.cols, [
- {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
- {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
- ]);
- SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
- const billsTag = $.billsTag({
- relaTree: stageTree,
- selector: '#bills-tag',
- relaSpread: slSpread,
- updateUrl: window.location.pathname + '/tag',
- readOnly: true,
- afterModify: function (nodes) {
- SpreadJsObj.repaintNodesRowHeader(slSpread.getActiveSheet(), nodes);
- },
- afterLocated: function () {
- stagePosSpreadObj.loadCurPosData();
- },
- afterShow: function () {
- slSpread.refresh();
- if (spSpread) spSpread.refresh();
- },
- });
- const stageTreeSpreadObj = {
- loadExprToInput(sheet) {
- const sel = sheet.getSelections()[0];
- const col = sheet.zh_setting.cols[sel.col];
- if (col.type === 'Number') {
- const data = SpreadJsObj.getSelectObject(sheet);
- if (!data) {
- $('#bills-expr').val('');
- return;
- }
- const nodePos = stagePos.getLedgerPos(data.id);
- if (nodePos && nodePos.length > 0) {
- $('#bills-expr').val('');
- } else {
- const exprInfo = getExprInfo(col.field);
- const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
- $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
- }
- } else {
- $('#bills-expr').val('');
- }
- },
- selectionChanged: function (e, info) {
- if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
- SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
- stagePosSpreadObj.loadCurPosData();
- if (posSearch) {
- posSearch.search();
- }
- }
- SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
- stageTreeSpreadObj.loadExprToInput(info.sheet);
- },
- topRowChanged(e, info) {
- SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
- },
- };
- slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
- slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
- stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
- $.contextMenu({
- selector: '#stage-ledger',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
- return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
- },
- items: {
- 'locateZjjl': {
- name: '定位至中间计量',
- icon: 'fa-sign-in',
- callback: function (key, opt) {
- if (!detail) {
- detail = new Detail($('#detail-spread'));
- }
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
- if (leafUsedBills) {
- if (!$('#zhongjian').hasClass('active')) {
- const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
- $('a', '.side-menu').removeClass('active');
- $('.tab-content .tab-select-show').removeClass('active');
- tab.addClass('active');
- tabPanel.addClass('active');
- showSideTools(tab.hasClass('active'));
- slSpread.refresh();
- spSpread.refresh();
- }
- const relaXmj = stageIm.getRelaXmj(leafUsedBills);
- const im = stageIm.getRelaImData4Rela(relaXmj, leafUsedBills, usedPos);
- SpreadJsObj.locateData(detail.sheet, im);
- detail.spread.refresh();
- $('#zhongjian .sjs-bottom').height('400px');
- $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
- detail.reLoadDetailData();
- } else {
- toastr.error('无可定位中间计量');
- }
- },
- },
- tagSpr: '----',
- tag: {
- name: '书签',
- callback: function (key, opt, menu, e) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- addTag.do(node);
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return !node;
- }
- },
- showSpr: '----',
- showLast: {
- name: '显示至最底层',
- callback: function (key, opt, menu, e) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- setTimeout(() => {
- showWaitingView();
- stageTree.expandByCustom(x => {
- return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
- });
- SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
- closeWaitingView();
- }, 100);
- },
- },
- exportSpr: '----',
- exportSelectNodeXlsx: {
- name: '导出选中节点至Excel',
- callback: function (key, opt, menu, e) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
- },
- disabled: function (key, opt) {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- return !node;
- }
- },
- }
- });
- const stagePosSpreadObj = {
- loadExprToInput(sheet) {
- const sel = sheet.getSelections()[0];
- if (!sel) return;
- const col = sheet.zh_setting.cols[sel.col];
- if (col && col.type === 'Number') {
- const data = SpreadJsObj.getSelectObject(sheet);
- if (data) {
- const exprInfo = getExprInfo(col.field);
- const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
- $('#pos-expr').val(value);
- } else {
- $('#pos-expr').val('');
- }
- } else {
- $('#pos-expr').val('');
- }
- },
- /**
- * 加载计量单元 根据当前台账选择节点
- */
- loadCurPosData: function () {
- const sheet = slSpread.getActiveSheet();
- const node = SpreadJsObj.getSelectObject(sheet);
- if (node) {
- const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
- SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
- getNodeList(node.id);
- // 如果是附件是当前节点,隐藏
- // if ($('#dqjiedian').hasClass('active')) {
- // $('#showAttachment').hide();
- // }
- } else {
- SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
- }
- stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
- },
- selectionChanged: function (e, info) {
- stagePosSpreadObj.loadExprToInput(info.sheet);
- },
- };
- // 加载上下窗口resizer
- $.divResizer({
- select: '#main-resize',
- callback: function () {
- slSpread.refresh();
- let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
- $(".sp-wrap").height(bcontent-30);
- spSpread.refresh();
- window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
- }
- });
- // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
- postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;stageChange;tag;sumDeal' }, function (result) {
- for (const l of result.ledgerData) {
- if (!l.is_leaf) continue;
- const sd = result.sumDeal.find(x => { return x.code === l.b_code && x.name === l.name && x.unit === l.unit; });
- l.unit_price = sd ? sd.unit_price : 0;
- l.deal_tp = ZhCalc.mul(l.unit_price, l.deal_qty, tenderInfo.decimal.tp);
- l.sgfh_tp = ZhCalc.mul(l.unit_price, l.sgfh_qty, tenderInfo.decimal.tp);
- l.sjcl_tp = ZhCalc.mul(l.unit_price, l.sjcl_qty, tenderInfo.decimal.tp);
- l.qtcl_tp = ZhCalc.mul(l.unit_price, l.qtcl_qty, tenderInfo.decimal.tp);
- l.total_price = ZhCalc.mul(l.unit_price, l.quantity, tenderInfo.decimal.tp);
- }
- // 加载树结构
- stageTree.loadDatas(result.ledgerData);
- treeCalc.calculateAll(stageTree);
- for (const t of result.tags) {
- t.node = stageTree.datas.find(x => {return x.id === t.lid});
- }
- billsTag.loadDatas(result.tags);
- // 加载部位明细
- stagePos.loadDatas(result.posData);
- stagePos.calculateAll();
- SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
- SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
- stagePosSpreadObj.loadCurPosData();
- SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
- // 加载中间计量
- stageIm.init(tenderInfo, relaStage, imType, tenderInfo.decimal);
- stageIm.loadData4Rela(result.ledgerData, result.posData, result.detailData, result.stageChange || [], result.detailAtt);
- }, null, true);
- spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
- $.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();
- slSpread.refresh();
- spSpread.refresh();
- if (searchLedger) searchLedger.spread.refresh();
- if (detail) detail.spread.refresh();
- }
- });
- const posSearch = (function () {
- let resultArr = [];
- const search = function () {
- resultArr = [];
- const keyword = $('#pos-search-keyword').val();
- const checkOver = $('#pos-over-search')[0].checked;
- const checkEmpty = $('#pos-empty-search')[0].checked;
- const sortData = spSpread.getActiveSheet().zh_data;
- if (checkOver || checkEmpty) {
- if (sortData) {
- for (let i = 0, iLength = sortData.length; i < iLength; i++) {
- const sd = sortData[i];
- let match = false;
- if (checkOver) {
- if (sd.end_gather_qty) {
- if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
- }
- }
- if (checkEmpty) {
- if (sd.quantity) {
- if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
- }
- }
- if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
- if (match) {
- resultArr.push({index: i, data: sd});
- }
- }
- }
- } else if (keyword && keyword !== '') {
- if (sortData) {
- for (let i = 0, iLength = sortData.length; i < iLength; i++) {
- const sd = sortData[i];
- if (sd.name && sd.name.indexOf(keyword) > -1) {
- resultArr.push({index: i, data: sd});
- }
- }
- }
- }
- $('#pos-search-result').html('结果:' + resultArr.length);
- };
- const searchAndLocate = function () {
- search();
- if (resultArr.length > 0) {
- const sheet = spSpread.getActiveSheet();
- const sel = sheet.getSelections()[0];
- const curRow = sel ? sel.row : 0;
- const pos = resultArr[0];
- if (pos.index !== curRow) {
- sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
- sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
- SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
- }
- }
- };
- const locateNext = function () {
- if (resultArr.length > 0) {
- const sheet = spSpread.getActiveSheet();
- const sel = sheet.getSelections()[0];
- const curRow = sel ? sel.row : 0;
- let next = _.find(resultArr, function (d) {
- return d.index > curRow;
- });
- if (!next) next = resultArr[0];
- if (next.index !== curRow) {
- sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
- sheet.showRow(next.index, spreadNS.VerticalPosition.center);
- SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
- }
- }
- };
- const locatePre = function () {
- if (resultArr.length > 0) {
- const sheet = spSpread.getActiveSheet();
- const sel = sheet.getSelections()[0];
- const curRow = sel ? sel.row : 0;
- let next = _.findLast(resultArr, function (d) {
- return d.index < curRow;
- });
- if (!next) next = resultArr[resultArr.length - 1];
- if (next.index !== curRow) {
- sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
- sheet.showRow(next.index, spreadNS.VerticalPosition.center);
- SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
- }
- }
- };
- return {search, searchAndLocate, locateNext, locatePre};
- })();
- $('#pos-search-keyword').bind('keydown', function(e){
- if (e.keyCode == 13) posSearch.searchAndLocate();
- });
- $('#pos-empty-search').click(function () {
- if (this.checked) {
- $('[for=' + this.id +']').addClass('text-warning');
- } else {
- $('[for=' + this.id +']').removeClass('text-warning');
- }
- if (this.checked) {
- if ($('#pos-over-search')[0].checked) {
- $('#pos-search-keyword').attr('placeholder', '按名称查询');
- } else {
- $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
- }
- } else {
- if ($('#pos-over-search')[0].checked) {
- $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
- } else {
- $('#pos-search-keyword').attr('placeholder', '按名称查询');
- }
- }
- posSearch.searchAndLocate();
- });
- $('#pos-over-search').click(function () {
- if (this.checked) {
- $('[for=' + this.id +']').addClass('text-danger');
- } else {
- $('[for=' + this.id +']').removeClass('text-danger');
- }
- if (this.checked) {
- if ($('#pos-empty-search')[0].checked) {
- $('#pos-search-keyword').attr('placeholder', '按名称查询');
- } else {
- $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
- }
- } else {
- if ($('#pos-empty-search')[0].checked) {
- $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
- } else {
- $('#pos-search-keyword').attr('placeholder', '按名称查询');
- }
- }
- posSearch.searchAndLocate();
- });
- $('#pos-search-next').click(() => {posSearch.locateNext()});
- $('#pos-search-pre').click(() => {posSearch.locatePre()});
- $.divResizer({
- select: '#right-spr',
- callback: function () {
- slSpread.refresh();
- spSpread.refresh();
- if (searchLedger) {
- searchLedger.spread.refresh();
- }
- if (detail) {
- detail.spread.refresh();
- }
- window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
- }
- });
- // 中间计量加载上下窗口resizer
- $.divResizer({
- select: '#zhongjian-spr',
- callback: function () {
- if (detail) {
- detail.spread.refresh();
- }
- $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
- window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
- }
- });
- // 附件加载上下窗口resizer
- $.divResizer({
- select: '#file-spr',
- callback: function () {
- window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
- }
- });
- class Detail {
- constructor (obj) {
- const self = this;
- this.spreadSetting = {
- cols: [
- {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
- {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@'},
- {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
- {
- title: relaStage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
- colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@'
- },
- {
- title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
- normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
- return data.attachment ? data.attachment.length : 0;
- }
- },
- ],
- headRows: 1,
- emptyRows: 0,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- selectedBackColor: '#fffacd',
- imageClick: function (data) {
- self.makeAttTable(data);
- $('#im-file').modal('show');
- }
- };
- this.spread = SpreadJsObj.createNewSpread(obj[0]);
- this.sheet = this.spread.getActiveSheet();
- SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
- this.detailObj = {
- selectionChanged: function (e, info) {
- self.reLoadDetailData();
- if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
- self.loadLocateInfo();
- }
- },
- };
- this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
- this._initImTypeSetRela();
- this._initLocateRela();
- this._initAttRela();
- this.reBuildImData();
- }
- makeAttTable (data) {
- let html = [];
- if (data.attachment) {
- for (const att of data.attachment) {
- const delHtml = (parseInt(att.uid) === userID && att.renew)
- ? '<a class="delete-att text-danger ml-1" href="javascript:void(0);" data-imid="'+ data.att_uuid +'" data-attid="'+ att.file_id +'" title="删除"><i class="fa fa-remove "></i></a>'
- : '';
- const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
- const downloadHtml = '<a href="'+ window.location.pathname + '/im-file/download?im_id='+ data.att_uuid +'&file_id='+ att.file_id +'" title="下载"><i class="fa fa-download "></i></a>';
- html.push('<tr><td style="width: 200px">' + att.filename + att.fileext + '</td><td>' + att.username + '</td><td>' + att.in_time + '</td>',
- '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
- }
- }
- $('#im-attList').html(html.join(''));
- }
- _initAttRela() {
- // 上传附件
- const self = this;
- $('#upload-im-file').change(function () {
- const files = this.files;
- const sels = self.sheet.getSelections();
- const select = SpreadJsObj.getSelectObject(self.sheet);
- if (!select) return;
- const formData = new FormData();
- const baseInfo = {};
- if (select.att_uuid) {
- baseInfo.uuid = select.att_uuid;
- } else {
- baseInfo.im_type = select.im_type;
- baseInfo.lid = select.lid;
- baseInfo.pid = select.pid;
- baseInfo.code = select.code;
- baseInfo.name = select.name;
- baseInfo.unit = select.unit;
- baseInfo.unit_price = select.unit_price;
- baseInfo.pos_name = select.pos_name;
- }
- formData.append('base', JSON.stringify(baseInfo));
- for (const file of files) {
- if (file === undefined) {
- toast('未选择上传文件!', 'error');
- return false;
- }
- const filesize = file.size;
- if (filesize > 30 * 1024 * 1024) {
- toast('存在上传文件大小过大!', 'error');
- return false;
- }
- const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
- if (whiteList.indexOf(fileext) === -1) {
- toast('只能上传指定格式的附件!', 'error');
- return false;
- }
- formData.append('size', filesize);
- formData.append('file[]', file);
- }
- postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
- stageIm.loadUpdateDetailAtt(data);
- SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
- self.makeAttTable(select);
- $('#upload-im-file').val('');
- });
- });
- // 删除附件
- $('body').on('click', '.delete-att' ,function () {
- const sels = self.sheet.getSelections();
- const select = SpreadJsObj.getSelectObject(self.sheet);
- if (!select) return;
- const uuid = $(this).attr('data-imid');
- const file_id = $(this).attr('data-attid');
- postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
- stageIm.loadUpdateDetailAtt(result);
- SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
- self.makeAttTable(select);
- });
- });
- }
- _initImTypeSetRela() {
- const self = this;
- const gatherConfirmPopover = {
- reBind: function (obj, eventName, fun) {
- obj.unbind(eventName);
- obj.bind(eventName, fun);
- },
- check: function (pos, hint, okCallback) {
- const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
- const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
- this.reBind(cancelObj, 'click', function () {
- confirmObj.hide();
- });
- this.reBind(okObj, 'click', function () {
- okCallback();
- confirmObj.hide();
- });
- hintObj.text(hint);
- confirmObj.css("top", pos.y).css("left", pos.x).show();
- }
- };
- this.gsTree = stageIm.getGsTree();
- if (relaStage.im_type === imType.tz.value || relaStage.im_type === imType.bb.value) {
- const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
- jlCol.title = '本期计量金额';
- SpreadJsObj.reLoadSheetHeader(self.sheet);
- $('[name=type-title-contract]').text('本期合同计量金额');
- $('[name=type-title-qc]').text('本期变更计量金额');
- if ($('#show-qc-minus-jl').length > 0) {
- $('#show-qc-minus-jl').parent().hide();
- $('#qc-minus-jl').parent().hide();
- }
- } else {
- const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
- jlCol.title = '本期计量数量';
- SpreadJsObj.reLoadSheetHeader(self.sheet);
- $('[name=type-title-contract]').text('本期合同计量数量');
- $('[name=type-title-qc]').text('本期变更计量数量');
- if ($('#show-qc-minus-jl').length > 0) {
- $('#show-qc-minus-jl').parent().show();
- $('#qc-minus-jl').parent().show();
- }
- }
- if (relaStage.im_type === imType.bb.value || relaStage.im_type === imType.bw.value) {
- $('#show-jldy').parent().show();
- $('#jldy').parent().show();
- $('#show-xm-name').parent().hide();
- $('#xm-name').parent().hide();
- } else {
- $('#show-jldy').parent().hide();
- $('#jldy').parent().hide();
- $('#show-xm-name').parent().show();
- $('#xm-name').parent().show();
- }
- }
- _initLocateRela() {
- const self = this;
- $('#im-locate2bills').click(function () {
- const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
- const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
- if (select && select.source) {
- SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
- stagePosSpreadObj.loadCurPosData();
- }
- });
- $('#im-locate-pre').click(function () {
- const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
- const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
- if (select && select.source) {
- const targetIndex = Math.max(curIndex-1, 1);
- SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
- stagePosSpreadObj.loadCurPosData();
- $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
- }
- });
- $('#im-locate-next').click(function () {
- const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
- const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
- if (select && select.source) {
- const targetIndex = Math.min(curIndex+1, select.source.length);
- SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
- stagePosSpreadObj.loadCurPosData();
- $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
- }
- });
- }
- loadLocateInfo() {
- const select = SpreadJsObj.getSelectObject(this.sheet);
- if (select && select.source.length > 1) {
- $('#im-locate2bills').next().show();
- } else {
- $('#im-locate2bills').next().hide();
- }
- $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
- }
- reLoadDetailData() {
- const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
- $('#detail-show').show();
- const contractJl = data && data.contract_jl ? data.contract_jl : '';
- $('#show-contract-jl').text(contractJl);
- $('#contract-jl').val(contractJl);
- const qcJl = data && data.qc_jl ? data.qc_jl : '';
- $('#show-qc-jl').text(qcJl);
- $('#qc-jl').val(qcJl);
- const qcMinusJl = data && data.qc_minus_jl ? data.qc_minus_jl : '';
- $('#show-qc-minus-jl').text(qcMinusJl);
- $('#qc-jl-minus-jl').val(qcMinusJl);
- const bglCode = data && data.bgl_code ? data.bgl_code : '';
- $('#show-bgl-code').text(bglCode);
- $('#bgl-code').val(bglCode);
- const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
- $('#show-bgl-drawing-code').text(bglDrawingCode);
- $('#bgl-drawing-code').val(bglDrawingCode);
- const bwName = data && data.bw ? data.bw : '';
- $('#show-bw-name').text(bwName);
- $('#bw-name').val(bwName);
- const position = data && data.position ? data.position : '';
- $('#show-position').text(position);
- $('#position').val(position);
- const peg = data && data.peg ? data.peg : '';
- $('#show-peg').text(peg);
- $('#peg').val(peg);
- const xmName = data && data.xm ? data.xm: '';
- $('#show-xm-name').text(xmName);
- $('#xm-name').val(xmName);
- const jldy = data && data.jldy ? data.jldy: '';
- $('#show-jldy').text(jldy);
- $('#jldy').val(jldy);
- const drawingCode = data && data.drawing_code ? data.drawing_code: '';
- $('#show-drawing-code').text(drawingCode);
- $('#drawing-code').val(drawingCode);
- const calcMemo = data && data.calc_memo ? data.calc_memo: '';
- $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
- $('#calc-memo').val(calcMemo);
- const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
- $('#show-calc-img').attr('src', calcImgSrc);
- $('#calc-img').attr('src', calcImgSrc);
- $('#view-calc-img').attr('src', calcImgSrc);
- const calcImgRemark = data && data.calc_img_remark || '';
- $('#view-calc-remark').val(calcImgRemark);
- $("#view-calc-remark").attr('readonly', true);
- $('#text-edit').val(calcImgRemark)
- }
- reBuildImData() {
- const imData = stageIm.buildImData();
- SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
- this.reLoadDetailData();
- this.loadLocateInfo();
- }
- }
- // 展开收起附件
- $('a', '.right-nav').bind('click', function () {
- //const main = $('#main-view'), tool = $('#tools-view');
- const tab = $(this), tabPanel = $(tab.attr('content'));
- if (!tab.hasClass('active')) {
- $('a', '.side-menu').removeClass('active');
- $('.tab-content .tab-select-show').removeClass('active');
- tab.addClass('active');
- tabPanel.addClass('active');
- showSideTools(tab.hasClass('active'));
- if (tab.attr('content') === '#search' && !searchLedger) {
- searchLedger = $.billsSearch({
- selector: '#search',
- searchSpread: slSpread,
- searchOver: true,
- searchEmpty: true,
- resultSpreadSetting: {
- cols: [
- {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
- {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
- {title: '名称', field: 'name', width: 150, 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},
- {title: '部位', field: 'bw', hAlign: 2, width: 90},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- headColWidth: [30],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- },
- afterLocated: function () {
- stagePosSpreadObj.loadCurPosData();
- },
- customSearch: [
- {
- key: 'less', title: '漏计', valid: true,
- check: function (node) {
- if (node.quantity) {
- return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
- } else if (node.total_price) {
- return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
- }
- }
- }, {
- key: 'over', title: '超计', valid: true,
- check: function (node) {
- return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
- }
- }, {
- key: 'empty', title: '漏计', valid: false,
- check: function (node) {
- if (node.quantity) {
- return !node.end_gather_qty || checkZero(node.end_gather_qty);
- } else if (node.total_price) {
- return !node.end_gather_tp || checkZero(node.end_gather_tp);
- }
- }
- },
- ],
- });
- searchLedger.spread.refresh();
- }
- if (tab.attr('content') === '#fujian') {
- const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
- getNodeList(node.id);
- }
- if (tab.attr('content') === '#zhongjian') {
- if (!detail) {
- detail = new Detail($('#detail-spread'));
- detail.spread.refresh();
- $('#zhongjian .sjs-bottom').height('400px');
- $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
- } else {
- detail.spread.refresh();
- }
- }
- } else {
- tab.removeClass('active');
- tabPanel.removeClass('active');
- showSideTools(tab.hasClass('active'));
- }
- slSpread.refresh();
- spSpread.refresh();
- });
- // 切换附件里节点和所有附件
- $('#fujian .nav-link').on('click', function () {
- const tabPanel = $(this).attr('fujian-content');
- if (tabPanel !== 'syfujian') {
- $('#showPage').hide();
- $('#bach-download').prop('type', 'curr');
- } else {
- $('#showPage').show();
- $('#bach-download').prop('type', 'all')
- }
- $('#showAttachment').hide();
- });
- // 获取附件信息
- $('.list-table').on('click', '.att-file-name', 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);
- });
- $('#edit-att').hide();
- $('#show-att').show();
- if (att !== undefined) {
- // 进来先把编辑功能隐藏
- $('#btn-att a').eq(3).hide()
- $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
- const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
- $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
- $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
- $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
- $('#show-att tr').eq(3).children('td').text(att.remark);
- // 附件uid等于当前用户id, 附件上传本人
- if (parseInt(cur_uid) === att.uid) {
- $('#btn-att').show();
- $('#btn-att a').eq(2).hide();
- $('#btn-att a').eq(4).hide();
- $('#btn-att a').eq(5).hide();
- } else {
- $('#btn-att').hide();
- $('#btn-att a').eq(3).hide();
- $('#btn-att a').eq(2).hide();
- $('#btn-att a').eq(4).hide();
- $('#btn-att a').eq(5).hide();
- }
- $('#showAttachment').attr('file-id', fid);
- $('#showAttachment').show();
- } else {
- $('#showAttachment').hide();
- $('#showAttachment').attr('file-id', '');
- toastr.error('附件信息获取失败');
- }
- });
- // $('body').on('click', '.alllist-table a', handleFileList);
- $('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 === 'view') {
- const data = {id: fid};
- postData('/tender/' + relaTender.id + '/measure/stage/' + relaStage.order + '/check/file', data, function (result) {
- const { filepath } = result
- $('#load-file').attr('href', filepath);
- $('#load-file')[0].click();
- });
- } else if (content === 'location') {
- const att = attData.find(item => item.id === parseInt(fid));
- if (Object.keys(att).length) {
- SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
- stagePosSpreadObj.loadCurPosData();
- }
- }
- });
- // 切换页数
- $('.page-select').on('click', function () {
- const totalPageNum = parseInt($('#totalPage').text());
- const lastPageNum = parseInt($('#currentPage').text());
- const status = $(this).attr('content');
- if (status === 'pre' && lastPageNum > 1) {
- getAllList(lastPageNum-1);
- $('#showAttachment').hide();
- $('#syfujian .check-all-file').prop('checked', false)
- } else if (status === 'next' && lastPageNum < totalPageNum) {
- getAllList(lastPageNum+1);
- $('#showAttachment').hide();
- $('#syfujian .check-all-file').prop('checked', false)
- }
- });
- // 批量下载
- $('#bach-download').click(function() {
- const fileIds = [];
- const type = $(this).attr('type');
- let node = ''
- if (type === 'curr') {
- node = '#nodelist-table .check-file:checked'
- } else {
- node = '#alllist-table .check-file:checked'
- }
- $(node).each(function() {
- const fileId = $(this).attr('file-id');
- fileId && fileIds.push(fileId);
- });
- if (fileIds.length) {
- if (fileIds.length > 20) {
- return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
- }
- toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
- $(this).attr('disabled', "true")
- const btn = $(this);
- const fileArr = [];
- for (const id of fileIds) {
- const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
- fileArr.push({
- url: fileInfo.orginpath, //文件的oss存储路径 (必填)
- name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
- foldPath: '' // (可选, 文件在压缩包中的存储路径)
- });
- }
- const packageName = `${relaTender.name}-计量台账-第${relaStage.order}期-附件.zip`;
- try {
- zipOss.downloadFromAliOss(fileArr, packageName, btn);
- } catch (e) {
- btn.removeAttr('disabled');
- toastr.clear();
- toastr.error('批量下载失败');
- }
- // postCompressFile(`/tender/${relaTender.id}/measure/stage/${relaStage.order}/download/compresse-file`, {fileIds}, function(result) {
- // toastr.clear()
- // toastr.success('压缩文件成功')
- // btn.removeAttr('disabled')
- // const href = window.URL.createObjectURL(result)
- // $('#zipDown').attr('href', href);
- // $('#zipDown').attr('download', `${relaTender.name}-计量台账-第${relaStage.order}期-附件.zip`);
- // $("#zipDown")[0].click();
- // }, () => {
- // btn.removeAttr('disabled')
- // toastr.clear()
- // toastr.error('批量下载失败')
- // });
- }
- });
- // 监听附件check是否选中
- $('.list-table').on('click', '.check-file', function() {
- const checkedList = $(this).parents('.list-table').children().find('input:checked');
- const childs = $(this).parents('.list-table').children().length;
- const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
- if (checkedList.length === childs) {
- checkBox.prop("checked", true);
- } else {
- checkBox.prop("checked", false);
- }
- });
- $('.check-all-file').click(function() {
- const isCheck = $(this).is(':checked');
- $(this).parents('table').find('.list-table').each(function() {
- $(this).find('input:checkbox').prop("checked", isCheck);
- })
- });
- // 显示层次
- (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":
- case "5":
- tree.expandByLevel(parseInt(tag));
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "last":
- tree.expandByCustom(() => { return true; });
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "leafXmj":
- tree.expandToLeafXmj();
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "curMeasure":
- tree.expandByCustom(function (node) {
- for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
- if (node[field]) {
- return true;
- }
- }
- return false;
- });
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- }
- closeWaitingView();
- }, 100);
- });
- })('a[name=showLevel]', slSpread.getActiveSheet());
- });
|