revise.js 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. const invalidFields = {
  11. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price'],
  12. gcl: ['dgn_qty1', 'dgn_qty2'],
  13. posCode: ['b_code'],
  14. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp'],
  15. posXmj: ['code'],
  16. };
  17. function transExpr(expr) {
  18. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  19. }
  20. $(document).ready(() => {
  21. let stdXmj, stdGcl, searchLedger;
  22. autoFlashHeight();
  23. // 初始化spread
  24. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  25. const billsSheet = billsSpread.getActiveSheet();
  26. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  27. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  28. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  29. const posSheet = posSpread.getActiveSheet();
  30. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  31. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  32. // 初始化 节点树结构
  33. const treeSetting = {
  34. id: 'ledger_id',
  35. pid: 'ledger_pid',
  36. order: 'order',
  37. level: 'level',
  38. rootId: -1,
  39. keys: ['id', 'tender_id', 'ledger_id'],
  40. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  41. };
  42. if (!isTz) {
  43. treeSetting.calcFields.push('deal_tp');
  44. }
  45. treeSetting.calcFun = function (node) {
  46. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  47. };
  48. const billsTree = createNewPathTree('revise', treeSetting);
  49. // 初始化 计量单元
  50. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  51. // 清单 相关方法&绑定spreadjs事件
  52. const billsTreeSpreadObj = {
  53. loadExprToInput(sheet) {
  54. const sel = sheet.getSelections()[0];
  55. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  56. if (col && col.type === 'Number') {
  57. const data = SpreadJsObj.getSelectObject(sheet);
  58. if (data) {
  59. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  60. if (col.field.indexOf('dgn') >= 0) {
  61. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== ''));
  62. } else if (col.field === 'unit_price') {
  63. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true));
  64. } else {
  65. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0));
  66. }
  67. } else {
  68. $('#bills-expr').val('').attr('readOnly', true);
  69. }
  70. } else {
  71. $('#bills-expr').val('').attr('readOnly', true);
  72. }
  73. },
  74. getDefaultSelectInfo: function (sheet) {
  75. const tree = sheet.zh_tree;
  76. if (!tree) return;
  77. const sel = sheet.getSelections()[0];
  78. const node = sheet.zh_tree.nodes[sel.row];
  79. if (!node) return;
  80. let count = 1;
  81. if (sel.rowCount > 1) {
  82. for (let r = 1; r < sel.rowCount; r++) {
  83. const rNode = sheet.zh_tree.nodes[sel.row + r];
  84. if (rNode.level > node.level) continue;
  85. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  86. toastr.warning('请选择同一节点下的节点,进行该操作');
  87. return;
  88. }
  89. count += 1;
  90. }
  91. }
  92. return [tree, node, count];
  93. },
  94. /**
  95. * 刷新顶部按钮是否可用
  96. * @param sheet
  97. * @param selections
  98. */
  99. refreshOperationValid: function (sheet, selection) {
  100. const setObjEnable = function (obj, enable) {
  101. if (enable) {
  102. obj.removeClass('disabled');
  103. } else {
  104. obj.addClass('disabled');
  105. }
  106. };
  107. const invalidAll = function () {
  108. setObjEnable($('a[type=add]'), false);
  109. setObjEnable($('a[type=delete]'), false);
  110. setObjEnable($('a[type=up-move]'), false);
  111. setObjEnable($('a[type=down-move]'), false);
  112. setObjEnable($('a[type=up-level]'), false);
  113. setObjEnable($('a[type=down-level]'), false);
  114. };
  115. const sel = selection ? selection[0] : sheet.getSelections()[0];
  116. const row = sel ? sel.row : -1;
  117. const tree = sheet.zh_tree;
  118. if (!tree) {
  119. invalidAll();
  120. return;
  121. }
  122. const first = sheet.zh_tree.nodes[row];
  123. if (!first) {
  124. invalidAll();
  125. return;
  126. }
  127. let last = first, sameParent = true, nodeUsed = first.used;
  128. if (sel.rowCount > 1 && first) {
  129. for (let r = 1; r < sel.rowCount; r++) {
  130. const rNode = tree.nodes[sel.row + r];
  131. if (!rNode) {
  132. sameParent = false;
  133. break;
  134. }
  135. nodeUsed = nodeUsed || rNode.used;
  136. if (rNode.level > first.level) continue;
  137. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  138. sameParent = false;
  139. break;
  140. }
  141. last = rNode;
  142. }
  143. }
  144. const preNode = tree.getPreSiblingNode(first);
  145. const valid = !sheet.zh_setting.readOnly;
  146. setObjEnable($('a[type=add]'), valid && first && first.level > 1);
  147. setObjEnable($('a[type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed);
  148. setObjEnable($('a[type=up-move]'), valid && first && sameParent && first.level > 1 && preNode);
  149. setObjEnable($('a[type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
  150. if (isTz) {
  151. const posRange = last ? pos.getLedgerPos(last.id) : [];
  152. setObjEnable($('a[type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  153. && first.level > 2 && ((!posRange || posRange.length === 0) || tree.isLastSibling(last)));
  154. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  155. setObjEnable($('a[type=down-level]'), valid && first && sameParent && !nodeUsed
  156. && first.level > 1 && preNode && (!preNodePosRange || preNodePosRange.length === 0));
  157. } else {
  158. setObjEnable($('#up-level'), valid && first && sameParent && first.level > 2 && tree.getParent(first));
  159. setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode);
  160. }
  161. setObjEnable($('#cut'), valid);
  162. setObjEnable($('#paste'), valid);
  163. },
  164. /**
  165. *
  166. * @param sheet
  167. * @param data
  168. */
  169. refreshTree: function (sheet, data) {
  170. SpreadJsObj.massOperationSheet(sheet, function () {
  171. const tree = sheet.zh_tree;
  172. // 处理删除
  173. if (data.delete) {
  174. data.delete.sort(function (a, b) {
  175. return b.deleteIndex - a.deleteIndex;
  176. });
  177. for (const d of data.delete) {
  178. sheet.deleteRows(d.deleteIndex, 1);
  179. }
  180. }
  181. // 处理新增
  182. if (data.create) {
  183. const newNodes = data.create;
  184. if (newNodes) {
  185. newNodes.sort(function (a, b) {
  186. return a.index - b.index;
  187. });
  188. for (const node of newNodes) {
  189. sheet.addRows(node.index, 1);
  190. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  191. }
  192. }
  193. }
  194. // 处理更新
  195. if (data.update) {
  196. const rows = [];
  197. for (const u of data.update) {
  198. rows.push(tree.nodes.indexOf(u));
  199. }
  200. SpreadJsObj.reLoadRowsData(sheet, rows);
  201. }
  202. // 处理展开
  203. if (data.expand) {
  204. const expanded = [];
  205. for (const e of data.expand) {
  206. if (expanded.indexOf(e) === -1) {
  207. const posterity = tree.getPosterity(e);
  208. for (const p of posterity) {
  209. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  210. expanded.push(p);
  211. }
  212. }
  213. }
  214. }
  215. });
  216. },
  217. selectionChanged: function (e, info) {
  218. if (info.newSelections) {
  219. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row) {
  220. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  221. posSpreadObj.loadCurPosData();
  222. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  223. posSearch.search($('#pos-keyword').val());
  224. }
  225. }
  226. billsTreeSpreadObj.loadExprToInput(info.sheet);
  227. },
  228. /**
  229. * 新增节点
  230. * @param spread
  231. */
  232. baseOpr: function (sheet, type, addCount = 1) {
  233. const self = this;
  234. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  235. if (!tree || !node || !count) return;
  236. if (type === 'delete') {
  237. const parent = tree.getParent(node);
  238. const children = parent ? parent.children : tree.children;
  239. const index = children.indexOf(node);
  240. for (let i = 0; i < count; i++) {
  241. const child = children[i+index];
  242. if (tree.checkNodeUsed(child, pos)) {
  243. toastr.warning('选中的节点已计量,不可删除');
  244. return;
  245. }
  246. }
  247. } else if (type === 'up-level') {
  248. const parent = tree.getParent(node);
  249. const children = parent ? parent.children : tree.children;
  250. const index = children.indexOf(node);
  251. for (let i = index; i < children.length; i++) {
  252. const child = children[index];
  253. if (tree.checkNodeUsed(child, pos)) {
  254. if (i >= index + count) {
  255. toastr.warning('其后节点已计量,选中的节点不可升级');
  256. } else {
  257. toastr.warning('选中的节点已计量,不可升级');
  258. }
  259. return;
  260. }
  261. }
  262. } else if (type === 'down-level') {
  263. const parent = tree.getParent(node);
  264. const children = parent ? parent.children : tree.children;
  265. const index = children.indexOf(node);
  266. for (let i = 0; i < count; i++) {
  267. const child = children[i+index];
  268. if (tree.checkNodeUsed(child, pos)) {
  269. toastr.warning('选中的节点已计量,不可降级');
  270. return;
  271. }
  272. }
  273. }
  274. postData(window.location.pathname + '/update', {
  275. postType: type,
  276. postData: {
  277. id: node.ledger_id,
  278. count: type === 'add' ? addCount : count,
  279. }
  280. }, function (result) {
  281. const refreshData = tree.loadPostData(result);
  282. self.refreshTree(sheet, refreshData);
  283. if (type === 'delete') {
  284. const sel = sheet.getSelections()[0];
  285. if (sel) {
  286. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  287. }
  288. } else if (['up-move', 'down-move'].indexOf(type) > -1) {
  289. const sel = sheet.getSelections()[0];
  290. if (sel) {
  291. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  292. }
  293. } else if (type === 'add') {
  294. const sel = sheet.getSelections()[0];
  295. if (sel) {
  296. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  297. }
  298. }
  299. self.refreshOperationValid(sheet);
  300. });
  301. },
  302. /**
  303. * 编辑单元格响应事件
  304. * @param {Object} e
  305. * @param {Object} info
  306. */
  307. editEnded: function (e, info) {
  308. if (info.sheet.zh_setting) {
  309. const col = info.sheet.zh_setting.cols[info.col];
  310. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  311. const node = sortData[info.row];
  312. const data = {
  313. id: node.id,
  314. tender_id: node.tender_id,
  315. ledger_id: node.ledger_id
  316. };
  317. // 未改变值则不提交
  318. const orgValue = node[col.field];
  319. const newValue = trimInvalidChar(info.editingText);
  320. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  321. return;
  322. }
  323. // 台账模式,检查计量单元相关
  324. if (isTz) {
  325. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  326. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  327. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  328. if (!node.children || node.children.length ===0) {
  329. const lPos = pos.getLedgerPos(node.id);
  330. if (lPos && lPos.length > 0) {
  331. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  332. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  333. return;
  334. }
  335. }
  336. }
  337. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  338. const lPos = pos.getLedgerPos(node.id);
  339. if (lPos && lPos.length > 0) {
  340. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  341. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  342. return;
  343. }
  344. }
  345. }
  346. // 获取更新数据
  347. if (info.editingText) {
  348. const text = newValue;
  349. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  350. toastr.error('节点已计量,请勿删除编号');
  351. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  352. return;
  353. }
  354. if (col.type === 'Number') {
  355. const num = _.toNumber(text);
  356. if (_.isFinite(num)) {
  357. data[col.field] = num;
  358. } else {
  359. try {
  360. data[col.field] = math.evaluate(transExpr(text));
  361. } catch(err) {
  362. toastr.error('输入的表达式非法');
  363. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  364. return;
  365. }
  366. }
  367. } else {
  368. data[col.field] = text;
  369. }
  370. } else {
  371. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  372. toastr.error('节点已计量,请勿删除编号');
  373. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  374. return;
  375. }
  376. data[col.field] = null;
  377. }
  378. // 更新至服务器
  379. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  380. const refreshNode = billsTree.loadPostData(result);
  381. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  382. });
  383. }
  384. },
  385. clipboardPasting: function (e, info) {
  386. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  387. info.cancel = true;
  388. if (!setting || !tree) return;
  389. // const range = info.cellRange;
  390. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  391. // const node = tree.nodes[iRow];
  392. // if (tree.checkNodeUsed(node, pos)) {
  393. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  394. // return;
  395. // }
  396. // }
  397. const pasteData = info.pasteData.html
  398. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  399. : (info.pasteData.text === ''
  400. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  401. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  402. const hint = {
  403. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  404. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  405. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  406. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  407. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  408. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  409. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  410. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  411. };
  412. const datas = [], filterNodes = [];
  413. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  414. const curRow = info.cellRange.row + iRow;
  415. const node = tree.nodes[curRow];
  416. if (!node) continue;
  417. let bPaste = false;
  418. const data = info.sheet.zh_tree.getNodeKeyData(node);
  419. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  420. const curCol = info.cellRange.col + iCol;
  421. const colSetting = info.sheet.zh_setting.cols[curCol];
  422. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  423. toastMessageUniq(hint.parent);
  424. continue;
  425. }
  426. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  427. toastMessageUniq(hint.gcl);
  428. continue;
  429. }
  430. const lPos = pos.getLedgerPos(node.id);
  431. if (lPos && lPos.length > 0) {
  432. if (value === '' && colSetting.field === 'b_code') {
  433. toastMessageUniq(hint.posCode);
  434. continue;
  435. }
  436. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  437. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  438. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  439. toastMessageUniq(hint.posQty);
  440. continue;
  441. }
  442. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  443. toastMessageUniq(hint.posXmj);
  444. continue;
  445. }
  446. }
  447. const value = trimInvalidChar(pasteData[iRow][iCol]);
  448. if (tree.checkNodeUsed(node, pos) && col.field === 'unit_price') {
  449. toastMessageUniq (hint.usedUp);
  450. continue;
  451. }
  452. if (colSetting.type === 'Number') {
  453. const num = _.toNumber(value);
  454. if (num) {
  455. data[colSetting.field] = num;
  456. } else {
  457. try {
  458. data[colSetting.field] = math.evaluate(transExpr(value));
  459. } catch (err) {
  460. toastMessageUniq(hint.invalidExpr);
  461. continue;
  462. }
  463. }
  464. } else {
  465. if (node.used && (col.field === 'code' || col.field ==='b_code')
  466. && data[colSetting.field] !== '' && value === '') {
  467. toastMessageUniq(hint.usedCode);
  468. continue;
  469. }
  470. data[colSetting.field] = value;
  471. }
  472. bPaste = true;
  473. }
  474. if (bPaste) {
  475. datas.push(data);
  476. } else {
  477. filterNodes.push(node);
  478. }
  479. }
  480. if (datas.length > 0) {
  481. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  482. const refreshNode = tree.loadPostData(result);
  483. if (refreshNode.update) {
  484. refreshNode.update = refreshNode.update.concat(filterNodes);
  485. }
  486. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  487. }, function () {
  488. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  489. });
  490. } else {
  491. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  492. }
  493. },
  494. clipboardPasted: function (e, info) {
  495. const hint = {
  496. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  497. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  498. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  499. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  500. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  501. };
  502. const tree = info.sheet.zh_tree;
  503. if (!tree) { return; }
  504. const sortData = info.sheet.zh_tree.nodes;
  505. const datas = [], filterNodes = [];
  506. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  507. let bPaste = false;
  508. const curRow = info.cellRange.row + iRow;
  509. const node = sortData[curRow];
  510. if (node) {
  511. const data = info.sheet.zh_tree.getNodeKeyData(node);
  512. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  513. const curCol = info.cellRange.col + iCol;
  514. const colSetting = info.sheet.zh_setting.cols[curCol];
  515. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  516. const lPos = pos.getLedgerPos(node.id);
  517. if (lPos && lPos.length > 0) {
  518. if (value === '' && colSetting.field === 'b_code') {
  519. toastMessageUniq(hint.posCode);
  520. continue;
  521. }
  522. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  523. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  524. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  525. toastMessageUniq(hint.posQty);
  526. continue;
  527. }
  528. }
  529. if (node.used && col.field === 'unit_price') {
  530. toastMessageUniq (hint.usedUp);
  531. continue;
  532. }
  533. if (colSetting.type === 'Number') {
  534. const num = _.toNumber(value);
  535. if (num) {
  536. data[colSetting.field] = num;
  537. } else {
  538. try {
  539. data[colSetting.field] = math.evaluate(transExpr(value));
  540. } catch (err) {
  541. toastMessageUniq(hint.invalidExpr);
  542. continue;
  543. }
  544. }
  545. } else {
  546. if (node.used && (col.field === 'code' || col.field ==='b_code')
  547. && data[colSetting.field] !== '' && value === '') {
  548. toastMessageUniq(hint.usedCode);
  549. continue;
  550. }
  551. data[colSetting.field] = value;
  552. }
  553. bPaste = true;
  554. }
  555. if (bPaste) {
  556. datas.push(data);
  557. } else {
  558. filterNodes.push(node);
  559. }
  560. }
  561. }
  562. if (datas.length > 0) {
  563. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  564. const refreshNode = tree.loadPostData(result);
  565. if (refreshNode.update) {
  566. refreshNode.update = refreshNode.update.concat(filterNodes);
  567. }
  568. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  569. }, function () {
  570. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  571. });
  572. } else {
  573. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  574. }
  575. },
  576. deletePress: function (sheet) {
  577. if (!sheet.zh_setting) return;
  578. const sel = sheet.getSelections()[0], datas = [];
  579. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  580. const node = sheet.zh_tree.nodes[iRow];
  581. if (sheet.zh_tree.checkNodeUsed(node, pos)) {
  582. toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  583. return;
  584. }
  585. const data = sheet.zh_tree.getNodeKeyData(node);
  586. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  587. const col = sheet.zh_setting.cols[iCol];
  588. data[col.field] = null;
  589. }
  590. datas.push(data);
  591. }
  592. if (datas.length > 0) {
  593. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  594. const refreshNode = sheet.zh_tree.loadPostData(result);
  595. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  596. });
  597. }
  598. },
  599. pasteBlock: function (spread, copyInfo) {
  600. const self = this;
  601. const sheet = spread.getActiveSheet();
  602. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  603. postData(window.location.pathname + '/update', {
  604. postType: 'paste-block',
  605. postData: {
  606. id: tree.getNodeKey(node),
  607. tid: copyInfo.tid,
  608. block: copyInfo.block,
  609. }
  610. }, function (data) {
  611. pos.updateDatas(data.pos);
  612. const result = tree.loadPostData(data.ledger);
  613. self.refreshTree(sheet, result);
  614. const sel = sheet.getSelections()[0];
  615. if (sel) {
  616. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  617. }
  618. self.refreshOperationValid(sheet);
  619. removeLocalCache(copyBlockTag);
  620. }, null, true);
  621. },
  622. topRowChanged: function (e, info) {
  623. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  624. },
  625. editStarting(e, info) {
  626. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  627. const col = info.sheet.zh_setting.cols[info.col];
  628. const node = info.sheet.zh_tree.nodes[info.row];
  629. if (!node) {
  630. info.cancel = true;
  631. return;
  632. }
  633. switch (col.field) {
  634. case 'code':
  635. const posRange = pos.getLedgerPos(node.id);
  636. return posRange && posRange.length > 0;
  637. case 'unit_price':
  638. info.cancel = (node.children && node.children.length > 0) || node.used;
  639. break;
  640. case 'sgfh_qty':
  641. case 'sgfh_tp':
  642. case 'sjcl_qty':
  643. case 'sjcl_tp':
  644. case 'qtcl_qty':
  645. case 'qtcl_tp':
  646. case 'deal_qty':
  647. case 'deal_tp':
  648. info.cancel = (node.children && node.children.length > 0);
  649. break;
  650. case 'dgn_qty1':
  651. case 'dgn_qty2':
  652. info.cancel = !_.isEmpty(node.b_code);
  653. break;
  654. }
  655. },
  656. cut: function (sheet, sel, callback) {
  657. if (!sheet || !sel) return;
  658. if (sel.colCount >= sheet.zh_setting.cols.length) {
  659. toastr.warning('请勿选中整行剪切');
  660. return;
  661. }
  662. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  663. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  664. const node = sortData[iRow];
  665. if (node) {
  666. const data = sheet.zh_tree.getNodeKeyData(node);
  667. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  668. const col = sheet.zh_setting.cols[iCol];
  669. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  670. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  671. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  672. const lPos = pos.getLedgerPos(node.id);
  673. if (lPos && lPos.length > 0) {
  674. toastr.error('不可剪切');
  675. return;
  676. }
  677. }
  678. const style = sheet.getStyle(iRow, iCol);
  679. if (style.locked) {
  680. toastr.error('不可剪切');
  681. return;
  682. }
  683. const colSetting = sheet.zh_setting.cols[iCol];
  684. data[colSetting.field] = null;
  685. }
  686. datas.push(data);
  687. }
  688. }
  689. if (datas.length > 0) {
  690. callback();
  691. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  692. const refreshNode = sheet.zh_tree.loadPostData(result);
  693. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  694. });
  695. }
  696. },
  697. sortCode: function (sheet) {
  698. const tree = sheet.zh_tree;
  699. if (!tree) return;
  700. const select = SpreadJsObj.getSelectObject(sheet);
  701. if (!select || !select.code || select.code === '') return;
  702. const recursiveSortCode = function (data, parentCode, children) {
  703. if (!children || children.length === 0) return;
  704. for (const [i, child] of children.entries()) {
  705. if (!child.b_code || child.b_code === '') {
  706. const code = parentCode + '-' + (i + 1);
  707. const cData = tree.getNodeKeyData(child);
  708. cData.code = code;
  709. data.push(cData);
  710. if (!tree.isLeafXmj(child)) {
  711. recursiveSortCode(data, code, child.children);
  712. }
  713. }
  714. }
  715. };
  716. const data = [];
  717. recursiveSortCode(data, select.code, select.children);
  718. if (data.length > 0) {
  719. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  720. const refreshNode = tree.loadPostData(result);
  721. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  722. })
  723. }
  724. }
  725. };
  726. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  727. billsTreeSpreadObj.loadExprToInput(billsSheet);
  728. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  729. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  730. if (!readOnly) {
  731. // 增删上下移升降级
  732. $('a[name="base-opr"]').click(function () {
  733. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  734. });
  735. $('a[name=cpc]').click(function () {
  736. billsSpread.commandManager().execute({
  737. cmd: this.getAttribute('type'),
  738. sheetName: billsSheet.name()
  739. });
  740. });
  741. $('#bills-expr').bind('change mouseleave', function () {
  742. if (this.readOnly) return;
  743. const expr = $(this);
  744. const select = SpreadJsObj.getSelectObject(billsSheet);
  745. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  746. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  747. const data = {
  748. id: select.id,
  749. tender_id: select.tender_id,
  750. ledger_id: select.ledger_id
  751. };
  752. if (newValue !== '') {
  753. const num = _.toNumber(newValue);
  754. if (num) {
  755. data[field] = num;
  756. } else {
  757. try {
  758. data[field] = math.evaluate(transExpr(newValue));
  759. } catch (err) {
  760. toastr.error('输入的表达式非法');
  761. return;
  762. }
  763. }
  764. } else {
  765. data[field] = null;
  766. }
  767. // 更新至服务器
  768. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  769. const refreshNode = billsTree.loadPostData(result);
  770. expr.val(select[field]);
  771. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  772. });
  773. });
  774. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  775. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  776. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  777. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  778. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  779. SpreadJsObj.Clipboard.setCopyData(copyText);
  780. });
  781. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  782. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  783. let batchInsertObj;
  784. $.contextMenu.types.batchInsert = function (item, opt, root) {
  785. const self = this;
  786. if ($.isFunction(item.icon)) {
  787. item._icon = item.icon.call(this, this, $t, key, item);
  788. } else {
  789. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  790. // to enable font awesome
  791. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  792. } else {
  793. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  794. }
  795. }
  796. this.addClass(item._icon);
  797. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="20" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  798. .appendTo(this);
  799. const $input = $obj.find('input');
  800. const event = () => {
  801. if (self.hasClass('context-menu-disabled')) return;
  802. item.batchInsert($input[0], root);
  803. };
  804. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  805. $input.click((e) => {e.stopPropagation();})
  806. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  807. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  808. };
  809. // 右键菜单
  810. $.contextMenu({
  811. selector: '#bills-spread',
  812. build: function ($trigger, e) {
  813. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  814. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  815. },
  816. items: {
  817. 'create': {
  818. name: '新增',
  819. icon: 'fa-sign-in',
  820. callback: function (key, opt) {
  821. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  822. },
  823. disabled: function (key, opt) {
  824. const sheet = billsSheet;
  825. const selection = sheet.getSelections();
  826. const sel = selection ? selection[0] : sheet.getSelections()[0];
  827. const row = sel ? sel.row : -1;
  828. const tree = sheet.zh_tree;
  829. if (!tree) return true;
  830. const first = sheet.zh_tree.nodes[row];
  831. const valid = !sheet.zh_setting.readOnly;
  832. return !(valid && first && first.level > 1);
  833. }
  834. },
  835. 'delete': {
  836. name: '删除',
  837. icon: 'fa-remove',
  838. callback: function (key, opt) {
  839. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  840. },
  841. disabled: function (key, opt) {
  842. const sheet = billsSheet;
  843. const selection = sheet.getSelections();
  844. const sel = selection ? selection[0] : sheet.getSelections()[0];
  845. const row = sel ? sel.row : -1;
  846. const tree = sheet.zh_tree;
  847. if (!tree) return true;
  848. const first = sheet.zh_tree.nodes[row];
  849. let last = first, sameParent = true, nodeUsed = first.used;
  850. if (sel.rowCount > 1 && first) {
  851. for (let r = 1; r < sel.rowCount; r++) {
  852. const rNode = tree.nodes[sel.row + r];
  853. if (!rNode) {
  854. sameParent = false;
  855. break;
  856. }
  857. nodeUsed = nodeUsed || rNode.used;
  858. if (rNode.level > first.level) continue;
  859. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  860. sameParent = false;
  861. break;
  862. }
  863. last = rNode;
  864. }
  865. }
  866. const valid = !sheet.zh_setting.readOnly;
  867. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed);
  868. }
  869. },
  870. 'sprBase': '-----------',
  871. 'batchInsert': {
  872. name: '批量插入',
  873. type: 'batchInsert',
  874. value: '2',
  875. icon: 'fa-sign-in',
  876. batchInsert: function (obj, root) {
  877. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  878. obj.value = obj.max;
  879. toastr.warning('批量插入不可多于' + obj.max);
  880. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  881. obj.value = obj.min;
  882. toastr.warning('批量插入不可少于' + obj.min);
  883. } else {
  884. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  885. root.$menu.trigger('contextmenu:hide');
  886. }
  887. },
  888. disabled: function (key, opt) {
  889. const sheet = billsSheet;
  890. const selection = sheet.getSelections();
  891. const sel = selection ? selection[0] : sheet.getSelections()[0];
  892. const row = sel ? sel.row : -1;
  893. const tree = sheet.zh_tree;
  894. if (!tree) return true;
  895. const first = sheet.zh_tree.nodes[row];
  896. const valid = !sheet.zh_setting.readOnly;
  897. return !(valid && first && first.level > 1);
  898. }
  899. },
  900. 'batchInsertBillsPos': {
  901. name: '批量插入清单-计量单元',
  902. icon: 'fa-sign-in',
  903. disabled: function (key, opt) {
  904. if (!isTz) return true;
  905. const select = SpreadJsObj.getSelectObject(billsSheet);
  906. if (select) {
  907. if (select.code && select.code !== '') {
  908. return !billsTree.isLeafXmj(select);
  909. } else {
  910. const parent = billsTree.getParent(select);
  911. return !(parent && billsTree.isLeafXmj(parent));
  912. }
  913. } else {
  914. return false;
  915. }
  916. },
  917. callback: function (key, opt) {
  918. if (!batchInsertObj) {
  919. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  920. } else {
  921. batchInsertObj.initView();
  922. }
  923. $('#batch').modal('show');
  924. }
  925. },
  926. 'sprBatch': '-----------',
  927. 'importGclBills2Xmj': {
  928. name: '导入工程量清单至项目节',
  929. icon: 'fa-file-excel-o',
  930. disabled: function (key, opt) {
  931. const node = SpreadJsObj.getSelectObject(billsSheet);
  932. return readOnly
  933. || (node.children && node.children.length > 0)
  934. || (!_.isNil(node.b_code) && node.b_code !== '')
  935. || billsTree.checkNodeUsed(node, pos);
  936. },
  937. callback: function (key, opt) {
  938. const node = SpreadJsObj.getSelectObject(billsSheet);
  939. importExcel.doImport({
  940. template: {
  941. hint: '工程量清单',
  942. url: '/template/导入工程量清单EXCEL格式.xls',
  943. },
  944. callback: function (sheet) {
  945. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  946. const sel = billsSheet.getSelections();
  947. const refreshNode = billsTree.loadPostData(result);
  948. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  949. if (refreshNode.create[0]) {
  950. if (sel && sel[0]) {
  951. billsSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  952. } else {
  953. billsSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  954. }
  955. }
  956. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  957. }, null);
  958. }
  959. });
  960. }
  961. },
  962. }
  963. });
  964. }
  965. // 计量单元 相关方法&绑定spreadjs事件
  966. const posSpreadObj = {
  967. /**
  968. * 加载计量单元 根据当前台账选择节点
  969. */
  970. loadCurPosData: function () {
  971. const node = SpreadJsObj.getSelectObject(billsSheet);
  972. if (node) {
  973. const posData = pos.getLedgerPos(node.id) || [];
  974. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  975. } else {
  976. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  977. }
  978. SpreadJsObj.resetFieldReadOnly(posSheet);
  979. },
  980. editStarting: function (e, info) {
  981. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  982. },
  983. /**
  984. * 编辑单元格响应事件
  985. * @param {Object} e
  986. * @param {Object} info
  987. */
  988. editEnded: function (e, info) {
  989. if (!info.sheet.zh_setting) {
  990. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  991. return;
  992. }
  993. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  994. const col = info.sheet.zh_setting.cols[info.col];
  995. const orgText = posData ? posData[col.field] : null;
  996. const newText = trimInvalidChar(info.editingText);
  997. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  998. const node = posSpreadObj.billsNode;
  999. if (!node) {
  1000. toastr.error('数据错误,请选择台账节点后再试');
  1001. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1002. return;
  1003. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1004. toastr.error('父节点不可插入计量单元');
  1005. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1006. return;
  1007. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1008. toastr.error('项目节不可插入计量单元');
  1009. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1010. return;
  1011. }
  1012. const data = {postType: 'pos'};
  1013. if (col.field === 'name') {
  1014. if (newText === '' && posData) {
  1015. toastr.error('部位名称不可为空', 'error');
  1016. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1017. return;
  1018. } else if (!posData) {
  1019. if (newText && newText !== '') {
  1020. data.posPostType = 'add';
  1021. const sortData = info.sheet.zh_data;
  1022. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1023. data.postData = { name: newText, lid: node.id, porder: order};
  1024. } else {
  1025. return;
  1026. }
  1027. } else {
  1028. data.posPostType = 'update';
  1029. data.postData = {id: posData.id, name: newText};
  1030. }
  1031. } else if (!posData) {
  1032. toastr.warning('新增计量单元请先输入名称');
  1033. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1034. return;
  1035. } else {
  1036. data.posPostType = 'update';
  1037. data.postData = {id: posData.id};
  1038. if (col.type === 'Number') {
  1039. const num = _.toNumber(newText);
  1040. if (_.isFinite(num)) {
  1041. data.postData[col.field] = num;
  1042. } else {
  1043. try {
  1044. data.postData[col.field] = math.evaluate(transExpr(newText));
  1045. } catch(err) {
  1046. toastr.error('输入的表达式非法');
  1047. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1048. return;
  1049. }
  1050. }
  1051. } else {
  1052. data.postData[col.field] = newText;
  1053. }
  1054. }
  1055. postData(window.location.pathname + '/update', data, function (result) {
  1056. const updateRst = pos.updateDatas(result.pos);
  1057. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1058. if (updateRst.create.length > 0) {
  1059. posSpreadObj.loadCurPosData();
  1060. } else {
  1061. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1062. }
  1063. const loadResult = billsTree.loadPostData(result.ledger);
  1064. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1065. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1066. }, function () {
  1067. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1068. });
  1069. },
  1070. /**
  1071. * 删除按钮响应事件
  1072. * @param sheet
  1073. */
  1074. deletePress: function (sheet) {
  1075. if (!sheet.zh_settting) return;
  1076. const sortData = sheet.zh_data;
  1077. const datas = [], posSelects = [];
  1078. const sel = sheet.getSelections()[0];
  1079. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1080. let bDel = false;
  1081. const node = sortData[iRow];
  1082. if (node) {
  1083. const data = {id: node.id};
  1084. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1085. const colSetting = sheet.zh_setting.cols[iCol];
  1086. if (colSetting.field === 'name') {
  1087. toastr.error('部位名称不能为空');
  1088. return;
  1089. }
  1090. const style = sheet.getStyle(iRow, iCol);
  1091. if (!style.locked) {
  1092. const colSetting = sheet.zh_setting.cols[iCol];
  1093. data[colSetting.field] = null;
  1094. bDel = true;
  1095. }
  1096. }
  1097. if (bDel) {
  1098. datas.push(data);
  1099. posSelects.push(node);
  1100. }
  1101. }
  1102. }
  1103. if (datas.length > 0) {
  1104. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  1105. pos.updateDatas(result.pos);
  1106. posSpreadObj.loadCurPosData();
  1107. const loadResult = billsTree.loadPostData(result.ledger);
  1108. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1109. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1110. }, function () {
  1111. posSpreadObj.loadCurPosData();
  1112. });
  1113. }
  1114. },
  1115. /**
  1116. * 删除 计量单元
  1117. * @param sheet
  1118. */
  1119. deletePos: function (sheet) {
  1120. const selection = sheet.getSelections();
  1121. const data = {
  1122. postType: 'pos',
  1123. posPostType: 'delete',
  1124. postData: [],
  1125. };
  1126. const row = selection[0].row, count = selection[0].rowCount;
  1127. const sortData = sheet.zh_data;
  1128. for (let iRow = 0; iRow < count; iRow++) {
  1129. const posData = sortData[iRow + row];
  1130. if (posData) {
  1131. if (posData.used) {
  1132. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1133. return;
  1134. }
  1135. data.postData.push(sortData[iRow + row].id);
  1136. }
  1137. }
  1138. if (data.postData.length > 0) {
  1139. postData(window.location.pathname + '/update', data, function (result) {
  1140. pos.removeDatas(result.pos);
  1141. sheet.deleteRows(row, count);
  1142. const loadResult = billsTree.loadPostData(result.ledger);
  1143. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1144. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1145. });
  1146. }
  1147. },
  1148. clipboardPasting: function (e, info) {
  1149. if (!info.sheet.zh_setting) {
  1150. info.cancel = true;
  1151. return;
  1152. }
  1153. const range = info.cellRange;
  1154. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  1155. const posData = info.sheet.zh_data[iRow];
  1156. if (posData && posData.used) {
  1157. toastr.warning('"' + pos.name +'"已计量,请勿修改');
  1158. info.cancel = true;
  1159. return;
  1160. }
  1161. }
  1162. },
  1163. /**
  1164. * 粘贴单元格响应事件
  1165. * @param e
  1166. * @param info
  1167. */
  1168. clipboardPasted: function (e, info) {
  1169. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1170. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1171. }
  1172. const node = SpreadJsObj.getSelectObject(billsSheet);
  1173. if (node.code && (node.code !== '')) {
  1174. toastr.error('项目节不可含有节点明细');
  1175. posSpreadObj.loadCurPosData();
  1176. return;
  1177. }
  1178. if (node.children && (node.children.length > 0)) {
  1179. toastr.error('仅节点子项可以含有计量单元');
  1180. posSpreadObj.loadCurPosData();
  1181. return;
  1182. }
  1183. if (!info.sheet.zh_setting) {
  1184. posSpreadObj.loadCurPosData();
  1185. return;
  1186. }
  1187. const data = [];
  1188. const sortData = info.sheet.zh_data || [];
  1189. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1190. if (info.cellRange.col !== 0) {
  1191. toastr.warning('新增计量单元请先输入名称');
  1192. posSpreadObj.loadCurPosData();
  1193. return;
  1194. }
  1195. }
  1196. let bHint = false;
  1197. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1198. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1199. let bPaste = true;
  1200. const curRow = info.cellRange.row + iRow;
  1201. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  1202. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1203. const curCol = info.cellRange.col + iCol;
  1204. const colSetting = info.sheet.zh_setting.cols[curCol];
  1205. if (!colSetting) continue;
  1206. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1207. if (colSetting.type === 'Number') {
  1208. const num = _.toNumber(posData[colSetting.field]);
  1209. if (num) {
  1210. posData[colSetting.field] = num;
  1211. } else {
  1212. try {
  1213. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  1214. } catch (err) {
  1215. if (!bHint) {
  1216. toastr.warning('粘贴了非法表达式,已过滤');
  1217. bHint = true;
  1218. }
  1219. bPaste = false;
  1220. }
  1221. }
  1222. }
  1223. }
  1224. if (bPaste) {
  1225. data.push(posData);
  1226. }
  1227. }
  1228. if (data.length === 0) {
  1229. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1230. return;
  1231. }
  1232. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  1233. pos.updateDatas(result.pos);
  1234. posSpreadObj.loadCurPosData();
  1235. const loadResult = billsTree.loadPostData(result.ledger);
  1236. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1237. posSpreadObj.loadCurPosData();
  1238. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1239. }, function () {
  1240. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1241. });
  1242. },
  1243. selectionChanged: function (e, info) {
  1244. const col = info.sheet.zh_setting.cols[info.newSelections[0].col];
  1245. const cell = info.sheet.getCell(info.newSelections[0].col, info.newSelections[0].col);
  1246. if (col && col.type === 'Number') {
  1247. const data = SpreadJsObj.getSelectObject(info.sheet);
  1248. if (data) {
  1249. $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
  1250. .attr('row', info.newSelections[0].row).attr('readOnly', readOnly || cell.locked());
  1251. } else {
  1252. $('#pos-expr').val('').attr('readOnly', true);
  1253. }
  1254. } else {
  1255. $('#pos-expr').val('').attr('readOnly', true);
  1256. }
  1257. },
  1258. addPegs: function (pegs) {
  1259. if (!pegs || pegs.length <= 0) return;
  1260. const node = SpreadJsObj.getSelectObject(billsSheet);
  1261. if (!node) return;
  1262. const sheet = posSpread.getActiveSheet();
  1263. const sortData = sheet.zh_data || [];
  1264. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1265. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1266. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  1267. pos.updateDatas(result.pos);
  1268. posSpreadObj.loadCurPosData();
  1269. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1270. });
  1271. }
  1272. };
  1273. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  1274. if (!readOnly && isTz) {
  1275. $('#pos-expr').bind('change mouseleave', function () {
  1276. if (this.readOnly) return;
  1277. const expr = $(this);
  1278. const select = SpreadJsObj.getSelectObject(posSheet);
  1279. const row = posSheet.getSelections()[0].row;
  1280. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1281. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1282. const data = {id: select.id};
  1283. if (newValue !== '') {
  1284. const num = _.toNumber(newValue);
  1285. if (num) {
  1286. data[field] = num;
  1287. } else {
  1288. try {
  1289. data[field] = math.evaluate(transExpr(newValue));
  1290. } catch (err) {
  1291. toastr.error('输入的表达式非法');
  1292. return;
  1293. }
  1294. }
  1295. } else {
  1296. data[field] = null;
  1297. }
  1298. // 更新至服务器
  1299. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  1300. const updateRst = pos.updateDatas(result.pos);
  1301. expr.val(select[field]);
  1302. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1303. SpreadJsObj.reLoadRowData(posSheet, row);
  1304. const loadResult = billsTree.loadPostData(result.ledger);
  1305. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1306. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1307. });
  1308. });
  1309. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  1310. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  1311. posSpread.bind(spreadNS.Events.ClipboardPasting, posSpreadObj.clipboardPasting);
  1312. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  1313. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  1314. const mergePeg = NewMergePeg({ callback: posSpreadObj.addPegs });
  1315. $.contextMenu({
  1316. selector: '#pos-spread',
  1317. build: function ($trigger, e) {
  1318. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  1319. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1320. },
  1321. items: {
  1322. 'delete': {
  1323. name: '删除',
  1324. icon: 'fa-remove',
  1325. disabled: function (key, opt) {
  1326. if (posSheet.zh_data) {
  1327. const selection = posSheet.getSelections();
  1328. return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1329. } else {
  1330. return true;
  1331. }
  1332. },
  1333. callback: function (key, opt) {
  1334. posSpreadObj.deletePos(posSheet);
  1335. }
  1336. },
  1337. 'merge-peg': {
  1338. name: '合并起讫桩号',
  1339. disabled: function (key, opt) {
  1340. const node = SpreadJsObj.getSelectObject(billsSheet);
  1341. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1342. },
  1343. callback: function (key, opt) {
  1344. mergePeg.show();
  1345. },
  1346. visible: function (key, opt) {
  1347. return isTz;
  1348. }
  1349. }
  1350. }
  1351. });
  1352. }
  1353. // 加载清单&计量单元数据
  1354. postData(window.location.pathname + '/load', {}, function (result) {
  1355. billsTree.loadDatas(result.bills);
  1356. treeCalc.calculateAll(billsTree);
  1357. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  1358. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  1359. pos.loadDatas(result.pos);
  1360. posSpreadObj.loadCurPosData();
  1361. SpreadJsObj.resetTopAndSelect(posSheet);
  1362. }, null);
  1363. $.divResizer({
  1364. select: '#revise-resize',
  1365. callback: function () {
  1366. billsSpread.refresh();
  1367. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1368. $(".sp-wrap").height(bcontent-30);
  1369. posSpread.refresh();
  1370. }
  1371. });
  1372. class DealBills {
  1373. constructor (selector, spreadSetting) {
  1374. const self = this;
  1375. this.loaded = false;
  1376. this.obj = $(selector)[0];
  1377. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  1378. this.spreadSetting = spreadSetting;
  1379. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1380. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1381. if (!readOnly) {
  1382. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1383. const dealSheet = info.sheet;
  1384. const mainSheet = billsSheet;
  1385. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  1386. if (!dealBills) { return; }
  1387. const mainTree = mainSheet.zh_tree;
  1388. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1389. if (!mainNode || !mainTree) { return; }
  1390. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1391. toastr.warning('非最底层项目下,不应添加节点');
  1392. return;
  1393. }
  1394. postData(window.location.pathname + '/update', {
  1395. postType: 'add-deal',
  1396. postData: {
  1397. id: mainNode.ledger_id,
  1398. type: mainNode.code ? 'child' : 'next',
  1399. dealBills: {
  1400. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  1401. unit_price: dealBills.unit_price,
  1402. }
  1403. },
  1404. }, function (result) {
  1405. const refreshData = mainTree.loadPostData(result);
  1406. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1407. const sel = mainSheet.getSelections()[0];
  1408. if (sel && refreshData.create[0]) {
  1409. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1410. }
  1411. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1412. billsSpread.focus();
  1413. posSpreadObj.loadCurPosData();
  1414. });
  1415. });
  1416. }
  1417. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1418. }
  1419. loadData (callback) {
  1420. if (this.loaded) {
  1421. if (callback) callback();
  1422. return;
  1423. }
  1424. const self = this;
  1425. postData(this.url+'/get-data', {}, function (data) {
  1426. self.data = data;
  1427. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1428. self.loaded = true;
  1429. if (callback) callback();
  1430. });
  1431. }
  1432. calculateData () {
  1433. if (this.data) {
  1434. for (const d of this.data) {
  1435. d.total_price = _.multiply(d.quantity, d.unit_price);
  1436. }
  1437. }
  1438. }
  1439. }
  1440. class BgBills {
  1441. constructor (selector, spreadSetting) {
  1442. this.loaded = false;
  1443. this.obj = $(selector)[0];
  1444. this.spreadSetting = spreadSetting;
  1445. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1446. this.sheet = this.spread.getActiveSheet();
  1447. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1448. if (!readOnly) {
  1449. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1450. const dealSheet = info.sheet;
  1451. const mainSheet = billsSheet;
  1452. const bgBills = SpreadJsObj.getSelectObject(dealSheet);
  1453. if (!bgBills) { return; }
  1454. const mainTree = mainSheet.zh_tree;
  1455. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1456. if (!mainNode || !mainTree) { return; }
  1457. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1458. toastr.warning('非最底层项目下,不应添加变更清单');
  1459. return;
  1460. }
  1461. postData(window.location.pathname + '/update', {
  1462. postType: 'add-bg',
  1463. postData: {
  1464. id: mainNode.ledger_id,
  1465. type: mainNode.code ? 'child' : 'next',
  1466. dealBills: {
  1467. b_code: bgBills.code, name: bgBills.name, unit: bgBills.unit,
  1468. unit_price: bgBills.unit_price,
  1469. }
  1470. },
  1471. }, function (result) {
  1472. const refreshData = mainTree.loadPostData(result);
  1473. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1474. const sel = mainSheet.getSelections()[0];
  1475. if (sel && refreshData.create[0]) {
  1476. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1477. }
  1478. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1479. billsSpread.focus();
  1480. posSpreadObj.loadCurPosData();
  1481. });
  1482. });
  1483. }
  1484. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1485. }
  1486. loadData () {
  1487. if (this.loaded) return;
  1488. const self = this;
  1489. postData('/tender/' + window.location.pathname.split('/')[2] +'/change/bills', {type: 'gather'}, function (data) {
  1490. self.data = data;
  1491. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1492. self.loaded = true;
  1493. });
  1494. }
  1495. }
  1496. class BatchInsertBillsPosObj {
  1497. constructor (obj) {
  1498. const self = this;
  1499. this.obj = obj;
  1500. this.billsCount = 6;
  1501. this.posCount = 1000;
  1502. // 初始化 清单编号窗口 参数
  1503. this.qdSpreadSetting = {
  1504. cols: [
  1505. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  1506. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  1507. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  1508. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1509. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  1510. ],
  1511. emptyRows: this.billsCount,
  1512. headRows: 1,
  1513. headRowHeight: [32],
  1514. headerFont: '12px 微软雅黑',
  1515. font: '12px 微软雅黑',
  1516. };
  1517. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  1518. // 初始化 部位数量复核表 参数
  1519. this.posSpreadSetting = {
  1520. cols: [
  1521. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  1522. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  1523. ],
  1524. emptyRows: this.posCount,
  1525. headRows: 1,
  1526. headRowHeight: [32],
  1527. headerFont: '12px 微软雅黑',
  1528. font: '12px 微软雅黑',
  1529. };
  1530. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  1531. this.posSpreadSetting.cols.push(
  1532. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  1533. )
  1534. }
  1535. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  1536. // 初始化 签约节点 参数
  1537. this.dealSpreadSetting = {
  1538. cols: [
  1539. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  1540. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  1541. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1542. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  1543. ],
  1544. emptyRows: 0,
  1545. headRows: 1,
  1546. headRowHeight: [32],
  1547. headerFont: '12px 微软雅黑',
  1548. font: '12px 微软雅黑',
  1549. };
  1550. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  1551. // 初始化 清单编号、部位数量复核表 表格
  1552. this.initView();
  1553. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  1554. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  1555. // 拉取签约节点数据
  1556. dealBills.loadData(() => {
  1557. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1558. });
  1559. // 双击签约节点,自动添加到清单编号窗口
  1560. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1561. const deal = info.sheet.zh_data[info.row];
  1562. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  1563. const sel = qdSheet.getSelections()[0];
  1564. qdSheet.getCell(sel.row, 0).value(deal.code);
  1565. qdSheet.getCell(sel.row, 1).value(deal.name);
  1566. qdSheet.getCell(sel.row, 2).value(deal.unit);
  1567. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  1568. if (sel.row + 1 === qdSheet.getRowCount()) {
  1569. const count = sel.row + 2;
  1570. qdSheet.setRowCount(count);
  1571. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  1572. const colCount = posSheet.getColumnCount() + 1;
  1573. posSheet.setColumnCount(colCount);
  1574. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  1575. }
  1576. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  1577. qdSheet.getParent().focus();
  1578. });
  1579. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  1580. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  1581. const count = posSheet.getColumnCount() - 2;
  1582. if (billsCount > count) {
  1583. posSheet.setColumnCount(billsCount + 2);
  1584. for (let i = count + 1; i <= billsCount; i++) {
  1585. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  1586. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  1587. }
  1588. }
  1589. });
  1590. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  1591. if (info.col === 0) {
  1592. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  1593. if (dealBills && dealBills.length > 0) {
  1594. const bills = _.find(dealBills, {code: info.editingText});
  1595. if (bills) {
  1596. info.sheet.getCell(info.row, 1).value(bills.name);
  1597. info.sheet.getCell(info.row, 2).value(bills.unit);
  1598. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  1599. }
  1600. }
  1601. }
  1602. });
  1603. this.obj.bind('shown.bs.modal', function () {
  1604. self.qdSpread.refresh();
  1605. self.posSpread.refresh();
  1606. self.dealSpread.refresh();
  1607. });
  1608. $('#batch-ok').click(function () {
  1609. const selection = billsSheet.getSelections();
  1610. const row = selection[0].row;
  1611. const select = billsTree.nodes[row];
  1612. if (select) {
  1613. const insertData = {};
  1614. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  1615. insertData.id = select[billsTree.setting.id];
  1616. insertData.batchData = self.getBatchData();
  1617. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  1618. pos.updateDatas(data.pos);
  1619. const result = billsTree.loadPostData(data.ledger);
  1620. billsTreeSpreadObj.refreshTree(billsSheet, result);
  1621. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  1622. self.obj.modal('hide');
  1623. }, null, true);
  1624. }
  1625. });
  1626. $.contextMenu({
  1627. selector: '.batch-l-t',
  1628. build: function ($trigger, e) {
  1629. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  1630. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1631. },
  1632. items: {
  1633. 'create': {
  1634. name: '新增行',
  1635. icon: 'fa-sign-in',
  1636. callback: function (key, opt) {
  1637. const qdSheet = self.qdSpread.getActiveSheet();
  1638. const posSheet = self.posSpread.getActiveSheet();
  1639. qdSheet.addRows(qdSheet.getRowCount(), 1);
  1640. const index = qdSheet.getRowCount();
  1641. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  1642. posSheet.addColumns(posSheet.getColumnCount(), 1);
  1643. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  1644. },
  1645. },
  1646. 'delete': {
  1647. name: '删除行',
  1648. icon: 'fa-remove',
  1649. callback: function (key, opt) {
  1650. const qdSheet = self.qdSpread.getActiveSheet();
  1651. const posSheet = self.posSpread.getActiveSheet();
  1652. const sel = qdSheet.getSelections()[0];
  1653. qdSheet.deleteRows(sel.row, sel.rowCount);
  1654. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  1655. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  1656. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  1657. }
  1658. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  1659. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  1660. }
  1661. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  1662. },
  1663. },
  1664. }
  1665. });
  1666. }
  1667. // 初始化左侧表格
  1668. initView () {
  1669. // 初始化 清单编号
  1670. const qdSheet = this.qdSpread.getActiveSheet();
  1671. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  1672. SpreadJsObj.refreshColumnAlign(qdSheet);
  1673. // 清理原有数据
  1674. SpreadJsObj.beginMassOperation(qdSheet);
  1675. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1676. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  1677. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  1678. }
  1679. qdSheet.setSelection(0, 0, 1 ,1);
  1680. SpreadJsObj.endMassOperation(qdSheet);
  1681. // 初始化 部位数量复核表
  1682. const posSheet = this.posSpread.getActiveSheet();
  1683. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  1684. SpreadJsObj.refreshColumnAlign(posSheet);
  1685. // 清理原有数据
  1686. SpreadJsObj.beginMassOperation(posSheet);
  1687. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  1688. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1689. posSheet.setSelection(0, 0, 1 ,1);
  1690. SpreadJsObj.endMassOperation(posSheet);
  1691. // 检查签约节点数据,以工具栏数据为准
  1692. if (dealBills) {
  1693. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1694. }
  1695. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  1696. }
  1697. // 获取界面数据
  1698. getBatchData () {
  1699. const result = [];
  1700. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  1701. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  1702. if (qdSheet.getText(iRow, 0) === '') { continue; }
  1703. const qd = {
  1704. b_code: qdSheet.getText(iRow, 0),
  1705. name: qdSheet.getText(iRow, 1),
  1706. unit: qdSheet.getText(iRow, 2),
  1707. price: _.toNumber(qdSheet.getText(iRow, 3)),
  1708. pos: [],
  1709. };
  1710. result.push(qd);
  1711. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  1712. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  1713. if (value !== 0 && !isNaN(value)) {
  1714. qd.pos.push({
  1715. name: posSheet.getText(iPosRow, 0),
  1716. drawing_code: posSheet.getText(iPosRow, 1),
  1717. quantity: value,
  1718. });
  1719. }
  1720. }
  1721. }
  1722. return result;
  1723. }
  1724. }
  1725. const dealBills = new DealBills('#deal-bills-spread', {
  1726. cols: [
  1727. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1728. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1729. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1730. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1731. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1732. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1733. ],
  1734. emptyRows: 0,
  1735. headRows: 1,
  1736. headRowHeight: [32],
  1737. defaultRowHeight: 21,
  1738. headerFont: '12px 微软雅黑',
  1739. font: '12px 微软雅黑',
  1740. selectedBackColor: '#fffacd',
  1741. });
  1742. const bgBills = new BgBills('#bg-bills-spread', {
  1743. cols: [
  1744. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1745. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1746. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1747. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1748. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1749. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1750. ],
  1751. emptyRows: 0,
  1752. headRows: 1,
  1753. headRowHeight: [32],
  1754. defaultRowHeight: 21,
  1755. headerFont: '12px 微软雅黑',
  1756. font: '12px 微软雅黑',
  1757. selectedBackColor: '#fffacd',
  1758. });
  1759. $.divResizer({
  1760. select: '#revise-right-spr',
  1761. callback: function () {
  1762. billsSpread.refresh();
  1763. if (posSpread) {
  1764. posSpread.refresh();
  1765. }
  1766. if (stdXmj) {
  1767. stdXmj.spread.refresh();
  1768. }
  1769. if (stdGcl) {
  1770. stdGcl.spread.refresh();
  1771. }
  1772. if (dealBills) {
  1773. dealBills.spread.refresh();
  1774. }
  1775. if (bgBills) {
  1776. bgBills.spread.refresh();
  1777. }
  1778. if (searchLedger) {
  1779. searchLedger.spread.refresh();
  1780. }
  1781. }
  1782. });
  1783. $.subMenu({
  1784. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1785. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1786. key: 'menu.1.0.0',
  1787. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1788. callback: function (info) {
  1789. if (info.mini) {
  1790. $('.panel-title').addClass('fluid');
  1791. $('#sub-menu').removeClass('panel-sidebar');
  1792. } else {
  1793. $('.panel-title').removeClass('fluid');
  1794. $('#sub-menu').addClass('panel-sidebar');
  1795. }
  1796. autoFlashHeight();
  1797. billsSpread.refresh();
  1798. if (posSpread) {
  1799. posSpread.refresh();
  1800. }
  1801. if (stdXmj) {
  1802. stdXmj.spread.refresh();
  1803. }
  1804. if (stdGcl) {
  1805. stdGcl.spread.refresh();
  1806. }
  1807. if (dealBills) {
  1808. dealBills.spread.refresh();
  1809. }
  1810. if (bgBills) {
  1811. bgBills.spread.refresh();
  1812. }
  1813. if (searchLedger) {
  1814. searchLedger.spread.refresh();
  1815. }
  1816. }
  1817. });
  1818. const showSideTools = function (show) {
  1819. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1820. if (show) {
  1821. right.show();
  1822. autoFlashHeight();
  1823. /**
  1824. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1825. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1826. * 故需要通过最终的parent.width再计算一次left.width
  1827. *
  1828. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1829. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1830. *
  1831. */
  1832. //left.css('width', parent.width() - right.outerWidth());
  1833. //left.css('width', parent.width() - right.outerWidth());
  1834. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1835. left.css('width', percent + '%');
  1836. } else {
  1837. left.width(parent.width());
  1838. right.hide();
  1839. }
  1840. };
  1841. $('#content-tab').addClass('active');
  1842. $('#xd-content').addClass('active');
  1843. showSideTools(true);
  1844. billsSpread.refresh();
  1845. if (posSpread) {
  1846. posSpread.refresh();
  1847. }
  1848. const stdLibCellDoubleClick = function (e, info) {
  1849. const stdSheet = info.sheet;
  1850. const mainSheet = billsSheet;
  1851. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  1852. const stdTree = stdSheet.zh_tree;
  1853. const stdNode = stdTree.nodes[info.row];
  1854. const mainTree = mainSheet.zh_tree;
  1855. const sel = mainSheet.getSelections()[0];
  1856. const mainNode = mainTree.nodes[sel.row];
  1857. if (!stdNode) return;
  1858. if (info.sheet.zh_setting.stdType === 'gcl') {
  1859. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1860. toastr.warning('非最底层项目下,不应添加节点');
  1861. return;
  1862. }
  1863. }
  1864. postData(window.location.pathname + '/update', {
  1865. postType: 'add-std',
  1866. postData: {
  1867. id: mainTree.getNodeKey(mainNode),
  1868. tender_id: mainNode.tender_id,
  1869. stdType: info.sheet.zh_setting.stdType,
  1870. stdLibId: stdNode.list_id,
  1871. stdNode: stdTree.getNodeKey(stdNode)
  1872. }
  1873. }, function (result) {
  1874. const refreshNode = mainTree.loadPostData(result);
  1875. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  1876. if (sel) {
  1877. if (refreshNode.create && refreshNode.create.length > 0) {
  1878. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  1879. } else {
  1880. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  1881. if (node) {
  1882. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  1883. }
  1884. }
  1885. }
  1886. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1887. billsSpread.focus();
  1888. posSpreadObj.loadCurPosData();
  1889. });
  1890. };
  1891. const stdXmjSetting = {
  1892. selector: '#std-xmj',
  1893. stdType: 'xmj',
  1894. treeSetting: {
  1895. id: 'chapter_id',
  1896. pid: 'pid',
  1897. order: 'order',
  1898. level: 'level',
  1899. rootId: -1,
  1900. keys: ['id', 'list_id', 'chapter_id'],
  1901. },
  1902. spreadSetting: {
  1903. cols: [
  1904. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1905. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1906. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1907. ],
  1908. treeCol: 0,
  1909. emptyRows: 0,
  1910. headRows: 1,
  1911. headRowHeight: [32],
  1912. defaultRowHeight: 21,
  1913. headerFont: '12px 微软雅黑',
  1914. font: '12px 微软雅黑',
  1915. headColWidth: [0],
  1916. selectedBackColor: '#fffacd',
  1917. },
  1918. cellDoubleClick: stdLibCellDoubleClick,
  1919. page: 'revise',
  1920. tid: window.location.pathname.split('/')[2],
  1921. };
  1922. const stdGclSetting = {
  1923. selector: '#std-gcl',
  1924. stdType: 'gcl',
  1925. treeSetting: {
  1926. id: 'bill_id',
  1927. pid: 'pid',
  1928. order: 'order',
  1929. level: 'level',
  1930. rootId: -1,
  1931. keys: ['id', 'list_id', 'bill_id']
  1932. },
  1933. spreadSetting: {
  1934. cols: [
  1935. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1936. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1937. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1938. ],
  1939. treeCol: 0,
  1940. emptyRows: 0,
  1941. headRows: 1,
  1942. headRowHeight: [32],
  1943. defaultRowHeight: 21,
  1944. headerFont: '12px 微软雅黑',
  1945. font: '12px 微软雅黑',
  1946. headColWidth: [0],
  1947. selectedBackColor: '#fffacd',
  1948. },
  1949. cellDoubleClick: stdLibCellDoubleClick,
  1950. page: 'revise',
  1951. tid: window.location.pathname.split('/')[2],
  1952. };
  1953. // 展开收起标准节点
  1954. $('a', '#side-menu').bind('click', function (e) {
  1955. e.preventDefault();
  1956. const tab = $(this), tabPanel = $(tab.attr('content'));
  1957. // 展开工具栏、切换标签
  1958. if (!tab.hasClass('active')) {
  1959. const close = $('.active', '#side-menu').length === 0;
  1960. $('a', '#side-menu').removeClass('active');
  1961. tab.addClass('active');
  1962. $('.tab-content .tab-pane').removeClass('active');
  1963. tabPanel.addClass('active');
  1964. showSideTools(tab.hasClass('active'));
  1965. if (tab.attr('content') === '#std-xmj') {
  1966. if (!stdXmj) {
  1967. stdXmj = new stdLib(stdXmjSetting);
  1968. }
  1969. stdXmj.spread.refresh();
  1970. } else if (tab.attr('content') === '#std-gcl') {
  1971. if (!stdGcl) {
  1972. stdGcl = new stdLib(stdGclSetting);
  1973. }
  1974. stdGcl.spread.refresh();
  1975. } else if (tab.attr('content') === '#deal-bills') {
  1976. dealBills.loadData();
  1977. dealBills.spread.refresh();
  1978. } else if (tab.attr('content') === '#bg-bills') {
  1979. bgBills.loadData();
  1980. bgBills.spread.refresh();
  1981. } else if (tab.attr('content') === '#search' && !searchLedger) {
  1982. if (!searchLedger) {
  1983. searchLedger = $.billsSearch({
  1984. selector: '#search',
  1985. searchSpread: billsSpread,
  1986. resultSpreadSetting: {
  1987. cols: [
  1988. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1989. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1990. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  1991. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  1992. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1993. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1994. ],
  1995. emptyRows: 0,
  1996. headRows: 1,
  1997. headRowHeight: [32],
  1998. defaultRowHeight: 21,
  1999. headerFont: '12px 微软雅黑',
  2000. font: '12px 微软雅黑',
  2001. selectedBackColor: '#fffacd',
  2002. },
  2003. afterLocated: function () {
  2004. posSpreadObj.loadCurPosData();
  2005. }
  2006. });
  2007. }
  2008. searchLedger.spread.refresh();
  2009. }
  2010. }
  2011. else {// 收起工具栏
  2012. tab.removeClass('active');
  2013. tabPanel.removeClass('active');
  2014. showSideTools(tab.hasClass('active'));
  2015. }
  2016. billsSpread.refresh();
  2017. if (posSpread) {
  2018. posSpread.refresh();
  2019. }
  2020. });
  2021. if (!readOnly) {
  2022. // 修订详情 保存
  2023. $('#save').click(function () {
  2024. const content = $('#content').val();
  2025. postData('save', { content: content }, function () {
  2026. $('#content').attr('org-value', content);
  2027. });
  2028. });
  2029. }
  2030. // 显示层次
  2031. (function (select, sheet) {
  2032. $(select).click(function () {
  2033. if (!sheet.zh_tree) return;
  2034. const tag = $(this).attr('tag');
  2035. const tree = sheet.zh_tree;
  2036. switch (tag) {
  2037. case "1":
  2038. case "2":
  2039. case "3":
  2040. case "4":
  2041. case "5":
  2042. tree.expandByLevel(parseInt(tag));
  2043. SpreadJsObj.refreshTreeRowVisible(sheet);
  2044. break;
  2045. case "last":
  2046. tree.expandByCustom(() => { return true; });
  2047. SpreadJsObj.refreshTreeRowVisible(sheet);
  2048. break;
  2049. case "leafXmj":
  2050. tree.expandToLeafXmj();
  2051. SpreadJsObj.refreshTreeRowVisible(sheet);
  2052. break;
  2053. }
  2054. });
  2055. })('a[name=showLevel]', billsSheet);
  2056. });