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