ledger.js 84 KB

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