revise.js 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552
  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. let bDel = false;
  674. const node = sheet.zh_tree.nodes[iRow];
  675. if (sheet.zh_tree.checkNodeUsed(node, pos)) {
  676. toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  677. return;
  678. }
  679. const data = sheet.zh_tree.getNodeKeyData(node);
  680. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  681. const col = sheet.zh_setting.cols[iCol];
  682. const style = sheet.getStyle(iRow, iCol);
  683. if (!style.locked) {
  684. data[col.field] = null;
  685. const exprInfo = getExprInfo(col.field);
  686. if (exprInfo) {
  687. data[exprInfo.expr] = '';
  688. }
  689. bDel = true;
  690. }
  691. }
  692. if (bDel) datas.push(data);
  693. }
  694. if (datas.length > 0) {
  695. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  696. const refreshNode = sheet.zh_tree.loadPostData(result);
  697. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  698. billsTreeSpreadObj.loadExprToInput(sheet);
  699. });
  700. }
  701. },
  702. pasteBlock: function (spread, copyInfo) {
  703. const self = this;
  704. const sheet = spread.getActiveSheet();
  705. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  706. postData(window.location.pathname + '/update', {
  707. postType: 'paste-block',
  708. postData: {
  709. id: tree.getNodeKey(node),
  710. tid: copyInfo.tid,
  711. block: copyInfo.block,
  712. }
  713. }, function (data) {
  714. pos.updateDatas(data.pos);
  715. const result = tree.loadPostData(data.ledger);
  716. self.refreshTree(sheet, result);
  717. const sel = sheet.getSelections()[0];
  718. if (sel) {
  719. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  720. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  721. }
  722. self.refreshOperationValid(sheet);
  723. removeLocalCache(copyBlockTag);
  724. }, null, true);
  725. },
  726. topRowChanged: function (e, info) {
  727. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  728. },
  729. editStarting(e, info) {
  730. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  731. const col = info.sheet.zh_setting.cols[info.col];
  732. const node = info.sheet.zh_tree.nodes[info.row];
  733. if (!node) {
  734. info.cancel = true;
  735. return;
  736. }
  737. const exprInfo = getExprInfo(col.field);
  738. if (exprInfo) {
  739. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  740. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  741. }
  742. }
  743. switch (col.field) {
  744. case 'code':
  745. const posRange = pos.getLedgerPos(node.id);
  746. info.cancel = posRange && posRange.length > 0;
  747. break;
  748. case 'unit_price':
  749. info.cancel = (node.children && node.children.length > 0) || node.used;
  750. break;
  751. case 'sgfh_qty':
  752. case 'sgfh_tp':
  753. case 'sjcl_qty':
  754. case 'sjcl_tp':
  755. case 'qtcl_qty':
  756. case 'qtcl_tp':
  757. case 'deal_qty':
  758. case 'deal_tp':
  759. info.cancel = (node.children && node.children.length > 0);
  760. break;
  761. case 'dgn_qty1':
  762. case 'dgn_qty2':
  763. info.cancel = !_.isEmpty(node.b_code);
  764. break;
  765. }
  766. },
  767. cut: function (sheet, sel, callback) {
  768. if (!sheet || !sel) return;
  769. if (sel.colCount >= sheet.zh_setting.cols.length) {
  770. toastr.warning('请勿选中整行剪切');
  771. return;
  772. }
  773. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  774. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  775. const node = sortData[iRow];
  776. if (node) {
  777. const data = sheet.zh_tree.getNodeKeyData(node);
  778. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  779. const col = sheet.zh_setting.cols[iCol];
  780. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  781. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  782. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  783. const lPos = pos.getLedgerPos(node.id);
  784. if (lPos && lPos.length > 0) {
  785. toastr.error('不可剪切');
  786. return;
  787. }
  788. }
  789. const style = sheet.getStyle(iRow, iCol);
  790. if (style.locked) {
  791. toastr.error('不可剪切');
  792. return;
  793. }
  794. const colSetting = sheet.zh_setting.cols[iCol];
  795. data[colSetting.field] = null;
  796. const exprInfo = getExprInfo(colSetting.field);
  797. if (exprInfo) {
  798. data[exprInfo.expr] = '';
  799. }
  800. }
  801. datas.push(data);
  802. }
  803. }
  804. if (datas.length > 0) {
  805. callback();
  806. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  807. const refreshNode = sheet.zh_tree.loadPostData(result);
  808. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  809. });
  810. }
  811. },
  812. sortCode: function (sheet) {
  813. const tree = sheet.zh_tree;
  814. if (!tree) return;
  815. const select = SpreadJsObj.getSelectObject(sheet);
  816. if (!select || !select.code || select.code === '') return;
  817. const recursiveSortCode = function (data, parentCode, children) {
  818. if (!children || children.length === 0) return;
  819. for (const [i, child] of children.entries()) {
  820. if (!child.b_code || child.b_code === '') {
  821. const code = parentCode + '-' + (i + 1);
  822. const cData = tree.getNodeKeyData(child);
  823. cData.code = code;
  824. data.push(cData);
  825. if (!tree.isLeafXmj(child)) {
  826. recursiveSortCode(data, code, child.children);
  827. }
  828. }
  829. }
  830. };
  831. const data = [];
  832. recursiveSortCode(data, select.code, select.children);
  833. if (data.length > 0) {
  834. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  835. const refreshNode = tree.loadPostData(result);
  836. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  837. })
  838. }
  839. }
  840. };
  841. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  842. billsTreeSpreadObj.loadExprToInput(billsSheet);
  843. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  844. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  845. if (!readOnly) {
  846. // 增删上下移升降级
  847. $('a[name="base-opr"]').click(function () {
  848. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  849. });
  850. $('a[name=cpc]').click(function () {
  851. billsSpread.commandManager().execute({
  852. cmd: this.getAttribute('type'),
  853. sheetName: billsSheet.name()
  854. });
  855. });
  856. $('#bills-expr').bind('change onblur', function () {
  857. if (this.readOnly) return;
  858. const expr = $(this);
  859. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  860. const select = billsTree.getItemsByIndex(row);
  861. if (!select) return;
  862. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  863. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  864. const data = {
  865. id: select.id,
  866. tender_id: select.tender_id,
  867. ledger_id: select.ledger_id
  868. };
  869. const exprInfo = getExprInfo(field);
  870. if (newValue !== '') {
  871. const num = _.toNumber(newValue);
  872. if (num) {
  873. data[field] = num;
  874. if (exprInfo) {
  875. data[exprInfo.expr] = '';
  876. }
  877. } else {
  878. try {
  879. data[field] = math.evaluate(transExpr(newValue));
  880. if (exprInfo) {
  881. data[exprInfo.expr] = newValue;
  882. }
  883. } catch (err) {
  884. toastr.error('输入的表达式非法');
  885. return;
  886. }
  887. }
  888. } else {
  889. data[field] = null;
  890. if (exprInfo) {
  891. data[exprInfo.expr] = '';
  892. }
  893. }
  894. // 更新至服务器
  895. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  896. const refreshNode = billsTree.loadPostData(result);
  897. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  898. });
  899. });
  900. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  901. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  902. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  903. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  904. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  905. SpreadJsObj.Clipboard.setCopyData(copyText);
  906. });
  907. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  908. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  909. }
  910. // 右键菜单
  911. let batchInsertObj;
  912. $.contextMenu.types.batchInsert = function (item, opt, root) {
  913. const self = this;
  914. if ($.isFunction(item.icon)) {
  915. item._icon = item.icon.call(this, this, $t, key, item);
  916. } else {
  917. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  918. // to enable font awesome
  919. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  920. } else {
  921. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  922. }
  923. }
  924. this.addClass(item._icon);
  925. 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>')
  926. .appendTo(this);
  927. const $input = $obj.find('input');
  928. const event = () => {
  929. if (self.hasClass('context-menu-disabled')) return;
  930. item.batchInsert($input[0], root);
  931. };
  932. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  933. $input.click((e) => {e.stopPropagation();})
  934. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  935. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  936. };
  937. const billsContextMenuOptions = {
  938. selector: '#bills-spread',
  939. build: function ($trigger, e) {
  940. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  941. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  942. },
  943. items: {}
  944. };
  945. if (!readOnly) {
  946. billsContextMenuOptions.items.create = {
  947. name: '新增',
  948. icon: 'fa-sign-in',
  949. callback: function (key, opt) {
  950. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  951. },
  952. disabled: function (key, opt) {
  953. const sheet = billsSheet;
  954. const selection = sheet.getSelections();
  955. const sel = selection ? selection[0] : sheet.getSelections()[0];
  956. const row = sel ? sel.row : -1;
  957. const tree = sheet.zh_tree;
  958. if (!tree) return true;
  959. const first = sheet.zh_tree.nodes[row];
  960. const valid = !sheet.zh_setting.readOnly;
  961. return !(valid && first && first.level > 1);
  962. }
  963. };
  964. billsContextMenuOptions.items.delete = {
  965. name: '删除',
  966. icon: 'fa-remove',
  967. callback: function (key, opt) {
  968. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  969. },
  970. disabled: function (key, opt) {
  971. const sheet = billsSheet;
  972. const selection = sheet.getSelections();
  973. const sel = selection ? selection[0] : sheet.getSelections()[0];
  974. const row = sel ? sel.row : -1;
  975. const tree = sheet.zh_tree;
  976. if (!tree) return true;
  977. const first = sheet.zh_tree.nodes[row];
  978. let last = first, sameParent = true, nodeUsed = first.used;
  979. if (sel.rowCount > 1 && first) {
  980. for (let r = 1; r < sel.rowCount; r++) {
  981. const rNode = tree.nodes[sel.row + r];
  982. if (!rNode) {
  983. sameParent = false;
  984. break;
  985. }
  986. nodeUsed = nodeUsed || rNode.used;
  987. if (rNode.level > first.level) continue;
  988. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  989. sameParent = false;
  990. break;
  991. }
  992. last = rNode;
  993. }
  994. }
  995. const valid = !sheet.zh_setting.readOnly;
  996. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed);
  997. }
  998. };
  999. billsContextMenuOptions.items.sprBase = '-----------';
  1000. }
  1001. billsContextMenuOptions.items.copyBlock = {
  1002. name: '复制整块',
  1003. icon: 'fa-files-o',
  1004. callback: function (key, opt) {
  1005. const copyBlockList = [];
  1006. const sheet = billsSheet;
  1007. const sel = sheet.getSelections()[0];
  1008. let iRow = sel.row;
  1009. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1010. while (iRow < sel.row + sel.rowCount) {
  1011. const node = sheet.zh_tree.nodes[iRow];
  1012. if (node.ledger_pid !== pid) {
  1013. toastr.error('仅可同时选中同层节点');
  1014. return;
  1015. }
  1016. const posterity = sheet.zh_tree.getPosterity(node);
  1017. iRow += posterity.length + 1;
  1018. posterity.unshift(node);
  1019. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1020. }
  1021. for (const cbl of copyBlockList) {
  1022. for (const b of cbl) {
  1023. const posRange = pos.getLedgerPos(b.id);
  1024. if (posRange && posRange.length > 0) b.pos = posRange;
  1025. }
  1026. }
  1027. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1028. },
  1029. visible: function (key, opt) {
  1030. const sheet = billsSheet;
  1031. const selection = sheet.getSelections();
  1032. const row = selection[0].row;
  1033. const select = billsTree.nodes[row];
  1034. return select;
  1035. },
  1036. disabled: function (key, opt) {
  1037. const sheet = billsSheet;
  1038. const selection = sheet.getSelections();
  1039. const row = selection[0].row;
  1040. const select = billsTree.nodes[row];
  1041. return select && select.level <= 1;
  1042. }
  1043. };
  1044. if (!readOnly) {
  1045. billsContextMenuOptions.items.pasteBlock = {
  1046. name: '粘贴整块',
  1047. icon: 'fa-clipboard',
  1048. disabled: function (key, opt) {
  1049. //const block = treeOperationObj.block || [];
  1050. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1051. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1052. },
  1053. callback: function (key, opt) {
  1054. //const block = treeOperationObj.block || [];
  1055. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1056. if (copyInfo.block.length > 0) {
  1057. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  1058. } else {
  1059. document.execCommand('paste');
  1060. }
  1061. },
  1062. visible: function (key, opt) {
  1063. return !readOnly;
  1064. }
  1065. };
  1066. billsContextMenuOptions.items.sprBlock = '-----------';
  1067. }
  1068. if (!readOnly) {
  1069. billsContextMenuOptions.items.batchInsert = {
  1070. name: '批量插入',
  1071. type: 'batchInsert',
  1072. value: '2',
  1073. icon: 'fa-sign-in',
  1074. batchInsert: function (obj, root) {
  1075. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1076. obj.value = obj.max;
  1077. toastr.warning('批量插入不可多于' + obj.max);
  1078. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1079. obj.value = obj.min;
  1080. toastr.warning('批量插入不可少于' + obj.min);
  1081. } else {
  1082. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  1083. root.$menu.trigger('contextmenu:hide');
  1084. }
  1085. },
  1086. disabled: function (key, opt) {
  1087. const sheet = billsSheet;
  1088. const selection = sheet.getSelections();
  1089. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1090. const row = sel ? sel.row : -1;
  1091. const tree = sheet.zh_tree;
  1092. if (!tree) return true;
  1093. const first = sheet.zh_tree.nodes[row];
  1094. const valid = !sheet.zh_setting.readOnly;
  1095. return !(valid && first && first.level > 1);
  1096. }
  1097. };
  1098. billsContextMenuOptions.items.batchInsertBillsPos = {
  1099. name: '批量插入清单-计量单元',
  1100. icon: 'fa-sign-in',
  1101. disabled: function (key, opt) {
  1102. if (!isTz) return true;
  1103. const select = SpreadJsObj.getSelectObject(billsSheet);
  1104. if (select) {
  1105. if (select.code && select.code !== '') {
  1106. return !billsTree.isLeafXmj(select);
  1107. } else {
  1108. const parent = billsTree.getParent(select);
  1109. return !(parent && billsTree.isLeafXmj(parent));
  1110. }
  1111. } else {
  1112. return false;
  1113. }
  1114. },
  1115. callback: function (key, opt) {
  1116. if (!batchInsertObj) {
  1117. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1118. } else {
  1119. batchInsertObj.initView();
  1120. }
  1121. $('#batch').modal('show');
  1122. }
  1123. };
  1124. billsContextMenuOptions.items.sprBatch = '-----------';
  1125. billsContextMenuOptions.items.importGclBills2Xmj = {
  1126. name: '导入工程量清单至项目节',
  1127. icon: 'fa-file-excel-o',
  1128. disabled: function (key, opt) {
  1129. const node = SpreadJsObj.getSelectObject(billsSheet);
  1130. return readOnly
  1131. || (node.children && node.children.length > 0)
  1132. || (!_.isNil(node.b_code) && node.b_code !== '')
  1133. || billsTree.checkNodeUsed(node, pos);
  1134. },
  1135. callback: function (key, opt) {
  1136. const node = SpreadJsObj.getSelectObject(billsSheet);
  1137. importExcel.doImport({
  1138. template: {
  1139. hint: '工程量清单',
  1140. url: '/template/导入工程量清单EXCEL格式.xls',
  1141. },
  1142. callback: function (sheet) {
  1143. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  1144. const sel = billsSheet.getSelections();
  1145. const refreshNode = billsTree.loadPostData(result);
  1146. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1147. if (refreshNode.create[0]) {
  1148. if (sel && sel[0]) {
  1149. billsSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  1150. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel[0].row, refreshNode.create[0].index]);
  1151. } else {
  1152. billsSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  1153. SpreadJsObj.reloadRowsBackColor(billsSheet, [refreshNode.create[0].index]);
  1154. }
  1155. }
  1156. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1157. }, null);
  1158. }
  1159. });
  1160. }
  1161. };
  1162. }
  1163. $.contextMenu(billsContextMenuOptions);
  1164. // 计量单元 相关方法&绑定spreadjs事件
  1165. const posSpreadObj = {
  1166. refreshOperationValid: function (sheet, selection) {
  1167. const setObjEnable = function (obj, enable) {
  1168. if (enable) {
  1169. obj.removeClass('disabled');
  1170. } else {
  1171. obj.addClass('disabled');
  1172. }
  1173. };
  1174. const invalidAll = function () {
  1175. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1176. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1177. };
  1178. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1179. const row = sel ? sel.row : -1;
  1180. const first = sheet.zh_data[row];
  1181. if (!first) {
  1182. invalidAll();
  1183. return;
  1184. }
  1185. let last = first;
  1186. if (sel.rowCount > 1 && first) {
  1187. for (let r = 1; r < sel.rowCount; r++) {
  1188. const rNode = sheet.zh_data[sel.row + r];
  1189. if (!rNode) break;
  1190. last = rNode;
  1191. }
  1192. }
  1193. const preNode = sheet.zh_data[row - 1];
  1194. const valid = !sheet.zh_setting.readOnly;
  1195. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode);
  1196. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1));
  1197. },
  1198. loadExprToInput: function () {
  1199. const sel = posSheet.getSelections()[0];
  1200. if (!sel) return;
  1201. const col = posSheet.zh_setting.cols[sel.col];
  1202. const cell = posSheet.getCell(sel.col, sel.col);
  1203. if (col && col.type === 'Number') {
  1204. const data = SpreadJsObj.getSelectObject(posSheet);
  1205. if (data) {
  1206. const exprInfo = getExprInfo(col.field);
  1207. const value = exprInfo
  1208. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1209. : data[col.field];
  1210. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1211. .attr('readOnly', readOnly || cell.locked()).attr('data-row', sel.row);
  1212. } else {
  1213. $('#pos-expr').val('').attr('readOnly', true);
  1214. $('#pos-expr').removeAttr('data-row');
  1215. }
  1216. } else {
  1217. $('#pos-expr').val('').attr('readOnly', true);
  1218. $('#pos-expr').removeAttr('data-row');
  1219. }
  1220. },
  1221. /**
  1222. * 加载计量单元 根据当前台账选择节点
  1223. */
  1224. loadCurPosData: function () {
  1225. const node = SpreadJsObj.getSelectObject(billsSheet);
  1226. if (node) {
  1227. const posData = pos.getLedgerPos(node.id) || [];
  1228. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  1229. } else {
  1230. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  1231. }
  1232. SpreadJsObj.resetFieldReadOnly(posSheet);
  1233. posSpreadObj.loadExprToInput();
  1234. posSpreadObj.refreshOperationValid(posSheet);
  1235. },
  1236. baseOpr: function (sheet, type) {
  1237. const data = {
  1238. postType: 'pos',
  1239. posPostType: type === 'delete' ? type : 'update',
  1240. postData: [],
  1241. };
  1242. const selection = sheet.getSelections();
  1243. const row = selection[0].row, count = selection[0].rowCount;
  1244. const first = sheet.zh_data[row];
  1245. if (type === 'delete') {
  1246. for (let iRow = 0; iRow < count; iRow++) {
  1247. const posData = sheet.zh_data[iRow + row];
  1248. if (posData) {
  1249. if (posData.used) {
  1250. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1251. return;
  1252. }
  1253. data.postData.push(sheet.zh_data[iRow + row].id);
  1254. }
  1255. }
  1256. } else if (type === 'up-move') {
  1257. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1258. for (let iRow = 0; iRow < count; iRow++) {
  1259. const posData = sheet.zh_data[iRow + row];
  1260. if (posData) {
  1261. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1262. preUpdate.porder = posData.porder;
  1263. }
  1264. }
  1265. data.postData.push(preUpdate);
  1266. } else if (type === 'down-move') {
  1267. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1268. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1269. const posData = sheet.zh_data[iRow + row];
  1270. if (posData) {
  1271. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  1272. nextUpdate.porder = posData.porder;
  1273. }
  1274. }
  1275. data.postData.push(nextUpdate);
  1276. }
  1277. if (data.postData.length > 0) {
  1278. postData(window.location.pathname + '/update', data, function (result) {
  1279. if (type === 'delete') {
  1280. pos.removeDatas(result.pos);
  1281. sheet.deleteRows(row, count);
  1282. const loadResult = billsTree.loadPostData(result.ledger);
  1283. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1284. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1285. posSpreadObj.refreshOperationValid(posSheet);
  1286. } else {
  1287. pos.updateDatas(result.pos);
  1288. const sel = selection[0];
  1289. if (sel) {
  1290. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1291. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1292. }
  1293. posSpreadObj.loadCurPosData();
  1294. }
  1295. });
  1296. }
  1297. },
  1298. editStarting: function (e, info) {
  1299. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1300. const sel = info.sheet.getSelections();
  1301. if (!sel || !sel[0]) return;
  1302. const col = info.sheet.zh_setting.cols[sel[0].col];
  1303. const node = SpreadJsObj.getSelectObject(info.sheet);
  1304. const exprInfo = getExprInfo(col.field);
  1305. if (exprInfo) {
  1306. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1307. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1308. }
  1309. }
  1310. },
  1311. /**
  1312. * 编辑单元格响应事件
  1313. * @param {Object} e
  1314. * @param {Object} info
  1315. */
  1316. editEnded: function (e, info) {
  1317. if (!info.sheet.zh_setting) {
  1318. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1319. return;
  1320. }
  1321. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1322. const col = info.sheet.zh_setting.cols[info.col];
  1323. const orgText = posData ? posData[col.field] : null;
  1324. const newText = trimInvalidChar(info.editingText);
  1325. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  1326. const node = posSpreadObj.billsNode;
  1327. if (!node) {
  1328. toastr.error('数据错误,请选择台账节点后再试');
  1329. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1330. return;
  1331. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1332. toastr.error('父节点不可插入计量单元');
  1333. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1334. return;
  1335. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1336. toastr.error('项目节不可插入计量单元');
  1337. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1338. return;
  1339. }
  1340. const data = {postType: 'pos'};
  1341. if (col.field === 'name') {
  1342. if (newText === '' && posData) {
  1343. toastr.error('部位名称不可为空', 'error');
  1344. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1345. return;
  1346. } else if (!posData) {
  1347. if (newText && newText !== '') {
  1348. data.posPostType = 'add';
  1349. const sortData = info.sheet.zh_data;
  1350. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1351. data.postData = { name: newText, lid: node.id, porder: order};
  1352. } else {
  1353. return;
  1354. }
  1355. } else {
  1356. data.posPostType = 'update';
  1357. data.postData = {id: posData.id, name: newText};
  1358. }
  1359. } else if (!posData) {
  1360. toastr.warning('新增计量单元请先输入名称');
  1361. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1362. return;
  1363. } else {
  1364. data.posPostType = 'update';
  1365. data.postData = {id: posData.id};
  1366. if (col.type === 'Number') {
  1367. const exprInfo = getExprInfo(col.field);
  1368. const num = _.toNumber(newText);
  1369. if (_.isFinite(num)) {
  1370. data.postData[col.field] = num;
  1371. if (exprInfo) {
  1372. data.postData[exprInfo.expr] = '';
  1373. }
  1374. } else {
  1375. try {
  1376. data.postData[col.field] = math.evaluate(transExpr(newText));
  1377. if (exprInfo) {
  1378. data.postData[exprInfo.expr] = newText;
  1379. }
  1380. } catch(err) {
  1381. toastr.error('输入的表达式非法');
  1382. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1383. return;
  1384. }
  1385. }
  1386. } else {
  1387. data.postData[col.field] = newText;
  1388. }
  1389. }
  1390. postData(window.location.pathname + '/update', data, function (result) {
  1391. const updateRst = pos.updateDatas(result.pos);
  1392. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1393. if (updateRst.create.length > 0) {
  1394. posSpreadObj.loadCurPosData();
  1395. } else {
  1396. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1397. }
  1398. const loadResult = billsTree.loadPostData(result.ledger);
  1399. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1400. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1401. }, function () {
  1402. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1403. });
  1404. },
  1405. /**
  1406. * 删除按钮响应事件
  1407. * @param sheet
  1408. */
  1409. deletePress: function (sheet) {
  1410. if (!sheet.zh_setting) return;
  1411. const sortData = sheet.zh_data;
  1412. const datas = [], posSelects = [];
  1413. const sel = sheet.getSelections()[0];
  1414. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1415. let bDel = false;
  1416. const node = sortData[iRow];
  1417. if (node) {
  1418. const data = {id: node.id};
  1419. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1420. const colSetting = sheet.zh_setting.cols[iCol];
  1421. if (colSetting.field === 'name') {
  1422. toastr.error('部位名称不能为空');
  1423. return;
  1424. }
  1425. const style = sheet.getStyle(iRow, iCol);
  1426. if (!style.locked) {
  1427. const colSetting = sheet.zh_setting.cols[iCol];
  1428. data[colSetting.field] = null;
  1429. const exprInfo = getExprInfo(colSetting.field);
  1430. if (exprInfo) {
  1431. data[exprInfo.expr] = '';
  1432. }
  1433. bDel = true;
  1434. }
  1435. }
  1436. if (bDel) {
  1437. datas.push(data);
  1438. posSelects.push(node);
  1439. }
  1440. }
  1441. }
  1442. if (datas.length > 0) {
  1443. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  1444. pos.updateDatas(result.pos);
  1445. posSpreadObj.loadCurPosData();
  1446. const loadResult = billsTree.loadPostData(result.ledger);
  1447. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1448. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1449. }, function () {
  1450. posSpreadObj.loadCurPosData();
  1451. });
  1452. }
  1453. },
  1454. /**
  1455. * 删除 计量单元
  1456. * @param sheet
  1457. */
  1458. deletePos: function (sheet) {
  1459. const selection = sheet.getSelections();
  1460. const data = {
  1461. postType: 'pos',
  1462. posPostType: 'delete',
  1463. postData: [],
  1464. };
  1465. const row = selection[0].row, count = selection[0].rowCount;
  1466. const sortData = sheet.zh_data;
  1467. for (let iRow = 0; iRow < count; iRow++) {
  1468. const posData = sortData[iRow + row];
  1469. if (posData) {
  1470. if (posData.used) {
  1471. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1472. return;
  1473. }
  1474. data.postData.push(sortData[iRow + row].id);
  1475. }
  1476. }
  1477. if (data.postData.length > 0) {
  1478. postData(window.location.pathname + '/update', data, function (result) {
  1479. pos.removeDatas(result.pos);
  1480. sheet.deleteRows(row, count);
  1481. const loadResult = billsTree.loadPostData(result.ledger);
  1482. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1483. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1484. });
  1485. }
  1486. },
  1487. /**
  1488. * 粘贴单元格响应事件
  1489. * @param e
  1490. * @param info
  1491. */
  1492. clipboardPasted: function (e, info) {
  1493. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1494. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1495. }
  1496. const node = SpreadJsObj.getSelectObject(billsSheet);
  1497. if (node.code && (node.code !== '')) {
  1498. toastr.error('项目节不可含有节点明细');
  1499. posSpreadObj.loadCurPosData();
  1500. return;
  1501. }
  1502. if (node.children && (node.children.length > 0)) {
  1503. toastr.error('仅节点子项可以含有计量单元');
  1504. posSpreadObj.loadCurPosData();
  1505. return;
  1506. }
  1507. if (!info.sheet.zh_setting) {
  1508. posSpreadObj.loadCurPosData();
  1509. return;
  1510. }
  1511. const data = [];
  1512. const sortData = info.sheet.zh_data || [];
  1513. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1514. if (info.cellRange.col !== 0) {
  1515. toastr.warning('新增计量单元请先输入名称');
  1516. posSpreadObj.loadCurPosData();
  1517. return;
  1518. }
  1519. }
  1520. let bHint = false;
  1521. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1522. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1523. let bPaste = true;
  1524. const curRow = info.cellRange.row + iRow;
  1525. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  1526. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1527. const curCol = info.cellRange.col + iCol;
  1528. const colSetting = info.sheet.zh_setting.cols[curCol];
  1529. if (!colSetting) continue;
  1530. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1531. if (colSetting.type === 'Number') {
  1532. const num = _.toNumber(posData[colSetting.field]);
  1533. if (num) {
  1534. posData[colSetting.field] = num;
  1535. } else {
  1536. try {
  1537. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  1538. const exprInfo = getExprInfo(colSetting.field);
  1539. if (exprInfo) {
  1540. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1541. }
  1542. } catch (err) {
  1543. if (!bHint) {
  1544. toastr.warning('粘贴了非法表达式,已过滤');
  1545. bHint = true;
  1546. }
  1547. bPaste = false;
  1548. }
  1549. }
  1550. }
  1551. }
  1552. if (bPaste) {
  1553. data.push(posData);
  1554. }
  1555. }
  1556. if (data.length === 0) {
  1557. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1558. return;
  1559. }
  1560. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  1561. pos.updateDatas(result.pos);
  1562. posSpreadObj.loadCurPosData();
  1563. const loadResult = billsTree.loadPostData(result.ledger);
  1564. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1565. posSpreadObj.loadCurPosData();
  1566. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1567. }, function () {
  1568. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1569. });
  1570. },
  1571. selectionChanged: function (e, info) {
  1572. posSpreadObj.loadExprToInput();
  1573. posSpreadObj.refreshOperationValid(posSheet);
  1574. },
  1575. addPegs: function (pegs) {
  1576. if (!pegs || pegs.length <= 0) return;
  1577. const node = SpreadJsObj.getSelectObject(billsSheet);
  1578. if (!node) return;
  1579. const sheet = posSpread.getActiveSheet();
  1580. const sortData = sheet.zh_data || [];
  1581. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1582. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1583. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  1584. pos.updateDatas(result.pos);
  1585. posSpreadObj.loadCurPosData();
  1586. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1587. });
  1588. }
  1589. };
  1590. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  1591. if (!readOnly && isTz) {
  1592. $('a[name="pos-opr"]').click(function () {
  1593. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  1594. });
  1595. $('#pos-expr').bind('change onblur', function () {
  1596. if (this.readOnly) return;
  1597. const expr = $(this);
  1598. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1599. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  1600. if (!select) return;
  1601. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1602. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  1603. const data = {id: select.id};
  1604. const exprInfo = getExprInfo(field);
  1605. if (newValue !== '') {
  1606. const num = _.toNumber(newValue);
  1607. if (num) {
  1608. data[field] = num;
  1609. if (exprInfo) data[exprInfo.expr] = '';
  1610. } else {
  1611. try {
  1612. data[field] = math.evaluate(transExpr(newValue));
  1613. if (exprInfo) data[exprInfo.expr] = newValue;
  1614. } catch (err) {
  1615. toastr.error('输入的表达式非法');
  1616. return;
  1617. }
  1618. }
  1619. } else {
  1620. data[field] = null;
  1621. if (exprInfo) data[exprInfo.expr] = '';
  1622. }
  1623. // 更新至服务器
  1624. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  1625. const updateRst = pos.updateDatas(result.pos);
  1626. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1627. SpreadJsObj.reLoadRowData(posSheet, row);
  1628. const loadResult = billsTree.loadPostData(result.ledger);
  1629. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1630. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1631. });
  1632. });
  1633. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  1634. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  1635. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  1636. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  1637. const mergePeg = NewMergePeg({ callback: posSpreadObj.addPegs });
  1638. $.contextMenu({
  1639. selector: '#pos-spread',
  1640. build: function ($trigger, e) {
  1641. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  1642. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1643. },
  1644. items: {
  1645. 'delete': {
  1646. name: '删除',
  1647. icon: 'fa-remove',
  1648. disabled: function (key, opt) {
  1649. if (posSheet.zh_data) {
  1650. const selection = posSheet.getSelections();
  1651. return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1652. } else {
  1653. return true;
  1654. }
  1655. },
  1656. callback: function (key, opt) {
  1657. posSpreadObj.deletePos(posSheet);
  1658. }
  1659. },
  1660. 'merge-peg': {
  1661. name: '合并起讫桩号',
  1662. disabled: function (key, opt) {
  1663. const node = SpreadJsObj.getSelectObject(billsSheet);
  1664. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1665. },
  1666. callback: function (key, opt) {
  1667. mergePeg.show();
  1668. },
  1669. visible: function (key, opt) {
  1670. return isTz;
  1671. }
  1672. }
  1673. }
  1674. });
  1675. }
  1676. // 加载清单&计量单元数据
  1677. postData(window.location.pathname + '/load', {}, function (result) {
  1678. billsTree.loadDatas(result.bills);
  1679. treeCalc.calculateAll(billsTree);
  1680. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  1681. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  1682. pos.loadDatas(result.pos);
  1683. posSpreadObj.loadCurPosData();
  1684. SpreadJsObj.resetTopAndSelect(posSheet);
  1685. checkList.loadHisCheckData();
  1686. }, null);
  1687. $.divResizer({
  1688. select: '#revise-resize',
  1689. callback: function () {
  1690. billsSpread.refresh();
  1691. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1692. $(".sp-wrap").height(bcontent-30);
  1693. posSpread.refresh();
  1694. }
  1695. });
  1696. class DealBills {
  1697. constructor (selector, spreadSetting) {
  1698. const self = this;
  1699. this.loaded = false;
  1700. this.obj = $(selector)[0];
  1701. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  1702. this.spreadSetting = spreadSetting;
  1703. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1704. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1705. if (!readOnly) {
  1706. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1707. const dealSheet = info.sheet;
  1708. const mainSheet = billsSheet;
  1709. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  1710. if (!dealBills) { return; }
  1711. const mainTree = mainSheet.zh_tree;
  1712. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1713. if (!mainNode || !mainTree) { return; }
  1714. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1715. toastr.warning('非最底层项目下,不应添加节点');
  1716. return;
  1717. }
  1718. postData(window.location.pathname + '/update', {
  1719. postType: 'add-deal',
  1720. postData: {
  1721. id: mainNode.ledger_id,
  1722. type: mainNode.code ? 'child' : 'next',
  1723. dealBills: {
  1724. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  1725. unit_price: dealBills.unit_price,
  1726. }
  1727. },
  1728. }, function (result) {
  1729. const refreshData = mainTree.loadPostData(result);
  1730. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1731. const sel = mainSheet.getSelections()[0];
  1732. if (sel && refreshData.create[0]) {
  1733. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1734. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  1735. }
  1736. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1737. billsSpread.focus();
  1738. posSpreadObj.loadCurPosData();
  1739. });
  1740. });
  1741. }
  1742. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1743. }
  1744. loadData (callback) {
  1745. if (this.loaded) {
  1746. if (callback) callback();
  1747. return;
  1748. }
  1749. const self = this;
  1750. postData(this.url+'/get-data', {}, function (data) {
  1751. self.data = data;
  1752. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1753. self.loaded = true;
  1754. if (callback) callback();
  1755. });
  1756. }
  1757. calculateData () {
  1758. if (this.data) {
  1759. for (const d of this.data) {
  1760. d.total_price = _.multiply(d.quantity, d.unit_price);
  1761. }
  1762. }
  1763. }
  1764. }
  1765. class BgBills {
  1766. constructor (selector, spreadSetting) {
  1767. this.loaded = false;
  1768. this.obj = $(selector)[0];
  1769. this.spreadSetting = spreadSetting;
  1770. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1771. this.sheet = this.spread.getActiveSheet();
  1772. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1773. if (!readOnly) {
  1774. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1775. const dealSheet = info.sheet;
  1776. const mainSheet = billsSheet;
  1777. const bgBills = SpreadJsObj.getSelectObject(dealSheet);
  1778. if (!bgBills) { return; }
  1779. const mainTree = mainSheet.zh_tree;
  1780. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1781. if (!mainNode || !mainTree) { return; }
  1782. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1783. toastr.warning('非最底层项目下,不应添加变更清单');
  1784. return;
  1785. }
  1786. postData(window.location.pathname + '/update', {
  1787. postType: 'add-bg',
  1788. postData: {
  1789. id: mainNode.ledger_id,
  1790. type: mainNode.code ? 'child' : 'next',
  1791. dealBills: {
  1792. b_code: bgBills.code, name: bgBills.name, unit: bgBills.unit,
  1793. unit_price: bgBills.unit_price,
  1794. }
  1795. },
  1796. }, function (result) {
  1797. const refreshData = mainTree.loadPostData(result);
  1798. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1799. const sel = mainSheet.getSelections()[0];
  1800. if (sel && refreshData.create[0]) {
  1801. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1802. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  1803. }
  1804. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1805. billsSpread.focus();
  1806. posSpreadObj.loadCurPosData();
  1807. });
  1808. });
  1809. }
  1810. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1811. }
  1812. loadData () {
  1813. if (this.loaded) return;
  1814. const self = this;
  1815. postData('/tender/' + window.location.pathname.split('/')[2] +'/change/bills', {type: 'gather'}, function (data) {
  1816. self.data = data;
  1817. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1818. self.loaded = true;
  1819. });
  1820. }
  1821. }
  1822. class BatchInsertBillsPosObj {
  1823. constructor (obj) {
  1824. const self = this;
  1825. this.obj = obj;
  1826. this.billsCount = 6;
  1827. this.posCount = 1000;
  1828. this.filter = getLocalCache('zh-calc-batch-filter');
  1829. if (!this.filter) {
  1830. this.filter = '1';
  1831. }
  1832. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  1833. // 初始化 清单编号窗口 参数
  1834. this.qdSpreadSetting = {
  1835. cols: [
  1836. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  1837. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  1838. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  1839. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1840. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  1841. ],
  1842. emptyRows: this.billsCount,
  1843. headRows: 1,
  1844. headRowHeight: [32],
  1845. headerFont: '12px 微软雅黑',
  1846. font: '12px 微软雅黑',
  1847. };
  1848. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  1849. // 初始化 部位数量复核表 参数
  1850. this.posSpreadSetting = {
  1851. cols: [
  1852. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  1853. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  1854. ],
  1855. emptyRows: this.posCount,
  1856. headRows: 1,
  1857. headRowHeight: [32],
  1858. headerFont: '12px 微软雅黑',
  1859. font: '12px 微软雅黑',
  1860. };
  1861. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  1862. this.posSpreadSetting.cols.push(
  1863. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  1864. )
  1865. }
  1866. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  1867. // 初始化 签约节点 参数
  1868. this.dealSpreadSetting = {
  1869. cols: [
  1870. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  1871. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  1872. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1873. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  1874. ],
  1875. emptyRows: 0,
  1876. headRows: 1,
  1877. headRowHeight: [32],
  1878. headerFont: '12px 微软雅黑',
  1879. font: '12px 微软雅黑',
  1880. };
  1881. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  1882. // 初始化 清单编号、部位数量复核表 表格
  1883. this.initView();
  1884. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  1885. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  1886. // 拉取签约节点数据
  1887. dealBills.loadData(() => {
  1888. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1889. });
  1890. // 双击签约节点,自动添加到清单编号窗口
  1891. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1892. const deal = info.sheet.zh_data[info.row];
  1893. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  1894. const sel = qdSheet.getSelections()[0];
  1895. qdSheet.getCell(sel.row, 0).value(deal.code);
  1896. qdSheet.getCell(sel.row, 1).value(deal.name);
  1897. qdSheet.getCell(sel.row, 2).value(deal.unit);
  1898. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  1899. if (sel.row + 1 === qdSheet.getRowCount()) {
  1900. const count = sel.row + 2;
  1901. qdSheet.setRowCount(count);
  1902. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  1903. const colCount = posSheet.getColumnCount() + 1;
  1904. posSheet.setColumnCount(colCount);
  1905. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  1906. }
  1907. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  1908. qdSheet.getParent().focus();
  1909. });
  1910. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  1911. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  1912. const count = posSheet.getColumnCount() - 2;
  1913. if (billsCount > count) {
  1914. posSheet.setColumnCount(billsCount + 2);
  1915. for (let i = count + 1; i <= billsCount; i++) {
  1916. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  1917. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  1918. }
  1919. }
  1920. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  1921. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  1922. if (dealBills && dealBills.length > 0) {
  1923. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1924. const curRow = iRow + info.cellRange.row;
  1925. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  1926. if (bills) {
  1927. info.sheet.getCell(curRow, 1).value(bills.name);
  1928. info.sheet.getCell(curRow, 2).value(bills.unit);
  1929. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  1930. }
  1931. }
  1932. }
  1933. }
  1934. });
  1935. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  1936. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  1937. const count = qdSheet.getRowCount();
  1938. if (billsCount > count) {
  1939. qdSheet.setRowCount(billsCount);
  1940. for (let i = count + 1; i <= billsCount; i++) {
  1941. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  1942. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  1943. }
  1944. }
  1945. });
  1946. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  1947. if (info.col === 0) {
  1948. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  1949. if (dealBills && dealBills.length > 0) {
  1950. const bills = _.find(dealBills, {code: info.editingText});
  1951. if (bills) {
  1952. info.sheet.getCell(info.row, 1).value(bills.name);
  1953. info.sheet.getCell(info.row, 2).value(bills.unit);
  1954. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  1955. }
  1956. }
  1957. }
  1958. });
  1959. this.obj.bind('shown.bs.modal', function () {
  1960. self.qdSpread.refresh();
  1961. self.posSpread.refresh();
  1962. self.dealSpread.refresh();
  1963. });
  1964. $('#batch-ok').click(function () {
  1965. const selection = billsSheet.getSelections();
  1966. const sel = selection[0];
  1967. const row = selection[0].row;
  1968. const select = billsTree.nodes[row];
  1969. if (select) {
  1970. const insertData = {};
  1971. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  1972. insertData.id = select[billsTree.setting.id];
  1973. insertData.batchData = self.getBatchData();
  1974. if (insertData.batchData.length > 0) {
  1975. postData(window.location.pathname + '/update', {
  1976. postType: 'batch-insert',
  1977. postData: insertData
  1978. }, function (data) {
  1979. pos.updateDatas(data.pos);
  1980. const result = billsTree.loadPostData(data.ledger);
  1981. billsTreeSpreadObj.refreshTree(billsSheet, result);
  1982. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  1983. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  1984. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  1985. posSpreadObj.loadCurPosData();
  1986. self.obj.modal('hide');
  1987. }, null, true);
  1988. } else {
  1989. self.obj.modal('hide');
  1990. }
  1991. }
  1992. });
  1993. $('input[name=batch-filter]').change(function () {
  1994. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  1995. });
  1996. $.contextMenu({
  1997. selector: '.batch-l-t',
  1998. build: function ($trigger, e) {
  1999. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2000. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2001. },
  2002. items: {
  2003. 'create': {
  2004. name: '新增行',
  2005. icon: 'fa-sign-in',
  2006. callback: function (key, opt) {
  2007. const qdSheet = self.qdSpread.getActiveSheet();
  2008. const posSheet = self.posSpread.getActiveSheet();
  2009. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2010. const index = qdSheet.getRowCount();
  2011. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2012. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2013. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2014. },
  2015. },
  2016. 'delete': {
  2017. name: '删除行',
  2018. icon: 'fa-remove',
  2019. callback: function (key, opt) {
  2020. const qdSheet = self.qdSpread.getActiveSheet();
  2021. const posSheet = self.posSpread.getActiveSheet();
  2022. const sel = qdSheet.getSelections()[0];
  2023. qdSheet.deleteRows(sel.row, sel.rowCount);
  2024. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2025. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2026. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2027. }
  2028. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2029. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2030. }
  2031. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2032. },
  2033. },
  2034. }
  2035. });
  2036. }
  2037. // 初始化左侧表格
  2038. initView () {
  2039. // 初始化 清单编号
  2040. const qdSheet = this.qdSpread.getActiveSheet();
  2041. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  2042. SpreadJsObj.refreshColumnAlign(qdSheet);
  2043. // 清理原有数据
  2044. SpreadJsObj.beginMassOperation(qdSheet);
  2045. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2046. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  2047. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  2048. }
  2049. qdSheet.setSelection(0, 0, 1 ,1);
  2050. SpreadJsObj.endMassOperation(qdSheet);
  2051. // 初始化 部位数量复核表
  2052. const posSheet = this.posSpread.getActiveSheet();
  2053. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  2054. SpreadJsObj.refreshColumnAlign(posSheet);
  2055. // 清理原有数据
  2056. SpreadJsObj.beginMassOperation(posSheet);
  2057. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  2058. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2059. posSheet.setSelection(0, 0, 1 ,1);
  2060. SpreadJsObj.endMassOperation(posSheet);
  2061. // 检查签约节点数据,以工具栏数据为准
  2062. if (dealBills) {
  2063. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2064. }
  2065. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  2066. }
  2067. // 获取界面数据
  2068. getBatchData () {
  2069. const result = [];
  2070. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  2071. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  2072. if (qdSheet.getText(iRow, 0) === '') { continue; }
  2073. const qd = {
  2074. b_code: qdSheet.getText(iRow, 0),
  2075. name: qdSheet.getText(iRow, 1),
  2076. unit: qdSheet.getText(iRow, 2),
  2077. price: _.toNumber(qdSheet.getText(iRow, 3)),
  2078. pos: [],
  2079. };
  2080. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  2081. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  2082. if (value !== 0 && !isNaN(value)) {
  2083. qd.pos.push({
  2084. name: posSheet.getText(iPosRow, 0),
  2085. drawing_code: posSheet.getText(iPosRow, 1),
  2086. quantity: value, porder: qd.pos.length + 1,
  2087. });
  2088. }
  2089. }
  2090. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  2091. }
  2092. return result;
  2093. }
  2094. }
  2095. const dealBills = new DealBills('#deal-bills-spread', {
  2096. cols: [
  2097. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2098. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2099. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2100. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2101. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2102. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2103. ],
  2104. emptyRows: 0,
  2105. headRows: 1,
  2106. headRowHeight: [32],
  2107. headColWidth: [30],
  2108. defaultRowHeight: 21,
  2109. headerFont: '12px 微软雅黑',
  2110. font: '12px 微软雅黑',
  2111. selectedBackColor: '#fffacd',
  2112. });
  2113. const bgBills = new BgBills('#bg-bills-spread', {
  2114. cols: [
  2115. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2116. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2117. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2118. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2119. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2120. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2121. ],
  2122. emptyRows: 0,
  2123. headRows: 1,
  2124. headRowHeight: [32],
  2125. headColWidth: [30],
  2126. defaultRowHeight: 21,
  2127. headerFont: '12px 微软雅黑',
  2128. font: '12px 微软雅黑',
  2129. selectedBackColor: '#fffacd',
  2130. });
  2131. $.divResizer({
  2132. select: '#revise-right-spr',
  2133. callback: function () {
  2134. billsSpread.refresh();
  2135. if (posSpread) {
  2136. posSpread.refresh();
  2137. }
  2138. if (stdXmj) {
  2139. stdXmj.spread.refresh();
  2140. }
  2141. if (stdGcl) {
  2142. stdGcl.spread.refresh();
  2143. }
  2144. if (dealBills) {
  2145. dealBills.spread.refresh();
  2146. }
  2147. if (bgBills) {
  2148. bgBills.spread.refresh();
  2149. }
  2150. if (searchLedger) {
  2151. searchLedger.spread.refresh();
  2152. }
  2153. if (errorList) {
  2154. errorList.spread.refresh();
  2155. }
  2156. if (checkList) {
  2157. checkList.spread.refresh();
  2158. }
  2159. }
  2160. });
  2161. $.subMenu({
  2162. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2163. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2164. key: 'menu.1.0.0',
  2165. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2166. callback: function (info) {
  2167. if (info.mini) {
  2168. $('.panel-title').addClass('fluid');
  2169. $('#sub-menu').removeClass('panel-sidebar');
  2170. } else {
  2171. $('.panel-title').removeClass('fluid');
  2172. $('#sub-menu').addClass('panel-sidebar');
  2173. }
  2174. autoFlashHeight();
  2175. billsSpread.refresh();
  2176. if (posSpread) {
  2177. posSpread.refresh();
  2178. }
  2179. if (stdXmj) {
  2180. stdXmj.spread.refresh();
  2181. }
  2182. if (stdGcl) {
  2183. stdGcl.spread.refresh();
  2184. }
  2185. if (dealBills) {
  2186. dealBills.spread.refresh();
  2187. }
  2188. if (bgBills) {
  2189. bgBills.spread.refresh();
  2190. }
  2191. if (searchLedger) {
  2192. searchLedger.spread.refresh();
  2193. }
  2194. if (errorList) {
  2195. errorList.spread.refresh();
  2196. }
  2197. if (checkList) {
  2198. checkList.spread.refresh();
  2199. }
  2200. }
  2201. });
  2202. $('#content-tab').addClass('active');
  2203. $('#xd-content').addClass('active');
  2204. showSideTools(true);
  2205. billsSpread.refresh();
  2206. if (posSpread) {
  2207. posSpread.refresh();
  2208. }
  2209. const stdLibCellDoubleClick = function (e, info) {
  2210. const stdSheet = info.sheet;
  2211. const mainSheet = billsSheet;
  2212. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  2213. const stdTree = stdSheet.zh_tree;
  2214. const stdNode = stdTree.nodes[info.row];
  2215. const mainTree = mainSheet.zh_tree;
  2216. const sel = mainSheet.getSelections()[0];
  2217. const mainNode = mainTree.nodes[sel.row];
  2218. if (!stdNode) return;
  2219. if (info.sheet.zh_setting.stdType === 'gcl') {
  2220. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2221. toastr.warning('非最底层项目下,不应添加节点');
  2222. return;
  2223. }
  2224. }
  2225. postData(window.location.pathname + '/update', {
  2226. postType: 'add-std',
  2227. postData: {
  2228. id: mainTree.getNodeKey(mainNode),
  2229. tender_id: mainNode.tender_id,
  2230. stdType: info.sheet.zh_setting.stdType,
  2231. stdLibId: stdNode.list_id,
  2232. stdNode: stdTree.getNodeKey(stdNode)
  2233. }
  2234. }, function (result) {
  2235. const refreshNode = mainTree.loadPostData(result);
  2236. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  2237. if (sel) {
  2238. if (refreshNode.create && refreshNode.create.length > 0) {
  2239. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  2240. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  2241. } else {
  2242. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  2243. if (node) {
  2244. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  2245. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  2246. }
  2247. }
  2248. }
  2249. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2250. billsSpread.focus();
  2251. posSpreadObj.loadCurPosData();
  2252. });
  2253. };
  2254. const stdXmjSetting = {
  2255. selector: '#std-xmj',
  2256. stdType: 'xmj',
  2257. treeSetting: {
  2258. id: 'chapter_id',
  2259. pid: 'pid',
  2260. order: 'order',
  2261. level: 'level',
  2262. rootId: -1,
  2263. keys: ['id', 'list_id', 'chapter_id'],
  2264. },
  2265. spreadSetting: {
  2266. cols: [
  2267. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2268. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2269. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2270. ],
  2271. treeCol: 0,
  2272. emptyRows: 0,
  2273. headRows: 1,
  2274. headRowHeight: [32],
  2275. defaultRowHeight: 21,
  2276. headerFont: '12px 微软雅黑',
  2277. font: '12px 微软雅黑',
  2278. headColWidth: [30],
  2279. selectedBackColor: '#fffacd',
  2280. },
  2281. cellDoubleClick: stdLibCellDoubleClick,
  2282. page: 'revise',
  2283. tid: window.location.pathname.split('/')[2],
  2284. };
  2285. const stdGclSetting = {
  2286. selector: '#std-gcl',
  2287. stdType: 'gcl',
  2288. treeSetting: {
  2289. id: 'bill_id',
  2290. pid: 'pid',
  2291. order: 'order',
  2292. level: 'level',
  2293. rootId: -1,
  2294. keys: ['id', 'list_id', 'bill_id']
  2295. },
  2296. spreadSetting: {
  2297. cols: [
  2298. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2299. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2300. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2301. ],
  2302. treeCol: 0,
  2303. emptyRows: 0,
  2304. headRows: 1,
  2305. headRowHeight: [32],
  2306. defaultRowHeight: 21,
  2307. headerFont: '12px 微软雅黑',
  2308. font: '12px 微软雅黑',
  2309. headColWidth: [30],
  2310. selectedBackColor: '#fffacd',
  2311. },
  2312. cellDoubleClick: stdLibCellDoubleClick,
  2313. page: 'revise',
  2314. tid: window.location.pathname.split('/')[2],
  2315. };
  2316. // 展开收起标准节点
  2317. $('a', '#side-menu').bind('click', function (e) {
  2318. e.preventDefault();
  2319. const tab = $(this), tabPanel = $(tab.attr('content'));
  2320. // 展开工具栏、切换标签
  2321. if (!tab.hasClass('active')) {
  2322. const close = $('.active', '#side-menu').length === 0;
  2323. $('a', '#side-menu').removeClass('active');
  2324. tab.addClass('active');
  2325. $('.tab-content .tab-pane').removeClass('active');
  2326. tabPanel.addClass('active');
  2327. showSideTools(tab.hasClass('active'));
  2328. if (tab.attr('content') === '#std-xmj') {
  2329. if (!stdXmj) {
  2330. stdXmj = new stdLib(stdXmjSetting);
  2331. }
  2332. stdXmj.spread.refresh();
  2333. } else if (tab.attr('content') === '#std-gcl') {
  2334. if (!stdGcl) {
  2335. stdGcl = new stdLib(stdGclSetting);
  2336. }
  2337. stdGcl.spread.refresh();
  2338. } else if (tab.attr('content') === '#deal-bills') {
  2339. dealBills.loadData();
  2340. dealBills.spread.refresh();
  2341. } else if (tab.attr('content') === '#bg-bills') {
  2342. bgBills.loadData();
  2343. bgBills.spread.refresh();
  2344. } else if (tab.attr('content') === '#search') {
  2345. if (!searchLedger) {
  2346. searchLedger = $.billsSearch({
  2347. selector: '#search',
  2348. searchSpread: billsSpread,
  2349. resultSpreadSetting: {
  2350. cols: [
  2351. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@', readOnly: true},
  2352. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2353. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  2354. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  2355. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2356. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2357. ],
  2358. emptyRows: 0,
  2359. headRows: 1,
  2360. headRowHeight: [32],
  2361. headColWidth: [30],
  2362. defaultRowHeight: 21,
  2363. headerFont: '12px 微软雅黑',
  2364. font: '12px 微软雅黑',
  2365. selectedBackColor: '#fffacd',
  2366. },
  2367. afterLocated: function () {
  2368. posSpreadObj.loadCurPosData();
  2369. }
  2370. });
  2371. }
  2372. searchLedger.spread.refresh();
  2373. } else if (tab.attr('content') === '#error-list') {
  2374. errorList.spread.refresh();
  2375. } else if (tab.attr('content') === '#check-list') {
  2376. checkList.spread.refresh();
  2377. }
  2378. }
  2379. else {// 收起工具栏
  2380. tab.removeClass('active');
  2381. tabPanel.removeClass('active');
  2382. showSideTools(tab.hasClass('active'));
  2383. }
  2384. billsSpread.refresh();
  2385. if (posSpread) {
  2386. posSpread.refresh();
  2387. }
  2388. });
  2389. if (!readOnly) {
  2390. // 修订详情 保存
  2391. $('#save').click(function () {
  2392. const content = $('#content').val();
  2393. postData('save', { content: content }, function () {
  2394. $('#content').attr('org-value', content);
  2395. });
  2396. });
  2397. }
  2398. // 显示层次
  2399. (function (select, sheet) {
  2400. $(select).click(function () {
  2401. if (!sheet.zh_tree) return;
  2402. const tag = $(this).attr('tag');
  2403. const tree = sheet.zh_tree;
  2404. switch (tag) {
  2405. case "1":
  2406. case "2":
  2407. case "3":
  2408. case "4":
  2409. case "5":
  2410. tree.expandByLevel(parseInt(tag));
  2411. SpreadJsObj.refreshTreeRowVisible(sheet);
  2412. break;
  2413. case "last":
  2414. tree.expandByCustom(() => { return true; });
  2415. SpreadJsObj.refreshTreeRowVisible(sheet);
  2416. break;
  2417. case "leafXmj":
  2418. tree.expandToLeafXmj();
  2419. SpreadJsObj.refreshTreeRowVisible(sheet);
  2420. break;
  2421. }
  2422. });
  2423. })('a[name=showLevel]', billsSheet);
  2424. const dataChecker = DataChecker({
  2425. checkUrl: window.location.pathname + '/check',
  2426. completeData: function (data) {
  2427. pos.updateDatas({update: data.source.pos});
  2428. const loadResult = billsTree.loadPostData({update: data.source.bills});
  2429. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2430. posSpreadObj.loadCurPosData();
  2431. for (const e of data.error) {
  2432. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  2433. }
  2434. },
  2435. errorList: errorList,
  2436. });
  2437. LedgerChecker({
  2438. ledgerTree: billsTree,
  2439. ledgerPos: pos,
  2440. checkList: checkList,
  2441. decimal: decimal,
  2442. checkOption: {
  2443. sibling: { enable: 1 },
  2444. empty_code: { enable: 1 },
  2445. calc: {
  2446. enable: 1,
  2447. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  2448. },
  2449. zero: { enable: 1 },
  2450. tp: {
  2451. enable: 1,
  2452. fields: [
  2453. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  2454. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  2455. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  2456. {qty: 'quantity', tp: 'total_price'},
  2457. {qty: 'deal_qty', tp: 'deal_tp'},
  2458. ],
  2459. },
  2460. }
  2461. });
  2462. $('[name=revise-start]').submit(function (e) {
  2463. if (checkAuditorFrom()) {
  2464. $(this).parent().parent().parent().modal('hide');
  2465. dataChecker.checkAndPost(this.action, {});
  2466. $('#hide-all').hide();
  2467. }
  2468. return false;
  2469. });
  2470. });