123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347 |
- '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_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.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({
- 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;change;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(relaStage, imType, tenderInfo.decimal);
- stageIm.loadData4Rela(result.ledgerData, result.posData, result.detailData, result.changeData, 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},
- ],
- 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());
- });
|