ledger.js 121 KB

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