|
@@ -281,8 +281,11 @@ const showSideTools = function (show) {
|
|
|
if (setting.searchOver || setting.searchEmpty) {
|
|
|
filter.push('<select class="form-control form-control-sm" id="search-filter">');
|
|
|
filter.push('<option value="">台账</option>');
|
|
|
- if (setting.searchOver) filter.push('<option value="over">超计</option>');
|
|
|
- if (setting.searchEmpty) filter.push('<option value="less">漏计</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>');
|
|
@@ -316,10 +319,8 @@ const showSideTools = function (show) {
|
|
|
let searchResult = [];
|
|
|
const search = function () {
|
|
|
const filter = $('#search-filter').val();
|
|
|
- if (filter === 'over') {
|
|
|
- searchOver();
|
|
|
- } else if (filter === 'less') {
|
|
|
- searchLess();
|
|
|
+ if (filter) {
|
|
|
+ searchCustom(filter);
|
|
|
} else {
|
|
|
searchBills();
|
|
|
}
|
|
@@ -339,20 +340,18 @@ const showSideTools = function (show) {
|
|
|
}
|
|
|
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;
|
|
|
- }
|
|
|
+ const getCheckFun = function (key) {
|
|
|
+ const cs = setting.customSearch.find(function (x) {return x.key === key});
|
|
|
+ return cs ? cs.check : null;
|
|
|
};
|
|
|
- const searchOver = function () {
|
|
|
+ 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 (setting.checkOver && setting.checkOver(node)) {
|
|
|
+ if (checkFun && checkFun(node)) {
|
|
|
if (!keyword ||
|
|
|
(node.code && node.code.indexOf(keyword) > -1) ||
|
|
|
(node.b_code && node.b_code.indexOf(keyword) > -1) ||
|
|
@@ -366,45 +365,12 @@ const showSideTools = function (show) {
|
|
|
calculateCompletePercent(searchResult);
|
|
|
SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
|
|
|
};
|
|
|
- const searchEmpty = function () {
|
|
|
- const keyword = $('#searchKeyword', obj).val();
|
|
|
- searchResult = [];
|
|
|
- const sortData = SpreadJsObj.getSortData(searchSheet);
|
|
|
- for (const node of sortData) {
|
|
|
- if (node.children && node.children.length > 0) continue;
|
|
|
- if (setting.checkEmpty && setting.checkEmpty(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 searchLess = function () {
|
|
|
- const keyword = $('#searchKeyword', obj).val();
|
|
|
- searchResult = [];
|
|
|
- const sortData = SpreadJsObj.getSortData(searchSheet);
|
|
|
- for (const node of sortData) {
|
|
|
- if (node.children && node.children.length > 0) continue;
|
|
|
- if (setting.checkLess && setting.checkLess(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);
|
|
|
- }
|
|
|
- }
|
|
|
+ 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;
|
|
|
}
|
|
|
- calculateCompletePercent(searchResult);
|
|
|
- SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
|
|
|
};
|
|
|
|
|
|
$('input', obj).bind('keydown', function (e) {
|