ledger.js 102 KB

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