revise.js 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  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) || tree.isLastSibling(last)));
  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. if (data.postData.length > 0) {
  670. postData(window.location.pathname + '/update', data, function (result) {
  671. pos.removeDatas(result.pos);
  672. sheet.deleteRows(row, count);
  673. const loadResult = billsTree.loadPostData(result.ledger);
  674. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  675. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  676. });
  677. }
  678. },
  679. clipboardPasting: function (e, info) {
  680. if (!info.sheet.zh_setting) {
  681. info.cancel = true;
  682. return;
  683. }
  684. const range = info.cellRange;
  685. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  686. const posData = info.sheet.zh_data[iRow];
  687. if (posData && posData.used) {
  688. toastr.warning('"' + pos.name +'"已计量,请勿修改');
  689. info.cancel = true;
  690. return;
  691. }
  692. }
  693. },
  694. /**
  695. * 粘贴单元格响应事件
  696. * @param e
  697. * @param info
  698. */
  699. clipboardPasted: function (e, info) {
  700. const node = SpreadJsObj.getSelectObject(billsSheet);
  701. if (node.code && (node.code !== '')) {
  702. toastr.error('项目节不可含有清单明细');
  703. posSpreadObj.loadCurPosData();
  704. return;
  705. }
  706. if (node.children && (node.children.length > 0)) {
  707. toastr.error('仅清单子项可以含有部位明细');
  708. posSpreadObj.loadCurPosData();
  709. return;
  710. }
  711. if (!info.sheet.zh_setting) {
  712. posSpreadObj.loadCurPosData();
  713. return;
  714. }
  715. const data = [];
  716. const sortData = info.sheet.zh_data || [];
  717. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  718. if (info.cellRange.col !== 0) {
  719. toast('新增部位请先输入名称', 'warning');
  720. posSpreadObj.loadCurPosData();
  721. return;
  722. }
  723. }
  724. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  725. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  726. const curRow = info.cellRange.row + iRow;
  727. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  728. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  729. const curCol = info.cellRange.col + iCol;
  730. const colSetting = info.sheet.zh_setting.cols[curCol];
  731. posData[colSetting.field] = info.sheet.getText(curRow, curCol);
  732. if (colSetting.type === 'Number') {
  733. posData[colSetting.field] = _.toNumber(posData[colSetting.field]);
  734. }
  735. }
  736. data.push(posData);
  737. }
  738. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  739. pos.updateDatas(result.pos);
  740. posSpreadObj.loadCurPosData();
  741. const loadResult = billsTree.loadPostData(result.ledger);
  742. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  743. posSpreadObj.loadCurPosData();
  744. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  745. }, function () {
  746. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  747. });
  748. },
  749. };
  750. posSpreadObj.loadCurPosData();
  751. SpreadJsObj.resetTopAndSelect(posSheet);
  752. if (!readOnly) {
  753. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  754. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  755. posSpread.bind(spreadNS.Events.ClipboardPasting, posSpreadObj.clipboardPasting);
  756. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  757. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  758. $.contextMenu({
  759. selector: '#pos-spread',
  760. build: function ($trigger, e) {
  761. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  762. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  763. },
  764. items: {
  765. 'delete': {
  766. name: '删除',
  767. icon: 'fa-remove',
  768. disabled: function (key, opt) {
  769. if (posSheet.zh_data) {
  770. const selection = posSheet.getSelections();
  771. return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  772. } else {
  773. return true;
  774. }
  775. },
  776. callback: function (key, opt) {
  777. posSpreadObj.deletePos(posSheet);
  778. }
  779. },
  780. 'debug': {
  781. name: 'debug',
  782. callback: function (key, opt) {
  783. console.log(SpreadJsObj.getSelectObject(posSheet));
  784. }
  785. }
  786. }
  787. });
  788. }
  789. $.divResizer({
  790. select: '#revise-resize',
  791. callback: function () {
  792. billsSpread.refresh();
  793. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  794. $(".sp-wrap").height(bcontent-40);
  795. posSpread.refresh();
  796. }
  797. });
  798. class stdLib {
  799. constructor(selector, stdType, treeSetting, spreadSetting) {
  800. const self = this;
  801. this.obj = $(selector + '-spread')[0];
  802. this.stdType = stdType;
  803. this.treeSetting = treeSetting;
  804. treeSetting.preUrl = this.url;
  805. this.spreadSetting = spreadSetting;
  806. this.spread = SpreadJsObj.createNewSpread(this.obj);
  807. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  808. if (!readOnly) {
  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.code && mainNode.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. }
  844. this.pathTree = createNewPathTree('base', this.treeSetting);
  845. this.cacheLib = [];
  846. $('select', selector).change(function () {
  847. self.loadLib(parseInt(this.value));
  848. });
  849. }
  850. loadLib (listId) {
  851. const cacheData = this.cacheLib.find(function (lib) {
  852. return lib.id === listId;
  853. });
  854. if (cacheData) {
  855. this.pathTree.loadDatas(cacheData.data);
  856. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'tree', this.pathTree);
  857. } else {
  858. const self = this;
  859. postData('/std-lib/get-data', {stdType: this.stdType, list_id: listId}, function (data) {
  860. self.cacheLib.push({id: listId, data: data});
  861. self.pathTree.loadDatas(data);
  862. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'tree', self.pathTree);
  863. });
  864. }
  865. }
  866. }
  867. class DealBills {
  868. constructor (selector, spreadSetting) {
  869. const self = this;
  870. this.loaded = false;
  871. this.obj = $(selector)[0];
  872. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  873. this.spreadSetting = spreadSetting;
  874. this.spread = SpreadJsObj.createNewSpread(this.obj);
  875. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  876. if (!readOnly) {
  877. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  878. const dealSheet = info.sheet;
  879. const mainSheet = ledgerSpread.getActiveSheet();
  880. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  881. if (!dealBills) { return; }
  882. const mainTree = mainSheet.zh_tree;
  883. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  884. if (!mainNode || !mainTree) { return; }
  885. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  886. toastr.warning('非最底层项目下,不应添加清单');
  887. return;
  888. }
  889. postData(window.location.pathname + '/update', {
  890. postType: 'add-deal',
  891. postData: {
  892. id: mainNode.ledger_id,
  893. type: mainNode.code ? 'child' : 'next',
  894. dealBills: {
  895. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  896. unit_price: dealBills.unit_price,
  897. }
  898. },
  899. }, function (result) {
  900. const refreshData = mainTree.loadPostData(result);
  901. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  902. const sel = mainSheet.getSelections()[0];
  903. if (sel && refreshData.create[0]) {
  904. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  905. }
  906. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  907. });
  908. });
  909. }
  910. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  911. }
  912. loadData () {
  913. if (this.loaded) return;
  914. const self = this;
  915. postData(this.url+'/get-data', {}, function (data) {
  916. self.data = data;
  917. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  918. self.loaded = true;
  919. });
  920. }
  921. calculateData () {
  922. if (this.data) {
  923. for (const d of this.data) {
  924. d.total_price = _.multiply(d.quantity, d.unit_price);
  925. }
  926. }
  927. }
  928. }
  929. class BatchInsertBillsPosObj {
  930. constructor (obj) {
  931. const self = this;
  932. this.obj = obj;
  933. this.billsCount = 6;
  934. this.posCount = 1000;
  935. // 初始化 清单编号窗口 参数
  936. this.qdSpreadSetting = {
  937. cols: [
  938. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  939. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  940. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  941. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  942. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  943. ],
  944. emptyRows: this.billsCount,
  945. headRows: 1,
  946. headRowHeight: [40],
  947. };
  948. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  949. // 初始化 部位数量复核表 参数
  950. this.posSpreadSetting = {
  951. cols: [
  952. {title: '部位', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  953. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  954. ],
  955. emptyRows: this.posCount,
  956. headRows: 1,
  957. headRowHeight: [40],
  958. };
  959. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  960. this.posSpreadSetting.cols.push(
  961. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  962. )
  963. }
  964. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  965. // 初始化 签约清单 参数
  966. this.dealSpreadSetting = {
  967. cols: [
  968. {title: '清单编号', field: 'code', width: 80, formatter: '@', readOnly: true},
  969. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true},
  970. {title: '单位', field: 'unit', width: 50, formatter: '@', readOnly: true},
  971. {title: '单价', field: 'unit_price', width: 50, readOnly: true},
  972. ],
  973. emptyRows: 0,
  974. headRows: 1,
  975. headRowHeight: [40],
  976. };
  977. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  978. // 初始化 清单编号、部位数量复核表 表格
  979. this.initView();
  980. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  981. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  982. // 拉取签约清单数据
  983. dealBills.loadData();
  984. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  985. // 双击签约清单,自动添加到清单编号窗口
  986. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  987. const deal = info.sheet.zh_data[info.row];
  988. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  989. const sel = qdSheet.getSelections()[0];
  990. qdSheet.getCell(sel.row, 0).value(deal.code);
  991. qdSheet.getCell(sel.row, 1).value(deal.name);
  992. qdSheet.getCell(sel.row, 2).value(deal.unit);
  993. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  994. if (sel.row + 1 === qdSheet.getRowCount()) {
  995. const count = sel.row + 2;
  996. qdSheet.setRowCount(count);
  997. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  998. const colCount = posSheet.getColumnCount() + 1
  999. posSheet.setColumnCount(colCount);
  1000. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('数量' + count);
  1001. }
  1002. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  1003. });
  1004. this.obj.bind('shown.bs.modal', function () {
  1005. self.qdSpread.refresh();
  1006. self.posSpread.refresh();
  1007. self.dealSpread.refresh();
  1008. });
  1009. $('#batch-ok').click(function () {
  1010. const selection = billsSheet.getSelections();
  1011. const row = selection[0].row;
  1012. const select = billsTree.nodes[row];
  1013. if (select) {
  1014. const insertData = {};
  1015. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  1016. insertData.id = select[billsTree.setting.id];
  1017. insertData.batchData = self.getBatchData();
  1018. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  1019. pos.updateDatas(data.pos);
  1020. const result = billsTree.loadPostData(data.ledger);
  1021. billsTreeSpreadObj.refreshTree(sheet, result);
  1022. billsTreeSpreadObj.refreshOperationValid(sheet, selection);
  1023. self.obj.modal('hide');
  1024. }, null, true);
  1025. }
  1026. });
  1027. }
  1028. // 初始化左侧表格
  1029. initView () {
  1030. // 初始化 清单编号
  1031. const qdSheet = this.qdSpread.getActiveSheet();
  1032. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  1033. SpreadJsObj.refreshColumnAlign(qdSheet);
  1034. // 清理原有数据
  1035. SpreadJsObj.beginMassOperation(qdSheet);
  1036. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1037. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  1038. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  1039. }
  1040. qdSheet.setSelection(0, 0, 1 ,1);
  1041. SpreadJsObj.endMassOperation(qdSheet);
  1042. // 初始化 部位数量复核表
  1043. const posSheet = this.posSpread.getActiveSheet();
  1044. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  1045. SpreadJsObj.refreshColumnAlign(posSheet);
  1046. // 清理原有数据
  1047. SpreadJsObj.beginMassOperation(posSheet);
  1048. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  1049. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1050. posSheet.setSelection(0, 0, 1 ,1);
  1051. SpreadJsObj.endMassOperation(posSheet);
  1052. // 检查签约清单数据,以工具栏数据为准
  1053. if (dealBills) {
  1054. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1055. }
  1056. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  1057. }
  1058. // 获取界面数据
  1059. getBatchData () {
  1060. const result = [];
  1061. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  1062. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  1063. if (qdSheet.getText(iRow, 0) === '') { continue; }
  1064. const qd = {
  1065. b_code: qdSheet.getText(iRow, 0),
  1066. name: qdSheet.getText(iRow, 1),
  1067. unit: qdSheet.getText(iRow, 2),
  1068. price: _.toNumber(qdSheet.getText(iRow, 3)),
  1069. pos: [],
  1070. };
  1071. result.push(qd);
  1072. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  1073. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  1074. if (value !== 0 && !isNaN(value)) {
  1075. qd.pos.push({
  1076. name: posSheet.getText(iPosRow, 0),
  1077. drawing_code: posSheet.getText(iPosRow, 1),
  1078. quantity: value,
  1079. });
  1080. }
  1081. }
  1082. }
  1083. return result;
  1084. }
  1085. }
  1086. let stdXmj, stdGcl, searchLedger;
  1087. const dealBills = new DealBills('#deal-bills-spread', {
  1088. cols: [
  1089. {title: '清单编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1090. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  1091. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1092. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1093. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1094. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1095. ],
  1096. emptyRows: 0,
  1097. headRows: 1,
  1098. headRowHeight: [40],
  1099. defaultRowHeight: 21,
  1100. });
  1101. $.divResizer({
  1102. select: '#revise-right-spr',
  1103. callback: function () {
  1104. billsSpread.refresh();
  1105. if (posSpread) {
  1106. posSpread.refresh();
  1107. }
  1108. if (stdXmj) {
  1109. stdXmj.spread.refresh();
  1110. }
  1111. if (stdGcl) {
  1112. stdGcl.spread.refresh();
  1113. }
  1114. }
  1115. });
  1116. // 展开收起标准清单
  1117. $('a', '#side-menu').bind('click', function (e) {
  1118. e.preventDefault();
  1119. const tab = $(this), tabPanel = $(tab.attr('content'));
  1120. const showSideTools = function (show) {
  1121. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1122. if (show) {
  1123. right.show();
  1124. autoFlashHeight();
  1125. /**
  1126. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1127. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1128. * 故需要通过最终的parent.width再计算一次left.width
  1129. *
  1130. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1131. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1132. *
  1133. */
  1134. //left.css('width', parent.width() - right.outerWidth());
  1135. //left.css('width', parent.width() - right.outerWidth());
  1136. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1137. left.css('width', percent + '%');
  1138. } else {
  1139. left.width(parent.width());
  1140. right.hide();
  1141. }
  1142. };
  1143. // 展开工具栏、切换标签
  1144. if (!tab.hasClass('active')) {
  1145. const close = $('.active', '#side-menu').length === 0;
  1146. $('a', '#side-menu').removeClass('active');
  1147. tab.addClass('active');
  1148. $('.tab-content .tab-pane').removeClass('active');
  1149. tabPanel.addClass('active');
  1150. showSideTools(tab.hasClass('active'));
  1151. if (tab.attr('content') === '#std-xmj') {
  1152. if (!stdXmj) {
  1153. stdXmj = new stdLib('#std-xmj', 'xmj', {
  1154. id: 'chapter_id',
  1155. pid: 'pid',
  1156. order: 'order',
  1157. level: 'level',
  1158. rootId: -1,
  1159. keys: ['id', 'list_id', 'chapter_id'],
  1160. }, {
  1161. cols: [
  1162. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1163. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  1164. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1165. ],
  1166. treeCol: 0,
  1167. emptyRows: 0,
  1168. headRows: 1,
  1169. headRowHeight: [40],
  1170. defaultRowHeight: 21,
  1171. });
  1172. stdXmj.loadLib($('select', '#std-xmj').val());
  1173. }
  1174. stdXmj.spread.refresh();
  1175. } else if (tab.attr('content') === '#std-gcl') {
  1176. if (!stdGcl) {
  1177. stdGcl = new stdLib('#std-gcl', 'gcl', {
  1178. id: 'bill_id',
  1179. pid: 'pid',
  1180. order: 'order',
  1181. level: 'level',
  1182. rootId: -1,
  1183. keys: ['id', 'list_id', 'bill_id']
  1184. }, {
  1185. cols: [
  1186. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1187. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  1188. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1189. ],
  1190. treeCol: 0,
  1191. emptyRows: 0,
  1192. headRows: 1,
  1193. headRowHeight: [40],
  1194. defaultRowHeight: 21,
  1195. });
  1196. stdGcl.loadLib($('select', '#std-gcl').val());
  1197. }
  1198. stdGcl.spread.refresh();
  1199. } else if (tab.attr('content') === '#deal-bills') {
  1200. dealBills.loadData();
  1201. dealBills.spread.refresh();
  1202. } else if (tab.attr('content') === '#search' && !searchLedger) {
  1203. if (!searchLedger) {
  1204. searchLedger = $.billsSearch({
  1205. selector: '#search',
  1206. searchSpread: billsSpread,
  1207. resultSpreadSetting: {
  1208. cols: [
  1209. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1210. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1211. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  1212. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  1213. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1214. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1215. ],
  1216. emptyRows: 0,
  1217. headRows: 1,
  1218. headRowHeight: [40],
  1219. defaultRowHeight: 21,
  1220. },
  1221. afterLocated: function () {
  1222. posSpreadObj.loadCurPosData();
  1223. }
  1224. });
  1225. }
  1226. searchLedger.spread.refresh();
  1227. }
  1228. }
  1229. billsSpread.refresh();
  1230. if (posSpread) {
  1231. posSpread.refresh();
  1232. }
  1233. });
  1234. if (!readOnly) {
  1235. // 修订详情 保存
  1236. $('#save').click(function () {
  1237. const content = $('textarea').val();
  1238. postData('save', { content: content });
  1239. });
  1240. }
  1241. // 显示层次
  1242. (function (select, sheet) {
  1243. $(select).click(function () {
  1244. if (!sheet.zh_tree) return;
  1245. const tag = $(this).attr('tag');
  1246. const tree = sheet.zh_tree;
  1247. switch (tag) {
  1248. case "1":
  1249. case "2":
  1250. case "3":
  1251. case "4":
  1252. case "5":
  1253. tree.expandByLevel(parseInt(tag));
  1254. SpreadJsObj.refreshTreeRowVisible(sheet);
  1255. break;
  1256. case "last":
  1257. tree.expandByCustom(() => { return true; });
  1258. SpreadJsObj.refreshTreeRowVisible(sheet);
  1259. break;
  1260. case "leafXmj":
  1261. tree.expandToLeafXmj();
  1262. SpreadJsObj.refreshTreeRowVisible(sheet);
  1263. break;
  1264. }
  1265. });
  1266. })('a[name=showLevel]', billsSheet);
  1267. });