revise.js 99 KB

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