cs_tools.js 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589
  1. 'use strict';
  2. /**
  3. * cs_errorList:错误列表
  4. * 使用范围:
  5. * 台账分解(原报)、台账修订(原报)、计量台账(所有角色)
  6. *
  7. * posSearch & billsSearch:台账搜索相关
  8. * 使用范围:
  9. * 0号台账:台账分解、台账审批、台账修订、部位台账;
  10. * 期计量:计量台账、部位台账
  11. *
  12. * 所有工具均基于spreadjs,请放在gc.spread.sheets.all.10.0.1.min.js/spreadjs_zh.js之后
  13. *
  14. * @author Mai
  15. * @date
  16. * @version
  17. */
  18. const showSideTools = function (show) {
  19. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  20. if (show) {
  21. right.show();
  22. autoFlashHeight();
  23. /**
  24. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  25. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  26. * 故需要通过最终的parent.width再计算一次left.width
  27. *
  28. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  29. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  30. *
  31. */
  32. //left.css('width', parent.width() - right.outerWidth());
  33. //left.css('width', parent.width() - right.outerWidth());
  34. const percent = 100 - right.outerWidth() /parent.width() * 100;
  35. left.css('width', percent + '%');
  36. } else {
  37. left.width(parent.width());
  38. right.hide();
  39. }
  40. };
  41. const showSelectTab = function(select, spread, afterShow) {
  42. const tab = $(select), tabPanel = $(tab.attr('content'));
  43. $('a', '.side-menu').removeClass('active');
  44. tab.addClass('active');
  45. $('.tab-content .tab-pane').removeClass('active');
  46. tabPanel.addClass('active');
  47. showSideTools(true);
  48. spread && spread.refresh();
  49. if (afterShow) afterShow();
  50. };
  51. (function($){
  52. /**
  53. * 错误列表
  54. * @param setting
  55. * {
  56. * tabSelector: 'a[content=#error-list]',
  57. * selector: '#error-list',
  58. * relaSpread: ledgerSpread,
  59. * storeKey: 'ledger-error-' + tenderId,
  60. * }
  61. * @returns {{spread: *}}
  62. */
  63. $.cs_errorList = function (setting) {
  64. if (!setting.spreadSetting) {
  65. setting.spreadSetting = {
  66. cols: [
  67. {title: '行号', field: 'serialNo', width: 50, formatter: '@', hAlign: 1},
  68. {
  69. title: '错误类型', field: 'errorType', width: 85, formatter: '@',
  70. getValue: function (x) {
  71. switch (x.errorType) {
  72. case 'gather': return '汇总错误';
  73. case 'qty': return '数量';
  74. case 'tp': return '金额';
  75. case 'over': return '超计';
  76. case 'sibling': return '项目节清单同层';
  77. case 'same_code': return '重复项目节编号';
  78. case 's2b_over_gxby': return '违规计量(工序报验)';
  79. case 's2b_over_dagl': return '违规计量(档案管理)';
  80. case 's2b_lost_gxby': return '遗漏计量(工序报验)';
  81. case 's2b_lost_dagl': return '遗漏计量(档案管理)';
  82. case 'minus_cb': return '负变更清单漏计';
  83. default: return '';
  84. }
  85. }
  86. },
  87. {title: '清单编号', field: 'b_code', width: 85, formatter: '@'},
  88. {title: '清单名称', field: 'name', width: 165, formatter: '@'},
  89. {title: '备注', field: 'memo', width: 100, formatter: '@'},
  90. ],
  91. emptyRows: 0,
  92. headRows: 1,
  93. headRowHeight: [32],
  94. defaultRowHeight: 21,
  95. headerFont: '12px 微软雅黑',
  96. font: '12px 微软雅黑',
  97. selectedBackColor: '#fffacd',
  98. readOnly: true,
  99. };
  100. }
  101. const clearErrorData = function () {
  102. if (setting.storeKey) removeLocalCache(setting.storeKey);
  103. };
  104. const autoShowHistory = function (show) {
  105. if (setting.storeKey) {
  106. setLocalCache(setting.storeKey + '-showHis', show.toString());
  107. }
  108. };
  109. if (setting.selector && setting.relaSpread) {
  110. const resultId = setting.id + '-spread';
  111. const obj = $(setting.selector);
  112. obj.html(
  113. ' <div id="' + resultId + '" class="sjs-sh">\n' +
  114. ' </div>'
  115. );
  116. autoFlashHeight();
  117. const spread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
  118. const sheet = spread.getActiveSheet();
  119. SpreadJsObj.initSheet(sheet, setting.spreadSetting);
  120. spread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  121. const sheet = info.sheet;
  122. const data = sheet.zh_data;
  123. if (!data) { return }
  124. const curBills = data[info.row];
  125. if (!curBills) { return }
  126. SpreadJsObj.locateTreeNode(setting.relaSpread.getActiveSheet(), curBills.ledger_id, true);
  127. if (setting.afterLocated) {
  128. setting.afterLocated();
  129. }
  130. });
  131. const loadErrorData = function (data, his = false) {
  132. const sourceTree = setting.relaSpread.getActiveSheet().zh_tree;
  133. if (!sourceTree) return;
  134. for (const d of data) {
  135. d.serialNo = sourceTree.getNodeIndex(sourceTree.getItems(d.ledger_id)) + 1;
  136. }
  137. data.sort(function (a, b) {
  138. return a.serialNo ? (b.serialNo ? a.serialNo - b.serialNo : 1) : 1;
  139. });
  140. SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, data);
  141. if (!his && setting.storeKey) {
  142. setLocalCache(setting.storeKey, JSON.stringify(data));
  143. }
  144. $(setting.tabSelector).show();
  145. };
  146. const showErrorList = function () {
  147. const tab = $(setting.tabSelector), tabPanel = $(tab.attr('content'));
  148. $('a', '.side-menu').removeClass('active');
  149. tab.addClass('active');
  150. $('.tab-content .tab-pane').removeClass('active');
  151. tabPanel.addClass('active');
  152. showSideTools(true);
  153. spread.refresh();
  154. if (setting.afterShow) setting.afterShow();
  155. };
  156. const loadHisErrorData = function () {
  157. if (setting.storeKey) {
  158. const storeStr = getLocalCache(setting.storeKey);
  159. const storeData = storeStr ? JSON.parse(storeStr) : [];
  160. if (storeData.length > 0) {
  161. loadErrorData(storeData, true);
  162. const showHis = getLocalCache(setting.storeKey + '-showHis');
  163. if (showHis === 'true') {
  164. showErrorList();
  165. removeLocalCache(setting.storeKey + '-showHis');
  166. }
  167. }
  168. }
  169. };
  170. return {
  171. spread: spread,
  172. loadErrorData: loadErrorData,
  173. clearErrorData: clearErrorData,
  174. loadHisErrorData: loadHisErrorData,
  175. show: showErrorList,
  176. autoShowHistory: autoShowHistory,
  177. };
  178. } else {
  179. const loadErrorData = function (data) {
  180. if (setting.storeKey) {
  181. setLocalCache(setting.storeKey, JSON.stringify(data));
  182. }
  183. };
  184. return {
  185. loadErrorData: loadErrorData,
  186. clearErrorData: clearErrorData,
  187. autoShowHistory: autoShowHistory,
  188. };
  189. }
  190. };
  191. $.ledger_checkList = function (setting) {
  192. const checkTypeText = [];
  193. for (const ct in setting.checkType) {
  194. checkTypeText[setting.checkType[ct].value] = setting.checkType[ct].text;
  195. }
  196. if (!setting.spreadSetting) {
  197. setting.spreadSetting = {
  198. cols: [
  199. {
  200. title: '类型', field: 'type', width: 150, formatter: '@',
  201. getValue: function (data){
  202. if (setting.checkType) {
  203. return checkTypeText[data.type] || '';
  204. } else {
  205. return '';
  206. }
  207. }
  208. },
  209. {title: '行号', field: 'serialNo', hAlign: 1, width: 40, formatter: '@'},
  210. {title: '项目节编号\n(变更令号)', field: 'code', width: 80, formatter: '@'},
  211. {title: '清单编号', field: 'b_code', width: 80, formatter: '@'},
  212. {title: '名称', field: 'name', width: 150, formatter: '@'},
  213. ],
  214. emptyRows: 0,
  215. headRows: 1,
  216. headRowHeight: [32],
  217. defaultRowHeight: 21,
  218. headerFont: '12px 微软雅黑',
  219. font: '12px 微软雅黑',
  220. selectedBackColor: '#fffacd',
  221. readOnly: true,
  222. };
  223. }
  224. const clearCheckData = function () {
  225. if (setting.storeKey) removeLocalCache(setting.storeKey);
  226. };
  227. const autoShowHistory = function (show) {
  228. if (setting.storeKey) {
  229. setLocalCache(setting.storeKey + '-showHis', show.toString());
  230. }
  231. };
  232. if (setting.selector && setting.relaSpread) {
  233. const resultId = setting.id + '-spread';
  234. const obj = $(setting.selector);
  235. const dropdown = [];
  236. if (setting.checkType) {
  237. dropdown.push('<div class="dropdown">');
  238. 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>');
  239. dropdown.push('<div class="dropdown-menu" aria-labelledby="'+ setting.id + 'drop">');
  240. dropdown.push('<a class="dropdown-item" href="javascript: void(0);" check-type="all">所有类型</a>');
  241. for (const ct in setting.checkType) {
  242. dropdown.push('<a class="dropdown-item" href="javascript: void(0);" check-type="' + setting.checkType[ct].value +'">' + setting.checkType[ct].text + '</a>');
  243. }
  244. dropdown.push('</div>');
  245. dropdown.push('</div>');
  246. }
  247. obj.html(
  248. '<div class="sjs-bar">\n' +
  249. ' <div class="pb-1 d-flex">\n' + dropdown.join('') +
  250. ' <span class="ml-auto pr-2" id="' + setting.id + '-time">检查时间:2020-08-01 13:20:25</span>\n' +
  251. ' </div>\n' +
  252. '</div>' +
  253. '<div id="' + resultId + '" class="sjs-sh">\n' +
  254. '</div>'
  255. );
  256. autoFlashHeight();
  257. const spread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
  258. const sheet = spread.getActiveSheet();
  259. SpreadJsObj.initSheet(sheet, setting.spreadSetting);
  260. spread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  261. const sheet = info.sheet;
  262. const data = sheet.zh_data;
  263. if (!data) { return }
  264. const curBills = data[info.row];
  265. if (!curBills) { return }
  266. SpreadJsObj.locateTreeNode(setting.relaSpread.getActiveSheet(), curBills.ledger_id, true);
  267. if (setting.afterLocated) {
  268. setting.afterLocated();
  269. }
  270. });
  271. const filterCheckData = function () {
  272. const filter = $(this).attr('check-type');
  273. $('#' + setting.id + 'drop').html(this.innerHTML);
  274. for (const d of sheet.zh_data) {
  275. if (filter === 'all') {
  276. d.visible = true;
  277. } else {
  278. d.visible = d.type == filter;
  279. }
  280. }
  281. SpreadJsObj.refreshTreeRowVisible(sheet);
  282. };
  283. $('a[check-type]').bind('click', filterCheckData);
  284. const hideCheckData = function () {
  285. const tab = $(setting.tabSelector), tabPanel = $(tab.attr('content'));
  286. if (tab.hasClass('active')) {
  287. $('a', '.side-menu').removeClass('active');
  288. tab.addClass('active');
  289. $('.tab-content .tab-pane').removeClass('active');
  290. tabPanel.addClass('active');
  291. showSideTools(false);
  292. if (spread) spread.refresh();
  293. if (setting.afterShow) setting.afterShow();
  294. tab.hide();
  295. }
  296. };
  297. const loadCheckData = function (data, his = false) {
  298. const sourceTree = setting.relaSpread.getActiveSheet().zh_tree;
  299. if (!sourceTree) return;
  300. for (const d of data.warning_data) {
  301. d.serialNo = sourceTree.getNodeIndex(sourceTree.getItems(d.ledger_id)) + 1;
  302. }
  303. $('#' + setting.id + '-time').html('检查时间:' + moment(data.check_time).format('YYYY-MM-DD HH:mm:ss'));
  304. SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, data.warning_data);
  305. if (!his && setting.storeKey) {
  306. setLocalCache(setting.storeKey, JSON.stringify(data));
  307. }
  308. $(setting.tabSelector).show();
  309. };
  310. const showCheckList = function () {
  311. const tab = $(setting.tabSelector), tabPanel = $(tab.attr('content'));
  312. $('a', '.side-menu').removeClass('active');
  313. tab.addClass('active');
  314. $('.tab-content .tab-pane').removeClass('active');
  315. tabPanel.addClass('active');
  316. showSideTools(true);
  317. spread.refresh();
  318. if (setting.afterShow) setting.afterShow();
  319. };
  320. const loadHisCheckData = function () {
  321. if (setting.storeKey) {
  322. const storeStr = getLocalCache(setting.storeKey);
  323. const storeData = storeStr ? JSON.parse(storeStr) : null;
  324. if (storeData) {
  325. loadCheckData(storeData, true);
  326. const showHis = getLocalCache(setting.storeKey + '-showHis');
  327. if (showHis === 'true') {
  328. showCheckList();
  329. removeLocalCache(setting.storeKey + '-showHis');
  330. }
  331. }
  332. }
  333. };
  334. return {
  335. spread: spread,
  336. loadCheckData: loadCheckData,
  337. clearCheckData: clearCheckData,
  338. loadHisCheckData: loadHisCheckData,
  339. show: showCheckList,
  340. hide: hideCheckData,
  341. autoShowHistory: autoShowHistory,
  342. };
  343. } else {
  344. const loadCheckData = function (data) {
  345. if (setting.storeKey) {
  346. setLocalCache(setting.storeKey, JSON.stringify(data));
  347. }
  348. };
  349. return {
  350. loadCheckData: loadCheckData,
  351. clearCheckData: clearCheckData,
  352. autoShowHistory: autoShowHistory,
  353. };
  354. }
  355. };
  356. $.posSearch = function (setting) {
  357. if (!setting.selector || !setting.searchSpread) return;
  358. const searchHtml =
  359. ' <div class="ml-2">\n' +
  360. ' <div class="input-group input-group-sm">\n' +
  361. ' <input type="text" class="form-control" placeholder="输入名称查找" id="pos-keyword">\n' +
  362. ' <div class="input-group-append">\n' +
  363. ' <span class="input-group-text" id="pos-search-hint">结果:0</span>\n' +
  364. ' </div>\n' +
  365. ' <div class="input-group-append" >\n' +
  366. ' <button class="btn btn-outline-secondary" type="button" title="上一个" id="search-pre-pos"><i class="fa fa-angle-double-left"></i></button>\n' +
  367. ' <button class="btn btn-outline-secondary" type="button" title="下一个" id="search-next-pos"><i class="fa fa-angle-double-right"></i></button>\n' +
  368. ' </div>\n' +
  369. ' </div>\n' +
  370. ' </div>\n';
  371. $(setting.selector).html(searchHtml);
  372. const sheet = setting.searchSpread.getActiveSheet();
  373. const searchObj = (function () {
  374. let resultArr = [];
  375. const search = function (keyword) {
  376. if (keyword && keyword !== '') {
  377. resultArr = [];
  378. const sortData = sheet.zh_data;
  379. if (sortData) {
  380. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  381. const sd = sortData[i];
  382. if (sd.name && sd.name.indexOf(keyword) > -1) {
  383. resultArr.push({index: i, data: sd});
  384. }
  385. }
  386. }
  387. } else {
  388. resultArr = [];
  389. }
  390. $('#pos-search-hint').html('结果:' + resultArr.length);
  391. };
  392. const searchAndLocate = function (keyword) {
  393. search(keyword);
  394. if (resultArr.length > 0) {
  395. const sel = sheet.getSelections()[0];
  396. const curRow = sel ? sel.row : 0;
  397. const pos = resultArr[0];
  398. if (pos.index !== curRow) {
  399. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  400. sheet.getParent().focus();
  401. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  402. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  403. }
  404. }
  405. };
  406. const locateNext = function () {
  407. if (resultArr.length > 0) {
  408. const sel = sheet.getSelections()[0];
  409. const curRow = sel ? sel.row : 0;
  410. let next = _.find(resultArr, function (d) {
  411. return d.index > curRow;
  412. });
  413. if (!next) next = resultArr[0];
  414. if (next.index !== curRow) {
  415. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  416. sheet.getParent().focus();
  417. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  418. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  419. }
  420. }
  421. };
  422. const locatePre = function () {
  423. if (resultArr.length > 0) {
  424. const sel = sheet.getSelections()[0];
  425. const curRow = sel ? sel.row : 0;
  426. let next = _.findLast(resultArr, function (d) {
  427. return d.index < curRow;
  428. });
  429. if (!next) next = resultArr[resultArr.length - 1];
  430. if (next.index !== curRow) {
  431. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  432. sheet.getParent().focus();
  433. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  434. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  435. }
  436. }
  437. };
  438. return {search, searchAndLocate, locateNext, locatePre};
  439. })();
  440. // $('#pos-keyword').bind('input propertychange', function () {
  441. // posSearch.search(this.value);
  442. // });
  443. $('#pos-keyword').bind('keydown', function(e){
  444. if (e.keyCode == 13) searchObj.searchAndLocate(this.value);
  445. });
  446. $('#search-pre-pos').click(function () {
  447. searchObj.locatePre();
  448. });
  449. $('#search-next-pos').click(function () {
  450. searchObj.locateNext();
  451. });
  452. return searchObj;
  453. };
  454. $.billsSearch = function (setting) {
  455. if (!setting.selector || !setting.searchSpread || !setting.resultSpreadSetting) return;
  456. if (!setting.searchRangeStr) setting.searchRangeStr = '项目节编号/清单编号/名称/台账数量';
  457. if (!setting.keyId) setting.keyId = 'ledger_id';
  458. const resultId = setting.id + '-search-result';
  459. const obj = $(setting.selector);
  460. let filter = [];
  461. if (setting.searchOver || setting.searchEmpty) {
  462. filter.push('<select class="input-group-text" id="search-filter">');
  463. filter.push('<option value="">台账</option>');
  464. if (setting.customSearch) {
  465. for (const cs of setting.customSearch) {
  466. if (cs.valid) filter.push('<option value="' + cs.key + '">' + cs.title + '</option>');
  467. }
  468. }
  469. filter.push('</select>');
  470. }
  471. obj.html(
  472. ' <div class="sjs-bar">\n' +
  473. ' <div class="input-group input-group-sm pb-1">\n' +
  474. ' <div class="input-group-prepend">\n' +
  475. filter.join('') +
  476. ' </div>' +
  477. ' <input id="searchKeyword" type="text" class="form-control" autocomplete="off" placeholder="可查找 ' + setting.searchRangeStr + '" aria-label="Recipient\'s username" aria-describedby="button-addon2">\n' +
  478. ' <div class="input-group-append">\n' +
  479. ' <button class="btn btn-outline-secondary" type="button"">搜索</button>\n' +
  480. ' </div>\n' +
  481. ' </div>\n' +
  482. ' </div>\n' +
  483. ' <div id="' + resultId + '" class="sjs-sh">\n' +
  484. ' </div>'
  485. );
  486. autoFlashHeight();
  487. const resultSpread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
  488. SpreadJsObj.initSheet(resultSpread.getActiveSheet(), setting.resultSpreadSetting);
  489. const searchSheet = setting.searchSpread.getActiveSheet();
  490. let searchResult = [];
  491. const search = function () {
  492. const filter = $('#search-filter').val();
  493. if (filter) {
  494. searchCustom(filter);
  495. } else {
  496. searchBills();
  497. }
  498. };
  499. const searchBills = function () {
  500. const keyword = $('#searchKeyword', obj).val();
  501. const keyNum = _.toNumber(keyword);
  502. searchResult = [];
  503. const sortData = SpreadJsObj.getSortData(searchSheet);
  504. for (const node of sortData) {
  505. if ((node.code && node.code.indexOf(keyword) > -1) ||
  506. (node.b_code && node.b_code.indexOf(keyword) > -1) ||
  507. (node.name && node.name.indexOf(keyword) > -1) ||
  508. (!_.isNaN(keyNum) && checkZero(ZhCalc.sub(keyNum, node.quantity)))
  509. ) {
  510. const data = JSON.parse(JSON.stringify(node));
  511. data.visible = true;
  512. searchResult.push(data);
  513. }
  514. }
  515. SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
  516. };
  517. const getCheckFun = function (key) {
  518. const cs = setting.customSearch.find(function (x) {return x.key === key});
  519. return cs ? cs.check : null;
  520. };
  521. const getParantFun = function (key) {
  522. const cs = setting.customSearch.find(function (x) {return x.key === key});
  523. return cs && cs.parent !== undefined ? cs.parent : false;
  524. };
  525. const searchCustom = function (key) {
  526. const keyword = $('#searchKeyword', obj).val();
  527. const keyNum = _.toNumber(keyword);
  528. const checkFun = getCheckFun(key);
  529. searchResult = [];
  530. const sortData = SpreadJsObj.getSortData(searchSheet);
  531. const parantFun = getParantFun(key);
  532. for (const node of sortData) {
  533. if (node.children && node.children.length > 0 && !parantFun) continue;
  534. if (checkFun && checkFun(node)) {
  535. if (!keyword ||
  536. (node.code && node.code.indexOf(keyword) > -1) ||
  537. (node.b_code && node.b_code.indexOf(keyword) > -1) ||
  538. (node.name && node.name.indexOf(keyword) > -1) ||
  539. (!_.isNaN(keyNum) && checkZero(ZhCalc.sub(keyNum, node.quantity)))
  540. ) {
  541. const data = JSON.parse(JSON.stringify(node));
  542. data.visible = true;
  543. searchResult.push(data);
  544. }
  545. }
  546. }
  547. calculateCompletePercent(searchResult);
  548. SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
  549. };
  550. const calculateCompletePercent = function (searchResult) {
  551. if (!searchResult) return;
  552. for (const sr of searchResult) {
  553. const base = ZhCalc.add(sr.total_price, sr.end_qc_tp);
  554. sr.complete_percent = base !== 0 ? ZhCalc.mul(ZhCalc.div(sr.end_gather_tp, base), 100, 2) : 0;
  555. }
  556. };
  557. $('input', obj).bind('keydown', function (e) {
  558. if (e.keyCode == 13) search();
  559. });
  560. $('button', obj).bind('click', () => {search()});
  561. resultSpread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  562. const sheet = info.sheet;
  563. const data = sheet.zh_data;
  564. if (!data) { return }
  565. const curBills = data[info.row];
  566. if (!curBills) { return }
  567. SpreadJsObj.locateTreeNode(searchSheet, curBills[setting.keyId], true);
  568. if (setting.afterLocated) {
  569. setting.afterLocated();
  570. }
  571. });
  572. return {spread: resultSpread};
  573. };
  574. $.listSearch = function (setting) {
  575. if (!setting.selector || !setting.searchSpread || !setting.resultSpreadSetting) return;
  576. if (!setting.searchRangeStr) setting.searchRangeStr = '清单编号/名称';
  577. const resultId = setting.id + '-search-result';
  578. const obj = $(setting.selector);
  579. let filter = [];
  580. if (setting.searchOver || setting.searchEmpty) {
  581. filter.push('<select class="input-group-text" id="search-filter">');
  582. filter.push('<option value="">台账</option>');
  583. if (setting.customSearch) {
  584. for (const cs of setting.customSearch) {
  585. if (cs.valid) filter.push('<option value="' + cs.key + '">' + cs.title + '</option>');
  586. }
  587. }
  588. filter.push('</select>');
  589. }
  590. obj.html(
  591. ' <div class="sjs-bar">\n' +
  592. ' <div class="input-group input-group-sm pb-1">\n' +
  593. ' <div class="input-group-prepend">\n' +
  594. filter.join('') +
  595. ' </div>' +
  596. ' <input id="searchKeyword" type="text" class="form-control" autocomplete="off" placeholder="可查找 ' + setting.searchRangeStr + '" aria-label="Recipient\'s username" aria-describedby="button-addon2">\n' +
  597. ' <div class="input-group-append">\n' +
  598. ' <button class="btn btn-outline-secondary" type="button"">搜索</button>\n' +
  599. ' </div>\n' +
  600. ' </div>\n' +
  601. ' </div>\n' +
  602. ' <div id="' + resultId + '" class="sjs-sh">\n' +
  603. ' </div>'
  604. );
  605. autoFlashHeight();
  606. const resultSpread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
  607. SpreadJsObj.initSheet(resultSpread.getActiveSheet(), setting.resultSpreadSetting);
  608. const searchSheet = setting.searchSpread.getActiveSheet();
  609. let searchResult = [];
  610. const search = function () {
  611. const filter = $('#search-filter').val();
  612. if (filter) {
  613. searchCustom(filter);
  614. } else {
  615. searchList();
  616. }
  617. };
  618. const searchList = function () {
  619. const keyword = $('#searchKeyword', obj).val();
  620. searchResult = [];
  621. const sortData = SpreadJsObj.getSortData(searchSheet);
  622. for (const [i, node] of sortData.entries()) {
  623. if (setting.check(node, keyword)) {
  624. const data = JSON.parse(JSON.stringify(node));
  625. data.searchIndex = i;
  626. data.visible = true;
  627. searchResult.push(data);
  628. }
  629. }
  630. SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
  631. };
  632. const getCheckFun = function (key) {
  633. const cs = setting.customSearch.find(function (x) {return x.key === key});
  634. return cs ? cs.check : null;
  635. };
  636. const searchCustom = function (key) {
  637. const keyword = $('#searchKeyword', obj).val();
  638. const checkFun = getCheckFun(key);
  639. searchResult = [];
  640. const sortData = SpreadJsObj.getSortData(searchSheet);
  641. for (const [i, node] of sortData.entries()) {
  642. if (checkFun && checkFun(node)) {
  643. if (setting.check(node, keyword)) {
  644. const data = JSON.parse(JSON.stringify(node));
  645. data.searchIndex = i;
  646. data.visible = true;
  647. searchResult.push(data);
  648. }
  649. }
  650. }
  651. SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
  652. };
  653. $('input', obj).bind('keydown', function (e) {
  654. if (e.keyCode == 13) search();
  655. });
  656. $('button', obj).bind('click', () => {search()});
  657. resultSpread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  658. const cur = SpreadJsObj.getSelectObject(info.sheet);
  659. if (!cur) return;
  660. SpreadJsObj.locateRow(searchSheet, cur.searchIndex);
  661. if (setting.afterLocated) {
  662. setting.afterLocated();
  663. }
  664. });
  665. return {spread: resultSpread};
  666. };
  667. $.billsTag = function (setting) {
  668. if (!setting.selector || !setting.relaSpread) return;
  669. if (!setting.tagType) setting.tagType = [
  670. {tagClass: 'text-primary', color: '#007bff'},
  671. {tagClass: 'text-success', color: '#28a745'},
  672. {tagClass: 'text-danger', color: '#dc3545'},
  673. {tagClass: 'text-warning', color: '#da9500'},
  674. {tagClass: 'text-info', color: '#17a2b8'},
  675. ];
  676. const obj = $(setting.selector);
  677. const html = [], pageLength = 15;
  678. let billsTags = [], classIndexes = [], billsIndexes = {}, curShow = [];
  679. html.push('<div class="sjs-bar d-flex justify-content-between">');
  680. // 下拉过滤
  681. html.push('<div class="dropdown mr-2">');
  682. 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>');
  683. 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">');
  684. html.push('<a class="dropdown-item" href="javascript: void(0);" tagType="all" ><i class="fa fa-list-ol"></i></a>');
  685. for (const t of setting.tagType) {
  686. html.push(`<a class="dropdown-item ${t.tagClass}" href="javascript: void(0);" tagType="${t.tagClass}" ><i class="fa fa-tag"></i></a>`);
  687. t.tags = [];
  688. classIndexes.push(t);
  689. }
  690. html.push('</div>', '</div>');
  691. // 搜索框
  692. html.push('<div class="input-group input-group-sm">');
  693. html.push('<input type="text" class="form-control" placeholder="可查找 项目节编号 / 清单编号 /名称" id="bills-tag-keyword" autocomplete="off">');
  694. html.push('<div class="input-group-append">', '<div class="input-group-cancel">',
  695. '<a href="javascript: void(0);" id="bills-tag-clear" class="text-danger"><i class="fa fa-times-circle" title="移除搜索结果"></i></a>', '</div>',
  696. '<button class="btn btn-outline-secondary" type="button" id="bills-tag-search">搜索</button>', '</div>');
  697. html.push('</div>');
  698. html.push('</div>');
  699. // 书签列表
  700. html.push('<div class="sjs-sh" style="overflow: auto;" id="bills-tag-list"></div>');
  701. obj.html(html.join(''));
  702. const clearViewTags = function () {
  703. const viewTags = $('.tag-item', obj);
  704. if (viewTags && viewTags.length > 0) viewTags.remove();
  705. billsTags.forEach(x => {x.display = false});
  706. };
  707. const getTagEditHtml = function(tag) {
  708. const tagClass = classIndexes.find(x => {return x.color === tag.color}) || {};
  709. const tagHtml = [];
  710. tagHtml.push('<div name="tag-edit">');
  711. tagHtml.push('<div class="card-header p-2"><div class="dropdown">');
  712. 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>`);
  713. // 下拉选择颜色
  714. tagHtml.push('<div class="dropdown-menu" aria-labelledby="tag-change-color" style="min-width:60px">',
  715. '<a class="dropdown-item text-primary" href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>',
  716. '<a class="dropdown-item text-success " href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>',
  717. '<a class="dropdown-item text-danger " href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>',
  718. '<a class="dropdown-item text-warning " href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>',
  719. '<a class="dropdown-item text-info " href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>', '</div>');
  720. tagHtml.push('</div>');
  721. tag.node && tagHtml.push((tag.node.code || '') + (tag.node.b_code || ''), ' / ', tag.node.name || '');
  722. tagHtml.push('</div>');
  723. tagHtml.push('<div class="card-body p-2">');
  724. tagHtml.push('<p class="card-text">', '<textarea class="form-control form-control-sm p-1" id="tag-comment">', tag.comment, '</textarea>', '</p>');
  725. tagHtml.push('<div class="d-flex justify-content-between">');
  726. // 参与人可见
  727. tagHtml.push('<div class="custom-control custom-switch mr-2">');
  728. tagHtml.push('<input type="checkbox" class="custom-control-input custom-control-warning-input" id="tag-share"', tag.share ? 'checked' : '', '>');
  729. 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>');
  730. tagHtml.push('</div>');
  731. // 编辑按钮
  732. 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>',
  733. '<button type="button" class="btn btn-sm btn-outline-success mr-1" id="tag-edit-ok"><i class="fa fa-check"></i> 确定</button>',
  734. '<button type="button" class="btn btn-sm btn-outline-secondary" id="tag-edit-cancel">取消</button>', '</div>');
  735. tagHtml.push('</div>');
  736. tagHtml.push('</div>');
  737. tagHtml.push('</div>');
  738. return tagHtml.join('');
  739. };
  740. const getTagDisplayHtml = function (tag) {
  741. console.log(tag);
  742. const tagClass = classIndexes.find(x => {return x.color === tag.color}) || {};
  743. const tagHtml = [];
  744. tagHtml.push('<div name="tag-view">');
  745. tagHtml.push('<div class="card-header p-2"><div class="dropdown">');
  746. tagHtml.push(`<div class="pull-left mr-2"><i class="fa fa-tag ${tagClass.tagClass}"></i></div>`);
  747. tagHtml.push('</div>');
  748. tag.node && tagHtml.push((tag.node.code || '') + (tag.node.b_code || ''), ' / ', tag.node.name || '');
  749. if (tag.share) {
  750. 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>`);
  751. }
  752. tagHtml.push('<div class="pull-right edit-tag-btn">');
  753. const lid = tag.node ? tag.node.ledger_id : -1;
  754. tagHtml.push(`<a class="mr-1" name="bills-tag-locate" href="javascript: void(0);" lid="${lid}"><i class="fa fa-crosshairs"></i> 定位</a>`);
  755. 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>`);
  756. tagHtml.push('</div>');
  757. tagHtml.push('<div class="card-body p-2">', '<p class="card-text">', tag.comment, '</p>', '</div>');
  758. tagHtml.push('</div>');
  759. return tagHtml.join('');
  760. };
  761. const searchTagsAndShow = function () {
  762. const keyword = $('#bills-tag-keyword').val();
  763. const filterClass = $('#bills-tag-filter')[0].classList;
  764. const tagClass = filterClass.length > 2 ? filterClass[2] : null;
  765. const ci = tagClass ? classIndexes.find(x => {return x.tagClass === tagClass}) : null;
  766. curShow = billsTags.filter(x => {
  767. if (ci && ci.color !== x.color) return false;
  768. if (!keyword) return true;
  769. if (x.node.code && x.node.code.indexOf(keyword) >= 0) return true;
  770. if (x.node.b_code && x.node.b_code.indexOf(keyword) >= 0) return true;
  771. if (x.node.name && x.node.name.indexOf(keyword) >= 0) return true;
  772. return false;
  773. });
  774. reloadViewTags();
  775. };
  776. const refreshTagView = function (tag) {
  777. const obj = $('#bills-tag-' + tag.id);
  778. if (obj && obj.length > 0) {
  779. obj.html(getTagDisplayHtml(tag));
  780. }
  781. };
  782. const refreshBillsTagView = function (bills) {
  783. const bi = billsIndexes[bills.id] || [];
  784. for (const tag of bi) {
  785. refreshTagView(tag);
  786. }
  787. };
  788. const reviewTag = function (tag, isTop = false) {
  789. const obj = $('#bills-tag-' + tag.id);
  790. if (obj && obj.length > 0) {
  791. obj.html(getTagDisplayHtml(tag));
  792. } else {
  793. const objHtml = [];
  794. objHtml.push(`<div class="card border-primary my-2 tag-item" id="bills-tag-${tag.id}" tag-id="${tag.id}">`);
  795. objHtml.push(getTagDisplayHtml(tag));
  796. objHtml.push('</div>');
  797. if (isTop) {
  798. $('#bills-tag-list').prepend(objHtml.join(''));
  799. } else {
  800. $('#bills-tag-list').append(objHtml.join(''));
  801. }
  802. }
  803. tag.display = true;
  804. };
  805. const loadViewTags = function () {
  806. let showCount = 0;
  807. for (const t of curShow) {
  808. if (showCount >= pageLength) continue;
  809. if (t.display) continue;
  810. reviewTag(t);
  811. showCount++;
  812. }
  813. };
  814. const reloadViewTags = function () {
  815. clearViewTags();
  816. $("#bills-tag-lis").scrollTop(0);
  817. loadViewTags();
  818. };
  819. const _addToBillsIndex = function(data, isTop = false) {
  820. let bi = billsIndexes[data.lid];
  821. if (!bi) {
  822. bi = [];
  823. billsIndexes[data.lid] = bi;
  824. }
  825. isTop ? bi.unshift(data) : bi.push(data);
  826. };
  827. const loadDatas = function (datas) {
  828. billsTags = [];
  829. billsIndexes = {};
  830. for (const d of datas) {
  831. if (!d.node) continue;
  832. billsTags.push(d);
  833. _addToBillsIndex(d);
  834. }
  835. curShow = billsTags;
  836. reloadViewTags();
  837. };
  838. const updateDatas = function (data) {
  839. const refresh = {};
  840. if (data.add) {
  841. billsTags.push(data.add);
  842. _addToBillsIndex(data.add, true);
  843. refresh.add = data.add;
  844. }
  845. if (data.del) {
  846. const delTag = billsTags.find(x => {return x.id === data.del});
  847. billsTags.splice(billsTags.indexOf(delTag), 1);
  848. if (delTag.node) {
  849. const bi = billsIndexes[delTag.node.id];
  850. bi.splice(bi.indexOf(delTag), 1);
  851. }
  852. refresh.del = delTag;
  853. }
  854. if (data.update) {
  855. const updateTag = billsTags.find(x => {return x.id === data.update.id});
  856. for (const prop in data.update) {
  857. updateTag[prop] = data.update[prop];
  858. }
  859. refresh.update = updateTag;
  860. }
  861. return refresh;
  862. };
  863. const updateDatasAndShow = function (data) {
  864. const relaBills = [];
  865. const refresh = updateDatas(data);
  866. if (refresh.add) {
  867. reviewTag(refresh.add, true);
  868. relaBills.push(refresh.add.node);
  869. }
  870. if (refresh.del) {
  871. $('#bills-tag-' + refresh.del.id).remove();
  872. relaBills.push(refresh.del.node);
  873. }
  874. if (refresh.update) {
  875. refreshTagView(refresh.update);
  876. relaBills.push(refresh.update.node);
  877. }
  878. return relaBills;
  879. };
  880. const show = function () {
  881. showSelectTab(setting.selector, null, setting.afterShow);
  882. };
  883. const getBillsTagsColor = function (id) {
  884. const billsTags = billsIndexes[id] || [];
  885. return billsTags.length > 0 ? billsTags.map(x => {return x.color}) : undefined;
  886. };
  887. const getBillsTagsInfo = function (id) {
  888. const billsTags = billsIndexes[id] || [];
  889. return billsTags.length > 0 ? billsTags.map(x => {
  890. const tagClass = classIndexes.find(tc => {return tc.color === x.color}) || {};
  891. return {color: x.color, comment: x.comment, tagClass: tagClass.tagClass};
  892. }) : undefined;
  893. };
  894. const afterDeleteBills = function (nodes) {
  895. for (const node of nodes) {
  896. const bi = billsIndexes[node.id];
  897. if (!bi) continue;
  898. delete billsIndexes[node.id];
  899. for (const biTag of bi) {
  900. const delTag = billsTags.find(x => {return x.id === biTag.id});
  901. billsTags.splice(billsTags.indexOf(delTag), 1);
  902. $('#bills-tag-' + delTag.id).remove();
  903. }
  904. }
  905. };
  906. $('body').on('click', '[name=bills-tag-locate]', function () {
  907. const lid = parseInt(this.getAttribute('lid'));
  908. SpreadJsObj.locateTreeNode(setting.relaSpread.getActiveSheet(), lid);
  909. setting.afterLocated && setting.afterLocated();
  910. });
  911. $('body').on('click', '[name=bills-tag-edit]', function () {
  912. const tagId = this.getAttribute('tag-id');
  913. const tag = billsTags.find(x => {return x.id == tagId});
  914. if (tag) {
  915. const obj = $('#bills-tag-' + tag.id);
  916. $('[name=tag-view]', obj).hide();
  917. obj.append(getTagEditHtml(tag));
  918. }
  919. });
  920. $('body').on('click', '#tag-edit-cancel', function () {
  921. const obj = $('[name=tag-edit]').parent();
  922. $('[name=tag-edit]').remove();
  923. $('[name=tag-view]', obj).show();
  924. });
  925. $('body').on('click', '#tag-del', function () {
  926. const obj = $('[name=tag-edit]').parent();
  927. postData(setting.updateUrl, {del: parseInt(obj.attr('tag-id'))}, function (result) {
  928. if (!result.del) return;
  929. const bills = updateDatasAndShow(result);
  930. setting.afterModify && setting.afterModify(bills);
  931. });
  932. });
  933. $('body').on('click', '#tag-edit-ok', function () {
  934. const obj = $('[name=tag-edit]').parent();
  935. const data = {
  936. id: parseInt(obj.attr('tag-id')),
  937. share: $('#tag-share')[0].checked,
  938. comment: $('#tag-comment').val(),
  939. color: $('#tag-change-color').attr('tag-color'),
  940. };
  941. postData(setting.updateUrl, {update: data}, function (result) {
  942. if (!result.update) return;
  943. const bills = updateDatasAndShow(result);
  944. setting.afterModify && setting.afterModify(bills);
  945. });
  946. });
  947. $('body').on('click', '[name=tag-color]', function () {
  948. const tagClass = this.classList[1];
  949. const ci = classIndexes.find(tc => {return tc.tagClass === tagClass});
  950. const tcc = $('#tag-change-color');
  951. tcc.attr('tag-color', ci.color);
  952. tcc.find('i').attr('class', 'fa fa-tag ' + tagClass);
  953. });
  954. $('body').on('click', '[tagType]', function () {
  955. const tagClass = this.getAttribute('tagType');
  956. if (tagClass === 'all') {
  957. $('#bills-tag-filter').attr('class', 'fa fa-list-ol');
  958. } else {
  959. $('#bills-tag-filter').attr('class', 'fa fa-tag ' + tagClass);
  960. }
  961. searchTagsAndShow();
  962. });
  963. // 防抖
  964. function debounce(fun, delay) {
  965. let timer = null;
  966. return function () {
  967. if (timer) {
  968. clearTimeout(timer);
  969. }
  970. timer = setTimeout(fun, delay);
  971. }
  972. }
  973. $('#bills-tag-list').bind('scroll', debounce(function (e) {
  974. const obj = $('#bills-tag-list');
  975. var sum = obj[0].scrollHeight;
  976. if (sum <= obj.scrollTop() + obj.height()) {
  977. loadViewTags();
  978. }
  979. }, 300));
  980. $('#bills-tag-clear').bind('click', () => {
  981. if (!$('#bills-tag-keyword').val()) return;
  982. $('#bills-tag-keyword').val('');
  983. searchTagsAndShow();
  984. });
  985. $('#bills-tag-search').bind('click', () => {searchTagsAndShow();});
  986. $('#bills-tag-keyword').bind('keydown', e => {if (e.keyCode === 13) searchTagsAndShow();});
  987. return { loadDatas, updateDatasAndShow, show, getBillsTagsColor, getBillsTagsInfo, refreshBillsTagView, afterDeleteBills }
  988. };
  989. $.sumLoadMiss = function (setting) {
  990. if (!setting.spreadSetting) {
  991. setting.spreadSetting = {
  992. cols: [
  993. { title: '清单编号', field: 'b_code', width: 80, formatter: '@' },
  994. { title: '清单名称', field: 'name', width: 120, formatter: '@' },
  995. { title: '单位', field: 'unit', width: 50, formatter: '@' },
  996. { title: setting.type === 'stage' ? '合同数量' : '数量', field: 'qty', width: 60 },
  997. { title: '变更数量', field: 'qc_qty', width: 60, visible: setting.type === 'stage' },
  998. {
  999. title: '类型', field: 'type', width: 100, getValue: function (x) {
  1000. switch (x.type) {
  1001. case 'less': return '数量变少';
  1002. case 'miss': return '找不到清单';
  1003. case 'qc-conflict': return '变更冲突(已调用变更令)';
  1004. default: return '';
  1005. }
  1006. }
  1007. }
  1008. ],
  1009. emptyRows: 0,
  1010. headRows: 1,
  1011. headRowHeight: [32],
  1012. defaultRowHeight: 21,
  1013. headerFont: '12px 微软雅黑',
  1014. font: '12px 微软雅黑',
  1015. selectedBackColor: '#fffacd',
  1016. readOnly: true,
  1017. };
  1018. }
  1019. const clearMissData = function () {
  1020. if (setting.storeKey) removeLocalCache(setting.storeKey);
  1021. };
  1022. const autoShowHistory = function (show) {
  1023. if (setting.storeKey) {
  1024. setLocalCache(setting.storeKey + '-showHis', show.toString());
  1025. }
  1026. };
  1027. if (setting.selector && setting.relaSpread) {
  1028. const resultId = setting.id + '-spread';
  1029. const obj = $(setting.selector);
  1030. obj.html(
  1031. ' <div id="' + resultId + '" class="sjs-sh">\n' +
  1032. ' </div>'
  1033. );
  1034. autoFlashHeight();
  1035. const spread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
  1036. const sheet = spread.getActiveSheet();
  1037. SpreadJsObj.initSheet(sheet, setting.spreadSetting);
  1038. spread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1039. if (!setting.relaSpread) return;
  1040. const sheet = info.sheet;
  1041. const data = sheet.zh_data;
  1042. if (!data) { return }
  1043. const curBills = data[info.row];
  1044. if (!curBills) { return }
  1045. if (curBills.ledger_id) {
  1046. SpreadJsObj.locateTreeNode(setting.relaSpread.getActiveSheet(), curBills.ledger_id, true);
  1047. if (setting.afterLocated) {
  1048. setting.afterLocated();
  1049. }
  1050. } else {
  1051. toastr.warning('找不到该清单');
  1052. }
  1053. });
  1054. const loadMissData = function (data, his = false) {
  1055. const sourceTree = setting.relaSpread.getActiveSheet().zh_tree;
  1056. if (!sourceTree) return;
  1057. for (const d of data) {
  1058. d.serialNo = sourceTree.getNodeIndex(sourceTree.getItems(d.ledger_id)) + 1;
  1059. }
  1060. data.sort(function (a, b) {
  1061. return a.serialNo - b.serialNo;
  1062. });
  1063. SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, data);
  1064. if (!his && setting.storeKey) {
  1065. setLocalCache(setting.storeKey, JSON.stringify(data));
  1066. }
  1067. $(setting.tabSelector).show();
  1068. };
  1069. const showMissList = function () {
  1070. const tab = $(setting.tabSelector), tabPanel = $(tab.attr('content'));
  1071. $('a', '.side-menu').removeClass('active');
  1072. tab.addClass('active');
  1073. $('.tab-content .tab-pane').removeClass('active');
  1074. tabPanel.addClass('active');
  1075. showSideTools(true);
  1076. spread.refresh();
  1077. if (setting.afterShow) setting.afterShow();
  1078. };
  1079. const loadHisMissData = function () {
  1080. if (setting.storeKey) {
  1081. const storeStr = getLocalCache(setting.storeKey);
  1082. const storeData = storeStr ? JSON.parse(storeStr) : [];
  1083. if (storeData.length > 0) {
  1084. loadMissData(storeData, true);
  1085. const showHis = getLocalCache(setting.storeKey + '-showHis');
  1086. if (showHis === 'true') {
  1087. showMissList();
  1088. removeLocalCache(setting.storeKey + '-showHis');
  1089. }
  1090. }
  1091. }
  1092. };
  1093. return {
  1094. spread: spread,
  1095. loadMissData: loadMissData,
  1096. clearMissData: clearMissData,
  1097. loadHisMissData: loadHisMissData,
  1098. show: showMissList,
  1099. autoShowHistory: autoShowHistory,
  1100. };
  1101. } else {
  1102. const loadMissData = function (data) {
  1103. if (setting.storeKey) {
  1104. setLocalCache(setting.storeKey, JSON.stringify(data));
  1105. }
  1106. };
  1107. return {
  1108. loadErrorData: loadMissData,
  1109. clearErrorData: clearMissData,
  1110. autoShowHistory: autoShowHistory,
  1111. };
  1112. }
  1113. };
  1114. $.stdLib = function (setting) {
  1115. if (!setting.selector) return;
  1116. const obj = $(setting.selector);
  1117. const stdLibHtml = setting.libs.map(l => {
  1118. return `<option value="${l.id}" >${l.name}</option>`;
  1119. });
  1120. const relaSelect = {
  1121. showLevel: `std-${setting.stdType}-sl`,
  1122. searchText: `std-${setting.stdType}-st`,
  1123. searchResult: `std-${setting.stdType}-sr`,
  1124. searchPre: `std-${setting.stdType}-sp`,
  1125. searchNext: `std-${setting.stdType}-sn`,
  1126. searchClose: `std-${setting.stdType}-sc`,
  1127. };
  1128. obj.html(
  1129. '<div class="sjs-bar d-flex">\n' +
  1130. ' <div class="dropdown mr-1">\n' +
  1131. ' <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' +
  1132. ' <i class="fa fa-list-ol"></i> 显示层级\n' +
  1133. ' </button>\n' +
  1134. ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
  1135. ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
  1136. ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
  1137. ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
  1138. ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
  1139. ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
  1140. ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
  1141. ' </div>\n' +
  1142. ' </div>' +
  1143. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto">${stdLibHtml.join('')}</select></div>\n` +
  1144. ' <div class="ml-1">\n' +
  1145. ' <div class="dropdown">\n' +
  1146. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  1147. ' <i class="fa fa-search"></i>\n' +
  1148. ' </button>\n' +
  1149. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  1150. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  1151. ' <div class="d-inline-block">\n' +
  1152. ' <div class="input-group input-group-sm mr-1">' +
  1153. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  1154. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  1155. ' <div class="input-group-append" >\n' +
  1156. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  1157. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  1158. ' </div>\n' +
  1159. ' </div>\n' +
  1160. ' </div>\n' +
  1161. ` <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` +
  1162. ' </div>\n' +
  1163. ' </div>\n' +
  1164. ' </div>\n' +
  1165. ' </div>' +
  1166. '</div>\n' +
  1167. `<div id="std-${setting.stdType}-spread" class="sjs-sh"></div>\n`
  1168. );
  1169. autoFlashHeight();
  1170. const pathTree = createNewPathTree('base', setting.treeSetting);
  1171. const spreadSetting = {
  1172. cols: [
  1173. {title: '名称', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  1174. {title: '单位', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  1175. ],
  1176. treeCol: 0,
  1177. emptyRows: 0,
  1178. headRows: 1,
  1179. headRowHeight: [32],
  1180. defaultRowHeight: 21,
  1181. headerFont: '12px 微软雅黑',
  1182. font: '12px 微软雅黑',
  1183. headColWidth: [30],
  1184. selectedBackColor: '#fffacd',
  1185. readOnly: true,
  1186. stdType: setting.stdType,
  1187. };
  1188. spreadSetting.cols.unshift(setting.stdType === 'xmj'
  1189. ? {title: '项目节编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'}
  1190. : {title: '清单编号', field: 'b_code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'});
  1191. const spread = SpreadJsObj.createNewSpread($(`#std-${setting.stdType}-spread`)[0]);
  1192. const sheet = spread.getActiveSheet();
  1193. SpreadJsObj.initSheet(sheet, spreadSetting);
  1194. if (setting.cellDoubleClick) sheet.bind(spreadNS.Events.CellDoubleClick, setting.cellDoubleClick);
  1195. sheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1196. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  1197. SpreadJsObj.saveTopAndSelect(info.sheet, cacheKey.node);
  1198. }
  1199. });
  1200. sheet.bind(spreadNS.Events.TopRowChanged, function (e, info) {
  1201. SpreadJsObj.saveTopAndSelect(info.sheet, cacheKey.node);
  1202. });
  1203. const cacheLib = [];
  1204. const cacheKey = {
  1205. lib: setting.page + '-' + setting.tid + '-' + setting.stdType,
  1206. };
  1207. $('select', setting.selector).change(function () {
  1208. loadLib(parseInt(this.value), true);
  1209. });
  1210. (function (select, sheet) {
  1211. $(select).click(function () {
  1212. if (!sheet.zh_tree) return;
  1213. const tag = $(this).attr('tag');
  1214. const tree = sheet.zh_tree;
  1215. setTimeout(() => {
  1216. switch (tag) {
  1217. case "1":
  1218. case "2":
  1219. case "3":
  1220. case "4":
  1221. case "5":
  1222. tree.expandByLevel(parseInt(tag));
  1223. SpreadJsObj.refreshTreeRowVisible(sheet);
  1224. break;
  1225. case "last":
  1226. tree.expandByCustom(() => { return true; });
  1227. SpreadJsObj.refreshTreeRowVisible(sheet);
  1228. break;
  1229. }
  1230. }, 100);
  1231. });
  1232. })(`a[name=${relaSelect.showLevel}]`, sheet);
  1233. const loadLib = function(listId, reload = false) {
  1234. cacheKey.node = cacheLib.lib + '-' + listId;
  1235. const locateMemory = function () {
  1236. if (!reload) {
  1237. SpreadJsObj.loadTopAndSelect(sheet, cacheKey.node);
  1238. } else {
  1239. removeLocalCache(cacheKey.node);
  1240. }
  1241. };
  1242. const cacheData = cacheLib.find(function (lib) {
  1243. return lib.id === listId;
  1244. });
  1245. if (cacheData) {
  1246. pathTree.loadDatas(cacheData.data);
  1247. SpreadJsObj.loadSheetData(sheet, 'tree', pathTree);
  1248. locateMemory();
  1249. setLocalCache(cacheKey.lib, listId);
  1250. } else {
  1251. postData(`/std-lib/get-data`, {stdType: setting.stdType, list_id: listId}, function (data) {
  1252. cacheLib.push({id: listId, data: data});
  1253. pathTree.loadDatas(data);
  1254. SpreadJsObj.loadSheetData(sheet, 'tree', pathTree);
  1255. locateMemory();
  1256. setLocalCache(cacheKey.lib, listId);
  1257. });
  1258. }
  1259. };
  1260. const _loadCacheLib = function() {
  1261. let libId = getLocalCache(cacheKey.lib);
  1262. if (libId) {
  1263. $('select', setting.selector).val(libId);
  1264. loadLib(parseInt(libId));
  1265. } else {
  1266. loadLib(parseInt($('select', setting.selector).val()));
  1267. }
  1268. };
  1269. _loadCacheLib();
  1270. const searchObj = {
  1271. result: [],
  1272. cur: 0,
  1273. searchStdNode: function() {
  1274. const keyword = $(`#${relaSelect.searchText}`).val();
  1275. searchObj.result = keyword ? pathTree.nodes.filter(x => {
  1276. return x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0;
  1277. }) : [];
  1278. // searchObj.result = [];
  1279. // for (const x of pathTree.nodes) {
  1280. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  1281. // searchObj.result.push(x);
  1282. // }
  1283. // }
  1284. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  1285. searchObj.cur = 0;
  1286. if (searchObj.result.length > 0) {
  1287. SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]));
  1288. }
  1289. },
  1290. searchPre: function () {
  1291. if (searchObj.result.length === 0) return;
  1292. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  1293. SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  1294. },
  1295. searchNext: function () {
  1296. if (searchObj.result.length === 0) return;
  1297. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  1298. SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  1299. },
  1300. clear: function () {
  1301. $(`#${relaSelect.searchText}`).val('');
  1302. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  1303. searchObj.result = [];
  1304. searchObj.cur = 0;
  1305. }
  1306. };
  1307. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  1308. $(`#${relaSelect.searchPre}`).click(function (e) {
  1309. searchObj.searchPre();
  1310. e.stopPropagation();
  1311. });
  1312. $(`#${relaSelect.searchNext}`).click(function (e) {
  1313. searchObj.searchNext();
  1314. e.stopPropagation();
  1315. });
  1316. $(`#${relaSelect.searchClose}`).click(function (e) {
  1317. searchObj.clear();
  1318. e.stopPropagation();
  1319. });
  1320. return { spread }
  1321. };
  1322. $.gljLib = function (setting) {
  1323. if (!setting.selector) return;
  1324. const obj = $(setting.selector);
  1325. const stdLibHtml = setting.libs.map(l => {
  1326. return `<option value="${l.id}" >${l.name}</option>`;
  1327. });
  1328. const relaSelect = {
  1329. showLevel: `std-${setting.stdType}-sl`,
  1330. searchText: `std-${setting.stdType}-st`,
  1331. searchResult: `std-${setting.stdType}-sr`,
  1332. searchPre: `std-${setting.stdType}-sp`,
  1333. searchNext: `std-${setting.stdType}-sn`,
  1334. searchClose: `std-${setting.stdType}-sc`,
  1335. };
  1336. obj.html(
  1337. '<div class="sjs-bar d-flex">\n' +
  1338. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto">${stdLibHtml.join('')}</select></div>\n` +
  1339. ' <div class="ml-1">\n' +
  1340. ' <div class="dropdown">\n' +
  1341. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  1342. ' <i class="fa fa-search"></i>\n' +
  1343. ' </button>\n' +
  1344. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  1345. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  1346. ' <div class="d-inline-block">\n' +
  1347. ' <div class="input-group input-group-sm mr-1">' +
  1348. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  1349. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  1350. ' <div class="input-group-append" >\n' +
  1351. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  1352. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  1353. ' </div>\n' +
  1354. ' </div>\n' +
  1355. ' </div>\n' +
  1356. ` <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` +
  1357. ' </div>\n' +
  1358. ' </div>\n' +
  1359. ' </div>\n' +
  1360. ' </div>' +
  1361. '</div>\n' +
  1362. `<div id="std-${setting.stdType}-spread" class="${setting.spreadClassCss ? setting.spreadClassCss : 'sjs-sh'}"></div>\n`
  1363. );
  1364. autoFlashHeight();
  1365. const pathTree = createNewPathTree('base', setting.treeSetting);
  1366. const spreadSetting = {
  1367. cols: [
  1368. {title: '名称', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  1369. {title: '单位', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  1370. ],
  1371. treeCol: 0,
  1372. emptyRows: 0,
  1373. headRows: 1,
  1374. headRowHeight: [32],
  1375. defaultRowHeight: 21,
  1376. headerFont: '12px 微软雅黑',
  1377. font: '12px 微软雅黑',
  1378. headColWidth: [30],
  1379. selectedBackColor: '#fffacd',
  1380. readOnly: true,
  1381. stdType: setting.stdType,
  1382. };
  1383. spreadSetting.cols.unshift(setting.stdType === 'xmj'
  1384. ? {title: '项目节编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'}
  1385. : {title: '清单编号', field: 'b_code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'});
  1386. const spread = SpreadJsObj.createNewSpread($(`#std-${setting.stdType}-spread`)[0]);
  1387. const sheet = spread.getActiveSheet();
  1388. SpreadJsObj.initSheet(sheet, setting.spreadSetting ? setting.spreadSetting : spreadSetting);
  1389. if (setting.cellDoubleClick) sheet.bind(spreadNS.Events.CellDoubleClick, setting.cellDoubleClick);
  1390. sheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1391. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  1392. SpreadJsObj.saveTopAndSelect(info.sheet, cacheKey.node);
  1393. }
  1394. });
  1395. sheet.bind(spreadNS.Events.TopRowChanged, function (e, info) {
  1396. SpreadJsObj.saveTopAndSelect(info.sheet, cacheKey.node);
  1397. });
  1398. const cacheLib = [];
  1399. const cacheKey = {
  1400. lib: setting.page + '-' + setting.tid + '-' + setting.stdType,
  1401. };
  1402. $('select', setting.selector).change(function () {
  1403. loadLib(parseInt(this.value), true);
  1404. });
  1405. const loadLib = function(listId, reload = false) {
  1406. cacheKey.node = cacheLib.lib + '-' + listId;
  1407. const locateMemory = function () {
  1408. if (!reload) {
  1409. SpreadJsObj.loadTopAndSelect(sheet, cacheKey.node);
  1410. } else {
  1411. removeLocalCache(cacheKey.node);
  1412. }
  1413. };
  1414. const cacheData = cacheLib.find(function (lib) {
  1415. return lib.id === listId;
  1416. });
  1417. if (cacheData) {
  1418. pathTree.loadDatas(cacheData.data);
  1419. SpreadJsObj.loadSheetData(sheet, 'tree', pathTree);
  1420. locateMemory();
  1421. setLocalCache(cacheKey.lib, listId);
  1422. } else {
  1423. postData(`/std-lib/get-data`, {stdType: setting.stdType, list_id: listId}, function (data) {
  1424. cacheLib.push({id: listId, data: data});
  1425. pathTree.loadDatas(data);
  1426. SpreadJsObj.loadSheetData(sheet, 'tree', pathTree);
  1427. locateMemory();
  1428. setLocalCache(cacheKey.lib, listId);
  1429. });
  1430. }
  1431. };
  1432. const _loadCacheLib = function() {
  1433. let libId = getLocalCache(cacheKey.lib);
  1434. if (libId) {
  1435. $('select', setting.selector).val(libId);
  1436. loadLib(parseInt(libId));
  1437. } else {
  1438. loadLib(parseInt($('select', setting.selector).val()));
  1439. }
  1440. };
  1441. _loadCacheLib();
  1442. const searchObj = {
  1443. result: [],
  1444. cur: 0,
  1445. searchStdNode: function() {
  1446. const keyword = $(`#${relaSelect.searchText}`).val();
  1447. searchObj.result = keyword ? pathTree.nodes.filter(x => {
  1448. return x.code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0;
  1449. }) : [];
  1450. // searchObj.result = [];
  1451. // for (const x of pathTree.nodes) {
  1452. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  1453. // searchObj.result.push(x);
  1454. // }
  1455. // }
  1456. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  1457. searchObj.cur = 0;
  1458. if (searchObj.result.length > 0) {
  1459. SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]));
  1460. }
  1461. },
  1462. searchPre: function () {
  1463. if (searchObj.result.length === 0) return;
  1464. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  1465. SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  1466. },
  1467. searchNext: function () {
  1468. if (searchObj.result.length === 0) return;
  1469. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  1470. SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  1471. },
  1472. clear: function () {
  1473. $(`#${relaSelect.searchText}`).val('');
  1474. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  1475. searchObj.result = [];
  1476. searchObj.cur = 0;
  1477. }
  1478. };
  1479. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  1480. $(`#${relaSelect.searchPre}`).click(function (e) {
  1481. searchObj.searchPre();
  1482. e.stopPropagation();
  1483. });
  1484. $(`#${relaSelect.searchNext}`).click(function (e) {
  1485. searchObj.searchNext();
  1486. e.stopPropagation();
  1487. });
  1488. $(`#${relaSelect.searchClose}`).click(function (e) {
  1489. searchObj.clear();
  1490. e.stopPropagation();
  1491. });
  1492. return { spread }
  1493. };
  1494. })(jQuery);