ledger.js 123 KB

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