| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345 | '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({        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},                            {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());});
 |