revise.js 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. $(document).ready(() => {
  11. toastr.options = {
  12. "closeButton": false,
  13. "debug": false,
  14. "newestOnTop": false,
  15. "progressBar": false,
  16. "positionClass": "toast-top-center",
  17. "preventDuplicates": false,
  18. "onclick": null,
  19. "showDuration": "300",
  20. "hideDuration": "1000",
  21. "timeOut": "5000",
  22. "extendedTimeOut": "1000",
  23. "showEasing": "swing",
  24. "hideEasing": "linear",
  25. "showMethod": "fadeIn",
  26. "hideMethod": "fadeOut"
  27. };
  28. autoFlashHeight();
  29. // 初始化spread
  30. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  31. const billsSheet = billsSpread.getActiveSheet();
  32. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  33. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  34. const posSheet = posSpread.getActiveSheet();
  35. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  36. $.subMenu({
  37. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  38. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  39. key: 'revise.info.memu.1.0.0',
  40. callback: function (info) {
  41. if (info.mini) {
  42. $('.panel-title').addClass('fluid');
  43. $('#sub-menu').removeClass('panel-sidebar');
  44. } else {
  45. $('.panel-title').removeClass('fluid');
  46. $('#sub-menu').addClass('panel-sidebar');
  47. }
  48. autoFlashHeight();
  49. billsSpread.refresh();
  50. posSpread.refresh();
  51. }
  52. });
  53. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  54. // 初始化 清单树结构
  55. const treeSetting = {
  56. id: 'ledger_id',
  57. pid: 'ledger_pid',
  58. order: 'order',
  59. level: 'level',
  60. rootId: -1,
  61. keys: ['id', 'tender_id', 'ledger_id'],
  62. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  63. };
  64. if (!isTz) {
  65. treeSetting.calcFields.push('deal_tp');
  66. }
  67. treeSetting.calcFun = function (node) {
  68. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  69. };
  70. const billsTree = createNewPathTree('revise', treeSetting);
  71. billsTree.loadDatas(billsData);
  72. treeCalc.calculateAll(billsTree);
  73. // 加载至spread
  74. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  75. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  76. // 初始化 部位明细
  77. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  78. pos.loadDatas(posData);
  79. const billsTreeSpreadObj = {
  80. getDefaultSelectInfo: function (sheet) {
  81. const tree = sheet.zh_tree;
  82. if (!tree) return;
  83. const sel = sheet.getSelections()[0];
  84. const node = sheet.zh_tree.nodes[sel.row];
  85. if (!node) return;
  86. let count = 1;
  87. if (sel.rowCount > 1) {
  88. for (let r = 1; r < sel.rowCount; r++) {
  89. const rNode = sheet.zh_tree.nodes[sel.row + r];
  90. if (rNode.level > node.level) continue;
  91. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  92. toastr.warning('请选择同一清单下的节点,进行该操作');
  93. return;
  94. }
  95. count += 1;
  96. }
  97. }
  98. return [tree, node, count];
  99. },
  100. /**
  101. * 刷新顶部按钮是否可用
  102. * @param sheet
  103. * @param selections
  104. */
  105. refreshOperationValid: function (sheet, selection) {
  106. const setObjEnable = function (obj, enable) {
  107. if (enable) {
  108. obj.removeClass('disabled');
  109. } else {
  110. obj.addClass('disabled');
  111. }
  112. };
  113. const sel = selection ? selection[0] : sheet.getSelections()[0];
  114. const row = sel ? sel.row : -1;
  115. const tree = sheet.zh_tree;
  116. if (!tree) return;
  117. const first = sheet.zh_tree.nodes[row];
  118. let last = first, sameParent = true;
  119. if (sel.rowCount > 1) {
  120. for (let r = 1; r < sel.rowCount; r++) {
  121. const rNode = tree.nodes[sel.row + r];
  122. if (rNode.level > first.level) continue;
  123. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  124. sameParent = false;
  125. break;
  126. }
  127. last = rNode;
  128. }
  129. }
  130. const preNode = tree.getPreSiblingNode(first);
  131. const valid = !sheet.zh_setting.readOnly;
  132. setObjEnable($('#insert'), valid && first && first.level > 1);
  133. setObjEnable($('#delete'), valid && first && sameParent && first.level > 1);
  134. setObjEnable($('#up-move'), valid && first && sameParent && first.level > 1 && preNode);
  135. setObjEnable($('#down-move'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
  136. if (isTz) {
  137. const posRange = last ? pos.getLedgerPos(last.id) : [];
  138. setObjEnable($('#up-level'), valid && first && sameParent && tree.getParent(first) && first.level > 2 && (!posRange || posRange.length === 0));
  139. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  140. setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode && (!preNodePosRange || preNodePosRange.length === 0));
  141. } else {
  142. setObjEnable($('#up-level'), valid && first && sameParent && first.level > 2 && tree.getParent(first));
  143. setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode);
  144. }
  145. setObjEnable($('#cut'), valid);
  146. setObjEnable($('#paste'), valid);
  147. },
  148. /**
  149. *
  150. * @param sheet
  151. * @param data
  152. */
  153. refreshTree: function (sheet, data) {
  154. SpreadJsObj.massOperationSheet(sheet, function () {
  155. const tree = sheet.zh_tree;
  156. // 处理删除
  157. if (data.delete) {
  158. data.delete.sort(function (a, b) {
  159. return b.deleteIndex - a.deleteIndex;
  160. });
  161. for (const d of data.delete) {
  162. sheet.deleteRows(d.deleteIndex, 1);
  163. }
  164. }
  165. // 处理新增
  166. if (data.create) {
  167. const newNodes = data.create;
  168. if (newNodes) {
  169. newNodes.sort(function (a, b) {
  170. return a.index - b.index;
  171. });
  172. for (const node of newNodes) {
  173. sheet.addRows(node.index, 1);
  174. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  175. }
  176. }
  177. }
  178. // 处理更新
  179. if (data.update) {
  180. const rows = [];
  181. for (const u of data.update) {
  182. rows.push(tree.nodes.indexOf(u));
  183. }
  184. SpreadJsObj.reLoadRowsData(sheet, rows);
  185. }
  186. // 处理展开
  187. if (data.expand) {
  188. const expanded = [];
  189. for (const e of data.expand) {
  190. if (expanded.indexOf(e) === -1) {
  191. const posterity = tree.getPosterity(e);
  192. for (const p of posterity) {
  193. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  194. expanded.push(p);
  195. }
  196. }
  197. }
  198. }
  199. });
  200. },
  201. selectionChanged: function (e, info) {
  202. if (info.newSelections[0].row !== info.oldSelections[0].row) {
  203. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  204. posSpreadObj.loadCurPosData();
  205. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  206. posSearch.search($('#pos-keyword').val());
  207. }
  208. },
  209. /**
  210. * 新增节点
  211. * @param spread
  212. */
  213. baseOpr: function (sheet, type) {
  214. const self = this;
  215. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  216. if (!tree || !node || !count) return;
  217. if (type === 'delete') {
  218. const parent = tree.getParent(node);
  219. const children = parent ? parent.children : tree.children;
  220. const index = children.indexOf(node);
  221. for (let i = 0; i < count; i++) {
  222. const child = children[i+index];
  223. if (tree.checkNodeUsed(child, pos)) {
  224. toastr.warning('选中的清单已计量,不可删除');
  225. return;
  226. }
  227. }
  228. } else if (type === 'up-level') {
  229. const parent = tree.getParent(node);
  230. const children = parent ? parent.children : tree.children;
  231. const index = children.indexOf(node);
  232. for (let i = index; i < children.length; i++) {
  233. const child = children[index];
  234. if (tree.checkNodeUsed(child, pos)) {
  235. if (i >= index + count) {
  236. toastr.warning('其后清单已计量,选中的清单不可升级');
  237. } else {
  238. toastr.warning('选中的清单已计量,不可升级');
  239. }
  240. return;
  241. }
  242. }
  243. } else if (type === 'down-level') {
  244. const parent = tree.getParent(node);
  245. const children = parent ? parent.children : tree.children;
  246. const index = children.indexOf(node);
  247. for (let i = 0; i < count; i++) {
  248. const child = children[i+index];
  249. if (tree.checkNodeUsed(child, pos)) {
  250. toastr.warning('选中的清单已计量,不可降级');
  251. return;
  252. }
  253. }
  254. }
  255. postData(window.location.pathname + '/update', {
  256. postType: type,
  257. postData: {
  258. id: node.ledger_id,
  259. count: count,
  260. }
  261. }, function (result) {
  262. const refreshData = tree.loadPostData(result);
  263. self.refreshTree(sheet, refreshData);
  264. if (type === 'delete') {
  265. const sel = sheet.getSelections()[0];
  266. if (sel) {
  267. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  268. }
  269. } else if (['up-move', 'down-move'].indexOf(type) > -1) {
  270. const sel = sheet.getSelections()[0];
  271. if (sel) {
  272. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  273. }
  274. } else if (type === 'add') {
  275. const sel = sheet.getSelections()[0];
  276. if (sel) {
  277. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  278. }
  279. }
  280. self.refreshOperationValid(sheet);
  281. });
  282. },
  283. /**
  284. * 编辑单元格响应事件
  285. * @param {Object} e
  286. * @param {Object} info
  287. */
  288. editEnded: function (e, info) {
  289. if (info.sheet.zh_setting) {
  290. const col = info.sheet.zh_setting.cols[info.col];
  291. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  292. const node = sortData[info.row];
  293. const data = {
  294. id: node.id,
  295. tender_id: node.tender_id,
  296. ledger_id: node.ledger_id
  297. };
  298. // 未改变值则不提交
  299. const orgValue = node[col.field];
  300. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (info.editingText === ''))) {
  301. return;
  302. }
  303. // 台账模式,检查部位明细相关
  304. if (isTz) {
  305. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  306. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  307. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  308. if (!node.children || node.children.length ===0) {
  309. const lPos = pos.getLedgerPos(node.id);
  310. if (lPos && lPos.length > 0) {
  311. toastr.error('清单含有部位明细,不可修改施工图复核数量');
  312. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  313. return;
  314. }
  315. }
  316. }
  317. if (col.field === 'b_code' && (info.editingText === '' || !info.editingText)) {
  318. const lPos = pos.getLedgerPos(node.id);
  319. if (lPos && lPos.length > 0) {
  320. toastr.error('清单含有部位明细,请先删除部位明细,再删除清单编号');
  321. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  322. return;
  323. }
  324. }
  325. }
  326. // 获取更新数据
  327. if (info.editingText) {
  328. data[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText.replace('\n', '');
  329. } else {
  330. data[col.field] = null;
  331. }
  332. // 更新至服务器
  333. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  334. const refreshNode = billsTree.loadPostData(result);
  335. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  336. });
  337. }
  338. },
  339. clipboardPasting: function (e, info) {
  340. if (info.sheet.zh_setting) {
  341. const range = info.cellRange;
  342. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  343. const node = info.sheet.zh_tree.nodes[iRow];
  344. if (info.sheet.zh_tree.checkNodeUsed(node, pos)) {
  345. toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  346. info.cancel = true;
  347. return;
  348. }
  349. }
  350. }
  351. },
  352. clipboardPasted: function (e, info) {
  353. const tree = info.sheet.zh_tree;
  354. if (!tree) { return; }
  355. const sortData = info.sheet.zh_tree.nodes;
  356. const datas = [], filterNodes = [];
  357. let bHint = false, bPaste;
  358. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  359. bPaste = false;
  360. const curRow = info.cellRange.row + iRow;
  361. const node = sortData[curRow];
  362. if (node) {
  363. const data = info.sheet.zh_tree.getNodeKeyData(node);
  364. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  365. const curCol = info.cellRange.col + iCol;
  366. const colSetting = info.sheet.zh_setting.cols[curCol];
  367. const value = info.sheet.getText(curRow, curCol).replace('\n', '');
  368. const lPos = pos.getLedgerPos(node.id);
  369. if (lPos && lPos.length > 0) {
  370. if (value === '' && colSetting.field === 'b_code') {
  371. if (!bHint) {
  372. toastr.warning('清单含有部位明细,请先删除部位明细,再删除清单编号');
  373. bHint = true;
  374. }
  375. continue;
  376. }
  377. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  378. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  379. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  380. if (!bHint) {
  381. toastr.warning('清单含有部位明细,数量金额根据部位明细汇总计算所得,不可编辑');
  382. bHint = true;
  383. }
  384. continue;
  385. }
  386. }
  387. data[colSetting.field] = value;
  388. bPaste = true;
  389. }
  390. if (bPaste) {
  391. datas.push(data);
  392. } else {
  393. filterNodes.push(node);
  394. }
  395. }
  396. }
  397. if (datas.length > 0) {
  398. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  399. const refreshNode = tree.loadPostData(result);
  400. if (refreshNode.update) {
  401. refreshNode.update = refreshNode.update.concat(filterNodes);
  402. }
  403. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  404. }, function () {
  405. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  406. });
  407. } else {
  408. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  409. }
  410. },
  411. deletePress: function (sheet) {
  412. if (!sheet.zh_setting) return;
  413. const sel = sheet.getSelections()[0], datas = [];
  414. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  415. const node = sheet.zh_tree.nodes[iRow];
  416. if (sheet.zh_tree.checkNodeUsed(node, pos)) {
  417. toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  418. return;
  419. }
  420. const data = sheet.zh_tree.getNodeKeyData(node);
  421. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  422. const col = sheet.zh_setting.cols[iCol];
  423. data[col.field] = null;
  424. }
  425. datas.push(data);
  426. }
  427. if (datas.length > 0) {
  428. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  429. const refreshNode = sheet.zh_tree.loadPostData(result);
  430. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  431. });
  432. }
  433. },
  434. pasteBlock: function (spread, copyInfo) {
  435. const self = this;
  436. const sheet = spread.getActiveSheet();
  437. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  438. postData(window.location.pathname + '/update', {
  439. postType: 'paste-block',
  440. postData: {
  441. id: tree.getNodeKey(node),
  442. tid: copyInfo.tid,
  443. block: copyInfo.block,
  444. }
  445. }, function (data) {
  446. pos.updateDatas(data.pos);
  447. const result = tree.loadPostData(data.ledger);
  448. self.refreshTree(sheet, result);
  449. self.refreshOperationValid(sheet);
  450. removeLocalCache(copyBlockTag);
  451. }, null, true);
  452. },
  453. topRowChanged: function (e, info) {
  454. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  455. },
  456. };
  457. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  458. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  459. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  460. if (!readOnly) {
  461. // 增删上下移升降级
  462. $('a[name="base-opr"]').click(function () {
  463. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  464. });
  465. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  466. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  467. billsSpread.bind(spreadNS.Events.ClipboardPasted, billsTreeSpreadObj.clipboardPasted);
  468. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  469. let batchInsertObj;
  470. // 右键菜单
  471. $.contextMenu({
  472. selector: '#bills-spread',
  473. build: function ($trigger, e) {
  474. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  475. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  476. },
  477. items: {
  478. 'batchInsertBillsPos': {
  479. name: '批量插入清单-部位',
  480. icon: 'fa-sign-in',
  481. disabled: function (key, opt) {
  482. const select = SpreadJsObj.getSelectObject(billsSheet);
  483. if (select) {
  484. if (select.code && select.code !== '') {
  485. return !billsTree.isLeafXmj(select);
  486. } else {
  487. const parent = billsTree.getParent(select);
  488. return !(parent && billsTree.isLeafXmj(parent));
  489. }
  490. } else {
  491. return false;
  492. }
  493. },
  494. callback: function (key, opt) {
  495. if (!batchInsertObj) {
  496. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  497. } else {
  498. batchInsertObj.initView();
  499. }
  500. $('#batch').modal('show');
  501. }
  502. },
  503. 'debug': {
  504. name: 'debug',
  505. callback: function (key, opt) {
  506. console.log(SpreadJsObj.getSelectObject(billsSheet));
  507. }
  508. }
  509. }
  510. });
  511. }
  512. const posSpreadObj = {
  513. /**
  514. * 加载部位明细 根据当前台账选择节点
  515. */
  516. loadCurPosData: function () {
  517. const node = SpreadJsObj.getSelectObject(billsSheet);
  518. if (node) {
  519. const posData = pos.getLedgerPos(node.id) || [];
  520. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  521. } else {
  522. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  523. }
  524. SpreadJsObj.resetFieldReadOnly(posSheet);
  525. },
  526. editStarting: function (e, info) {
  527. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  528. },
  529. /**
  530. * 编辑单元格响应事件
  531. * @param {Object} e
  532. * @param {Object} info
  533. */
  534. editEnded: function (e, info) {
  535. if (!info.sheet.zh_setting) {
  536. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  537. return;
  538. }
  539. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  540. const col = info.sheet.zh_setting.cols[info.col];
  541. const orgText = posData ? posData[col.field] : null;
  542. const newText = info.sheet.getCell(info.row, info.col).text();
  543. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  544. const node = posSpreadObj.billsNode;
  545. if (!node) {
  546. toastr.error('数据错误,请选择台账节点后再试');
  547. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  548. return;
  549. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  550. toastr.error('父节点不可插入部位明细');
  551. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  552. return;
  553. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  554. toastr.error('项目节不可插入部位明细');
  555. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  556. return;
  557. }
  558. const data = {postType: 'pos'};
  559. if (col.field === 'name') {
  560. if (newText === '' && posData) {
  561. toastr.error('部位名称不可为空', 'error');
  562. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  563. return;
  564. } else if (!posData) {
  565. if (newText && newText !== '') {
  566. data.posPostType = 'add';
  567. const sortData = info.sheet.zh_data;
  568. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  569. data.postData = { name: newText, lid: node.id, porder: order};
  570. } else {
  571. return;
  572. }
  573. } else {
  574. data.posPostType = 'update-pos';
  575. data.postData = {id: posData.id, name: newText};
  576. }
  577. } else if (!posData) {
  578. toastr.warning('新增部位请先输入名称');
  579. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  580. return;
  581. } else {
  582. data.posPostType = 'update';
  583. data.postData = {id: posData.id};
  584. data.postData[col.field] = col.type === 'Number' ? parseFloat(newText) : newText;
  585. }
  586. postData(window.location.pathname + '/update', data, function (result) {
  587. const updateRst = pos.updateDatas(result.pos);
  588. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  589. if (updateRst.create.length > 0) {
  590. posSpreadObj.loadCurPosData();
  591. } else {
  592. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  593. }
  594. const loadResult = billsTree.loadPostData(result.ledger);
  595. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  596. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  597. }, function () {
  598. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  599. });
  600. },
  601. /**
  602. * 删除按钮响应事件
  603. * @param sheet
  604. */
  605. deletePress: function (sheet) {
  606. if (!sheet.zh_settting) return;
  607. const sortData = sheet.zh_data;
  608. const datas = [], posSelects = [];
  609. const sel = sheet.getSelections()[0];
  610. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  611. let bDel = false;
  612. const node = sortData[iRow];
  613. if (node) {
  614. const data = {id: node.id};
  615. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  616. const colSetting = sheet.zh_setting.cols[iCol];
  617. if (colSetting.field === 'name') {
  618. toastr.error('部位名称不能为空');
  619. return;
  620. }
  621. const style = sheet.getStyle(iRow, iCol);
  622. if (!style.locked) {
  623. const colSetting = sheet.zh_setting.cols[iCol];
  624. data[colSetting.field] = null;
  625. bDel = true;
  626. }
  627. }
  628. if (bDel) {
  629. datas.push(data);
  630. posSelects.push(node);
  631. }
  632. }
  633. }
  634. if (datas.length > 0) {
  635. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  636. pos.updateDatas(result.pos);
  637. posSpreadObj.loadCurPosData();
  638. const loadResult = billsTree.loadPostData(result.ledger);
  639. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  640. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  641. }, function () {
  642. posSpreadObj.loadCurPosData();
  643. });
  644. }
  645. },
  646. /**
  647. * 删除 部位明细
  648. * @param sheet
  649. */
  650. deletePos: function (sheet) {
  651. const selection = sheet.getSelections();
  652. const data = {
  653. postType: 'pos',
  654. posPostType: 'delete',
  655. postData: [],
  656. };
  657. const row = selection[0].row, count = selection[0].rowCount;
  658. const sortData = sheet.zh_data;
  659. for (let iRow = 0; iRow < count; iRow++) {
  660. const posData = sortData[iRow + row];
  661. if (posData) {
  662. if (posData.used) {
  663. toastr.error('"' + posData.name + '"已计量,请勿删除');
  664. return;
  665. }
  666. data.postData.push(sortData[iRow + row].id);
  667. }
  668. }
  669. console.log(data);
  670. if (data.postData.length > 0) {
  671. postData(window.location.pathname + '/update', data, function (result) {
  672. pos.removeDatas(result.pos);
  673. sheet.deleteRows(row, count);
  674. const loadResult = billsTree.loadPostData(result.ledger);
  675. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  676. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  677. });
  678. }
  679. },
  680. clipboardPasting: function (e, info) {
  681. if (!info.sheet.zh_setting) {
  682. info.cancel = true;
  683. return;
  684. }
  685. const range = info.cellRange;
  686. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  687. const posData = info.sheet.zh_data[iRow];
  688. if (posData && posData.used) {
  689. toastr.warning('"' + pos.name +'"已计量,请勿修改');
  690. info.cancel = true;
  691. return;
  692. }
  693. }
  694. },
  695. /**
  696. * 粘贴单元格响应事件
  697. * @param e
  698. * @param info
  699. */
  700. clipboardPasted: function (e, info) {
  701. const node = SpreadJsObj.getSelectObject(billsSheet);
  702. if (node.code && (node.code !== '')) {
  703. toastr.error('项目节不可含有清单明细');
  704. posSpreadObj.loadCurPosData();
  705. return;
  706. }
  707. if (node.children && (node.children.length > 0)) {
  708. toastr.error('仅清单子项可以含有部位明细');
  709. posSpreadObj.loadCurPosData();
  710. return;
  711. }
  712. if (!info.sheet.zh_setting) {
  713. posSpreadObj.loadCurPosData();
  714. return;
  715. }
  716. const data = [];
  717. const sortData = info.sheet.zh_data || [];
  718. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  719. if (info.cellRange.col !== 0) {
  720. toast('新增部位请先输入名称', 'warning');
  721. posSpreadObj.loadCurPosData();
  722. return;
  723. }
  724. }
  725. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  726. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  727. const curRow = info.cellRange.row + iRow;
  728. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  729. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  730. const curCol = info.cellRange.col + iCol;
  731. const colSetting = info.sheet.zh_setting.cols[curCol];
  732. posData[colSetting.field] = info.sheet.getText(curRow, curCol);
  733. if (colSetting.type === 'Number') {
  734. posData[colSetting.field] = _.toNumber(posData[colSetting.field]);
  735. }
  736. }
  737. data.push(posData);
  738. }
  739. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  740. pos.updateDatas(result.pos);
  741. posSpreadObj.loadCurPosData();
  742. const loadResult = billsTree.loadPostData(result.ledger);
  743. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  744. posSpreadObj.loadCurPosData();
  745. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  746. }, function () {
  747. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  748. });
  749. },
  750. };
  751. posSpreadObj.loadCurPosData();
  752. SpreadJsObj.resetTopAndSelect(posSheet);
  753. if (!readOnly) {
  754. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  755. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  756. posSpread.bind(spreadNS.Events.ClipboardPasting, posSpreadObj.clipboardPasting);
  757. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  758. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  759. $.contextMenu({
  760. selector: '#pos-spread',
  761. build: function ($trigger, e) {
  762. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  763. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  764. },
  765. items: {
  766. 'delete': {
  767. name: '删除',
  768. icon: 'fa-remove',
  769. disabled: function (key, opt) {
  770. if (posSheet.zh_data) {
  771. const selection = posSheet.getSelections();
  772. return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  773. } else {
  774. return true;
  775. }
  776. },
  777. callback: function (key, opt) {
  778. posSpreadObj.deletePos(posSheet);
  779. }
  780. },
  781. 'debug': {
  782. name: 'debug',
  783. callback: function (key, opt) {
  784. console.log(SpreadJsObj.getSelectObject(posSheet));
  785. }
  786. }
  787. }
  788. });
  789. }
  790. $.divResizer({
  791. select: '#revise-resize',
  792. callback: function () {
  793. billsSpread.refresh();
  794. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  795. $(".sp-wrap").height(bcontent-40);
  796. posSpread.refresh();
  797. }
  798. });
  799. class stdLib {
  800. constructor(selector, stdType, treeSetting, spreadSetting) {
  801. const self = this;
  802. this.obj = $(selector + '-spread')[0];
  803. this.stdType = stdType;
  804. this.treeSetting = treeSetting;
  805. treeSetting.preUrl = this.url;
  806. this.spreadSetting = spreadSetting;
  807. this.spread = SpreadJsObj.createNewSpread(this.obj);
  808. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  809. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  810. const stdSheet = info.sheet;
  811. const mainSheet = billsSheet;
  812. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  813. const stdTree = stdSheet.zh_tree;
  814. const stdNode = stdTree.nodes[info.row];
  815. const mainTree = mainSheet.zh_tree;
  816. const sel = mainSheet.getSelections()[0];
  817. const mainNode = mainTree.nodes[sel.row];
  818. if (!stdNode) return;
  819. if (stdType === 'bills') {
  820. if (!(mainNode.b_code && mainNode.b_code !== '') && !mainTree.isLeafXmj(mainNode)) {
  821. toastr.warning('非最底层项目下,不应添加清单');
  822. return;
  823. }
  824. }
  825. postData(window.location.pathname + '/update', {
  826. postType: 'add-std',
  827. postData: {
  828. id: mainTree.getNodeKey(mainNode),
  829. tender_id: mainNode.tender_id,
  830. stdType: stdType,
  831. stdLibId: stdNode.list_id,
  832. stdNode: stdTree.getNodeKey(stdNode)
  833. }
  834. }, function (result) {
  835. const refreshNode = mainTree.loadPostData(result);
  836. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  837. if (sel && refreshNode.create[0]) {
  838. mainSheet.setSelection(mainTree.nodes.indexOf(refreshNode.create[0]), sel.col, sel.rowCount, sel.colCount);
  839. }
  840. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  841. });
  842. });
  843. this.pathTree = createNewPathTree('base', this.treeSetting);
  844. this.cacheLib = [];
  845. $('select', selector).change(function () {
  846. self.loadLib(parseInt(this.value));
  847. });
  848. }
  849. loadLib (listId) {
  850. const cacheData = this.cacheLib.find(function (lib) {
  851. return lib.id === listId;
  852. });
  853. if (cacheData) {
  854. this.pathTree.loadDatas(cacheData.data);
  855. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'tree', this.pathTree);
  856. } else {
  857. const self = this;
  858. postData('/std-lib/get-data', {stdType: this.stdType, list_id: listId}, function (data) {
  859. self.cacheLib.push({id: listId, data: data});
  860. self.pathTree.loadDatas(data);
  861. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'tree', self.pathTree);
  862. });
  863. }
  864. }
  865. }
  866. class DealBills {
  867. constructor (selector, spreadSetting) {
  868. const self = this;
  869. this.loaded = false;
  870. this.obj = $(selector)[0];
  871. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  872. this.spreadSetting = spreadSetting;
  873. this.spread = SpreadJsObj.createNewSpread(this.obj);
  874. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  875. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  876. const dealSheet = info.sheet;
  877. const mainSheet = ledgerSpread.getActiveSheet();
  878. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  879. if (!dealBills) { return; }
  880. const mainTree = mainSheet.zh_tree;
  881. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  882. if (!mainNode || !mainTree) { return; }
  883. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  884. toastr.warning('非最底层项目下,不应添加清单');
  885. return;
  886. }
  887. postData(window.location.pathname + '/update', {
  888. postType: 'add-deal',
  889. postData: {
  890. id: mainNode.ledger_id,
  891. type: mainNode.code ? 'child' : 'next',
  892. dealBills: {
  893. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  894. unit_price: dealBills.unit_price,
  895. }
  896. },
  897. }, function (result) {
  898. const refreshData = mainTree.loadPostData(result);
  899. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  900. const sel = mainSheet.getSelections()[0];
  901. if (sel && refreshData.create[0]) {
  902. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  903. }
  904. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  905. });
  906. });
  907. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  908. }
  909. loadData () {
  910. if (this.loaded) return;
  911. const self = this;
  912. postData(this.url+'/get-data', {}, function (data) {
  913. self.data = data;
  914. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  915. self.loaded = true;
  916. });
  917. }
  918. calculateData () {
  919. if (this.data) {
  920. for (const d of this.data) {
  921. d.total_price = _.multiply(d.quantity, d.unit_price);
  922. }
  923. }
  924. }
  925. }
  926. class BatchInsertBillsPosObj {
  927. constructor (obj) {
  928. const self = this;
  929. this.obj = obj;
  930. this.billsCount = 6;
  931. this.posCount = 1000;
  932. // 初始化 清单编号窗口 参数
  933. this.qdSpreadSetting = {
  934. cols: [
  935. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  936. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  937. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  938. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  939. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  940. ],
  941. emptyRows: this.billsCount,
  942. headRows: 1,
  943. headRowHeight: [40],
  944. };
  945. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  946. // 初始化 部位数量复核表 参数
  947. this.posSpreadSetting = {
  948. cols: [
  949. {title: '部位', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  950. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  951. ],
  952. emptyRows: this.posCount,
  953. headRows: 1,
  954. headRowHeight: [40],
  955. };
  956. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  957. this.posSpreadSetting.cols.push(
  958. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  959. )
  960. }
  961. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  962. // 初始化 签约清单 参数
  963. this.dealSpreadSetting = {
  964. cols: [
  965. {title: '清单编号', field: 'code', width: 80, formatter: '@', readOnly: true},
  966. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true},
  967. {title: '单位', field: 'unit', width: 50, formatter: '@', readOnly: true},
  968. {title: '单价', field: 'unit_price', width: 50, readOnly: true},
  969. ],
  970. emptyRows: 0,
  971. headRows: 1,
  972. headRowHeight: [40],
  973. };
  974. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  975. // 初始化 清单编号、部位数量复核表 表格
  976. this.initView();
  977. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  978. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  979. // 拉取签约清单数据
  980. dealBills.loadData();
  981. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  982. // 双击签约清单,自动添加到清单编号窗口
  983. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  984. const deal = info.sheet.zh_data[info.row];
  985. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  986. const sel = qdSheet.getSelections()[0];
  987. qdSheet.getCell(sel.row, 0).value(deal.code);
  988. qdSheet.getCell(sel.row, 1).value(deal.name);
  989. qdSheet.getCell(sel.row, 2).value(deal.unit);
  990. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  991. if (sel.row + 1 === qdSheet.getRowCount()) {
  992. const count = sel.row + 2;
  993. qdSheet.setRowCount(count);
  994. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  995. const colCount = posSheet.getColumnCount() + 1
  996. posSheet.setColumnCount(colCount);
  997. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('数量' + count);
  998. }
  999. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  1000. });
  1001. this.obj.bind('shown.bs.modal', function () {
  1002. self.qdSpread.refresh();
  1003. self.posSpread.refresh();
  1004. self.dealSpread.refresh();
  1005. });
  1006. $('#batch-ok').click(function () {
  1007. const selection = billsSheet.getSelections();
  1008. const row = selection[0].row;
  1009. const select = billsTree.nodes[row];
  1010. if (select) {
  1011. const insertData = {};
  1012. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  1013. insertData.id = select[billsTree.setting.id];
  1014. insertData.batchData = self.getBatchData();
  1015. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  1016. pos.updateDatas(data.pos);
  1017. const result = billsTree.loadPostData(data.ledger);
  1018. billsTreeSpreadObj.refreshTree(sheet, result);
  1019. billsTreeSpreadObj.refreshOperationValid(sheet, selection);
  1020. self.obj.modal('hide');
  1021. }, null, true);
  1022. }
  1023. });
  1024. }
  1025. // 初始化左侧表格
  1026. initView () {
  1027. // 初始化 清单编号
  1028. const qdSheet = this.qdSpread.getActiveSheet();
  1029. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  1030. SpreadJsObj.refreshColumnAlign(qdSheet);
  1031. // 清理原有数据
  1032. SpreadJsObj.beginMassOperation(qdSheet);
  1033. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1034. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  1035. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  1036. }
  1037. qdSheet.setSelection(0, 0, 1 ,1);
  1038. SpreadJsObj.endMassOperation(qdSheet);
  1039. // 初始化 部位数量复核表
  1040. const posSheet = this.posSpread.getActiveSheet();
  1041. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  1042. SpreadJsObj.refreshColumnAlign(posSheet);
  1043. // 清理原有数据
  1044. SpreadJsObj.beginMassOperation(posSheet);
  1045. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  1046. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1047. posSheet.setSelection(0, 0, 1 ,1);
  1048. SpreadJsObj.endMassOperation(posSheet);
  1049. // 检查签约清单数据,以工具栏数据为准
  1050. if (dealBills) {
  1051. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1052. }
  1053. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  1054. }
  1055. // 获取界面数据
  1056. getBatchData () {
  1057. const result = [];
  1058. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  1059. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  1060. if (qdSheet.getText(iRow, 0) === '') { continue; }
  1061. const qd = {
  1062. b_code: qdSheet.getText(iRow, 0),
  1063. name: qdSheet.getText(iRow, 1),
  1064. unit: qdSheet.getText(iRow, 2),
  1065. price: _.toNumber(qdSheet.getText(iRow, 3)),
  1066. pos: [],
  1067. };
  1068. result.push(qd);
  1069. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  1070. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  1071. if (value !== 0 && !isNaN(value)) {
  1072. qd.pos.push({
  1073. name: posSheet.getText(iPosRow, 0),
  1074. drawing_code: posSheet.getText(iPosRow, 1),
  1075. quantity: value,
  1076. });
  1077. }
  1078. }
  1079. }
  1080. return result;
  1081. }
  1082. }
  1083. let stdXmj, stdGcl, searchLedger;
  1084. const dealBills = new DealBills('#deal-bills-spread', {
  1085. cols: [
  1086. {title: '清单编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1087. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  1088. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1089. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1090. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1091. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1092. ],
  1093. emptyRows: 0,
  1094. headRows: 1,
  1095. headRowHeight: [40],
  1096. defaultRowHeight: 21,
  1097. });
  1098. $.divResizer({
  1099. select: '#revise-right-spr',
  1100. callback: function () {
  1101. billsSpread.refresh();
  1102. if (posSpread) {
  1103. posSpread.refresh();
  1104. }
  1105. if (stdXmj) {
  1106. stdXmj.spread.refresh();
  1107. }
  1108. if (stdGcl) {
  1109. stdGcl.spread.refresh();
  1110. }
  1111. }
  1112. });
  1113. // 展开收起标准清单
  1114. $('a', '#side-menu').bind('click', function (e) {
  1115. e.preventDefault();
  1116. const tab = $(this), tabPanel = $(tab.attr('content'));
  1117. const showSideTools = function (show) {
  1118. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1119. if (show) {
  1120. right.show();
  1121. autoFlashHeight();
  1122. /**
  1123. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1124. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1125. * 故需要通过最终的parent.width再计算一次left.width
  1126. *
  1127. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1128. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1129. *
  1130. */
  1131. //left.css('width', parent.width() - right.outerWidth());
  1132. //left.css('width', parent.width() - right.outerWidth());
  1133. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1134. left.css('width', percent + '%');
  1135. } else {
  1136. left.width(parent.width());
  1137. right.hide();
  1138. }
  1139. };
  1140. // 展开工具栏、切换标签
  1141. if (!tab.hasClass('active')) {
  1142. const close = $('.active', '#side-menu').length === 0;
  1143. $('a', '#side-menu').removeClass('active');
  1144. tab.addClass('active');
  1145. $('.tab-content .tab-pane').removeClass('active');
  1146. tabPanel.addClass('active');
  1147. showSideTools(tab.hasClass('active'));
  1148. if (tab.attr('content') === '#std-xmj') {
  1149. if (!stdXmj) {
  1150. stdXmj = new stdLib('#std-xmj', 'xmj', {
  1151. id: 'chapter_id',
  1152. pid: 'pid',
  1153. order: 'order',
  1154. level: 'level',
  1155. rootId: -1,
  1156. keys: ['id', 'list_id', 'chapter_id'],
  1157. }, {
  1158. cols: [
  1159. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1160. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  1161. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1162. ],
  1163. treeCol: 0,
  1164. emptyRows: 0,
  1165. headRows: 1,
  1166. headRowHeight: [40],
  1167. defaultRowHeight: 21,
  1168. });
  1169. stdXmj.loadLib($('select', '#std-xmj').val());
  1170. }
  1171. stdXmj.spread.refresh();
  1172. } else if (tab.attr('content') === '#std-gcl') {
  1173. if (!stdGcl) {
  1174. stdGcl = new stdLib('#std-gcl', 'gcl', {
  1175. id: 'bill_id',
  1176. pid: 'pid',
  1177. order: 'order',
  1178. level: 'level',
  1179. rootId: -1,
  1180. keys: ['id', 'list_id', 'bill_id']
  1181. }, {
  1182. cols: [
  1183. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1184. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  1185. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1186. ],
  1187. treeCol: 0,
  1188. emptyRows: 0,
  1189. headRows: 1,
  1190. headRowHeight: [40],
  1191. defaultRowHeight: 21,
  1192. });
  1193. stdGcl.loadLib($('select', '#std-gcl').val());
  1194. }
  1195. stdGcl.spread.refresh();
  1196. } else if (tab.attr('content') === '#deal-bills') {
  1197. dealBills.loadData();
  1198. dealBills.spread.refresh();
  1199. } else if (tab.attr('content') === '#search' && !searchLedger) {
  1200. if (!searchLedger) {
  1201. searchLedger = $.billsSearch({
  1202. selector: '#search',
  1203. searchSpread: billsSpread,
  1204. resultSpreadSetting: {
  1205. cols: [
  1206. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1207. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1208. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  1209. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  1210. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1211. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1212. ],
  1213. emptyRows: 0,
  1214. headRows: 1,
  1215. headRowHeight: [40],
  1216. defaultRowHeight: 21,
  1217. },
  1218. afterLocated: function () {
  1219. posSpreadObj.loadCurPosData();
  1220. }
  1221. });
  1222. }
  1223. searchLedger.spread.refresh();
  1224. }
  1225. }
  1226. billsSpread.refresh();
  1227. if (posSpread) {
  1228. posSpread.refresh();
  1229. }
  1230. });
  1231. // 修订详情 保存
  1232. $('#save').click(function () {
  1233. const content = $('textarea').val();
  1234. postData('save', { content: content });
  1235. });
  1236. // 显示层次
  1237. (function (select, sheet) {
  1238. if (!sheet.zh_tree) return;
  1239. $(select).click(function () {
  1240. const tag = $(this).attr('tag');
  1241. const tree = sheet.zh_tree;
  1242. switch (tag) {
  1243. case "1":
  1244. case "2":
  1245. case "3":
  1246. case "4":
  1247. case "5":
  1248. tree.expandByLevel(parseInt(tag));
  1249. SpreadJsObj.refreshTreeRowVisible(sheet);
  1250. break;
  1251. case "last":
  1252. tree.expandByCustom(() => { return true; });
  1253. SpreadJsObj.refreshTreeRowVisible(sheet);
  1254. break;
  1255. case "leafXmj":
  1256. tree.expandToLeafXmj();
  1257. SpreadJsObj.refreshTreeRowVisible(sheet);
  1258. break;
  1259. }
  1260. });
  1261. })('a[name=showLevel]', billsSheet);
  1262. });