cs_tools.js 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595
  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 calulateSum = function () {
  619. if (searchResult.length === 0 || !setting.calcSum) return;
  620. searchResult.unshift(setting.calcSum(searchResult));
  621. };
  622. const searchList = function () {
  623. const keyword = $('#searchKeyword', obj).val();
  624. searchResult = [];
  625. const sortData = SpreadJsObj.getSortData(searchSheet);
  626. for (const [i, node] of sortData.entries()) {
  627. if (setting.check(node, keyword)) {
  628. const data = JSON.parse(JSON.stringify(node));
  629. data.searchIndex = i;
  630. data.visible = true;
  631. searchResult.push(data);
  632. }
  633. }
  634. calulateSum();
  635. SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
  636. };
  637. const getCheckFun = function (key) {
  638. const cs = setting.customSearch.find(function (x) {return x.key === key});
  639. return cs ? cs.check : null;
  640. };
  641. const searchCustom = function (key) {
  642. const keyword = $('#searchKeyword', obj).val();
  643. const checkFun = getCheckFun(key);
  644. searchResult = [];
  645. const sortData = SpreadJsObj.getSortData(searchSheet);
  646. for (const [i, node] of sortData.entries()) {
  647. if (checkFun && checkFun(node)) {
  648. if (setting.check(node, keyword)) {
  649. const data = JSON.parse(JSON.stringify(node));
  650. data.searchIndex = i;
  651. data.visible = true;
  652. searchResult.push(data);
  653. }
  654. }
  655. }
  656. calulateSum();
  657. SpreadJsObj.loadSheetData(resultSpread.getActiveSheet(), 'data', searchResult);
  658. };
  659. $('input', obj).bind('keydown', function (e) {
  660. if (e.keyCode == 13) search();
  661. });
  662. $('button', obj).bind('click', () => {search()});
  663. resultSpread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  664. const cur = SpreadJsObj.getSelectObject(info.sheet);
  665. if (!cur || cur.searchIndex < 0) return;
  666. SpreadJsObj.locateRow(searchSheet, cur.searchIndex);
  667. if (setting.afterLocated) {
  668. setting.afterLocated();
  669. }
  670. });
  671. return {spread: resultSpread};
  672. };
  673. $.billsTag = function (setting) {
  674. if (!setting.selector || !setting.relaSpread) return;
  675. if (!setting.tagType) setting.tagType = [
  676. {tagClass: 'text-primary', color: '#007bff'},
  677. {tagClass: 'text-success', color: '#28a745'},
  678. {tagClass: 'text-danger', color: '#dc3545'},
  679. {tagClass: 'text-warning', color: '#da9500'},
  680. {tagClass: 'text-info', color: '#17a2b8'},
  681. ];
  682. const obj = $(setting.selector);
  683. const html = [], pageLength = 15;
  684. let billsTags = [], classIndexes = [], billsIndexes = {}, curShow = [];
  685. html.push('<div class="sjs-bar d-flex justify-content-between">');
  686. // 下拉过滤
  687. html.push('<div class="dropdown mr-2">');
  688. 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>');
  689. 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">');
  690. html.push('<a class="dropdown-item" href="javascript: void(0);" tagType="all" ><i class="fa fa-list-ol"></i></a>');
  691. for (const t of setting.tagType) {
  692. html.push(`<a class="dropdown-item ${t.tagClass}" href="javascript: void(0);" tagType="${t.tagClass}" ><i class="fa fa-tag"></i></a>`);
  693. t.tags = [];
  694. classIndexes.push(t);
  695. }
  696. html.push('</div>', '</div>');
  697. // 搜索框
  698. html.push('<div class="input-group input-group-sm">');
  699. html.push('<input type="text" class="form-control" placeholder="可查找 项目节编号 / 清单编号 /名称" id="bills-tag-keyword" autocomplete="off">');
  700. html.push('<div class="input-group-append">', '<div class="input-group-cancel">',
  701. '<a href="javascript: void(0);" id="bills-tag-clear" class="text-danger"><i class="fa fa-times-circle" title="移除搜索结果"></i></a>', '</div>',
  702. '<button class="btn btn-outline-secondary" type="button" id="bills-tag-search">搜索</button>', '</div>');
  703. html.push('</div>');
  704. html.push('</div>');
  705. // 书签列表
  706. html.push('<div class="sjs-sh" style="overflow: auto;" id="bills-tag-list"></div>');
  707. obj.html(html.join(''));
  708. const clearViewTags = function () {
  709. const viewTags = $('.tag-item', obj);
  710. if (viewTags && viewTags.length > 0) viewTags.remove();
  711. billsTags.forEach(x => {x.display = false});
  712. };
  713. const getTagEditHtml = function(tag) {
  714. const tagClass = classIndexes.find(x => {return x.color === tag.color}) || {};
  715. const tagHtml = [];
  716. tagHtml.push('<div name="tag-edit">');
  717. tagHtml.push('<div class="card-header p-2"><div class="dropdown">');
  718. 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>`);
  719. // 下拉选择颜色
  720. tagHtml.push('<div class="dropdown-menu" aria-labelledby="tag-change-color" style="min-width:60px">',
  721. '<a class="dropdown-item text-primary" href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>',
  722. '<a class="dropdown-item text-success " href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>',
  723. '<a class="dropdown-item text-danger " href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>',
  724. '<a class="dropdown-item text-warning " href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>',
  725. '<a class="dropdown-item text-info " href="javascript: void(0);" name="tag-color"><i class="fa fa-tint"></i></a>', '</div>');
  726. tagHtml.push('</div>');
  727. tag.node && tagHtml.push((tag.node.code || '') + (tag.node.b_code || ''), ' / ', tag.node.name || '');
  728. tagHtml.push('</div>');
  729. tagHtml.push('<div class="card-body p-2">');
  730. tagHtml.push('<p class="card-text">', '<textarea class="form-control form-control-sm p-1" id="tag-comment">', tag.comment, '</textarea>', '</p>');
  731. tagHtml.push('<div class="d-flex justify-content-between">');
  732. // 参与人可见
  733. tagHtml.push('<div class="custom-control custom-switch mr-2">');
  734. tagHtml.push('<input type="checkbox" class="custom-control-input custom-control-warning-input" id="tag-share"', tag.share ? 'checked' : '', '>');
  735. 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>');
  736. tagHtml.push('</div>');
  737. // 编辑按钮
  738. 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>',
  739. '<button type="button" class="btn btn-sm btn-outline-success mr-1" id="tag-edit-ok"><i class="fa fa-check"></i> 确定</button>',
  740. '<button type="button" class="btn btn-sm btn-outline-secondary" id="tag-edit-cancel">取消</button>', '</div>');
  741. tagHtml.push('</div>');
  742. tagHtml.push('</div>');
  743. tagHtml.push('</div>');
  744. return tagHtml.join('');
  745. };
  746. const getTagDisplayHtml = function (tag) {
  747. console.log(tag);
  748. const tagClass = classIndexes.find(x => {return x.color === tag.color}) || {};
  749. const tagHtml = [];
  750. tagHtml.push('<div name="tag-view">');
  751. tagHtml.push('<div class="card-header p-2"><div class="dropdown">');
  752. tagHtml.push(`<div class="pull-left mr-2"><i class="fa fa-tag ${tagClass.tagClass}"></i></div>`);
  753. tagHtml.push('</div>');
  754. tag.node && tagHtml.push((tag.node.code || '') + (tag.node.b_code || ''), ' / ', tag.node.name || '');
  755. if (tag.share) {
  756. 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>`);
  757. }
  758. tagHtml.push('<div class="pull-right edit-tag-btn">');
  759. const lid = tag.node ? tag.node.ledger_id : -1;
  760. tagHtml.push(`<a class="mr-1" name="bills-tag-locate" href="javascript: void(0);" lid="${lid}"><i class="fa fa-crosshairs"></i> 定位</a>`);
  761. 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>`);
  762. tagHtml.push('</div>');
  763. tagHtml.push('<div class="card-body p-2">', '<p class="card-text">', tag.comment, '</p>', '</div>');
  764. tagHtml.push('</div>');
  765. return tagHtml.join('');
  766. };
  767. const searchTagsAndShow = function () {
  768. const keyword = $('#bills-tag-keyword').val();
  769. const filterClass = $('#bills-tag-filter')[0].classList;
  770. const tagClass = filterClass.length > 2 ? filterClass[2] : null;
  771. const ci = tagClass ? classIndexes.find(x => {return x.tagClass === tagClass}) : null;
  772. curShow = billsTags.filter(x => {
  773. if (ci && ci.color !== x.color) return false;
  774. if (!keyword) return true;
  775. if (x.node.code && x.node.code.indexOf(keyword) >= 0) return true;
  776. if (x.node.b_code && x.node.b_code.indexOf(keyword) >= 0) return true;
  777. if (x.node.name && x.node.name.indexOf(keyword) >= 0) return true;
  778. return false;
  779. });
  780. reloadViewTags();
  781. };
  782. const refreshTagView = function (tag) {
  783. const obj = $('#bills-tag-' + tag.id);
  784. if (obj && obj.length > 0) {
  785. obj.html(getTagDisplayHtml(tag));
  786. }
  787. };
  788. const refreshBillsTagView = function (bills) {
  789. const bi = billsIndexes[bills.id] || [];
  790. for (const tag of bi) {
  791. refreshTagView(tag);
  792. }
  793. };
  794. const reviewTag = function (tag, isTop = false) {
  795. const obj = $('#bills-tag-' + tag.id);
  796. if (obj && obj.length > 0) {
  797. obj.html(getTagDisplayHtml(tag));
  798. } else {
  799. const objHtml = [];
  800. objHtml.push(`<div class="card border-primary my-2 tag-item" id="bills-tag-${tag.id}" tag-id="${tag.id}">`);
  801. objHtml.push(getTagDisplayHtml(tag));
  802. objHtml.push('</div>');
  803. if (isTop) {
  804. $('#bills-tag-list').prepend(objHtml.join(''));
  805. } else {
  806. $('#bills-tag-list').append(objHtml.join(''));
  807. }
  808. }
  809. tag.display = true;
  810. };
  811. const loadViewTags = function () {
  812. let showCount = 0;
  813. for (const t of curShow) {
  814. if (showCount >= pageLength) continue;
  815. if (t.display) continue;
  816. reviewTag(t);
  817. showCount++;
  818. }
  819. };
  820. const reloadViewTags = function () {
  821. clearViewTags();
  822. $("#bills-tag-lis").scrollTop(0);
  823. loadViewTags();
  824. };
  825. const _addToBillsIndex = function(data, isTop = false) {
  826. let bi = billsIndexes[data.lid];
  827. if (!bi) {
  828. bi = [];
  829. billsIndexes[data.lid] = bi;
  830. }
  831. isTop ? bi.unshift(data) : bi.push(data);
  832. };
  833. const loadDatas = function (datas) {
  834. billsTags = [];
  835. billsIndexes = {};
  836. for (const d of datas) {
  837. if (!d.node) continue;
  838. billsTags.push(d);
  839. _addToBillsIndex(d);
  840. }
  841. curShow = billsTags;
  842. reloadViewTags();
  843. };
  844. const updateDatas = function (data) {
  845. const refresh = {};
  846. if (data.add) {
  847. billsTags.push(data.add);
  848. _addToBillsIndex(data.add, true);
  849. refresh.add = data.add;
  850. }
  851. if (data.del) {
  852. const delTag = billsTags.find(x => {return x.id === data.del});
  853. billsTags.splice(billsTags.indexOf(delTag), 1);
  854. if (delTag.node) {
  855. const bi = billsIndexes[delTag.node.id];
  856. bi.splice(bi.indexOf(delTag), 1);
  857. }
  858. refresh.del = delTag;
  859. }
  860. if (data.update) {
  861. const updateTag = billsTags.find(x => {return x.id === data.update.id});
  862. for (const prop in data.update) {
  863. updateTag[prop] = data.update[prop];
  864. }
  865. refresh.update = updateTag;
  866. }
  867. return refresh;
  868. };
  869. const updateDatasAndShow = function (data) {
  870. const relaBills = [];
  871. const refresh = updateDatas(data);
  872. if (refresh.add) {
  873. reviewTag(refresh.add, true);
  874. relaBills.push(refresh.add.node);
  875. }
  876. if (refresh.del) {
  877. $('#bills-tag-' + refresh.del.id).remove();
  878. relaBills.push(refresh.del.node);
  879. }
  880. if (refresh.update) {
  881. refreshTagView(refresh.update);
  882. relaBills.push(refresh.update.node);
  883. }
  884. return relaBills;
  885. };
  886. const show = function () {
  887. showSelectTab(setting.selector, null, setting.afterShow);
  888. };
  889. const getBillsTagsColor = function (id) {
  890. const billsTags = billsIndexes[id] || [];
  891. return billsTags.length > 0 ? billsTags.map(x => {return x.color}) : undefined;
  892. };
  893. const getBillsTagsInfo = function (id) {
  894. const billsTags = billsIndexes[id] || [];
  895. return billsTags.length > 0 ? billsTags.map(x => {
  896. const tagClass = classIndexes.find(tc => {return tc.color === x.color}) || {};
  897. return {color: x.color, comment: x.comment, tagClass: tagClass.tagClass};
  898. }) : undefined;
  899. };
  900. const afterDeleteBills = function (nodes) {
  901. for (const node of nodes) {
  902. const bi = billsIndexes[node.id];
  903. if (!bi) continue;
  904. delete billsIndexes[node.id];
  905. for (const biTag of bi) {
  906. const delTag = billsTags.find(x => {return x.id === biTag.id});
  907. billsTags.splice(billsTags.indexOf(delTag), 1);
  908. $('#bills-tag-' + delTag.id).remove();
  909. }
  910. }
  911. };
  912. $('body').on('click', '[name=bills-tag-locate]', function () {
  913. const lid = parseInt(this.getAttribute('lid'));
  914. SpreadJsObj.locateTreeNode(setting.relaSpread.getActiveSheet(), lid);
  915. setting.afterLocated && setting.afterLocated();
  916. });
  917. $('body').on('click', '[name=bills-tag-edit]', function () {
  918. const tagId = this.getAttribute('tag-id');
  919. const tag = billsTags.find(x => {return x.id == tagId});
  920. if (tag) {
  921. const obj = $('#bills-tag-' + tag.id);
  922. $('[name=tag-view]', obj).hide();
  923. obj.append(getTagEditHtml(tag));
  924. }
  925. });
  926. $('body').on('click', '#tag-edit-cancel', function () {
  927. const obj = $('[name=tag-edit]').parent();
  928. $('[name=tag-edit]').remove();
  929. $('[name=tag-view]', obj).show();
  930. });
  931. $('body').on('click', '#tag-del', function () {
  932. const obj = $('[name=tag-edit]').parent();
  933. postData(setting.updateUrl, {del: parseInt(obj.attr('tag-id'))}, function (result) {
  934. if (!result.del) return;
  935. const bills = updateDatasAndShow(result);
  936. setting.afterModify && setting.afterModify(bills);
  937. });
  938. });
  939. $('body').on('click', '#tag-edit-ok', function () {
  940. const obj = $('[name=tag-edit]').parent();
  941. const data = {
  942. id: parseInt(obj.attr('tag-id')),
  943. share: $('#tag-share')[0].checked,
  944. comment: $('#tag-comment').val(),
  945. color: $('#tag-change-color').attr('tag-color'),
  946. };
  947. postData(setting.updateUrl, {update: data}, function (result) {
  948. if (!result.update) return;
  949. const bills = updateDatasAndShow(result);
  950. setting.afterModify && setting.afterModify(bills);
  951. });
  952. });
  953. $('body').on('click', '[name=tag-color]', function () {
  954. const tagClass = this.classList[1];
  955. const ci = classIndexes.find(tc => {return tc.tagClass === tagClass});
  956. const tcc = $('#tag-change-color');
  957. tcc.attr('tag-color', ci.color);
  958. tcc.find('i').attr('class', 'fa fa-tag ' + tagClass);
  959. });
  960. $('body').on('click', '[tagType]', function () {
  961. const tagClass = this.getAttribute('tagType');
  962. if (tagClass === 'all') {
  963. $('#bills-tag-filter').attr('class', 'fa fa-list-ol');
  964. } else {
  965. $('#bills-tag-filter').attr('class', 'fa fa-tag ' + tagClass);
  966. }
  967. searchTagsAndShow();
  968. });
  969. // 防抖
  970. function debounce(fun, delay) {
  971. let timer = null;
  972. return function () {
  973. if (timer) {
  974. clearTimeout(timer);
  975. }
  976. timer = setTimeout(fun, delay);
  977. }
  978. }
  979. $('#bills-tag-list').bind('scroll', debounce(function (e) {
  980. const obj = $('#bills-tag-list');
  981. var sum = obj[0].scrollHeight;
  982. if (sum <= obj.scrollTop() + obj.height()) {
  983. loadViewTags();
  984. }
  985. }, 300));
  986. $('#bills-tag-clear').bind('click', () => {
  987. if (!$('#bills-tag-keyword').val()) return;
  988. $('#bills-tag-keyword').val('');
  989. searchTagsAndShow();
  990. });
  991. $('#bills-tag-search').bind('click', () => {searchTagsAndShow();});
  992. $('#bills-tag-keyword').bind('keydown', e => {if (e.keyCode === 13) searchTagsAndShow();});
  993. return { loadDatas, updateDatasAndShow, show, getBillsTagsColor, getBillsTagsInfo, refreshBillsTagView, afterDeleteBills }
  994. };
  995. $.sumLoadMiss = function (setting) {
  996. if (!setting.spreadSetting) {
  997. setting.spreadSetting = {
  998. cols: [
  999. { title: '清单编号', field: 'b_code', width: 80, formatter: '@' },
  1000. { title: '清单名称', field: 'name', width: 120, formatter: '@' },
  1001. { title: '单位', field: 'unit', width: 50, formatter: '@' },
  1002. { title: setting.type === 'stage' ? '合同数量' : '数量', field: 'qty', width: 60 },
  1003. { title: '变更数量', field: 'qc_qty', width: 60, visible: setting.type === 'stage' },
  1004. {
  1005. title: '类型', field: 'type', width: 100, getValue: function (x) {
  1006. switch (x.type) {
  1007. case 'less': return '数量变少';
  1008. case 'miss': return '找不到清单';
  1009. case 'qc-conflict': return '变更冲突(已调用变更令)';
  1010. default: return '';
  1011. }
  1012. }
  1013. }
  1014. ],
  1015. emptyRows: 0,
  1016. headRows: 1,
  1017. headRowHeight: [32],
  1018. defaultRowHeight: 21,
  1019. headerFont: '12px 微软雅黑',
  1020. font: '12px 微软雅黑',
  1021. selectedBackColor: '#fffacd',
  1022. readOnly: true,
  1023. };
  1024. }
  1025. const clearMissData = function () {
  1026. if (setting.storeKey) removeLocalCache(setting.storeKey);
  1027. };
  1028. const autoShowHistory = function (show) {
  1029. if (setting.storeKey) {
  1030. setLocalCache(setting.storeKey + '-showHis', show.toString());
  1031. }
  1032. };
  1033. if (setting.selector && setting.relaSpread) {
  1034. const resultId = setting.id + '-spread';
  1035. const obj = $(setting.selector);
  1036. obj.html(
  1037. ' <div id="' + resultId + '" class="sjs-sh">\n' +
  1038. ' </div>'
  1039. );
  1040. autoFlashHeight();
  1041. const spread = SpreadJsObj.createNewSpread($('#' + resultId)[0]);
  1042. const sheet = spread.getActiveSheet();
  1043. SpreadJsObj.initSheet(sheet, setting.spreadSetting);
  1044. spread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1045. if (!setting.relaSpread) return;
  1046. const sheet = info.sheet;
  1047. const data = sheet.zh_data;
  1048. if (!data) { return }
  1049. const curBills = data[info.row];
  1050. if (!curBills) { return }
  1051. if (curBills.ledger_id) {
  1052. SpreadJsObj.locateTreeNode(setting.relaSpread.getActiveSheet(), curBills.ledger_id, true);
  1053. if (setting.afterLocated) {
  1054. setting.afterLocated();
  1055. }
  1056. } else {
  1057. toastr.warning('找不到该清单');
  1058. }
  1059. });
  1060. const loadMissData = function (data, his = false) {
  1061. const sourceTree = setting.relaSpread.getActiveSheet().zh_tree;
  1062. if (!sourceTree) return;
  1063. for (const d of data) {
  1064. d.serialNo = sourceTree.getNodeIndex(sourceTree.getItems(d.ledger_id)) + 1;
  1065. }
  1066. data.sort(function (a, b) {
  1067. return a.serialNo - b.serialNo;
  1068. });
  1069. SpreadJsObj.loadSheetData(sheet, SpreadJsObj.DataType.Data, data);
  1070. if (!his && setting.storeKey) {
  1071. setLocalCache(setting.storeKey, JSON.stringify(data));
  1072. }
  1073. $(setting.tabSelector).show();
  1074. };
  1075. const showMissList = function () {
  1076. const tab = $(setting.tabSelector), tabPanel = $(tab.attr('content'));
  1077. $('a', '.side-menu').removeClass('active');
  1078. tab.addClass('active');
  1079. $('.tab-content .tab-pane').removeClass('active');
  1080. tabPanel.addClass('active');
  1081. showSideTools(true);
  1082. spread.refresh();
  1083. if (setting.afterShow) setting.afterShow();
  1084. };
  1085. const loadHisMissData = function () {
  1086. if (setting.storeKey) {
  1087. const storeStr = getLocalCache(setting.storeKey);
  1088. const storeData = storeStr ? JSON.parse(storeStr) : [];
  1089. if (storeData.length > 0) {
  1090. loadMissData(storeData, true);
  1091. const showHis = getLocalCache(setting.storeKey + '-showHis');
  1092. if (showHis === 'true') {
  1093. showMissList();
  1094. removeLocalCache(setting.storeKey + '-showHis');
  1095. }
  1096. }
  1097. }
  1098. };
  1099. return {
  1100. spread: spread,
  1101. loadMissData: loadMissData,
  1102. clearMissData: clearMissData,
  1103. loadHisMissData: loadHisMissData,
  1104. show: showMissList,
  1105. autoShowHistory: autoShowHistory,
  1106. };
  1107. } else {
  1108. const loadMissData = function (data) {
  1109. if (setting.storeKey) {
  1110. setLocalCache(setting.storeKey, JSON.stringify(data));
  1111. }
  1112. };
  1113. return {
  1114. loadErrorData: loadMissData,
  1115. clearErrorData: clearMissData,
  1116. autoShowHistory: autoShowHistory,
  1117. };
  1118. }
  1119. };
  1120. $.stdLib = function (setting) {
  1121. if (!setting.selector) return;
  1122. const obj = $(setting.selector);
  1123. const stdLibHtml = setting.libs.map(l => {
  1124. return `<option value="${l.id}" >${l.name}</option>`;
  1125. });
  1126. const relaSelect = {
  1127. showLevel: `std-${setting.stdType}-sl`,
  1128. searchText: `std-${setting.stdType}-st`,
  1129. searchResult: `std-${setting.stdType}-sr`,
  1130. searchPre: `std-${setting.stdType}-sp`,
  1131. searchNext: `std-${setting.stdType}-sn`,
  1132. searchClose: `std-${setting.stdType}-sc`,
  1133. };
  1134. obj.html(
  1135. '<div class="sjs-bar d-flex">\n' +
  1136. ' <div class="dropdown mr-1">\n' +
  1137. ' <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' +
  1138. ' <i class="fa fa-list-ol"></i> 显示层级\n' +
  1139. ' </button>\n' +
  1140. ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
  1141. ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
  1142. ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
  1143. ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
  1144. ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
  1145. ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
  1146. ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
  1147. ' </div>\n' +
  1148. ' </div>' +
  1149. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto">${stdLibHtml.join('')}</select></div>\n` +
  1150. ' <div class="ml-1">\n' +
  1151. ' <div class="dropdown">\n' +
  1152. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  1153. ' <i class="fa fa-search"></i>\n' +
  1154. ' </button>\n' +
  1155. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  1156. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  1157. ' <div class="d-inline-block">\n' +
  1158. ' <div class="input-group input-group-sm mr-1">' +
  1159. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  1160. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  1161. ' <div class="input-group-append" >\n' +
  1162. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  1163. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  1164. ' </div>\n' +
  1165. ' </div>\n' +
  1166. ' </div>\n' +
  1167. ` <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` +
  1168. ' </div>\n' +
  1169. ' </div>\n' +
  1170. ' </div>\n' +
  1171. ' </div>' +
  1172. '</div>\n' +
  1173. `<div id="std-${setting.stdType}-spread" class="sjs-sh"></div>\n`
  1174. );
  1175. autoFlashHeight();
  1176. const pathTree = createNewPathTree('base', setting.treeSetting);
  1177. const spreadSetting = {
  1178. cols: [
  1179. {title: '名称', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  1180. {title: '单位', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  1181. ],
  1182. treeCol: 0,
  1183. emptyRows: 0,
  1184. headRows: 1,
  1185. headRowHeight: [32],
  1186. defaultRowHeight: 21,
  1187. headerFont: '12px 微软雅黑',
  1188. font: '12px 微软雅黑',
  1189. headColWidth: [30],
  1190. selectedBackColor: '#fffacd',
  1191. readOnly: true,
  1192. stdType: setting.stdType,
  1193. };
  1194. spreadSetting.cols.unshift(setting.stdType === 'xmj'
  1195. ? {title: '项目节编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'}
  1196. : {title: '清单编号', field: 'b_code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'});
  1197. const spread = SpreadJsObj.createNewSpread($(`#std-${setting.stdType}-spread`)[0]);
  1198. const sheet = spread.getActiveSheet();
  1199. SpreadJsObj.initSheet(sheet, spreadSetting);
  1200. if (setting.cellDoubleClick) sheet.bind(spreadNS.Events.CellDoubleClick, setting.cellDoubleClick);
  1201. sheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1202. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  1203. SpreadJsObj.saveTopAndSelect(info.sheet, cacheKey.node);
  1204. }
  1205. });
  1206. sheet.bind(spreadNS.Events.TopRowChanged, function (e, info) {
  1207. SpreadJsObj.saveTopAndSelect(info.sheet, cacheKey.node);
  1208. });
  1209. const cacheLib = [];
  1210. const cacheKey = {
  1211. lib: setting.page + '-' + setting.tid + '-' + setting.stdType,
  1212. };
  1213. $('select', setting.selector).change(function () {
  1214. loadLib(parseInt(this.value), true);
  1215. });
  1216. (function (select, sheet) {
  1217. $(select).click(function () {
  1218. if (!sheet.zh_tree) return;
  1219. const tag = $(this).attr('tag');
  1220. const tree = sheet.zh_tree;
  1221. setTimeout(() => {
  1222. switch (tag) {
  1223. case "1":
  1224. case "2":
  1225. case "3":
  1226. case "4":
  1227. case "5":
  1228. tree.expandByLevel(parseInt(tag));
  1229. SpreadJsObj.refreshTreeRowVisible(sheet);
  1230. break;
  1231. case "last":
  1232. tree.expandByCustom(() => { return true; });
  1233. SpreadJsObj.refreshTreeRowVisible(sheet);
  1234. break;
  1235. }
  1236. }, 100);
  1237. });
  1238. })(`a[name=${relaSelect.showLevel}]`, sheet);
  1239. const loadLib = function(listId, reload = false) {
  1240. cacheKey.node = cacheLib.lib + '-' + listId;
  1241. const locateMemory = function () {
  1242. if (!reload) {
  1243. SpreadJsObj.loadTopAndSelect(sheet, cacheKey.node);
  1244. } else {
  1245. removeLocalCache(cacheKey.node);
  1246. }
  1247. };
  1248. const cacheData = cacheLib.find(function (lib) {
  1249. return lib.id === listId;
  1250. });
  1251. if (cacheData) {
  1252. pathTree.loadDatas(cacheData.data);
  1253. SpreadJsObj.loadSheetData(sheet, 'tree', pathTree);
  1254. locateMemory();
  1255. setLocalCache(cacheKey.lib, listId);
  1256. } else {
  1257. postData(`/std-lib/get-data`, {stdType: setting.stdType, list_id: listId}, function (data) {
  1258. cacheLib.push({id: listId, data: data});
  1259. pathTree.loadDatas(data);
  1260. SpreadJsObj.loadSheetData(sheet, 'tree', pathTree);
  1261. locateMemory();
  1262. setLocalCache(cacheKey.lib, listId);
  1263. });
  1264. }
  1265. };
  1266. const _loadCacheLib = function() {
  1267. let libId = getLocalCache(cacheKey.lib);
  1268. if (libId) {
  1269. $('select', setting.selector).val(libId);
  1270. loadLib(parseInt(libId));
  1271. } else {
  1272. loadLib(parseInt($('select', setting.selector).val()));
  1273. }
  1274. };
  1275. _loadCacheLib();
  1276. const searchObj = {
  1277. result: [],
  1278. cur: 0,
  1279. searchStdNode: function() {
  1280. const keyword = $(`#${relaSelect.searchText}`).val();
  1281. searchObj.result = keyword ? pathTree.nodes.filter(x => {
  1282. return x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0;
  1283. }) : [];
  1284. // searchObj.result = [];
  1285. // for (const x of pathTree.nodes) {
  1286. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  1287. // searchObj.result.push(x);
  1288. // }
  1289. // }
  1290. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  1291. searchObj.cur = 0;
  1292. if (searchObj.result.length > 0) {
  1293. SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]));
  1294. }
  1295. },
  1296. searchPre: function () {
  1297. if (searchObj.result.length === 0) return;
  1298. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  1299. SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  1300. },
  1301. searchNext: function () {
  1302. if (searchObj.result.length === 0) return;
  1303. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  1304. SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  1305. },
  1306. clear: function () {
  1307. $(`#${relaSelect.searchText}`).val('');
  1308. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  1309. searchObj.result = [];
  1310. searchObj.cur = 0;
  1311. }
  1312. };
  1313. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  1314. $(`#${relaSelect.searchPre}`).click(function (e) {
  1315. searchObj.searchPre();
  1316. e.stopPropagation();
  1317. });
  1318. $(`#${relaSelect.searchNext}`).click(function (e) {
  1319. searchObj.searchNext();
  1320. e.stopPropagation();
  1321. });
  1322. $(`#${relaSelect.searchClose}`).click(function (e) {
  1323. searchObj.clear();
  1324. e.stopPropagation();
  1325. });
  1326. return { spread }
  1327. };
  1328. $.gljLib = function (setting) {
  1329. if (!setting.selector) return;
  1330. const obj = $(setting.selector);
  1331. const stdLibHtml = setting.libs.map(l => {
  1332. return `<option value="${l.id}" >${l.name}</option>`;
  1333. });
  1334. const relaSelect = {
  1335. showLevel: `std-${setting.stdType}-sl`,
  1336. searchText: `std-${setting.stdType}-st`,
  1337. searchResult: `std-${setting.stdType}-sr`,
  1338. searchPre: `std-${setting.stdType}-sp`,
  1339. searchNext: `std-${setting.stdType}-sn`,
  1340. searchClose: `std-${setting.stdType}-sc`,
  1341. };
  1342. obj.html(
  1343. '<div class="sjs-bar d-flex">\n' +
  1344. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto">${stdLibHtml.join('')}</select></div>\n` +
  1345. ' <div class="ml-1">\n' +
  1346. ' <div class="dropdown">\n' +
  1347. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  1348. ' <i class="fa fa-search"></i>\n' +
  1349. ' </button>\n' +
  1350. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  1351. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  1352. ' <div class="d-inline-block">\n' +
  1353. ' <div class="input-group input-group-sm mr-1">' +
  1354. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  1355. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  1356. ' <div class="input-group-append" >\n' +
  1357. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  1358. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  1359. ' </div>\n' +
  1360. ' </div>\n' +
  1361. ' </div>\n' +
  1362. ` <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` +
  1363. ' </div>\n' +
  1364. ' </div>\n' +
  1365. ' </div>\n' +
  1366. ' </div>' +
  1367. '</div>\n' +
  1368. `<div id="std-${setting.stdType}-spread" class="${setting.spreadClassCss ? setting.spreadClassCss : 'sjs-sh'}"></div>\n`
  1369. );
  1370. autoFlashHeight();
  1371. const pathTree = createNewPathTree('base', setting.treeSetting);
  1372. const spreadSetting = {
  1373. cols: [
  1374. {title: '名称', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  1375. {title: '单位', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  1376. ],
  1377. treeCol: 0,
  1378. emptyRows: 0,
  1379. headRows: 1,
  1380. headRowHeight: [32],
  1381. defaultRowHeight: 21,
  1382. headerFont: '12px 微软雅黑',
  1383. font: '12px 微软雅黑',
  1384. headColWidth: [30],
  1385. selectedBackColor: '#fffacd',
  1386. readOnly: true,
  1387. stdType: setting.stdType,
  1388. };
  1389. spreadSetting.cols.unshift(setting.stdType === 'xmj'
  1390. ? {title: '项目节编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'}
  1391. : {title: '清单编号', field: 'b_code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'});
  1392. const spread = SpreadJsObj.createNewSpread($(`#std-${setting.stdType}-spread`)[0]);
  1393. const sheet = spread.getActiveSheet();
  1394. SpreadJsObj.initSheet(sheet, setting.spreadSetting ? setting.spreadSetting : spreadSetting);
  1395. if (setting.cellDoubleClick) sheet.bind(spreadNS.Events.CellDoubleClick, setting.cellDoubleClick);
  1396. sheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1397. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  1398. SpreadJsObj.saveTopAndSelect(info.sheet, cacheKey.node);
  1399. }
  1400. });
  1401. sheet.bind(spreadNS.Events.TopRowChanged, function (e, info) {
  1402. SpreadJsObj.saveTopAndSelect(info.sheet, cacheKey.node);
  1403. });
  1404. const cacheLib = [];
  1405. const cacheKey = {
  1406. lib: setting.page + '-' + setting.tid + '-' + setting.stdType,
  1407. };
  1408. $('select', setting.selector).change(function () {
  1409. loadLib(parseInt(this.value), true);
  1410. });
  1411. const loadLib = function(listId, reload = false) {
  1412. cacheKey.node = cacheLib.lib + '-' + listId;
  1413. const locateMemory = function () {
  1414. if (!reload) {
  1415. SpreadJsObj.loadTopAndSelect(sheet, cacheKey.node);
  1416. } else {
  1417. removeLocalCache(cacheKey.node);
  1418. }
  1419. };
  1420. const cacheData = cacheLib.find(function (lib) {
  1421. return lib.id === listId;
  1422. });
  1423. if (cacheData) {
  1424. pathTree.loadDatas(cacheData.data);
  1425. SpreadJsObj.loadSheetData(sheet, 'tree', pathTree);
  1426. locateMemory();
  1427. setLocalCache(cacheKey.lib, listId);
  1428. } else {
  1429. postData(`/std-lib/get-data`, {stdType: setting.stdType, list_id: listId}, function (data) {
  1430. cacheLib.push({id: listId, data: data});
  1431. pathTree.loadDatas(data);
  1432. SpreadJsObj.loadSheetData(sheet, 'tree', pathTree);
  1433. locateMemory();
  1434. setLocalCache(cacheKey.lib, listId);
  1435. });
  1436. }
  1437. };
  1438. const _loadCacheLib = function() {
  1439. let libId = getLocalCache(cacheKey.lib);
  1440. if (libId) {
  1441. $('select', setting.selector).val(libId);
  1442. loadLib(parseInt(libId));
  1443. } else {
  1444. loadLib(parseInt($('select', setting.selector).val()));
  1445. }
  1446. };
  1447. _loadCacheLib();
  1448. const searchObj = {
  1449. result: [],
  1450. cur: 0,
  1451. searchStdNode: function() {
  1452. const keyword = $(`#${relaSelect.searchText}`).val();
  1453. searchObj.result = keyword ? pathTree.nodes.filter(x => {
  1454. return x.code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0;
  1455. }) : [];
  1456. // searchObj.result = [];
  1457. // for (const x of pathTree.nodes) {
  1458. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  1459. // searchObj.result.push(x);
  1460. // }
  1461. // }
  1462. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  1463. searchObj.cur = 0;
  1464. if (searchObj.result.length > 0) {
  1465. SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]));
  1466. }
  1467. },
  1468. searchPre: function () {
  1469. if (searchObj.result.length === 0) return;
  1470. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  1471. SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  1472. },
  1473. searchNext: function () {
  1474. if (searchObj.result.length === 0) return;
  1475. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  1476. SpreadJsObj.locateTreeNode(sheet, pathTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  1477. },
  1478. clear: function () {
  1479. $(`#${relaSelect.searchText}`).val('');
  1480. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  1481. searchObj.result = [];
  1482. searchObj.cur = 0;
  1483. }
  1484. };
  1485. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  1486. $(`#${relaSelect.searchPre}`).click(function (e) {
  1487. searchObj.searchPre();
  1488. e.stopPropagation();
  1489. });
  1490. $(`#${relaSelect.searchNext}`).click(function (e) {
  1491. searchObj.searchNext();
  1492. e.stopPropagation();
  1493. });
  1494. $(`#${relaSelect.searchClose}`).click(function (e) {
  1495. searchObj.clear();
  1496. e.stopPropagation();
  1497. });
  1498. return { spread }
  1499. };
  1500. })(jQuery);