revise.js 101 KB

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