revise.js 120 KB

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