ledger.js 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  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. $(document).ready(function() {
  17. autoFlashHeight();
  18. // 初始化台账
  19. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  20. SpreadJsObj.addDeleteBind(ledgerSpread);
  21. const treeSetting = {
  22. id: 'ledger_id',
  23. pid: 'ledger_pid',
  24. order: 'order',
  25. level: 'level',
  26. rootId: -1,
  27. keys: ['id', 'tender_id', 'ledger_id'],
  28. preUrl: '/tender/' + getTenderId() + '/ledger',
  29. };
  30. if (checkTzMeasureType()) {
  31. treeSetting.calcFields = ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'];
  32. } else {
  33. treeSetting.calcFields = ['deal_tp', 'sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'];
  34. }
  35. treeSetting.calcFun = function (node) {
  36. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  37. };
  38. const ledgerTree = createNewPathTree('ledger', treeSetting);
  39. ledgerTree.loadDatas(ledger);
  40. treeCalc.calculateAll(ledgerTree);
  41. ledgerTreeCol.initSpreadSetting(ledgerSpreadSetting);
  42. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  43. // 加载台账数据到界面
  44. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  45. SpreadJsObj.loadTopAndSelect(ledgerSpread.getActiveSheet(), ckBillsSpread);
  46. // 初始化 部位明细
  47. const pos = new PosData({
  48. id: 'id', ledgerId: 'lid',
  49. });
  50. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  51. // 定义事件
  52. const treeOperationObj = {
  53. getSelectNode: function (sheet) {
  54. if (!sheet || !sheet.zh_tree) {
  55. return null;
  56. } else {
  57. const sel = sheet.getSelections()[0];
  58. return sheet.zh_tree.nodes[sel.row];
  59. }
  60. },
  61. /**
  62. * 刷新顶部按钮是否可用
  63. * @param sheet
  64. * @param selections
  65. */
  66. refreshOperationValid: function (sheet, selection) {
  67. const setObjEnable = function (obj, enable) {
  68. if (enable) {
  69. obj.removeClass('disabled');
  70. } else {
  71. obj.addClass('disabled');
  72. }
  73. };
  74. const sel = selection ? selection[0] : sheet.getSelections()[0];
  75. const row = sel ? sel.row : -1;
  76. const tree = sheet.zh_tree;
  77. if (!tree) { return; }
  78. const node = sheet.zh_tree.nodes[row];
  79. const preNode = tree.getPreSiblingNode(node);
  80. const valid = !sheet.zh_setting.readOnly;
  81. setObjEnable($('#insert'), valid && node && node.level > 1);
  82. setObjEnable($('#delete'), valid && node && node.level > 1);
  83. setObjEnable($('#up-move'), valid && node && node.level > 1 && preNode);
  84. setObjEnable($('#down-move'), valid && node && node.level > 1 && !tree.isLastSibling(node));
  85. if (checkTzMeasureType()) {
  86. const posRange = node ? pos.getLedgerPos(node.id) : [];
  87. setObjEnable($('#up-level'), valid && node && tree.getParent(node) && node.level > 2 && (!posRange || posRange.length === 0));
  88. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  89. setObjEnable($('#down-level'), valid && node && node.level > 1 && preNode && (!preNodePosRange || preNodePosRange.length === 0));
  90. } else {
  91. setObjEnable($('#up-level'), valid && node && node.level > 2 && tree.getParent(node));
  92. setObjEnable($('#down-level'), valid && node && node.level > 1 && preNode);
  93. }
  94. setObjEnable($('#cut'), valid);
  95. setObjEnable($('#paste'), valid);
  96. },
  97. refreshTree: function (sheet, data) {
  98. SpreadJsObj.massOperationSheet(sheet, function () {
  99. const tree = sheet.zh_tree;
  100. // 处理删除
  101. if (data.delete) {
  102. for (const d of data.delete) {
  103. sheet.deleteRows(tree.nodes.indexOf(d), 1);
  104. }
  105. }
  106. // 处理新增
  107. if (data.create) {
  108. const newNodes = data.create;
  109. if (newNodes) {
  110. newNodes.sort(function (a, b) {
  111. return a.index - b.index;
  112. });
  113. for (const node of newNodes) {
  114. sheet.addRows(node.index, 1);
  115. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  116. }
  117. }
  118. }
  119. // 处理更新
  120. if (data.update) {
  121. const rows = [];
  122. for (const u of data.update) {
  123. rows.push(tree.nodes.indexOf(u));
  124. }
  125. SpreadJsObj.reLoadRowsData(sheet, rows);
  126. }
  127. // 处理展开
  128. if (data.expand) {
  129. const expanded = [];
  130. for (const e of data.expand) {
  131. if (expanded.indexOf(e) === -1) {
  132. const posterity = tree.getPosterity(e);
  133. for (const p of posterity) {
  134. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  135. expanded.push(p);
  136. }
  137. }
  138. }
  139. }
  140. });
  141. },
  142. /**
  143. * 新增节点
  144. * @param spread
  145. */
  146. addNode: function (spread) {
  147. const self = this;
  148. const sheet = spread.getActiveSheet();
  149. const row = sheet.getSelections()[0].row;
  150. const tree = sheet.zh_tree;
  151. if (!tree) { return; }
  152. const node = sheet.zh_tree.nodes[row];
  153. if (!node) { return; }
  154. SpreadJsObj.massOperationSheet(sheet, function () {
  155. tree.baseOperation('/tender/' + getTenderId() + '/ledger/base-operation', node, 'add', function (result) {
  156. self.refreshTree(sheet, result);
  157. self.refreshOperationValid(sheet);
  158. });
  159. });
  160. },
  161. /**
  162. * 删除选中节点
  163. * @param spread
  164. */
  165. deleteNode: function (spread) {
  166. const self = this;
  167. const sheet = spread.getActiveSheet();
  168. const row = sheet.getSelections()[0].row;
  169. const tree = sheet.zh_tree;
  170. if (!tree) { return; }
  171. const node = sheet.zh_tree.nodes[row];
  172. if (!node) { return; }
  173. const count = ledgerTree.getPosterity(node).length;
  174. tree.baseOperation('/tender/' + getTenderId() + '/ledger/base-operation', node, 'delete', function (result) {
  175. //treeOperationObj.refreshTree(sheet, result);
  176. sheet.deleteRows(row, count + 1);
  177. for (const data of result.update) {
  178. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(data), tree.getPosterity(data).length + 1);
  179. }
  180. self.refreshOperationValid(sheet);
  181. for (const data of result.delete) {
  182. pos.removeDatasByMasterId(data.id);
  183. }
  184. posOperationObj.loadCurPosData();
  185. });
  186. },
  187. /**
  188. * 上移选中节点
  189. * @param spread
  190. */
  191. upMove: function (spread) {
  192. const self = this;
  193. const sheet = spread.getActiveSheet();
  194. const sel = sheet.getSelections()[0];
  195. const row = sel.row;
  196. const tree = sheet.zh_tree;
  197. if (!tree) { return; }
  198. const node = tree.nodes[row];
  199. if (!node) { return; }
  200. tree.baseOperation('/tender/' + getTenderId() + '/ledger/base-operation', node, 'up-move', function (result) {
  201. self.refreshTree(sheet, result);
  202. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  203. self.refreshOperationValid(sheet);
  204. });
  205. },
  206. /**
  207. * 下移选中节点
  208. * @param spread
  209. */
  210. downMove: function (spread) {
  211. const self = this;
  212. const sheet = spread.getActiveSheet();
  213. const sel = sheet.getSelections()[0];
  214. const row = sel.row;
  215. const tree = sheet.zh_tree;
  216. if (!tree) { return; }
  217. const node = tree.nodes[row];
  218. if (!node) { return; }
  219. tree.baseOperation('/tender/' + getTenderId() + '/ledger/base-operation', node, 'down-move', function (result) {
  220. self.refreshTree(sheet, result);
  221. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  222. self.refreshOperationValid(sheet);
  223. });
  224. },
  225. /**
  226. * 升级选中节点
  227. * @param spread
  228. */
  229. upLevel: function (spread) {
  230. const self = this;
  231. const sheet = spread.getActiveSheet();
  232. const row = sheet.getSelections()[0].row;
  233. const tree = sheet.zh_tree;
  234. if (!tree) { return; }
  235. const node = tree.nodes[row];
  236. if (!node) { return; }
  237. tree.baseOperation('/tender/' + getTenderId() + '/ledger/base-operation', node, 'up-level', function (result) {
  238. self.refreshTree(sheet, result);
  239. self.refreshOperationValid(sheet);
  240. });
  241. },
  242. /**
  243. * 降级选中节点
  244. * @param spread
  245. */
  246. downLevel: function (spread) {
  247. const self = this;
  248. const sheet = spread.getActiveSheet();
  249. const row = sheet.getSelections()[0].row;
  250. const tree = sheet.zh_tree;
  251. if (!tree) { return; }
  252. const node = tree.nodes[row];
  253. if (!node) { return; }
  254. tree.baseOperation('/tender/' + getTenderId() + '/ledger/base-operation', node, 'down-level', function (result) {
  255. self.refreshTree(sheet, result);
  256. self.refreshOperationValid(sheet);
  257. });
  258. },
  259. /**
  260. * 编辑单元格响应事件
  261. * @param {Object} e
  262. * @param {Object} info
  263. */
  264. editEnded: function (e, info) {
  265. if (info.sheet.zh_setting) {
  266. const col = info.sheet.zh_setting.cols[info.col];
  267. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  268. const node = sortData[info.row];
  269. const data = {
  270. id: node.id,
  271. tender_id: node.tender_id,
  272. ledger_id: node.ledger_id
  273. };
  274. // 未改变值则不提交
  275. const orgValue = node[col.field];
  276. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (info.editingText === ''))) {
  277. return;
  278. }
  279. // 台账模式,检查部位明细相关
  280. if (checkTzMeasureType()) {
  281. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  282. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  283. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  284. if (!node.children || node.children.length ===0) {
  285. const lPos = pos.getLedgerPos(node.id);
  286. if (lPos && lPos.length > 0) {
  287. toast('清单含有部位明细,请在部位明细输入数量', 'error');
  288. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  289. return;
  290. }
  291. }
  292. }
  293. if (col.field === 'b_code' && (info.editingText === '' || !info.editingText)) {
  294. const lPos = pos.getLedgerPos(node.id);
  295. if (lPos && lPos.length > 0) {
  296. toast('清单含有部位明细,请先删除部位明细,再删除清单编号', 'error');
  297. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  298. return;
  299. }
  300. }
  301. }
  302. // 获取更新数据
  303. if (info.editingText) {
  304. data[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText.replace('\n', '');
  305. } else {
  306. data[col.field] = null;
  307. }
  308. // 更新至服务器
  309. info.sheet.zh_tree.update('/tender/' + getTenderId() + '/ledger/update', data, function (result) {
  310. treeOperationObj.refreshTree(info.sheet, result);
  311. });
  312. }
  313. },
  314. /**
  315. * 粘贴单元格响应事件
  316. * @param e
  317. * @param info
  318. */
  319. clipboardPasted: function (e, info) {
  320. if (info.sheet.zh_setting && info.sheet.zh_dataType === 'tree') {
  321. const tree = info.sheet.zh_tree;
  322. if (!tree) { return; }
  323. const sortData = info.sheet.zh_tree.nodes;
  324. const datas = [], filterNodes = [];
  325. let bHint = false, bPaste;
  326. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  327. bPaste = false;
  328. const curRow = info.cellRange.row + iRow;
  329. const node = sortData[curRow];
  330. if (node) {
  331. const data = info.sheet.zh_tree.getNodeKeyData(node);
  332. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  333. const curCol = info.cellRange.col + iCol;
  334. const colSetting = info.sheet.zh_setting.cols[curCol];
  335. const value = info.sheet.getText(curRow, curCol).replace('\n', '');
  336. const lPos = pos.getLedgerPos(node.id);
  337. if (lPos && lPos.length > 0) {
  338. if (value === '' && colSetting.field === 'b_code') {
  339. if (!bHint) {
  340. toast('清单含有部位明细,请先删除部位明细,再删除清单编号', 'warning');
  341. bHint = true;
  342. }
  343. continue;
  344. }
  345. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  346. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  347. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  348. if (!bHint) {
  349. toast('清单含有部位明细,数量金额根据部位明细汇总计算所得,不可编辑', 'warning');
  350. bHint = true;
  351. }
  352. continue;
  353. }
  354. }
  355. data[colSetting.field] = value;
  356. bPaste = true;
  357. }
  358. if (bPaste) {
  359. datas.push(data);
  360. } else {
  361. filterNodes.push(node);
  362. }
  363. }
  364. }
  365. if (datas.length > 0) {
  366. info.sheet.zh_tree.update('/tender/' + getTenderId() + '/ledger/update', datas, function (result) {
  367. if (result.update) {
  368. result.update = result.update.concat(filterNodes);
  369. }
  370. treeOperationObj.refreshTree(info.sheet, result);
  371. }, function () {
  372. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  373. });
  374. } else {
  375. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  376. }
  377. }
  378. },
  379. /**
  380. * 删除按钮响应事件
  381. * @param sheet
  382. */
  383. deletePress: function (sheet) {
  384. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  385. const tree = sheet.zh_tree;
  386. if (!tree) { return; }
  387. const sortData = sheet.zh_tree.nodes;
  388. const datas = [], nodes = [];
  389. const sel = sheet.getSelections()[0];
  390. let bHint = false;
  391. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  392. const node = sortData[iRow];
  393. if (node) {
  394. let bDel = false;
  395. const data = sheet.zh_tree.getNodeKeyData(node);
  396. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  397. const col = sheet.zh_setting.cols[iCol];
  398. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  399. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  400. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  401. const lPos = pos.getLedgerPos(node.id);
  402. if (lPos && lPos.length > 0) {
  403. if (!bHint) {
  404. if (col.field === 'code') {
  405. toast('清单含有部位明细,请先删除部位明细,再删除清单编号', 'warning');
  406. } else {
  407. toast('清单含有部位明细,数量金额根据部位明细汇总计算所得,不可删除', 'warning');
  408. }
  409. bHint = true;
  410. }
  411. continue;
  412. }
  413. }
  414. const style = sheet.getStyle(iRow, iCol);
  415. if (!style.locked) {
  416. const colSetting = sheet.zh_setting.cols[iCol];
  417. data[colSetting.field] = null;
  418. bDel = true;
  419. }
  420. }
  421. if (bDel) {
  422. datas.push(data);
  423. nodes.push(node);
  424. }
  425. }
  426. }
  427. if (datas.length > 0) {
  428. sheet.zh_tree.update('/tender/' + getTenderId() + '/ledger/update', datas, function (result) {
  429. treeOperationObj.refreshTree(sheet, result);
  430. });
  431. }
  432. }
  433. },
  434. /**
  435. * 粘贴整块
  436. * @param spread
  437. * @param block
  438. */
  439. pasteBlock: function (spread, copyInfo) {
  440. const self = this;
  441. const sheet = spread.getActiveSheet();
  442. const row = sheet.getSelections()[0].row;
  443. const tree = sheet.zh_tree;
  444. if (!tree) { return; }
  445. const node = tree.nodes[row];
  446. if (!node) { return; }
  447. postData('/tender/' + getTenderId() + '/ledger/paste-block', {
  448. id: node[tree.setting.id],
  449. tid: copyInfo.tid,
  450. block: copyInfo.block,
  451. }, function (data) {
  452. pos.updateDatas(data.pos);
  453. const result = tree.loadPostData(data.ledger);
  454. self.refreshTree(sheet, result);
  455. self.refreshOperationValid(sheet);
  456. removeLocalCache(copyBlockTag);
  457. });
  458. },
  459. selectionChanged: function (e, info) {
  460. if (!info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  461. posOperationObj.loadCurPosData();
  462. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  463. posSearch.search($('#pos-keyword').val());
  464. }
  465. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  466. },
  467. topRowChanged(e, info) {
  468. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  469. }
  470. };
  471. // 绑定事件
  472. ledgerSpread.bind(GC.Spread.Sheets.Events.SelectionChanged, treeOperationObj.selectionChanged);
  473. ledgerSpread.bind(spreadNS.Events.TopRowChanged, treeOperationObj.topRowChanged);
  474. if (!ledgerSpreadSetting.readOnly) {
  475. ledgerSpread.bind(GC.Spread.Sheets.Events.SelectionChanged, function (e, info) {
  476. treeOperationObj.refreshOperationValid(info.sheet, info.newSelections);
  477. });
  478. ledgerSpread.bind(GC.Spread.Sheets.Events.EditEnded, treeOperationObj.editEnded);
  479. ledgerSpread.bind(GC.Spread.Sheets.Events.ClipboardPasted, treeOperationObj.clipboardPasted);
  480. SpreadJsObj.addDeleteBind(ledgerSpread, treeOperationObj.deletePress);
  481. ledgerSpread.bind(GC.Spread.Sheets.Events.ClipboardChanging, function (e, info) {
  482. console.log(info);
  483. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  484. });
  485. ledgerSpread.bind(GC.Spread.Sheets.Events.ClipboardChanged, function (e, info) {
  486. console.log(info.copyData.text);
  487. });
  488. ledgerSpread.bind(GC.Spread.Sheets.Events.ClipboardPasting, function (e, info) {
  489. });
  490. // 绑定 删除等 顶部按钮
  491. $('#insert').click(() => {
  492. treeOperationObj.addNode(ledgerSpread);
  493. });
  494. $('#delete').click(function () {
  495. treeOperationObj.deleteNode(ledgerSpread);
  496. });
  497. $('#up-move').click(function () {
  498. treeOperationObj.upMove(ledgerSpread);
  499. });
  500. $('#down-move').click(function () {
  501. treeOperationObj.downMove(ledgerSpread);
  502. });
  503. $('#up-level').click(function () {
  504. treeOperationObj.upLevel(ledgerSpread);
  505. });
  506. $('#down-level').click(function () {
  507. treeOperationObj.downLevel(ledgerSpread);
  508. });
  509. let batchInsertObj;
  510. // 右键菜单
  511. $.contextMenu({
  512. selector: '#ledger-spread',
  513. build: function ($trigger, e) {
  514. const target = SpreadJsObj.safeRightClickSelection($trigger, e, ledgerSpread);
  515. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  516. },
  517. items: {
  518. 'create': {
  519. name: '新增',
  520. icon: 'fa-sign-in',
  521. callback: function (key, opt) {
  522. treeOperationObj.addNode(ledgerSpread);
  523. },
  524. visible: function(key, opt){
  525. const sheet = ledgerSpread.getActiveSheet();
  526. const selection = sheet.getSelections();
  527. const row = selection[0].row;
  528. const select = ledgerTree.nodes[row];
  529. return select;
  530. }
  531. },
  532. 'delete': {
  533. name: '删除',
  534. icon: 'fa-remove',
  535. callback: function (key, opt) {
  536. treeOperationObj.deleteNode(ledgerSpread);
  537. },
  538. visible: function (key, opt) {
  539. const sheet = ledgerSpread.getActiveSheet();
  540. const selection = sheet.getSelections();
  541. const row = selection[0].row;
  542. const select = ledgerTree.nodes[row];
  543. return select;
  544. }
  545. },
  546. 'copyBlock': {
  547. name: '复制整块',
  548. icon: 'fa-files-o',
  549. callback: function (key, opt) {
  550. /*ledgerSpread.commandManager().execute({
  551. cmd:"copy",
  552. sheetName:ledgerSpread.getActiveSheet().name()
  553. });*/
  554. treeOperationObj.block = [];
  555. const copyBlockList = [];
  556. const sheet = ledgerSpread.getActiveSheet();
  557. const sel = sheet.getSelections()[0];
  558. let iRow = sel.row;
  559. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  560. while (iRow < sel.row + sel.rowCount) {
  561. const node = sheet.zh_tree.nodes[iRow];
  562. if (node.ledger_pid !== pid) {
  563. toast('error: 仅可同时选中同层节点', 'error', 'exclamation-circle');
  564. return;
  565. }
  566. copyBlockList.push(node.ledger_id);
  567. iRow += sheet.zh_tree.getPosterity(node).length + 1;
  568. }
  569. const tenderId = _.toInteger(getTenderId());
  570. setLocalCache(copyBlockTag, JSON.stringify({tid: tenderId, block: copyBlockList}));
  571. //treeOperationObj.block = copyBlockList;
  572. },
  573. visible: function (key, opt) {
  574. const sheet = ledgerSpread.getActiveSheet();
  575. const selection = sheet.getSelections();
  576. const row = selection[0].row;
  577. const select = ledgerTree.nodes[row];
  578. return select;
  579. }
  580. },
  581. 'pasteBlock': {
  582. name: '粘贴整块',
  583. icon: 'fa-clipboard',
  584. disabled: function (key, opt) {
  585. //const block = treeOperationObj.block || [];
  586. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  587. return !(copyInfo && copyInfo.tid && copyInfo.tid > 0 && copyInfo.block && copyInfo.block.length > 0);
  588. },
  589. callback: function (key, opt) {
  590. //const block = treeOperationObj.block || [];
  591. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  592. if (copyInfo.block.length > 0) {
  593. treeOperationObj.pasteBlock(ledgerSpread, copyInfo);
  594. } else {
  595. document.execCommand('paste');
  596. }
  597. }
  598. },
  599. 'batchInsertBillsPos': {
  600. name: '批量插入清单-部位',
  601. icon: 'fa-sign-in',
  602. disabled: function (key, opt) {
  603. const sheet = ledgerSpread.getActiveSheet();
  604. const selection = sheet.getSelections();
  605. const row = selection[0].row;
  606. const select = ledgerTree.nodes[row];
  607. if (select) {
  608. if (select.code && select.code !== '') {
  609. return !ledgerTree.isLeafXmj(select);
  610. } else {
  611. const parent = ledgerTree.getParent(select);
  612. return !(parent && ledgerTree.isLeafXmj(parent));
  613. }
  614. } else {
  615. return false;
  616. }
  617. },
  618. callback: function (key, opt) {
  619. if (!batchInsertObj) {
  620. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  621. } else {
  622. batchInsertObj.initView();
  623. }
  624. $('#batch').modal('show');
  625. }
  626. },
  627. 'importExcel': {
  628. name: '导入分项清单Excel',
  629. icon: 'file-excel-o',
  630. disabled: function (key, opt) {
  631. return tender.ledger_status !== 1;
  632. },
  633. callback: function (key, opt) {
  634. $('#upload-ledger').modal('show');
  635. }
  636. }
  637. }
  638. });
  639. } else {
  640. SpreadJsObj.forbiddenSpreadContextMenu('#ledger-spread', ledgerSpread);
  641. }
  642. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  643. const posSearch = (function () {
  644. let resultArr = [];
  645. const search = function (keyword) {
  646. if (keyword && keyword !== '') {
  647. resultArr = [];
  648. const sortData = posSpread.getActiveSheet().zh_data;
  649. if (sortData) {
  650. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  651. const sd = sortData[i];
  652. if (sd.name && sd.name.indexOf(keyword) > -1) {
  653. resultArr.push({index: i, data: sd});
  654. }
  655. }
  656. }
  657. $('#pos-search-hint').html(' ' + resultArr.length + '个匹配').show();
  658. } else {
  659. resultArr = [];
  660. $('#pos-search-hint').hide();
  661. }
  662. };
  663. const locateNext = function () {
  664. if (resultArr.length > 0) {
  665. const sheet = posSpread.getActiveSheet();
  666. const sel = sheet.getSelections()[0];
  667. const curRow = sel ? sel.row : 0;
  668. let next = _.find(resultArr, function (d) {
  669. return d.index > curRow;
  670. });
  671. if (!next) next = resultArr[0];
  672. if (next.index !== curRow) {
  673. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  674. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  675. }
  676. }
  677. };
  678. const locatePre = function () {
  679. if (resultArr.length > 0) {
  680. const sheet = posSpread.getActiveSheet();
  681. const sel = sheet.getSelections()[0];
  682. const curRow = sel ? sel.row : 0;
  683. let next = _.findLast(resultArr, function (d) {
  684. return d.index < curRow;
  685. });
  686. if (!next) next = resultArr[resultArr.length - 1];
  687. if (next.index !== curRow) {
  688. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  689. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  690. }
  691. }
  692. };
  693. return {search, locateNext, locatePre};
  694. })();
  695. // 台账模式加载部位明细数据
  696. if (checkTzMeasureType()) {
  697. $.divResizer({
  698. select: '#main-resize',
  699. callback: function () {
  700. ledgerSpread.refresh();
  701. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  702. $(".sp-wrap").height(bcontent-40);
  703. posSpread.refresh();
  704. }
  705. });
  706. SpreadJsObj.initSheet(posSpread.getActiveSheet(), posSpreadSetting);
  707. postData('/tender/' + getTenderId() + '/pos', null, function (data) {
  708. pos.loadDatas(data);
  709. posOperationObj.loadCurPosData();
  710. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  711. });
  712. $('#pos-keyword').bind('input propertychange', function () {
  713. posSearch.search(this.value);
  714. });
  715. $('#search-pre-pos').click(function () {
  716. posSearch.locatePre();
  717. });
  718. $('#search-next-pos').click(function () {
  719. posSearch.locateNext();
  720. });
  721. }
  722. // 绑定部位明细编辑事件
  723. const posOperationObj = {
  724. editStarting: function (e, info) {
  725. posOperationObj.ledgerTreeNode = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  726. },
  727. /**
  728. * 加载部位明细 根据当前台账选择节点
  729. */
  730. loadCurPosData: function () {
  731. const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  732. if (node) {
  733. const posData = pos.ledgerPos[itemsPre + node.id] || [];
  734. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', posData);
  735. } else {
  736. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', []);
  737. }
  738. },
  739. /**
  740. * 编辑单元格响应事件
  741. * @param {Object} e
  742. * @param {Object} info
  743. */
  744. editEnded: function (e, info) {
  745. if (info.sheet.zh_setting) {
  746. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  747. const col = info.sheet.zh_setting.cols[info.col];
  748. const orgText = posData ? posData[col.field] : null;
  749. const newText = info.sheet.getCell(info.row, info.col).text();
  750. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) {
  751. return;
  752. }
  753. //const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  754. const node = posOperationObj.ledgerTreeNode;
  755. if (!node) {
  756. toast('数据错误,请选择台账节点后再试', 'error');
  757. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  758. return;
  759. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  760. toast('父节点不可插入部位明细', 'error');
  761. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  762. return;
  763. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  764. toast('项目节不可插入部位明细', 'error');
  765. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  766. return;
  767. }
  768. const data = {};
  769. if (col.field === 'name') {
  770. if (newText === '' && posData) {
  771. toast('部位名称不可为空', 'error', 'exclamation-circle');
  772. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  773. return;
  774. } else if (!posData) {
  775. if (newText && newText !== '') {
  776. data.updateType = 'add';
  777. const sortData = info.sheet.zh_data;
  778. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  779. data.updateData = { name: newText, lid: node.id, tid: tender.id, porder: order};
  780. } else {
  781. return;
  782. }
  783. } else {
  784. data.updateType = 'update';
  785. data.updateData = {id: posData.id, name: newText};
  786. }
  787. } else if (!posData) {
  788. toast('新增部位请先输入名称', 'warning');
  789. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  790. return;
  791. } else {
  792. data.updateType = 'update';
  793. data.updateData = {id: posData.id};
  794. data.updateData[col.field] = col.type === 'Number' ? parseFloat(newText) : newText;
  795. }
  796. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  797. const updateRst = pos.updateDatas(result.pos);
  798. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  799. if (updateRst.create.length > 0) {
  800. // info.sheet.addRows(info.row, 1);
  801. // if (info.sheet.zh_data.length === 0) {
  802. // info.sheet.zh_data = pos.ledgerPos[itemsPre + node.id] || [];
  803. // }
  804. // SpreadJsObj.reLoadRowData(info.sheet, info.sheet.zh_data.length - 1);
  805. posOperationObj.loadCurPosData();
  806. } else {
  807. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  808. }
  809. const loadResult = ledgerTree.loadPostData(result.ledger);
  810. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  811. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  812. }, function () {
  813. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  814. });
  815. }
  816. },
  817. /**
  818. * 删除按钮响应事件
  819. * @param sheet
  820. */
  821. deletePress: function (sheet) {
  822. const self = this;
  823. if (sheet.zh_setting) {
  824. const sortData = sheet.zh_data;
  825. const datas = [], posSelects = [];
  826. const sel = sheet.getSelections()[0];
  827. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  828. let bDel = false;
  829. const node = sortData[iRow];
  830. if (node) {
  831. const data = {id: node.id};
  832. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  833. const colSetting = sheet.zh_setting.cols[iCol];
  834. if (colSetting.field === 'name') {
  835. toast('部位名称不能为空', 'error');
  836. return;
  837. }
  838. const style = sheet.getStyle(iRow, iCol);
  839. if (!style.locked) {
  840. const colSetting = sheet.zh_setting.cols[iCol];
  841. data[colSetting.field] = null;
  842. bDel = true;
  843. }
  844. }
  845. if (bDel) {
  846. datas.push(data);
  847. posSelects.push(node);
  848. }
  849. }
  850. }
  851. if (datas.length > 0) {
  852. postData('/tender/' + getTenderId() + '/pos/update', {updateType: 'update', updateData: datas}, function (result) {
  853. pos.updateDatas(result.pos);
  854. posOperationObj.loadCurPosData();
  855. const loadResult = ledgerTree.loadPostData(result.ledger);
  856. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  857. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  858. }, function () {
  859. posOperationObj.loadCurPosData();
  860. });
  861. }
  862. }
  863. },
  864. /**
  865. * 删除 部位明细
  866. * @param sheet
  867. */
  868. deletePos: function (sheet) {
  869. const selection = sheet.getSelections();
  870. const data = {
  871. updateType: 'delete',
  872. updateData: [],
  873. };
  874. const row = selection[0].row, count = selection[0].rowCount;
  875. const sortData = sheet.zh_data;
  876. for (let iRow = 0; iRow < count; iRow++) {
  877. if (sortData[iRow + row]) {
  878. data.updateData.push(sortData[iRow + row].id);
  879. }
  880. }
  881. if (data.updateData.length > 0) {
  882. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  883. pos.removeDatas(result.pos);
  884. sheet.deleteRows(row, count);
  885. const loadResult = ledgerTree.loadPostData(result.ledger);
  886. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  887. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  888. });
  889. }
  890. },
  891. /**
  892. * 粘贴单元格响应事件
  893. * @param e
  894. * @param info
  895. */
  896. clipboardPasted: function (e, info) {
  897. const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  898. if (node.code && (node.code !== '')) {
  899. toast('项目节不可含有清单明细', 'error');
  900. posOperationObj.loadCurPosData();
  901. return;
  902. }
  903. if (node.children && (node.children.length > 0)) {
  904. toast('仅清单子项可以含有部位明细', 'error');
  905. posOperationObj.loadCurPosData();
  906. return;
  907. }
  908. if (info.sheet.zh_setting) {
  909. const data = [];
  910. const sortData = info.sheet.zh_data || [];
  911. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  912. if (info.cellRange.col !== 0) {
  913. toast('新增部位请先输入名称', 'warning');
  914. posOperationObj.loadCurPosData();
  915. return;
  916. }
  917. }
  918. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  919. const curRow = info.cellRange.row + iRow;
  920. const posData = curRow >= sortData.length ? {lid: node.id} : {id: sortData[curRow].id, lid: node.id};
  921. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  922. const curCol = info.cellRange.col + iCol;
  923. const colSetting = info.sheet.zh_setting.cols[curCol];
  924. posData[colSetting.field] = info.sheet.getText(curRow, curCol);
  925. if (colSetting.type === 'Number') {
  926. posData[colSetting.field] = _.toNumber(posData[colSetting.field]);
  927. }
  928. }
  929. data.push(posData);
  930. }
  931. postData('/tender/' + getTenderId() + '/pos/paste', data, function (result) {
  932. pos.updateDatas(result.pos);
  933. posOperationObj.loadCurPosData();
  934. const loadResult = ledgerTree.loadPostData(result.ledger);
  935. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  936. posOperationObj.loadCurPosData();
  937. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  938. }, function () {
  939. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  940. });
  941. }
  942. },
  943. };
  944. if (!posSpreadSetting.readOnly) {
  945. SpreadJsObj.addDeleteBind(posSpread, posOperationObj.deletePress);
  946. posSpread.bind(spreadNS.Events.EditStarting, posOperationObj.editStarting);
  947. posSpread.bind(spreadNS.Events.EditEnded, posOperationObj.editEnded);
  948. posSpread.bind(spreadNS.Events.ClipboardPasted, posOperationObj.clipboardPasted);
  949. // 右键菜单
  950. $.contextMenu({
  951. selector: '#pos-spread',
  952. build: function ($trigger, e) {
  953. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  954. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  955. },
  956. items: {
  957. 'delete': {
  958. name: '删除',
  959. icon: 'fa-remove',
  960. disabled: function (key, opt) {
  961. const sheet = posSpread.getActiveSheet();
  962. if (sheet.zh_data) {
  963. const selection = sheet.getSelections();
  964. return sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  965. } else {
  966. return true;
  967. }
  968. },
  969. callback: function (key, opt) {
  970. posOperationObj.deletePos(posSpread.getActiveSheet());
  971. }
  972. },
  973. }
  974. });
  975. } else {
  976. SpreadJsObj.forbiddenSpreadContextMenu('#pos-spread', posSpread);
  977. }
  978. let stdChapter, stdBills, dealBills, searchLedger;
  979. $.divResizer({
  980. select: '#right-spr',
  981. callback: function () {
  982. ledgerSpread.refresh();
  983. if (posSpread) {
  984. posSpread.refresh();
  985. }
  986. if (stdChapter) {
  987. stdChapter.spread.refresh();
  988. }
  989. if (stdBills) {
  990. stdBills.spread.refresh();
  991. }
  992. if (dealBills) {
  993. dealBills.spread.refresh();
  994. }
  995. if (searchLedger) {
  996. searchLedger.spread.refresh();
  997. }
  998. }
  999. });
  1000. // 展开收起标准清单
  1001. $('a', '#side-menu').bind('click', function (e) {
  1002. e.preventDefault();
  1003. const tab = $(this), tabPanel = $(tab.attr('content'));
  1004. const showSideTools = function (show) {
  1005. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1006. if (show) {
  1007. right.show();
  1008. autoFlashHeight();
  1009. /**
  1010. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1011. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1012. * 故需要通过最终的parent.width再计算一次left.width
  1013. *
  1014. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1015. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1016. *
  1017. */
  1018. //left.css('width', parent.width() - right.outerWidth());
  1019. //left.css('width', parent.width() - right.outerWidth());
  1020. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1021. left.css('width', percent + '%');
  1022. } else {
  1023. left.width(parent.width());
  1024. right.hide();
  1025. }
  1026. };
  1027. // 展开工具栏、切换标签
  1028. if (!tab.hasClass('active')) {
  1029. const close = $('.active', '#side-menu').length === 0;
  1030. $('a', '#side-menu').removeClass('active');
  1031. tab.addClass('active');
  1032. $('.tab-content .tab-pane').removeClass('active');
  1033. tabPanel.addClass('active');
  1034. showSideTools(tab.hasClass('active'));
  1035. if (tab.attr('content') === '#std-chapter') {
  1036. if (!stdChapter) {
  1037. stdChapter = new stdLib('#std-chapter-spread', 'chapter', {
  1038. id: 'chapter_id',
  1039. pid: 'pid',
  1040. order: 'order',
  1041. level: 'level',
  1042. rootId: -1,
  1043. keys: ['id', 'list_id', 'chapter_id'],
  1044. }, {
  1045. cols: [
  1046. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1047. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  1048. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1049. ],
  1050. treeCol: 0,
  1051. emptyRows: 0,
  1052. headRows: 1,
  1053. headRowHeight: [40],
  1054. defaultRowHeight: 21,
  1055. });
  1056. stdChapter.loadLib(1);
  1057. }
  1058. stdChapter.spread.refresh();
  1059. } else if (tab.attr('content') === '#std-bills') {
  1060. if (!stdBills) {
  1061. stdBills = new stdLib('#std-bills-spread', 'bills', {
  1062. id: 'bill_id',
  1063. pid: 'pid',
  1064. order: 'order',
  1065. level: 'level',
  1066. rootId: -1,
  1067. keys: ['id', 'list_id', 'bill_id']
  1068. }, {
  1069. cols: [
  1070. {title: '清单编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1071. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  1072. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1073. ],
  1074. treeCol: 0,
  1075. emptyRows: 0,
  1076. headRows: 1,
  1077. headRowHeight: [40],
  1078. defaultRowHeight: 21,
  1079. });
  1080. stdBills.loadLib(1);
  1081. }
  1082. stdBills.spread.refresh();
  1083. } else if (tab.attr('content') === '#deal-bills') {
  1084. if (!dealBills) {
  1085. dealBills = new DealBills('#deal-bills-spread', {
  1086. cols: [
  1087. {title: '清单编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1088. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  1089. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1090. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1091. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1092. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1093. ],
  1094. emptyRows: 0,
  1095. headRows: 1,
  1096. headRowHeight: [40],
  1097. defaultRowHeight: 21,
  1098. });
  1099. dealBills.loadData();
  1100. }
  1101. dealBills.spread.refresh();
  1102. } else if (tab.attr('content') === '#search' && !searchLedger) {
  1103. if (!searchLedger) {
  1104. searchLedger = new SearchLedger($('#search'), {
  1105. cols: [
  1106. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1107. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1108. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  1109. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  1110. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1111. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1112. ],
  1113. emptyRows: 0,
  1114. headRows: 1,
  1115. headRowHeight: [40],
  1116. defaultRowHeight: 21,
  1117. });
  1118. }
  1119. searchLedger.spread.refresh();
  1120. }
  1121. } else { // 收起工具栏
  1122. tab.removeClass('active');
  1123. tabPanel.removeClass('active');
  1124. showSideTools(tab.hasClass('active'));
  1125. }
  1126. ledgerSpread.refresh();
  1127. if (posSpread) {
  1128. posSpread.refresh();
  1129. }
  1130. });
  1131. class stdLib {
  1132. constructor(selector, stdType, treeSetting, spreadSetting) {
  1133. this.obj = $(selector)[0];
  1134. this.url = '/std/' + stdType;
  1135. this.treeSetting = treeSetting;
  1136. treeSetting.preUrl = this.url;
  1137. this.spreadSetting = spreadSetting;
  1138. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1139. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1140. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1141. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1142. const stdSheet = info.sheet;
  1143. const mainSheet = ledgerSpread.getActiveSheet();
  1144. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  1145. const stdTree = stdSheet.zh_tree;
  1146. const stdNode = stdTree.nodes[info.row];
  1147. const mainTree = mainSheet.zh_tree;
  1148. const sel = mainSheet.getSelections()[0];
  1149. const mainNode = mainTree.nodes[sel.row];
  1150. if (!stdNode) { return; }
  1151. if (stdType === 'bills') {
  1152. if (!mainTree.isLeafXmj(mainNode)) {
  1153. toast('非最底层项目下,不应添加清单', 'warning');
  1154. return;
  1155. }
  1156. }
  1157. mainTree.postData('/tender/' + getTenderId() + '/ledger/add-by-std', mainNode, {
  1158. tender_id: mainNode.tender_id,
  1159. stdType: stdType,
  1160. stdLibId: stdNode.list_id,
  1161. stdNode: stdTree.getNodeKey(stdNode)
  1162. }, function (result) {
  1163. treeOperationObj.refreshTree(mainSheet, result);
  1164. treeOperationObj.refreshOperationValid(mainSheet);
  1165. });
  1166. });
  1167. this.pathTree = createNewPathTree('base', this.treeSetting);
  1168. }
  1169. loadLib (listId) {
  1170. const self = this;
  1171. postData(this.url+'/get-data', {list_id: listId}, function (data) {
  1172. self.pathTree.loadDatas(data);
  1173. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'tree', self.pathTree);
  1174. });
  1175. }
  1176. }
  1177. class DealBills {
  1178. constructor (selector, spreadSetting) {
  1179. const self = this;
  1180. this.obj = $(selector)[0];
  1181. this.url = '/tender/' + getTenderId() + '/deal';
  1182. this.spreadSetting = spreadSetting;
  1183. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1184. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1185. if (!readOnly) {
  1186. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1187. const dealSheet = info.sheet;
  1188. const mainSheet = ledgerSpread.getActiveSheet();
  1189. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  1190. if (!dealBills) { return; }
  1191. const mainTree = mainSheet.zh_tree;
  1192. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1193. if (!mainNode || !mainTree) { return; }
  1194. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1195. toast('非最底层项目下,不应添加清单', 'error');
  1196. return;
  1197. }
  1198. postData('/tender/' + getTenderId() + '/ledger/add-by-deal', {
  1199. id: mainNode.ledger_id,
  1200. type: mainNode.code ? 'child' : 'next',
  1201. dealBills: {
  1202. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  1203. unit_price: dealBills.unit_price,
  1204. },
  1205. }, function (result) {
  1206. const refreshData = mainTree.loadPostData(result);
  1207. treeOperationObj.refreshTree(mainSheet, refreshData);
  1208. treeOperationObj.refreshOperationValid(mainSheet);
  1209. });
  1210. });
  1211. }
  1212. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1213. $('#upload-deal-bills').click(function () {
  1214. const file = $('#deal-bills-file')[0];
  1215. const formData = new FormData();
  1216. formData.append('file', file.files[0]);
  1217. postDataWithFile(self.url+'/upload-excel', formData, function (data) {
  1218. self.data = data;
  1219. //self.calculateData();
  1220. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1221. $('#upload-deal').modal('hide');
  1222. }, function () {
  1223. $('#upload-deal').modal('hide');
  1224. });
  1225. });
  1226. }
  1227. loadData () {
  1228. const self = this;
  1229. postData(this.url+'/get-data', {}, function (data) {
  1230. self.data = data;
  1231. //self.calculateData();
  1232. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1233. });
  1234. }
  1235. calculateData () {
  1236. if (this.data) {
  1237. for (const d of this.data) {
  1238. d.total_price = _.multiply(d.quantity, d.unit_price);
  1239. }
  1240. }
  1241. }
  1242. }
  1243. class BatchInsertBillsPosObj {
  1244. constructor (obj) {
  1245. const self = this;
  1246. this.obj = obj;
  1247. this.billsCount = 6;
  1248. this.posCount = 1000;
  1249. // 初始化 清单编号窗口 参数
  1250. this.qdSpreadSetting = {
  1251. cols: [
  1252. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  1253. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  1254. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  1255. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1256. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  1257. ],
  1258. emptyRows: this.billsCount,
  1259. headRows: 1,
  1260. headRowHeight: [40],
  1261. };
  1262. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  1263. // 初始化 部位数量复核表 参数
  1264. this.posSpreadSetting = {
  1265. cols: [
  1266. {title: '部位', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  1267. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  1268. ],
  1269. emptyRows: this.posCount,
  1270. headRows: 1,
  1271. headRowHeight: [40],
  1272. };
  1273. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  1274. this.posSpreadSetting.cols.push(
  1275. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  1276. )
  1277. }
  1278. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  1279. // 初始化 签约清单 参数
  1280. this.dealSpreadSetting = {
  1281. cols: [
  1282. {title: '清单编号', field: 'code', width: 80, formatter: '@', readOnly: true},
  1283. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true},
  1284. {title: '单位', field: 'unit', width: 50, formatter: '@', readOnly: true},
  1285. {title: '单价', field: 'unit_price', width: 50, readOnly: true},
  1286. ],
  1287. emptyRows: 0,
  1288. headRows: 1,
  1289. headRowHeight: [40],
  1290. };
  1291. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  1292. // 初始化 清单编号、部位数量复核表 表格
  1293. this.initView();
  1294. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  1295. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  1296. // 拉取签约清单数据
  1297. if (dealBills) {
  1298. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1299. } else {
  1300. postData('/tender/' + getTenderId() + '/deal/get-data', {}, function (data) {
  1301. SpreadJsObj.loadSheetData(self.dealSpread.getActiveSheet(), 'data', data);
  1302. });
  1303. }
  1304. // 双击签约清单,自动添加到清单编号窗口
  1305. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1306. const deal = info.sheet.zh_data[info.row];
  1307. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  1308. const sel = qdSheet.getSelections()[0];
  1309. qdSheet.getCell(sel.row, 0).value(deal.code);
  1310. qdSheet.getCell(sel.row, 1).value(deal.name);
  1311. qdSheet.getCell(sel.row, 2).value(deal.unit);
  1312. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  1313. if (sel.row + 1 === qdSheet.getRowCount()) {
  1314. const count = sel.row + 2;
  1315. qdSheet.setRowCount(count);
  1316. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  1317. const colCount = posSheet.getColumnCount() + 1
  1318. posSheet.setColumnCount(colCount);
  1319. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('数量' + count);
  1320. }
  1321. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  1322. });
  1323. this.obj.bind('shown.bs.modal', function () {
  1324. self.qdSpread.refresh();
  1325. self.posSpread.refresh();
  1326. self.dealSpread.refresh();
  1327. });
  1328. $('#batch-ok').click(function () {
  1329. const sheet = ledgerSpread.getActiveSheet();
  1330. const selection = sheet.getSelections();
  1331. const row = selection[0].row;
  1332. const select = ledgerTree.nodes[row];
  1333. if (select) {
  1334. const insertData = {};
  1335. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  1336. insertData.id = select[ledgerTree.setting.id];
  1337. insertData.batchData = self.getBatchData();
  1338. postData('/tender/' + getTenderId() + '/ledger/batch-insert', insertData, function (data) {
  1339. pos.updateDatas(data.pos);
  1340. const result = ledgerTree.loadPostData(data.ledger);
  1341. treeOperationObj.refreshTree(sheet, result);
  1342. treeOperationObj.refreshOperationValid(sheet, selection);
  1343. self.obj.modal('hide');
  1344. });
  1345. }
  1346. });
  1347. }
  1348. // 初始化左侧表格
  1349. initView () {
  1350. // 初始化 清单编号
  1351. const qdSheet = this.qdSpread.getActiveSheet();
  1352. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  1353. SpreadJsObj.refreshColumnAlign(qdSheet);
  1354. // 清理原有数据
  1355. SpreadJsObj.beginMassOperation(qdSheet);
  1356. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1357. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  1358. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  1359. }
  1360. qdSheet.setSelection(0, 0, 1 ,1);
  1361. SpreadJsObj.endMassOperation(qdSheet);
  1362. // 初始化 部位数量复核表
  1363. const posSheet = this.posSpread.getActiveSheet();
  1364. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  1365. SpreadJsObj.refreshColumnAlign(posSheet);
  1366. // 清理原有数据
  1367. SpreadJsObj.beginMassOperation(posSheet);
  1368. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  1369. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1370. posSheet.setSelection(0, 0, 1 ,1);
  1371. SpreadJsObj.endMassOperation(posSheet);
  1372. // 检查签约清单数据,以工具栏数据为准
  1373. if (dealBills) {
  1374. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1375. }
  1376. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  1377. }
  1378. // 获取界面数据
  1379. getBatchData () {
  1380. const result = [];
  1381. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  1382. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  1383. if (qdSheet.getText(iRow, 0) === '') { continue; }
  1384. const qd = {
  1385. b_code: qdSheet.getText(iRow, 0),
  1386. name: qdSheet.getText(iRow, 1),
  1387. unit: qdSheet.getText(iRow, 2),
  1388. price: _.toNumber(qdSheet.getText(iRow, 3)),
  1389. pos: [],
  1390. };
  1391. result.push(qd);
  1392. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  1393. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  1394. if (value !== 0 && !isNaN(value)) {
  1395. qd.pos.push({
  1396. name: posSheet.getText(iPosRow, 0),
  1397. drawing_code: posSheet.getText(iPosRow, 1),
  1398. quantity: value, porder: qd.pos.length + 1,
  1399. });
  1400. }
  1401. }
  1402. }
  1403. return result;
  1404. }
  1405. }
  1406. class SearchLedger {
  1407. constructor(obj, spreadSetting) {
  1408. const self = this;
  1409. this.obj = obj;
  1410. this.spreadSetting = spreadSetting;
  1411. this.spread = SpreadJsObj.createNewSpread($('#search-result', this.obj)[0]);
  1412. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1413. SpreadJsObj.forbiddenSpreadContextMenu('#search-result', this.spread);
  1414. $('#searchLedger', this.obj).bind('click', function () {
  1415. const keyword = $('input', self.obj).val();
  1416. this.searchResult = [];
  1417. const sortData = SpreadJsObj.getSortData(ledgerSpread.getActiveSheet());
  1418. for (const node of sortData) {
  1419. if ((node.code && node.code.indexOf(keyword) > -1) ||
  1420. node.b_code && node.b_code.indexOf(keyword) > -1 ||
  1421. node.name && node.name.indexOf(keyword) > -1) {
  1422. const data = JSON.parse(JSON.stringify(node));
  1423. data.visible = true;
  1424. this.searchResult.push(data);
  1425. }
  1426. }
  1427. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', this.searchResult);
  1428. });
  1429. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1430. const sheet = info.sheet;
  1431. const data = sheet.zh_data;
  1432. if (!data) { return }
  1433. const curBills = data[info.row];
  1434. if (!curBills) { return }
  1435. SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), curBills.ledger_id, true);
  1436. });
  1437. }
  1438. }
  1439. $('#searchAccount').click(() => {
  1440. const data = {
  1441. keyword: $('#searchName').val(),
  1442. };
  1443. postData('/search/user', data, (data) => {
  1444. const resultDiv = $('#searchResult');
  1445. if (data) {
  1446. $('h5>span', resultDiv).text(data.name);
  1447. $('#addAuditor').attr('auditorId', data.id);
  1448. $('h6', resultDiv).text(data.role);
  1449. $('p', resultDiv).text(data.company);
  1450. resultDiv.show();
  1451. } else {
  1452. toast('未查询到该审核人', 'info');
  1453. resultDiv.hide();
  1454. }
  1455. }, () => {
  1456. $('#searchResult').hide();
  1457. });
  1458. });
  1459. // 审批人分组选择
  1460. $('#account_group').change(function () {
  1461. let account_html = '<option value="0">选择审批人</option>';
  1462. for (const account of accountList) {
  1463. if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
  1464. const role = account.role !== '' ? '(' + account.role + ')' : '';
  1465. const company = account.company !== '' ? ' -' + account.company : '';
  1466. account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
  1467. }
  1468. }
  1469. $('#account_list').html(account_html);
  1470. });
  1471. // 添加到审批流程中
  1472. $('body').on('change', '#account_list', function () {
  1473. let id = $(this).val();
  1474. id = parseInt(id);
  1475. if (id !== 0) {
  1476. const data = {
  1477. auditorId: $(this).val(),
  1478. };
  1479. postData('/tender/' + getTenderId() + '/ledger/audit/add', data, (data) => {
  1480. const html = [];
  1481. html.push('<li class="list-group-item" auditorId="' + data.audit_id + '"><a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  1482. html.push('<span>');
  1483. html.push(data.audit_order + ' ');
  1484. html.push(data.name + ' ');
  1485. html.push('</span>');
  1486. html.push('<small class="text-muted">');
  1487. html.push(data.role);
  1488. html.push('</small></li>');
  1489. $('#auditors').append(html.join(''));
  1490. // 如果是重新上报,添加到重新上报列表中
  1491. const auditorshtml = [];
  1492. // 重新上报时。令其它的审批人流程图标转换
  1493. $('#auditors-list li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  1494. // 添加新审批人
  1495. auditorshtml.push('<li class="list-group-item" data-auditid="' + data.audit_id + '">');
  1496. auditorshtml.push('<i class="fa fa-stop-circle"></i> ');
  1497. auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  1498. auditorshtml.push('</li>');
  1499. $('#auditors-list').append(auditorshtml.join(''));
  1500. const auditorshtml2 = [];
  1501. // 重新上报时。令其它的审批人流程图标转换
  1502. $('#auditors-list2 li i').removeClass('fa-stop-circle').addClass('fa-chevron-circle-down');
  1503. // 添加新审批人
  1504. auditorshtml2.push('<li class="list-group-item" data-auditid="' + data.audit_id + '">');
  1505. auditorshtml2.push('<h5 class="card-title"><i class="fa fa-stop-circle"></i> ');
  1506. auditorshtml2.push(data.name + ' <small class="text-muted">' + data.role + '</small></h5>');
  1507. auditorshtml2.push('</li>');
  1508. $('#auditors-list2').append(auditorshtml2.join(''));
  1509. });
  1510. }
  1511. });
  1512. // $('#addAuditor').click(() => {
  1513. // const data = {
  1514. // auditorId: $('#addAuditor').attr('auditorId'),
  1515. // };
  1516. // postData('/tender/' + getTenderId() + '/ledger/audit/add', data, (data) => {
  1517. // const html = [];
  1518. // html.push('<li class="list-group-item" auditorId="'+ data.audit_id +'"><a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  1519. // html.push('<span>');
  1520. // html.push(data.audit_order + ' ');
  1521. // html.push(data.name + ' ');
  1522. // html.push('</span>');
  1523. // html.push('<small class="text-muted">');
  1524. // html.push(data.role);
  1525. // html.push('</small></li>');
  1526. // $('#auditors').append(html.join(''));
  1527. // });
  1528. // });
  1529. $('body').on('click', '#auditors li>a', function () {
  1530. const li = $(this).parent();
  1531. const data = {
  1532. auditorId: parseInt(li.attr('auditorId')),
  1533. };
  1534. postData('/tender/' + getTenderId() + '/ledger/audit/delete', data, (data2) => {
  1535. li.remove();
  1536. for (const a of data2) {
  1537. const aLi = $('li[auditorId=' + a.audit_id + ']');
  1538. $('span', aLi).text(a.audit_order + ' ' + a.name + ' ');
  1539. }
  1540. // 如果是重新上报
  1541. // 令最后一个图标转换
  1542. $('#auditors-list li[data-auditid="' + data.auditorId + '"]').remove();
  1543. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  1544. $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
  1545. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  1546. }
  1547. $('#auditors-list2 li[data-auditid="' + data.auditorId + '"]').remove();
  1548. if ($('#auditors-list2 li').length !== 0 && !$('#auditors-list2 li i').hasClass('fa-stop-circle')) {
  1549. $('#auditors-list2 li').eq($('#auditors-list2 li').length-1).children('i')
  1550. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  1551. }
  1552. });
  1553. });
  1554. // 选择excel文件后,加载全部sheet
  1555. $('#upload-ledger-file').change(function () {
  1556. if (this.files.length === 0) {
  1557. $('#upload-ledger-sheets').html('').hide();
  1558. return;
  1559. }$('#upload-ledger-sheets').hide();
  1560. try {
  1561. xlsxUtils.import(this.files[0], (excelData) => {
  1562. if (excelData.SheetNames.length > 0) {
  1563. const html = [];
  1564. html.push('<hr></hr>');
  1565. html.push('<h6>选择导入的工作表</h6>');
  1566. for (const iName in excelData.SheetNames) {
  1567. const name = excelData.SheetNames[iName];
  1568. html.push('<div class="card p-2 mb-2">');
  1569. html.push('<div class="form-check">');
  1570. html.push('<input class="form-check-input" type="radio" name="sheetName" id="excel-sheet' + iName + '"', (iName == 0 ? ' checked=""' : ''), ' value="' + name + '"', '>');
  1571. html.push('<label class="form-check-label" for="excel-sheet' + iName + '">', name, '</label>');
  1572. html.push('</div>');
  1573. html.push('</div>');
  1574. }
  1575. $('#upload-ledger-sheets').html(html.join('')).show();
  1576. $('.mb-2.p-2').mouseenter(function () {
  1577. $(this).addClass('border-primary');
  1578. });
  1579. $('.mb-2.p-2').mouseleave(function () {
  1580. $(this).removeClass('border-primary');
  1581. })
  1582. } else {
  1583. toast('选择的Excel无有效数据,请重新选择', 'hint');
  1584. $('#upload-ledger-sheets').hide();
  1585. }
  1586. });
  1587. } catch(err) {
  1588. toast('加载excel异常,请刷新当前页面', 'error');
  1589. $('#upload-ledger-sheets').hide();
  1590. }
  1591. });
  1592. // 上传excel内容,并导入
  1593. $('#upload-ledger-ok').click(function () {
  1594. const sheetName = $('input[name=sheetName]:checked').val();
  1595. if (sheetName) {
  1596. const sheet = {
  1597. rows: xlsxUtils.getSheetByName(sheetName, {header: 1}),
  1598. merge: xlsxUtils._wb.Sheets[sheetName]["!merges"]
  1599. };
  1600. postDataCompress(window.location.pathname + '/upload-excel', sheet, function (result) {
  1601. ledgerTree.loadDatas(result.bills);
  1602. treeCalc.calculateAll(ledgerTree);
  1603. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1604. pos.loadDatas(result.pos);
  1605. posOperationObj.loadCurPosData();
  1606. $('#upload-ledger').modal('hide');
  1607. });
  1608. }
  1609. });
  1610. $('#upload-ledger').bind('hidden.bs.modal', function () {
  1611. $('#upload-ledger-file').val('');
  1612. $('#upload-ledger-sheets').html('');
  1613. });
  1614. $('#hideSp').click(function () {
  1615. $('#sp-list2').modal('hide');
  1616. });
  1617. // 显示层次
  1618. (function (select, sheet) {
  1619. if (!sheet.zh_tree) return;
  1620. $(select).click(function () {
  1621. const tag = $(this).attr('tag');
  1622. const tree = sheet.zh_tree;
  1623. switch (tag) {
  1624. case "1":
  1625. case "2":
  1626. case "3":
  1627. case "4":
  1628. case "5":
  1629. tree.expandByLevel(parseInt(tag));
  1630. SpreadJsObj.refreshTreeRowVisible(sheet);
  1631. break;
  1632. case "last":
  1633. tree.expandByCustom(() => { return true; });
  1634. SpreadJsObj.refreshTreeRowVisible(sheet);
  1635. break;
  1636. case "leafXmj":
  1637. tree.expandToLeafXmj();
  1638. SpreadJsObj.refreshTreeRowVisible(sheet);
  1639. break;
  1640. }
  1641. });
  1642. })('a[name=showLevel]', ledgerSpread.getActiveSheet());
  1643. });
  1644. // 检查上报情况
  1645. function checkAuditorFrom () {
  1646. if ($('#auditors li').length === 0) {
  1647. toast('请先选择审批人,再上报数据', 'error', 'exclamation-circle');
  1648. return false;
  1649. }
  1650. }