ledger.js 120 KB

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