cs_tools.js 94 KB

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