1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849 |
- 'use strict';
- /**
- * cs_errorList:错误列表
- * 使用范围:
- * 台账分解(原报)、台账修订(原报)、计量台账(所有角色)
- *
- * posSearch & billsSearch:台账搜索相关
- * 使用范围:
- * 0号台账:台账分解、台账审批、台账修订、部位台账;
- * 期计量:计量台账、部位台账
- *
- * 所有工具均基于spreadjs,请放在gc.spread.sheets.all.10.0.1.min.js/spreadjs_zh.js之后
- *
- * @author Mai
- * @date
- * @version
- */
- const showSideTools = function (show) {
- const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
- if (show) {
- right.show();
- autoFlashHeight();
- /**
- * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
- * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
- * 故需要通过最终的parent.width再计算一次left.width
- *
- * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
- * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
- *
- */
- //left.css('width', parent.width() - right.outerWidth());
- //left.css('width', parent.width() - right.outerWidth());
- const percent = 100 - right.outerWidth() /parent.width() * 100;
- left.css('width', percent + '%');
- } else {
- left.width(parent.width());
- right.hide();
- }
- };
- const showSelectTab = function(select, spread, afterShow) {
- const tab = $(select), tabPanel = $(tab.attr('content'));
- $('a', '.side-menu').removeClass('active');
- tab.addClass('active');
- $('.tab-content .tab-pane').removeClass('active');
- tabPanel.addClass('active');
- showSideTools(true);
- spread && spread.refresh();
- if (afterShow) afterShow();
- };
- (function($){
- /**
- * 错误列表
- * @param setting
- * {
- * tabSelector: 'a[content=#error-list]',
- * selector: '#error-list',
- * relaSpread: ledgerSpread,
- * storeKey: 'ledger-error-' + tenderId,
- * }
- * @returns {{spread: *}}
- */
- $.cs_errorList = function (setting) {
- if (!setting.spreadSetting) {
- setting.spreadSetting = {
- cols: [
- {title: '行号', field: 'serialNo', width: 50, formatter: '@', hAlign: 1},
- {
- title: '错误类型', field: 'errorType', width: 85, formatter: '@',
- getValue: function (x) {
- switch (x.errorType) {
- case 'gather': return '汇总错误';
- case 'qty': return '数量';
- case 'tp': return '金额';
- case 'over': return '超计';
- case 'sibling': return '项目节清单同层';
- case 'same_code': return '重复项目节编号';
- case 's2b_over_gxby': return '违规计量(工序报验)';
- case 's2b_over_dagl': return '违规计量(档案管理)';
- case 's2b_lost_gxby': return '遗漏计量(工序报验)';
- case 's2b_lost_dagl': return '遗漏计量(档案管理)';
- case 'minus_cb': return '负变更清单漏计';
- case 'change_over': return '变更令超计';
- case 'settle': return '结算清单';
- default: return '';
- }
- }
- },
- {title: '清单编号', field: 'b_code', width: 85, formatter: '@'},
- {title: '清单名称', field: 'name', width: 165, formatter: '@'},
- {title: '备注', field: 'memo', width: 100, formatter: '@'},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- readOnly: true,
- };
- }
- const clearErrorData = function () {
- if (setting.storeKey) removeLocalCache(setting.storeKey);
- };
- const autoShowHistory = function (show) {
- if (setting.storeKey) {
- setLocalCache(setting.storeKey + '-showHis', show.toString());
- }
- };
- if (setting.selector && setting.relaSpread) {
- const resultId = setting.id + '-spread';
- const obj = $(setting.selector);
- obj.html(
- ' <div id="' + resultId + '" class="sjs-sh">\n' +
- ' </div>'
- );
- autoFlashHeight();
- const spread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
- const sheet = spread.getActiveSheet();
- SpreadJsObj.initSheet(sheet, setting.spreadSetting);
- spread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
- const sheet = info.sheet;
- const data = sheet.zh_data;
- if (!data) { return }
- const curBills = data[info.row];
- if (!curBills) { return }
- SpreadJsObj.locateTreeNode(setting.relaSpread.getActiveSheet(), curBills.ledger_id, true);
- if (setting.afterLocated) {
- setting.afterLocated();
- }
- });
- const loadErrorData = function (data, his = false) {
- const sourceTree = setting.relaSpread.getActiveSheet().zh_tree;
- if (!sourceTree) return;
- for (const d of data) {
- if (d.ledger_id) {
- d.serialNo = sourceTree.getNodeIndex(sourceTree.getItems(d.ledger_id)) + 1;
- } else if (d.lid) {
- const nodeIndex = sourceTree.nodes.findIndex(x => { return x.id === d.lid });
- if (nodeIndex >= 0) {
- d.serialNo = nodeIndex + 1;
- d.ledger_id = sourceTree.nodes[nodeIndex].ledger_id;
- }
- }
- }
- data.sort(function (a, b) {
- return a.serialNo ? (b.serialNo ? a.serialNo - b.serialNo : 1) : 1;
- });
- SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, data);
- if (!his && setting.storeKey) {
- setLocalCache(setting.storeKey, JSON.stringify(data));
- }
- $(setting.tabSelector).show();
- };
- const showErrorList = function () {
- const tab = $(setting.tabSelector), tabPanel = $(tab.attr('content'));
- $('a', '.side-menu').removeClass('active');
- tab.addClass('active');
- $('.tab-content .tab-pane').removeClass('active');
- tabPanel.addClass('active');
- showSideTools(true);
- spread.refresh();
- if (setting.afterShow) setting.afterShow();
- };
- const loadHisErrorData = function () {
- if (setting.storeKey) {
- const storeStr = getLocalCache(setting.storeKey);
- const storeData = storeStr ? JSON.parse(storeStr) : [];
- if (storeData.length > 0) {
- loadErrorData(storeData, true);
- const showHis = getLocalCache(setting.storeKey + '-showHis');
- if (showHis === 'true') {
- showErrorList();
- removeLocalCache(setting.storeKey + '-showHis');
- }
- }
- }
- };
- return {
- spread: spread,
- loadErrorData: loadErrorData,
- clearErrorData: clearErrorData,
- loadHisErrorData: loadHisErrorData,
- show: showErrorList,
- autoShowHistory: autoShowHistory,
- };
- } else {
- const loadErrorData = function (data) {
- if (setting.storeKey) {
- setLocalCache(setting.storeKey, JSON.stringify(data));
- }
- };
- return {
- loadErrorData: loadErrorData,
- clearErrorData: clearErrorData,
- autoShowHistory: autoShowHistory,
- };
- }
- };
- $.ledger_checkList = function (setting) {
- const checkTypeText = [];
- for (const ct in setting.checkType) {
- checkTypeText[setting.checkType[ct].value] = setting.checkType[ct].text;
- }
- if (!setting.spreadSetting) {
- setting.spreadSetting = {
- cols: [
- {
- title: '类型', field: 'type', width: 150, formatter: '@',
- getValue: function (data){
- if (setting.checkType) {
- return checkTypeText[data.type] || '';
- } else {
- return '';
- }
- }
- },
- {title: '行号', field: 'serialNo', hAlign: 1, width: 40, formatter: '@'},
- {title: '项目节编号\n(变更令号)', field: 'code', width: 80, formatter: '@'},
- {title: '清单编号', field: 'b_code', width: 80, formatter: '@'},
- {title: '名称', field: 'name', width: 150, formatter: '@'},
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- readOnly: true,
- };
- }
- const clearCheckData = function () {
- if (setting.storeKey) removeLocalCache(setting.storeKey);
- };
- const autoShowHistory = function (show) {
- if (setting.storeKey) {
- setLocalCache(setting.storeKey + '-showHis', show.toString());
- }
- };
- if (setting.selector && setting.relaSpread) {
- const resultId = setting.id + '-spread';
- const obj = $(setting.selector);
- const dropdown = [];
- if (setting.checkType) {
- dropdown.push('<div class="dropdown">');
- dropdown.push('<button class="btn btn-sm btn-outline-primary dropdown-toggle" type="button" id="'+ setting.id + 'drop" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">所有类型</button>');
- dropdown.push('<div class="dropdown-menu" aria-labelledby="'+ setting.id + 'drop">');
- dropdown.push('<a class="dropdown-item" href="javascript: void(0);" check-type="all">所有类型</a>');
- for (const ct in setting.checkType) {
- dropdown.push('<a class="dropdown-item" href="javascript: void(0);" check-type="' + setting.checkType[ct].value +'">' + setting.checkType[ct].text + '</a>');
- }
- dropdown.push('</div>');
- dropdown.push('</div>');
- }
- obj.html(
- '<div class="sjs-bar">\n' +
- ' <div class="pb-1 d-flex">\n' + dropdown.join('') +
- ' <span class="ml-auto pr-2" id="' + setting.id + '-time">检查时间:2020-08-01 13:20:25</span>\n' +
- ' </div>\n' +
- '</div>' +
- '<div id="' + resultId + '" class="sjs-sh">\n' +
- '</div>'
- );
- autoFlashHeight();
- const spread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
- const sheet = spread.getActiveSheet();
- SpreadJsObj.initSheet(sheet, setting.spreadSetting);
- spread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
- const sheet = info.sheet;
- const data = sheet.zh_data;
- if (!data) { return }
- const curBills = data[info.row];
- if (!curBills) { return }
- SpreadJsObj.locateTreeNode(setting.relaSpread.getActiveSheet(), curBills.ledger_id, true);
- if (setting.afterLocated) {
- setting.afterLocated();
- }
- });
- const filterCheckData = function () {
- const filter = $(this).attr('check-type');
- $('#' + setting.id + 'drop').html(this.innerHTML);
- for (const d of sheet.zh_data) {
- if (filter === 'all') {
- d.visible = true;
- } else {
- d.visible = d.type == filter;
- }
- }
- SpreadJsObj.refreshTreeRowVisible(sheet);
- };
- $('a[check-type]').bind('click', filterCheckData);
- const hideCheckData = function () {
- const tab = $(setting.tabSelector), tabPanel = $(tab.attr('content'));
- if (tab.hasClass('active')) {
- $('a', '.side-menu').removeClass('active');
- tab.addClass('active');
- $('.tab-content .tab-pane').removeClass('active');
- tabPanel.addClass('active');
- showSideTools(false);
- if (spread) spread.refresh();
- if (setting.afterShow) setting.afterShow();
- tab.hide();
- }
- };
- const loadCheckData = function (data, his = false) {
- const sourceTree = setting.relaSpread.getActiveSheet().zh_tree;
- if (!sourceTree) return;
- for (const d of data.warning_data) {
- if (d.ledger_id) {
- d.serialNo = sourceTree.getNodeIndex(sourceTree.getItems(d.ledger_id)) + 1;
- } else if (d.lid) {
- const nodeIndex = sourceTree.nodes.findIndex(x => { return x.id === d.lid });
- if (nodeIndex >= 0) {
- d.serialNo = nodeIndex + 1;
- d.ledger_id = sourceTree.nodes[nodeIndex].ledger_id;
- }
- }
- }
- $('#' + setting.id + '-time').html('检查时间:' + moment(data.check_time).format('YYYY-MM-DD HH:mm:ss'));
- SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, data.warning_data);
- if (!his && setting.storeKey) {
- setLocalCache(setting.storeKey, JSON.stringify(data));
- }
- $(setting.tabSelector).show();
- };
- const showCheckList = function () {
- const tab = $(setting.tabSelector), tabPanel = $(tab.attr('content'));
- $('a', '.side-menu').removeClass('active');
- tab.addClass('active');
- $('.tab-content .tab-pane').removeClass('active');
- tabPanel.addClass('active');
- showSideTools(true);
- spread.refresh();
- if (setting.afterShow) setting.afterShow();
- };
- const loadHisCheckData = function () {
- if (setting.storeKey) {
- const storeStr = getLocalCache(setting.storeKey);
- const storeData = storeStr ? JSON.parse(storeStr) : null;
- if (storeData) {
- loadCheckData(storeData, true);
- const showHis = getLocalCache(setting.storeKey + '-showHis');
- if (showHis === 'true') {
- showCheckList();
- removeLocalCache(setting.storeKey + '-showHis');
- }
- }
- }
- };
- return {
- spread: spread,
- loadCheckData: loadCheckData,
- clearCheckData: clearCheckData,
- loadHisCheckData: loadHisCheckData,
- show: showCheckList,
- hide: hideCheckData,
- autoShowHistory: autoShowHistory,
- };
- } else {
- const loadCheckData = function (data) {
- if (setting.storeKey) {
- setLocalCache(setting.storeKey, JSON.stringify(data));
- }
- };
- return {
- loadCheckData: loadCheckData,
- clearCheckData: clearCheckData,
- autoShowHistory: autoShowHistory,
- };
- }
- };
- $.posSearch = function (setting) {
- if (!setting.selector || !setting.searchSpread) return;
- const searchHtml =
- ' <div class="ml-2">\n' +
- ' <div class="input-group input-group-sm">\n' +
- ' <input type="text" class="form-control" placeholder="输入名称查找" id="pos-keyword">\n' +
- ' <div class="input-group-append">\n' +
- ' <span class="input-group-text" id="pos-search-hint">结果:0</span>\n' +
- ' </div>\n' +
- ' <div class="input-group-append" >\n' +
- ' <button class="btn btn-outline-secondary" type="button" title="上一个" id="search-pre-pos"><i class="fa fa-angle-double-left"></i></button>\n' +
- ' <button class="btn btn-outline-secondary" type="button" title="下一个" id="search-next-pos"><i class="fa fa-angle-double-right"></i></button>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>\n';
- $(setting.selector).html(searchHtml);
- const sheet = setting.searchSpread.getActiveSheet();
- const searchObj = (function () {
- let resultArr = [];
- const search = function (keyword) {
- if (keyword && keyword !== '') {
- resultArr = [];
- const sortData = sheet.zh_data;
- 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});
- }
- }
- }
- } else {
- resultArr = [];
- }
- $('#pos-search-hint').html('结果:' + resultArr.length);
- };
- const searchAndLocate = function (keyword) {
- search(keyword);
- if (resultArr.length > 0) {
- 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.getParent().focus();
- sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
- SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
- }
- }
- };
- const locateNext = function () {
- if (resultArr.length > 0) {
- 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.getParent().focus();
- sheet.showRow(next.index, spreadNS.VerticalPosition.center);
- SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
- }
- }
- };
- const locatePre = function () {
- if (resultArr.length > 0) {
- 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.getParent().focus();
- sheet.showRow(next.index, spreadNS.VerticalPosition.center);
- SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
- }
- }
- };
- return {search, searchAndLocate, locateNext, locatePre};
- })();
- // $('#pos-keyword').bind('input propertychange', function () {
- // posSearch.search(this.value);
- // });
- $('#pos-keyword').bind('keydown', function(e){
- if (e.keyCode == 13) searchObj.searchAndLocate(this.value);
- });
- $('#search-pre-pos').click(function () {
- searchObj.locatePre();
- });
- $('#search-next-pos').click(function () {
- searchObj.locateNext();
- });
- return searchObj;
- };
- $.billsSearch = function (setting) {
- if (!setting.selector || !setting.searchSpread || !setting.resultSpreadSetting) return;
- if (!setting.searchRangeStr) setting.searchRangeStr = '项目节编号/清单编号/名称/台账数量';
- if (!setting.keyId) setting.keyId = 'ledger_id';
- const resultId = setting.id + '-search-result';
- const obj = $(setting.selector);
- let filter = [];
- if (setting.searchOver || setting.searchEmpty) {
- filter.push('<select class="input-group-text" id="search-filter">');
- filter.push('<option value="">台账</option>');
- if (setting.customSearch) {
- for (const cs of setting.customSearch) {
- if (cs.valid) filter.push('<option value="' + cs.key + '">' + cs.title + '</option>');
- }
- }
- filter.push('</select>');
- }
- obj.html(
- ' <div class="sjs-bar">\n' +
- ' <div class="input-group input-group-sm pb-1">\n' +
- ' <div class="input-group-prepend">\n' +
- filter.join('') +
- ' </div>' +
- ' <input id="searchKeyword" type="text" class="form-control" autocomplete="off" placeholder="可查找 ' + setting.searchRangeStr + '" aria-label="Recipient\'s username" aria-describedby="button-addon2">\n' +
- ' <div class="input-group-append">\n' +
- ' <button class="btn btn-outline-secondary" type="button"">搜索</button>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ' <div id="' + resultId + '" class="sjs-sh">\n' +
- ' </div>'
- );
- autoFlashHeight();
- const resultSpread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
- SpreadJsObj.initSheet(resultSpread.getActiveSheet(), setting.resultSpreadSetting);
- const searchSheet = setting.searchSpread.getActiveSheet();
- let searchResult = [];
- const search = function () {
- const filter = $('#search-filter').val();
- if (filter) {
- searchCustom(filter);
- } else {
- searchBills();
- }
- };
- const get18Bw = function(tree, data) {
- let parent = tree.getParent(data);
- while (parent && (!parent.code || /^[a-zA-Z]/.test(parent.code || ''))) {
- parent = tree.getParent(parent);
- }
- return parent ? parent.name : '';
- };
- const get08Bw = function(tree, data) {
- let parent = tree.getParent(data);
- let lastXmj = '', level4Xmj = '';
- while (parent) {
- if (parent.code && !lastXmj) lastXmj = parent.name;
- if (parent.code && parent.level === 4) level4Xmj = parent.name;
- parent = tree.getParent(parent);
- }
- return level4Xmj || lastXmj;
- };
- const getBw = function (data) {
- if (!data.b_code) return '';
- if (searchSheet.zh_dataType !== SpreadJsObj.DataType.Tree) return '';
- const sortTree = searchSheet.zh_tree;
- if (!sortTree.checkCodeType) return '';
- if (sortTree.checkCodeType() === '18') {
- return get18Bw(sortTree, data)
- } else {
- return get08Bw(sortTree, data);
- }
- };
- const searchBills = function () {
- const keyword = $('#searchKeyword', obj).val();
- const keyNum = _.toNumber(keyword);
- searchResult = [];
- const sortData = SpreadJsObj.getSortData(searchSheet);
- for (const node of sortData) {
- if (node.filter) continue;
- if ((node.code && node.code.indexOf(keyword) > -1) ||
- (node.b_code && node.b_code.indexOf(keyword) > -1) ||
- (node.name && node.name.indexOf(keyword) > -1) ||
- (!_.isNaN(keyNum) && checkZero(ZhCalc.sub(keyNum, node.quantity)))
- ) {
- const data = JSON.parse(JSON.stringify(node));
- data.visible = true;
- data.bw = getBw(data);
- searchResult.push(data);
- }
- }
- calculateCompletePercent(searchResult);
- calculateSum();
- SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
- };
- const getCheckFun = function (key) {
- const cs = setting.customSearch.find(function (x) {return x.key === key});
- return cs ? cs.check : null;
- };
- const getParentFun = function (key) {
- const cs = setting.customSearch.find(function (x) {return x.key === key});
- return cs && cs.parent !== undefined ? cs.parent : false;
- };
- const searchCustom = function (key) {
- const keyword = $('#searchKeyword', obj).val();
- const keyNum = _.toNumber(keyword);
- const checkFun = getCheckFun(key);
- searchResult = [];
- const sortData = SpreadJsObj.getSortData(searchSheet);
- const parentFun = getParentFun(key);
- for (const node of sortData) {
- if (node.children && node.children.length > 0 && !parentFun) continue;
- if (checkFun && checkFun(node)) {
- if (!keyword ||
- (node.code && node.code.indexOf(keyword) > -1) ||
- (node.b_code && node.b_code.indexOf(keyword) > -1) ||
- (node.name && node.name.indexOf(keyword) > -1) ||
- (!_.isNaN(keyNum) && checkZero(ZhCalc.sub(keyNum, node.quantity)))
- ) {
- const data = JSON.parse(JSON.stringify(node));
- data.visible = true;
- searchResult.push(data);
- }
- }
- }
- calculateCompletePercent(searchResult);
- calculateSum();
- SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
- };
- const calculateSum = function () {
- if (!searchResult || searchResult.length === 0 || !setting.calcSum) return;
- const sum = setting.calcSum(searchResult);
- if (sum) searchResult.unshift(sum);
- };
- const calculateCompletePercent = function (searchResult) {
- if (!searchResult) return;
- for (const sr of searchResult) {
- const base = ZhCalc.add(sr.total_price, sr.end_qc_tp);
- sr.complete_percent = base !== 0 ? ZhCalc.mul(ZhCalc.div(sr.end_gather_tp, base), 100, 2) : 0;
- }
- };
- $('input', obj).bind('keydown', function (e) {
- if (e.keyCode == 13) search();
- });
- $('button', obj).bind('click', () => {search()});
- resultSpread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
- const sheet = info.sheet;
- const data = sheet.zh_data;
- if (!data) { return }
- const curBills = data[info.row];
- if (!curBills || curBills[setting.keyId] === undefined) { return }
- SpreadJsObj.locateTreeNode(searchSheet, curBills[setting.keyId], true);
- if (setting.afterLocated) {
- setting.afterLocated();
- }
- });
- return {spread: resultSpread};
- };
- $.listSearch = function (setting) {
- if (!setting.selector || !setting.searchSpread || !setting.resultSpreadSetting) return;
- if (!setting.searchRangeStr) setting.searchRangeStr = '清单编号/名称';
- const resultId = setting.id + '-search-result';
- const obj = $(setting.selector);
- let filter = [];
- if (setting.searchOver || setting.searchEmpty) {
- filter.push('<select class="input-group-text" id="search-filter">');
- filter.push('<option value="">台账</option>');
- if (setting.customSearch) {
- for (const cs of setting.customSearch) {
- if (cs.valid) filter.push('<option value="' + cs.key + '">' + cs.title + '</option>');
- }
- }
- filter.push('</select>');
- }
- obj.html(
- ' <div class="sjs-bar">\n' +
- ' <div class="input-group input-group-sm pb-1">\n' +
- ' <div class="input-group-prepend">\n' +
- filter.join('') +
- ' </div>' +
- ' <input id="searchKeyword" type="text" class="form-control" autocomplete="off" placeholder="可查找 ' + setting.searchRangeStr + '" aria-label="Recipient\'s username" aria-describedby="button-addon2">\n' +
- ' <div class="input-group-append">\n' +
- ' <button class="btn btn-outline-secondary" type="button"">搜索</button>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ' <div id="' + resultId + '" class="sjs-sh">\n' +
- ' </div>'
- );
- autoFlashHeight();
- const resultSpread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
- SpreadJsObj.initSheet(resultSpread.getActiveSheet(), setting.resultSpreadSetting);
- const searchSheet = setting.searchSpread.getActiveSheet();
- let searchResult = [];
- const search = function () {
- const filter = $('#search-filter').val();
- if (filter) {
- searchCustom(filter);
- } else {
- searchList();
- }
- };
- const calulateSum = function () {
- if (searchResult.length === 0 || !setting.calcSum) return;
- searchResult.unshift(setting.calcSum(searchResult));
- };
- const searchList = function () {
- const keyword = $('#searchKeyword', obj).val();
- searchResult = [];
- const sortData = SpreadJsObj.getSortData(searchSheet);
- for (const [i, node] of sortData.entries()) {
- if (setting.check(node, keyword)) {
- const data = JSON.parse(JSON.stringify(node));
- data.searchIndex = i;
- data.visible = true;
- searchResult.push(data);
- }
- }
- calulateSum();
- SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
- };
- const getCheckFun = function (key) {
- const cs = setting.customSearch.find(function (x) {return x.key === key});
- return cs ? cs.check : null;
- };
- const searchCustom = function (key) {
- const keyword = $('#searchKeyword', obj).val();
- const checkFun = getCheckFun(key);
- searchResult = [];
- const sortData = SpreadJsObj.getSortData(searchSheet);
- for (const [i, node] of sortData.entries()) {
- if (checkFun && checkFun(node)) {
- if (setting.check(node, keyword)) {
- const data = JSON.parse(JSON.stringify(node));
- data.searchIndex = i;
- data.visible = true;
- searchResult.push(data);
- }
- }
- }
- calulateSum();
- SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
- };
- $('input', obj).bind('keydown', function (e) {
- if (e.keyCode == 13) search();
- });
- $('button', obj).bind('click', () => {search()});
- resultSpread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
- const cur = SpreadJsObj.getSelectObject(info.sheet);
- if (!cur || cur.searchIndex < 0) return;
- SpreadJsObj.locateRow(searchSheet, cur.searchIndex);
- if (setting.afterLocated) {
- setting.afterLocated();
- }
- });
- return {spread: resultSpread};
- };
- $.xmjSearch = function (setting) {
- if (!setting.selector || !setting.searchSpread) return;
- if (!setting.searchRangeStr) setting.searchRangeStr = '输入项目节编号、细目、计量单元查找';
- const searchHtml =
- ' <div class="ml-2">\n' +
- ' <div class="input-group input-group-sm">\n' +
- ' <input type="text" class="form-control" placeholder="'+ setting.searchRangeStr +'" id="xmj-keyword">\n' +
- ' <div class="input-group-append">\n' +
- ' <span class="input-group-text" id="xmj-search-hint">结果:0</span>\n' +
- ' </div>\n' +
- ' <div class="input-group-append" >\n' +
- ' <button class="btn btn-outline-secondary" type="button" title="上一个" id="search-pre-xmj"><i class="fa fa-angle-double-left"></i></button>\n' +
- ' <button class="btn btn-outline-secondary" type="button" title="下一个" id="search-next-xmj"><i class="fa fa-angle-double-right"></i></button>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>\n';
- $(setting.selector).html(searchHtml);
- const sheet = setting.searchSpread.getActiveSheet();
- const searchObj = (function () {
- let resultArr = [];
- const search = function (keyword) {
- if (keyword && keyword !== '') {
- resultArr = [];
- const sortData = sheet.zh_data;
- if (sortData) {
- for (let i = 0, iLength = sortData.length; i < iLength; i++) {
- const sd = sortData[i];
- if ((sd.jldy && sd.jldy.indexOf(keyword) > -1) || (sd.code && sd.code.indexOf(keyword) > -1) || (sd.bwmx && sd.bwmx.indexOf(keyword) > -1)) {
- resultArr.push({index: i, data: sd});
- }
- }
- }
- } else {
- resultArr = [];
- }
- $('#xmj-search-hint').html('结果:' + resultArr.length);
- };
- const searchAndLocate = function (keyword) {
- search(keyword);
- const sel = sheet.getSelections()[0];
- const curRow = sel ? sel.row : 0;
- sheet.setSelection(0, sel ? sel.col : 0, 1, 1);
- SpreadJsObj.reloadRowsBackColor(sheet, [0, curRow]);
- if (resultArr.length > 0) {
- const pos = resultArr[0];
- if (pos.index !== curRow) {
- sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
- sheet.getParent().focus();
- sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
- SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
- }
- }
- };
- const locateNext = function () {
- if (resultArr.length > 0) {
- 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.getParent().focus();
- sheet.showRow(next.index, spreadNS.VerticalPosition.center);
- SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
- }
- }
- };
- const locatePre = function () {
- if (resultArr.length > 0) {
- 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.getParent().focus();
- sheet.showRow(next.index, spreadNS.VerticalPosition.center);
- SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
- }
- }
- };
- return {search, searchAndLocate, locateNext, locatePre};
- })();
- // $('#pos-keyword').bind('input propertychange', function () {
- // posSearch.search(this.value);
- // });
- $('#xmj-keyword').bind('keydown', function(e){
- if (e.keyCode == 13) searchObj.searchAndLocate(this.value);
- });
- $('#search-pre-xmj').click(function () {
- searchObj.locatePre();
- });
- $('#search-next-xmj').click(function () {
- searchObj.locateNext();
- });
- return searchObj;
- };
- $.billsTag = function (setting) {
- if (!setting.selector || !setting.relaSpread) return;
- if (!setting.tagType) setting.tagType = [
- {tagClass: 'text-primary', color: '#007bff'},
- {tagClass: 'text-success', color: '#28a745'},
- {tagClass: 'text-danger', color: '#dc3545'},
- {tagClass: 'text-warning', color: '#da9500'},
- {tagClass: 'text-info', color: '#17a2b8'},
- ];
- if (!setting.key) setting.key = 'id';
- if (!setting.treeId) setting.treeId = 'ledger_id';
- const obj = $(setting.selector);
- const relaTree = setting.relaTree;
- const html = [], pageLength = 15;
- let billsTags = [], classIndexes = [], billsIndexes = {}, curShow = [];
- html.push('<div class="sjs-bar d-flex justify-content-between">');
- // 下拉过滤
- html.push('<div class="dropdown mr-2">');
- html.push('<a class="btn btn-sm btn-outline-secondary" id="dmb-bills-tag" data-toggle="dropdown" title="优先显示" aria-expanded="false"><i class="fa fa-list-ol" id="bills-tag-filter"></i></a>');
- html.push('<div class="dropdown-menu" aria-labelledby="dmb-bills-tag" style="min-width: 60px; position: absolute; transform: translate3d(0px, 22px, 0px); top: 0px; left: 0px; will-change: transform;" x-placement="bottom-start">');
- html.push('<a class="dropdown-item" href="javascript: void(0);" tagType="all" ><i class="fa fa-list-ol"></i></a>');
- for (const t of setting.tagType) {
- html.push(`<a class="dropdown-item ${t.tagClass}" href="javascript: void(0);" tagType="${t.tagClass}" ><i class="fa fa-tag"></i></a>`);
- t.tags = [];
- classIndexes.push(t);
- }
- html.push('</div>', '</div>');
- // 搜索框
- html.push('<div class="input-group input-group-sm">');
- html.push('<input type="text" class="form-control" placeholder="可查找 项目节编号 / 清单编号 /名称" id="bills-tag-keyword" autocomplete="off">');
- html.push('<div class="input-group-append">', '<div class="input-group-cancel">',
- '<a href="javascript: void(0);" id="bills-tag-clear" class="text-danger"><i class="fa fa-times-circle" title="移除搜索结果"></i></a>', '</div>',
- '<button class="btn btn-outline-secondary" type="button" id="bills-tag-search">搜索</button>', '</div>');
- html.push('</div>');
- html.push('</div>');
- // 书签列表
- html.push('<div class="sjs-sh" style="overflow: auto;" id="bills-tag-list"></div>');
- obj.html(html.join(''));
- const clearViewTags = function () {
- const viewTags = $('.tag-item', obj);
- if (viewTags && viewTags.length > 0) viewTags.remove();
- billsTags.forEach(x => {x.display = false});
- };
- const getTagEditHtml = function(tag) {
- const tagClass = classIndexes.find(x => {return x.color === tag.color}) || {};
- const tagHtml = [];
- tagHtml.push('<div name="tag-edit">');
- tagHtml.push('<div class="card-header p-2"><div class="dropdown">');
- tagHtml.push(`<a class="pull-left mr-2" href="javascript: void(0);" id="tag-change-color" tag-color="${tag.color}" data-toggle="dropdown" aria-expanded="false"><i class="fa fa-tag ${tagClass.tagClass}" title="修改书签颜色"></i></a>`);
- // 下拉选择颜色
- tagHtml.push('<div class="dropdown-menu" aria-labelledby="tag-change-color" style="min-width:60px">',
- '<a class="dropdown-item text-primary" href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>',
- '<a class="dropdown-item text-success " href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>',
- '<a class="dropdown-item text-danger " href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>',
- '<a class="dropdown-item text-warning " href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>',
- '<a class="dropdown-item text-info " href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>', '</div>');
- tagHtml.push('</div>');
- if (tag.node) {
- const posHint = tag.pos ? ' - ' + tag.pos.name : '';
- tagHtml.push((tag.node.code || '') + (tag.node.b_code || ''), ' / ', tag.node.name || '', posHint);
- }
- tagHtml.push('</div>');
- tagHtml.push('<div class="card-body p-2">');
- tagHtml.push('<p class="card-text">', '<textarea class="form-control form-control-sm p-1" id="tag-comment">', tag.comment, '</textarea>', '</p>');
- tagHtml.push('<div class="d-flex justify-content-between">');
- // 参与人可见
- tagHtml.push('<div class="custom-control custom-switch mr-2">');
- tagHtml.push('<input type="checkbox" class="custom-control-input custom-control-warning-input" id="tag-share"', tag.share ? 'checked' : '', '>');
- tagHtml.push('<label class="custom-control-label custom-control-warning-label" for="tag-share" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="所有参与台账审批管理的用户都可以看到这条书签"><i class="fa fa-users"></i> 参与者可见</label>');
- tagHtml.push('</div>');
- // 编辑按钮
- tagHtml.push('<div>', '<button type="button" class="btn btn-sm btn-outline-danger mr-3" id="tag-del"><i class="fa fa-close"></i> 删除书签</button>',
- '<button type="button" class="btn btn-sm btn-outline-success mr-1" id="tag-edit-ok"><i class="fa fa-check"></i> 确定</button>',
- '<button type="button" class="btn btn-sm btn-outline-secondary" id="tag-edit-cancel">取消</button>', '</div>');
- tagHtml.push('</div>');
- tagHtml.push('</div>');
- tagHtml.push('</div>');
- return tagHtml.join('');
- };
- const getTagDisplayHtml = function (tag) {
- const tagClass = classIndexes.find(x => {return x.color === tag.color}) || {};
- const tagHtml = [];
- const hidden = tag.node.filter ? 'style="display: none;"' : '';
- tagHtml.push(`<div name="tag-view" ${hidden}>`);
- tagHtml.push('<div class="card-header p-2"><div class="dropdown">');
- tagHtml.push(`<div class="pull-left mr-2"><i class="fa fa-tag ${tagClass.tagClass}"></i></div>`);
- tagHtml.push('</div>');
- if (tag.node) {
- const posHint = tag.pos ? ' - ' + tag.pos.name : '';
- tagHtml.push((tag.node.code || '') + (tag.node.b_code || ''), ' / ', tag.node.name || '', posHint);
- }
- if (tag.share) {
- tagHtml.push(`<div class="pull-right"><i class="fa fa-users text-warning" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="所有参与台账审批管理的用户都可以看到这条书签"></i> <span>${tag.u_name}</span></div>`);
- }
- tagHtml.push('<div class="pull-right edit-tag-btn">');
- const lid = tag.node ? tag.node[setting.treeId] : -1;
- tagHtml.push(`<a class="mr-1" name="bills-tag-locate" href="javascript: void(0);" lid="${lid}" pos_id="${tag.pos_id}"><i class="fa fa-crosshairs"></i> 定位</a>`);
- if (tag.uid === userID && !setting.readOnly) tagHtml.push(`<a href="javascript: void(0);" name="bills-tag-edit" tag-id="${tag.id}"><i class="fa fa-edit"></i> 编辑</a>`);
- tagHtml.push('</div>');
- if (tag.node && relaTree) {
- const parents = relaTree.getAllParents(tag.node);
- const parentName = [];
- parents.forEach(p => { if (p.code && p.level > 1) parentName.push(p.name); });
- if(parentName.length > 0) tagHtml.push(`<div>所属部位:${parentName.join('/')}</div>`);
- }
- tagHtml.push('<div class="card-body p-2">', '<p class="card-text">', tag.comment, '</p>', '</div>');
- tagHtml.push('</div>');
- return tagHtml.join('');
- };
- const searchTagsAndShow = function () {
- const keyword = $('#bills-tag-keyword').val();
- const filterClass = $('#bills-tag-filter')[0].classList;
- const tagClass = filterClass.length > 2 ? filterClass[2] : null;
- const ci = tagClass ? classIndexes.find(x => {return x.tagClass === tagClass}) : null;
- curShow = billsTags.filter(x => {
- if (ci && ci.color !== x.color) return false;
- if (!keyword) return true;
- if (x.node.code && x.node.code.indexOf(keyword) >= 0) return true;
- if (x.node.b_code && x.node.b_code.indexOf(keyword) >= 0) return true;
- if (x.node.name && x.node.name.indexOf(keyword) >= 0) return true;
- return false;
- });
- reloadViewTags();
- };
- const refreshTagView = function (tag) {
- const obj = $('#bills-tag-' + tag.id);
- if (obj && obj.length > 0) {
- obj.html(getTagDisplayHtml(tag));
- }
- };
- const refreshBillsTagView = function (bills) {
- const bi = billsIndexes[bills.id] || [];
- for (const tag of bi) {
- refreshTagView(tag);
- }
- };
- const refreshPosTagView = function(pos) {
- const posRange = pos instanceof Array ? pos : [pos];
- for (const p of posRange) {
- const bi = billsIndexes[p.lid] || [];
- const pi = bi.filter(x => { return x.pos_id === p.id; });
- for (const tag of pi) {
- refreshTagView(tag);
- }
- }
- };
- const reviewTag = function (tag, isTop = false) {
- const obj = $('#bills-tag-' + tag.id);
- if (obj && obj.length > 0) {
- obj.html(getTagDisplayHtml(tag));
- } else {
- const objHtml = [];
- objHtml.push(`<div class="card border-primary my-2 tag-item" id="bills-tag-${tag.id}" tag-id="${tag.id}">`);
- objHtml.push(getTagDisplayHtml(tag));
- objHtml.push('</div>');
- if (isTop) {
- $('#bills-tag-list').prepend(objHtml.join(''));
- } else {
- $('#bills-tag-list').append(objHtml.join(''));
- }
- }
- tag.display = true;
- };
- const loadViewTags = function () {
- let showCount = 0;
- for (const t of curShow) {
- if (showCount >= pageLength) continue;
- if (t.display) continue;
- reviewTag(t);
- showCount++;
- }
- };
- const reloadViewTags = function () {
- clearViewTags();
- $("#bills-tag-lis").scrollTop(0);
- loadViewTags();
- };
- const _addToBillsIndex = function(data, isTop = false) {
- let bi = billsIndexes[data.lid];
- if (!bi) {
- bi = [];
- billsIndexes[data.lid] = bi;
- }
- isTop ? bi.unshift(data) : bi.push(data);
- };
- const loadDatas = function (datas) {
- billsTags = [];
- billsIndexes = {};
- for (const d of datas) {
- if (!d.node) continue;
- billsTags.push(d);
- _addToBillsIndex(d);
- }
- curShow = billsTags;
- reloadViewTags();
- };
- const updateDatas = function (data) {
- const refresh = {};
- if (data.add) {
- billsTags.push(data.add);
- _addToBillsIndex(data.add, true);
- refresh.add = data.add;
- }
- if (data.del) {
- const delTag = billsTags.find(x => {return x.id === data.del});
- billsTags.splice(billsTags.indexOf(delTag), 1);
- if (delTag.node) {
- const bi = billsIndexes[delTag.node.id];
- bi.splice(bi.indexOf(delTag), 1);
- }
- refresh.del = delTag;
- }
- if (data.update) {
- const updateTag = billsTags.find(x => {return x.id === data.update.id});
- for (const prop in data.update) {
- updateTag[prop] = data.update[prop];
- }
- refresh.update = updateTag;
- }
- return refresh;
- };
- const updateDatasAndShow = function (data) {
- const relaBills = [];
- const refresh = updateDatas(data);
- if (refresh.add) {
- reviewTag(refresh.add, true);
- relaBills.push(refresh.add.node);
- }
- if (refresh.del) {
- $('#bills-tag-' + refresh.del.id).remove();
- relaBills.push(refresh.del.node);
- }
- if (refresh.update) {
- refreshTagView(refresh.update);
- relaBills.push(refresh.update.node);
- }
- return relaBills;
- };
- const show = function () {
- showSelectTab(setting.selector, null, setting.afterShow);
- };
- const getBillsTagsColor = function (id) {
- const billsTags = billsIndexes[id] || [];
- return billsTags.length > 0 ? billsTags.map(x => {return x.color}) : undefined;
- };
- const getBillsTagsInfo = function (id) {
- const billsTags = billsIndexes[id] || [];
- return billsTags.length > 0 ? billsTags.map(x => {
- const tagClass = classIndexes.find(tc => {return tc.color === x.color}) || {};
- return {color: x.color, comment: x.comment, tagClass: tagClass.tagClass};
- }) : undefined;
- };
- const getPosTagsColor = function (lid, pos_id) {
- const billsTags = billsIndexes[lid] || [];
- const posTags = billsTags.filter(x => { return x.pos_id === pos_id; });
- return posTags.length > 0 ? posTags.map(x => {return x.color}) : undefined;
- };
- const getPosTagsInfo = function(lid, pos_id) {
- const billsTags = billsIndexes[lid] || [];
- const posTags = billsTags.filter(x => { return x.pos_id === pos_id; });
- return posTags.length > 0 ? posTags.map(x => {
- const tagClass = classIndexes.find(tc => {return tc.color === x.color}) || {};
- return {color: x.color, comment: x.comment, tagClass: tagClass.tagClass};
- }) : undefined;
- };
- const afterDeleteBills = function (nodes) {
- for (const node of nodes) {
- const bi = billsIndexes[node.id];
- if (!bi) continue;
- delete billsIndexes[node.id];
- for (const biTag of bi) {
- const delTag = billsTags.find(x => {return x.id === biTag.id});
- billsTags.splice(billsTags.indexOf(delTag), 1);
- $('#bills-tag-' + delTag.id).remove();
- }
- }
- };
- const afterDeletePos = function (pos) {
- for (const p of pos) {
- const bi = billsIndexes[p.lid];
- if (!bi) continue;
- const pi = bi.filter(x => { return x.pos_id === p.id; });
- for (const piTag of pi) {
- const delTag = billsTags.find(x => {return x.id === piTag.id});
- billsTags.splice(billsTags.indexOf(delTag), 1);
- $('#bills-tag-' + delTag.id).remove();
- bi.splice(pi.indexOf(piTag), 1);
- }
- }
- };
- $('body').on('click', '[name=bills-tag-locate]', function () {
- const lid = parseInt(this.getAttribute('lid'));
- const pos_id = this.getAttribute('pos_id');
- SpreadJsObj.locateTreeNode(setting.relaSpread.getActiveSheet(), lid, true);
- setting.afterLocated && setting.afterLocated(lid, pos_id);
- });
- $('body').on('click', '[name=bills-tag-edit]', function () {
- const tagId = this.getAttribute('tag-id');
- const tag = billsTags.find(x => {return x.id == tagId});
- if (tag) {
- const obj = $('#bills-tag-' + tag.id);
- $('[name=tag-view]', obj).hide();
- obj.append(getTagEditHtml(tag));
- }
- });
- $('body').on('click', '#tag-edit-cancel', function () {
- const obj = $('[name=tag-edit]').parent();
- $('[name=tag-edit]').remove();
- $('[name=tag-view]', obj).show();
- });
- $('body').on('click', '#tag-del', function () {
- const obj = $('[name=tag-edit]').parent();
- postData(setting.updateUrl, {del: parseInt(obj.attr('tag-id'))}, function (result) {
- if (!result.del) return;
- const bills = updateDatasAndShow(result);
- setting.afterModify && setting.afterModify(bills);
- });
- });
- $('body').on('click', '#tag-edit-ok', function () {
- const obj = $('[name=tag-edit]').parent();
- const data = {
- id: parseInt(obj.attr('tag-id')),
- share: $('#tag-share')[0].checked,
- comment: $('#tag-comment').val(),
- color: $('#tag-change-color').attr('tag-color'),
- };
- postData(setting.updateUrl, {update: data}, function (result) {
- if (!result.update) return;
- const bills = updateDatasAndShow(result);
- setting.afterModify && setting.afterModify(bills);
- });
- });
- $('body').on('click', '[name=tag-color]', function () {
- const tagClass = this.classList[1];
- const ci = classIndexes.find(tc => {return tc.tagClass === tagClass});
- const tcc = $('#tag-change-color');
- tcc.attr('tag-color', ci.color);
- tcc.find('i').attr('class', 'fa fa-tag ' + tagClass);
- });
- $('body').on('click', '[tagType]', function () {
- const tagClass = this.getAttribute('tagType');
- if (tagClass === 'all') {
- $('#bills-tag-filter').attr('class', 'fa fa-list-ol');
- } else {
- $('#bills-tag-filter').attr('class', 'fa fa-tag ' + tagClass);
- }
- searchTagsAndShow();
- });
- // 防抖
- function debounce(fun, delay) {
- let timer = null;
- return function () {
- if (timer) {
- clearTimeout(timer);
- }
- timer = setTimeout(fun, delay);
- }
- }
- $('#bills-tag-list').bind('scroll', debounce(function (e) {
- const obj = $('#bills-tag-list');
- var sum = obj[0].scrollHeight;
- if (sum <= obj.scrollTop() + obj.height()) {
- loadViewTags();
- }
- }, 300));
- $('#bills-tag-clear').bind('click', () => {
- if (!$('#bills-tag-keyword').val()) return;
- $('#bills-tag-keyword').val('');
- searchTagsAndShow();
- });
- $('#bills-tag-search').bind('click', () => {searchTagsAndShow();});
- $('#bills-tag-keyword').bind('keydown', e => {if (e.keyCode === 13) searchTagsAndShow();});
- return { loadDatas, updateDatasAndShow, show,
- getBillsTagsColor, getBillsTagsInfo, getPosTagsColor, getPosTagsInfo,
- refreshBillsTagView, refreshPosTagView,
- afterDeleteBills, afterDeletePos }
- };
- $.sumLoadMiss = function (setting) {
- if (!setting.spreadSetting) {
- setting.spreadSetting = {
- cols: [
- { title: '清单编号', field: 'b_code', width: 80, formatter: '@' },
- { title: '清单名称', field: 'name', width: 120, formatter: '@' },
- { title: '单位', field: 'unit', width: 50, formatter: '@' },
- { title: setting.type === 'stage' ? '合同数量' : '数量', field: 'qty', width: 60 },
- { title: '变更数量', field: 'qc_qty', width: 60, visible: setting.type === 'stage' },
- {
- title: '类型', field: 'type', width: 100, getValue: function (x) {
- switch (x.type) {
- case 'less': return '数量变少';
- case 'miss': return '找不到清单';
- case 'qc-conflict': return '变更冲突(已调用变更令)';
- default: return '';
- }
- }
- }
- ],
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- selectedBackColor: '#fffacd',
- readOnly: true,
- };
- }
- const clearMissData = function () {
- if (setting.storeKey) removeLocalCache(setting.storeKey);
- };
- const autoShowHistory = function (show) {
- if (setting.storeKey) {
- setLocalCache(setting.storeKey + '-showHis', show.toString());
- }
- };
- if (setting.selector && setting.relaSpread) {
- const resultId = setting.id + '-spread';
- const obj = $(setting.selector);
- obj.html(
- ' <div id="' + resultId + '" class="sjs-sh">\n' +
- ' </div>'
- );
- autoFlashHeight();
- const spread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
- const sheet = spread.getActiveSheet();
- SpreadJsObj.initSheet(sheet, setting.spreadSetting);
- spread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
- if (!setting.relaSpread) return;
- const sheet = info.sheet;
- const data = sheet.zh_data;
- if (!data) { return }
- const curBills = data[info.row];
- if (!curBills) { return }
- if (curBills.ledger_id) {
- SpreadJsObj.locateTreeNode(setting.relaSpread.getActiveSheet(), curBills.ledger_id, true);
- if (setting.afterLocated) {
- setting.afterLocated();
- }
- } else {
- toastr.warning('找不到该清单');
- }
- });
- const loadMissData = function (data, his = false) {
- const sourceTree = setting.relaSpread.getActiveSheet().zh_tree;
- if (!sourceTree) return;
- for (const d of data) {
- d.serialNo = sourceTree.getNodeIndex(sourceTree.getItems(d.ledger_id)) + 1;
- }
- data.sort(function (a, b) {
- return a.serialNo - b.serialNo;
- });
- SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, data);
- if (!his && setting.storeKey) {
- setLocalCache(setting.storeKey, JSON.stringify(data));
- }
- $(setting.tabSelector).show();
- };
- const showMissList = function () {
- const tab = $(setting.tabSelector), tabPanel = $(tab.attr('content'));
- $('a', '.side-menu').removeClass('active');
- tab.addClass('active');
- $('.tab-content .tab-pane').removeClass('active');
- tabPanel.addClass('active');
- showSideTools(true);
- spread.refresh();
- if (setting.afterShow) setting.afterShow();
- };
- const loadHisMissData = function () {
- if (setting.storeKey) {
- const storeStr = getLocalCache(setting.storeKey);
- const storeData = storeStr ? JSON.parse(storeStr) : [];
- if (storeData.length > 0) {
- loadMissData(storeData, true);
- const showHis = getLocalCache(setting.storeKey + '-showHis');
- if (showHis === 'true') {
- showMissList();
- removeLocalCache(setting.storeKey + '-showHis');
- }
- }
- }
- };
- return {
- spread: spread,
- loadMissData: loadMissData,
- clearMissData: clearMissData,
- loadHisMissData: loadHisMissData,
- show: showMissList,
- autoShowHistory: autoShowHistory,
- };
- } else {
- const loadMissData = function (data) {
- if (setting.storeKey) {
- setLocalCache(setting.storeKey, JSON.stringify(data));
- }
- };
- return {
- loadErrorData: loadMissData,
- clearErrorData: clearMissData,
- autoShowHistory: autoShowHistory,
- };
- }
- };
- $.stdLib = function (setting) {
- if (!setting.selector) return;
- const obj = $(setting.selector);
- const stdLibHtml = setting.libs.map(l => {
- return `<option value="${l.id}" >${l.name}</option>`;
- });
- const relaSelect = {
- showLevel: `std-${setting.stdType}-sl`,
- searchText: `std-${setting.stdType}-st`,
- searchResult: `std-${setting.stdType}-sr`,
- searchPre: `std-${setting.stdType}-sp`,
- searchNext: `std-${setting.stdType}-sn`,
- searchClose: `std-${setting.stdType}-sc`,
- addParent: `std-${setting.stdType}-wp`
- };
- const hiddenOption = setting.showAddType ? '' : 'style="display: none;"';
- obj.html(
- '<div class="sjs-bar d-flex">\n' +
- ' <div class="dropdown mr-1">\n' +
- ' <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
- ' <i class="fa fa-list-ol"></i> 显示层级\n' +
- ' </button>\n' +
- ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
- ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
- ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
- ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
- ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
- ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
- ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
- ' </div>\n' +
- ' </div>' +
- ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto">${stdLibHtml.join('')}</select></div>\n` +
- ' <div class="ml-1">\n' +
- ' <div class="dropdown">\n' +
- ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
- ' <i class="fa fa-search"></i>\n' +
- ' </button>\n' +
- ' <div class="dropdown-menu dropdown-menu-right">\n' +
- ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
- ' <div class="d-inline-block">\n' +
- ' <div class="input-group input-group-sm mr-1">' +
- ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
- ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
- ' <div class="input-group-append" >\n' +
- ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
- ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>' +
- ` <div class="ml-1" ${hiddenOption}>\n` +
- ' <div class="dropdown">\n' +
- ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
- ' <i class="fa fa-cog"></i>\n' +
- ' </button>\n' +
- ' <div class="dropdown-menu dropdown-menu-right">\n' +
- ' <div class="px-2 border-primary border-1 d-flex" style="width: 100px">\n' +
- ' <div class="form-check form-check-inline">\n' +
- ` <input class="form-check-input pt-1" type="checkbox" id="${relaSelect.addParent}">\n` +
- ` <label class="form-check-label" for="${relaSelect.addParent}">添加父项</label>\n` +
- ' </div>' +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>' +
- '</div>\n' +
- `<div id="std-${setting.stdType}-spread" class="sjs-sh"></div>\n`
- );
- autoFlashHeight();
- const pathTree = createNewPathTree('base', setting.treeSetting);
- const spreadSetting = {
- cols: [
- {title: '名称', field: 'name', hAlign: 0, width: 180, formatter: '@'},
- {title: '单位', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
- ],
- treeCol: 0,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- headColWidth: [30],
- selectedBackColor: '#fffacd',
- readOnly: true,
- stdType: setting.stdType,
- };
- spreadSetting.cols.unshift(setting.stdType === 'xmj'
- ? {title: '项目节编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'}
- : {title: '清单编号', field: 'b_code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'});
- const spread = SpreadJsObj.createNewSpread($(`#std-${setting.stdType}-spread`)[0]);
- const sheet = spread.getActiveSheet();
- if (setting.spreadSetting) setting.spreadSetting.stdType = setting.stdType;
- SpreadJsObj.initSheet(sheet, setting.spreadSetting || spreadSetting);
- if (setting.cellDoubleClick) sheet.bind(spreadNS.Events.CellDoubleClick, function(e, info) {
- const stdSheet = info.sheet;
- if (!stdSheet.zh_setting || !stdSheet.zh_tree) return;
- const stdTree = stdSheet.zh_tree;
- const stdNode = stdTree.nodes[info.row];
- if (!stdNode) { return; }
- const updateData = { postType: 'add-std', postData: { stdType: stdSheet.zh_setting.stdType, withParent: $(`#${relaSelect.addParent}`)[0].checked } };
- const fullPath = stdTree.getAllParents(stdNode);
- fullPath.push(stdNode);
- fullPath.sort((x, y) => { return x.level - y.level; });
- updateData.postData.stdData = fullPath.map(x => {
- return { code: x.code || '', b_code: x.b_code || '', name: x.name, unit: x.unit, source: x.source, node_type: x.node_type }
- });
- updateData.postData.stdNode = stdNode;
- setting.cellDoubleClick(updateData, stdNode, stdTree);
- });
- sheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
- if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
- SpreadJsObj.saveTopAndSelect(info.sheet, cacheKey.node);
- console.log(SpreadJsObj.getSelectObject(info.sheet));
- }
- });
- sheet.bind(spreadNS.Events.TopRowChanged, function (e, info) {
- SpreadJsObj.saveTopAndSelect(info.sheet, cacheKey.node);
- });
- const cacheLib = [];
- const cacheKey = {
- lib: setting.page + '-' + setting.tid + '-' + setting.stdType,
- };
- $('select', setting.selector).change(function () {
- loadLib(parseInt(this.value), true);
- });
- (function (select, sheet) {
- $(select).click(function () {
- if (!sheet.zh_tree) return;
- const tag = $(this).attr('tag');
- const tree = sheet.zh_tree;
- setTimeout(() => {
- 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;
- }
- }, 100);
- });
- })(`a[name=${relaSelect.showLevel}]`, sheet);
- const loadLib = function(listId, reload = false) {
- cacheKey.node = cacheLib.lib + '-' + listId;
- const locateMemory = function () {
- if (!reload) {
- SpreadJsObj.loadTopAndSelect(sheet, cacheKey.node);
- } else {
- removeLocalCache(cacheKey.node);
- }
- };
- const cacheData = cacheLib.find(function (lib) {
- return lib.id === listId;
- });
- if (cacheData) {
- pathTree.loadDatas(cacheData.data);
- SpreadJsObj.loadSheetData(sheet, 'tree', pathTree);
- locateMemory();
- setLocalCache(cacheKey.lib, listId);
- } else {
- postData(`/std-lib/get-data`, {stdType: setting.stdType, list_id: listId}, function (data) {
- cacheLib.push({id: listId, data: data});
- pathTree.loadDatas(data);
- SpreadJsObj.loadSheetData(sheet, 'tree', pathTree);
- locateMemory();
- setLocalCache(cacheKey.lib, listId);
- });
- }
- };
- const _loadCacheLib = function() {
- let libId = getLocalCache(cacheKey.lib);
- if (libId) {
- $('select', setting.selector).val(libId);
- loadLib(parseInt(libId));
- } else {
- loadLib(parseInt($('select', setting.selector).val()));
- }
- };
- _loadCacheLib();
- const searchObj = {
- result: [],
- cur: 0,
- searchStdNode: function() {
- const keyword = $(`#${relaSelect.searchText}`).val();
- searchObj.result = keyword ? pathTree.nodes.filter(x => {
- return x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0;
- }) : [];
- // searchObj.result = [];
- // for (const x of pathTree.nodes) {
- // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
- // searchObj.result.push(x);
- // }
- // }
- $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
- searchObj.cur = 0;
- if (searchObj.result.length > 0) {
- SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]));
- }
- },
- searchPre: function () {
- if (searchObj.result.length === 0) return;
- searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
- SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]), true);
- },
- searchNext: function () {
- if (searchObj.result.length === 0) return;
- searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
- SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]), true);
- },
- clear: function () {
- $(`#${relaSelect.searchText}`).val('');
- $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
- searchObj.result = [];
- searchObj.cur = 0;
- }
- };
- $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
- $(`#${relaSelect.searchPre}`).click(function (e) {
- searchObj.searchPre();
- e.stopPropagation();
- });
- $(`#${relaSelect.searchNext}`).click(function (e) {
- searchObj.searchNext();
- e.stopPropagation();
- });
- $(`#${relaSelect.searchClose}`).click(function (e) {
- searchObj.clear();
- e.stopPropagation();
- });
- return { spread }
- };
- $.gljLib = function (setting) {
- if (!setting.selector) return;
- const obj = $(setting.selector);
- const stdLibHtml = setting.libs.map(l => {
- return `<option value="${l.id}" >${l.name}</option>`;
- });
- const relaSelect = {
- showLevel: `std-${setting.stdType}-sl`,
- searchText: `std-${setting.stdType}-st`,
- searchResult: `std-${setting.stdType}-sr`,
- searchPre: `std-${setting.stdType}-sp`,
- searchNext: `std-${setting.stdType}-sn`,
- searchClose: `std-${setting.stdType}-sc`,
- };
- obj.html(
- '<div class="sjs-bar d-flex">\n' +
- ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto">${stdLibHtml.join('')}</select></div>\n` +
- ' <div class="ml-1">\n' +
- ' <div class="dropdown">\n' +
- ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
- ' <i class="fa fa-search"></i>\n' +
- ' </button>\n' +
- ' <div class="dropdown-menu dropdown-menu-right">\n' +
- ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
- ' <div class="d-inline-block">\n' +
- ' <div class="input-group input-group-sm mr-1">' +
- ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
- ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
- ' <div class="input-group-append" >\n' +
- ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
- ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>\n' +
- ' </div>' +
- '</div>\n' +
- `<div id="std-${setting.stdType}-spread" class="${setting.spreadClassCss ? setting.spreadClassCss : 'sjs-sh'}"></div>\n`
- );
- autoFlashHeight();
- const pathTree = createNewPathTree('base', setting.treeSetting);
- const spreadSetting = {
- cols: [
- {title: '名称', field: 'name', hAlign: 0, width: 180, formatter: '@'},
- {title: '单位', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
- ],
- treeCol: 0,
- emptyRows: 0,
- headRows: 1,
- headRowHeight: [32],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- headColWidth: [30],
- selectedBackColor: '#fffacd',
- readOnly: true,
- stdType: setting.stdType,
- };
- spreadSetting.cols.unshift(setting.stdType === 'xmj'
- ? {title: '项目节编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'}
- : {title: '清单编号', field: 'b_code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'});
- const spread = SpreadJsObj.createNewSpread($(`#std-${setting.stdType}-spread`)[0]);
- const sheet = spread.getActiveSheet();
- SpreadJsObj.initSheet(sheet, setting.spreadSetting ? setting.spreadSetting : spreadSetting);
- if (setting.cellDoubleClick) sheet.bind(spreadNS.Events.CellDoubleClick, setting.cellDoubleClick);
- sheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
- if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
- SpreadJsObj.saveTopAndSelect(info.sheet, cacheKey.node);
- }
- });
- sheet.bind(spreadNS.Events.TopRowChanged, function (e, info) {
- SpreadJsObj.saveTopAndSelect(info.sheet, cacheKey.node);
- });
- const cacheLib = [];
- const cacheKey = {
- lib: setting.page + '-' + setting.tid + '-' + setting.stdType,
- };
- $('select', setting.selector).change(function () {
- loadLib(parseInt(this.value), true);
- });
- const loadLib = function(listId, reload = false) {
- cacheKey.node = cacheLib.lib + '-' + listId;
- const locateMemory = function () {
- if (!reload) {
- SpreadJsObj.loadTopAndSelect(sheet, cacheKey.node);
- } else {
- removeLocalCache(cacheKey.node);
- }
- };
- const cacheData = cacheLib.find(function (lib) {
- return lib.id === listId;
- });
- if (cacheData) {
- pathTree.loadDatas(cacheData.data);
- SpreadJsObj.loadSheetData(sheet, 'tree', pathTree);
- locateMemory();
- setLocalCache(cacheKey.lib, listId);
- } else {
- postData(`/std-lib/get-data`, {stdType: setting.stdType, list_id: listId}, function (data) {
- cacheLib.push({id: listId, data: data});
- pathTree.loadDatas(data);
- SpreadJsObj.loadSheetData(sheet, 'tree', pathTree);
- locateMemory();
- setLocalCache(cacheKey.lib, listId);
- });
- }
- };
- const _loadCacheLib = function() {
- let libId = getLocalCache(cacheKey.lib);
- if (libId) {
- $('select', setting.selector).val(libId);
- loadLib(parseInt(libId));
- } else {
- loadLib(parseInt($('select', setting.selector).val()));
- }
- };
- _loadCacheLib();
- const searchObj = {
- result: [],
- cur: 0,
- searchStdNode: function() {
- const keyword = $(`#${relaSelect.searchText}`).val();
- searchObj.result = keyword ? pathTree.nodes.filter(x => {
- return x.code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0;
- }) : [];
- // searchObj.result = [];
- // for (const x of pathTree.nodes) {
- // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
- // searchObj.result.push(x);
- // }
- // }
- $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
- searchObj.cur = 0;
- if (searchObj.result.length > 0) {
- SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]));
- }
- },
- searchPre: function () {
- if (searchObj.result.length === 0) return;
- searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
- SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]), true);
- },
- searchNext: function () {
- if (searchObj.result.length === 0) return;
- searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
- SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]), true);
- },
- clear: function () {
- $(`#${relaSelect.searchText}`).val('');
- $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
- searchObj.result = [];
- searchObj.cur = 0;
- }
- };
- $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
- $(`#${relaSelect.searchPre}`).click(function (e) {
- searchObj.searchPre();
- e.stopPropagation();
- });
- $(`#${relaSelect.searchNext}`).click(function (e) {
- searchObj.searchNext();
- e.stopPropagation();
- });
- $(`#${relaSelect.searchClose}`).click(function (e) {
- searchObj.clear();
- e.stopPropagation();
- });
- return { spread }
- };
- })(jQuery);
|