revise.js 106 KB

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