revise.js 115 KB

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