revise.js 118 KB

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