cs_tools.js 75 KB

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