cs_tools.js 87 KB

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