123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586 |
- '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();
- }
- };
- (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: '@'},
- {
- title: '错误类型', field: 'errorType', width: 60, formatter: '@',
- getValue: function (x) {
- switch (x.errorType) {
- case 'qty': return '数量';
- case 'tp': return '金额';
- default: return '';
- }
- }
- },
- {title: '清单编号', field: 'b_code', width: 135, formatter: '@'},
- {title: '清单名称', field: 'name', width: 215, 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);
- SpreadJsObj.forbiddenSpreadContextMenu('#' + resultId, spread);
- 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) {
- 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 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: '项目节编号', 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);
- SpreadJsObj.forbiddenSpreadContextMenu('#' + resultId, spread);
- 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) {
- d.serialNo = sourceTree.getNodeIndex(sourceTree.getItems(d.ledger_id)) + 1;
- }
- $('#' + 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 = '项目节编号/清单编号/名称';
- const resultId = setting.id + '-search-result';
- const obj = $(setting.selector);
- let filter = [];
- if (setting.searchOver || setting.searchEmpty) {
- filter.push('<select class="form-control form-control-sm" 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>');
- // filter.push('<div class="input-group-prepend">');
- // filter.push('<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">台账</button>');
- // filter.push('<div class="dropdown-menu">');
- // filter.push('<a class="dropdown-item" href="javascripty: void(0)" id="search-bills">台账</a>');
- // filter.push('<a class="dropdown-item" href="javascripty: void(0)" id="search-over">超计</a>');
- // filter.push('<a class="dropdown-item" href="javascripty: void(0)" id="search-less">漏计</a>');
- // filter.push('</div>');
- // filter.push('</div>');
- }
- 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" 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);
- SpreadJsObj.forbiddenSpreadContextMenu('#' + resultId, resultSpread);
- const searchSheet = setting.searchSpread.getActiveSheet();
- let searchResult = [];
- const search = function () {
- const filter = $('#search-filter').val();
- if (filter) {
- searchCustom(filter);
- } else {
- searchBills();
- }
- };
- const searchBills = function () {
- const keyword = $('#searchKeyword', obj).val();
- searchResult = [];
- const sortData = SpreadJsObj.getSortData(searchSheet);
- for (const node of sortData) {
- if ((node.code && node.code.indexOf(keyword) > -1) ||
- node.b_code && node.b_code.indexOf(keyword) > -1 ||
- node.name && node.name.indexOf(keyword) > -1) {
- const data = JSON.parse(JSON.stringify(node));
- data.visible = true;
- searchResult.push(data);
- }
- }
- 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 node of sortData) {
- if (node.children && node.children.length > 0) 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)) {
- const data = JSON.parse(JSON.stringify(node));
- data.visible = true;
- searchResult.push(data);
- }
- }
- }
- calculateCompletePercent(searchResult);
- SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
- };
- 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) { return }
- SpreadJsObj.locateTreeNode(searchSheet, curBills.ledger_id, true);
- if (setting.afterLocated) {
- setting.afterLocated();
- }
- });
- return {spread: resultSpread};
- };
- })(jQuery);
|