revise.js 58 KB

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