cs_tools.js 87 KB

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