revise.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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('ledger', 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. /**
  64. * 刷新顶部按钮是否可用
  65. * @param sheet
  66. * @param selections
  67. */
  68. refreshOperationValid: function (sheet) {
  69. const setObjEnable = function (obj, enable) {
  70. if (enable) {
  71. obj.removeClass('disabled');
  72. } else {
  73. obj.addClass('disabled');
  74. }
  75. };
  76. const tree = sheet.zh_tree;
  77. const node = SpreadJsObj.getSelectObject(sheet);
  78. const preNode = tree.getPreSiblingNode(node);
  79. const valid = !sheet.zh_setting.readOnly;
  80. setObjEnable($('a[type="add"]'), valid);
  81. setObjEnable($('a[type="delete"]'), valid && node);
  82. setObjEnable($('a[type="up-move"]'), valid && node && preNode);
  83. setObjEnable($('a[type="down-move"]'), valid && node && !tree.isLastSibling(node));
  84. if (isTz) {
  85. const posRange = node ? pos.getLedgerPos(node.id) : [];
  86. setObjEnable($('a[type="up-level"]'), valid && node && tree.getParent(node) && node.level > 2 && (!posRange || posRange.length === 0));
  87. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  88. setObjEnable($('a[type="down-level"]'), valid && node && preNode && (!preNodePosRange || preNodePosRange.length === 0));
  89. } else {
  90. setObjEnable($('#up-level'), valid && node && tree.getParent(node));
  91. setObjEnable($('#down-level'), valid && node && preNode);
  92. }
  93. setObjEnable($('#cut'), valid);
  94. setObjEnable($('#paste'), valid);
  95. },
  96. /**
  97. *
  98. * @param sheet
  99. * @param data
  100. */
  101. refreshTree: function (sheet, data) {
  102. SpreadJsObj.massOperationSheet(sheet, function () {
  103. const tree = sheet.zh_tree;
  104. // 处理删除
  105. if (data.delete) {
  106. for (const d of data.delete) {
  107. sheet.deleteRows(tree.nodes.indexOf(d), 1);
  108. }
  109. }
  110. // 处理新增
  111. if (data.create) {
  112. const newNodes = data.create;
  113. if (newNodes) {
  114. newNodes.sort(function (a, b) {
  115. return a.index - b.index;
  116. });
  117. for (const node of newNodes) {
  118. sheet.addRows(node.index, 1);
  119. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  120. }
  121. }
  122. }
  123. // 处理更新
  124. if (data.update) {
  125. const rows = [];
  126. for (const u of data.update) {
  127. rows.push(tree.nodes.indexOf(u));
  128. }
  129. SpreadJsObj.reLoadRowsData(sheet, rows);
  130. }
  131. // 处理展开
  132. if (data.expand) {
  133. const expanded = [];
  134. for (const e of data.expand) {
  135. if (expanded.indexOf(e) === -1) {
  136. const posterity = tree.getPosterity(e);
  137. for (const p of posterity) {
  138. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  139. expanded.push(p);
  140. }
  141. }
  142. }
  143. }
  144. });
  145. },
  146. selectionChanged: function (e, info) {
  147. if (info.newSelections[0].row !== info.oldSelections[0].row) {
  148. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  149. posSpreadObj.loadCurPosData();
  150. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  151. posSearch.search($('#pos-keyword').val());
  152. }
  153. },
  154. /**
  155. * 新增节点
  156. * @param spread
  157. */
  158. baseOpr: function (sheet, type) {
  159. const self = this;
  160. const tree = sheet.zh_tree;
  161. const node = SpreadJsObj.getSelectObject(sheet);
  162. if (!tree || !node) return;
  163. postData(window.location.pathname + '/base-opr', {id: node.ledger_id, postType: type}, function (result) {
  164. const refreshData = tree.loadPostData(result);
  165. self.refreshTree(sheet, refreshData);
  166. if (['up-move', 'down-move', 'up-level', 'down-level'].indexOf(type) > -1) {
  167. const sel = sheet.getSelections()[0];
  168. if (sel) {
  169. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  170. }
  171. }
  172. self.refreshOperationValid(sheet);
  173. });
  174. },
  175. /**
  176. * 编辑单元格响应事件
  177. * @param {Object} e
  178. * @param {Object} info
  179. */
  180. editEnded: function (e, info) {
  181. if (info.sheet.zh_setting) {
  182. const col = info.sheet.zh_setting.cols[info.col];
  183. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  184. const node = sortData[info.row];
  185. const data = {
  186. id: node.id,
  187. tender_id: node.tender_id,
  188. ledger_id: node.ledger_id
  189. };
  190. // 未改变值则不提交
  191. const orgValue = node[col.field];
  192. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (info.editingText === ''))) {
  193. return;
  194. }
  195. // 台账模式,检查部位明细相关
  196. if (checkTzMeasureType()) {
  197. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  198. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  199. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  200. if (!node.children || node.children.length ===0) {
  201. const lPos = pos.getLedgerPos(node.id);
  202. if (lPos && lPos.length > 0) {
  203. toast('清单含有部位明细,不可修改施工图复核数量', 'error');
  204. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  205. return;
  206. }
  207. }
  208. }
  209. if (col.field === 'b_code' && (info.editingText === '' || !info.editingText)) {
  210. const lPos = pos.getLedgerPos(node.id);
  211. if (lPos && lPos.length > 0) {
  212. toast('清单含有部位明细,请先删除部位明细,再删除清单编号', 'error');
  213. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  214. return;
  215. }
  216. }
  217. }
  218. // 获取更新数据
  219. if (info.editingText) {
  220. data[col.field] = col.type === 'Number' ? parseFloat(info.editingText) : info.editingText.replace('\n', '');
  221. } else {
  222. data[col.field] = null;
  223. }
  224. // 更新至服务器
  225. info.sheet.zh_tree.update('/tender/' + getTenderId() + '/ledger/update', data, function (result) {
  226. treeOperationObj.refreshTree(info.sheet, result);
  227. });
  228. }
  229. },
  230. topRowChanged: function (e, info) {
  231. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  232. },
  233. };
  234. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  235. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  236. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  237. if (!readOnly) {
  238. // 增删上下移升降级
  239. $('a[name="base-opr"]').click(function () {
  240. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  241. });
  242. let batchInsertObj;
  243. // 右键菜单
  244. $.contextMenu({
  245. selector: '#bills-spread',
  246. build: function ($trigger, e) {
  247. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  248. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  249. },
  250. items: {
  251. 'batchInsertBillsPos': {
  252. name: '批量插入清单-部位',
  253. icon: 'fa-sign-in',
  254. disabled: function (key, opt) {
  255. const select = SpreadJsObj.getSelectObject(billsSheet);
  256. if (select) {
  257. if (select.code && select.code !== '') {
  258. return !billsTree.isLeafXmj(select);
  259. } else {
  260. const parent = billsTree.getParent(select);
  261. return !(parent && billsTree.isLeafXmj(parent));
  262. }
  263. } else {
  264. return false;
  265. }
  266. },
  267. callback: function (key, opt) {
  268. if (!batchInsertObj) {
  269. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  270. } else {
  271. batchInsertObj.initView();
  272. }
  273. $('#batch').modal('show');
  274. }
  275. },
  276. }
  277. });
  278. }
  279. const posSpreadObj = {
  280. /**
  281. * 加载部位明细 根据当前台账选择节点
  282. */
  283. loadCurPosData: function () {
  284. const node = SpreadJsObj.getSelectObject(billsSheet);
  285. if (node) {
  286. const posData = pos.getLedgerPos(node.id) || [];
  287. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  288. } else {
  289. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  290. }
  291. SpreadJsObj.resetFieldReadOnly(posSheet);
  292. },
  293. editStarting: function (e, info) {
  294. posSpreadObj.ledgerTreeNode = SpreadJsObj.getSelectObject(billsSheet);
  295. },
  296. };
  297. posSpreadObj.loadCurPosData();
  298. SpreadJsObj.resetTopAndSelect(posSheet);
  299. $.divResizer({
  300. select: '#revise-resize',
  301. callback: function () {
  302. billsSpread.refresh();
  303. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  304. $(".sp-wrap").height(bcontent-40);
  305. posSpread.refresh();
  306. }
  307. });
  308. class stdLib {
  309. constructor(obj, stdType, treeSetting, spreadSetting) {
  310. this.obj = obj;
  311. this.url = '/std/' + stdType;
  312. this.treeSetting = treeSetting;
  313. treeSetting.preUrl = this.url;
  314. this.spreadSetting = spreadSetting;
  315. this.spread = SpreadJsObj.createNewSpread(this.obj);
  316. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  317. this.spread.getActiveSheet().bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  318. const stdSheet = info.sheet;
  319. const mainSheet = ledgerSpread.getActiveSheet();
  320. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  321. const stdTree = stdSheet.zh_tree;
  322. const stdNode = stdTree.nodes[info.row];
  323. const mainTree = mainSheet.zh_tree;
  324. const sel = mainSheet.getSelections()[0];
  325. const mainNode = mainTree.nodes[sel.row];
  326. if (!stdNode) { return; }
  327. mainTree.postData('/tender/' + getTenderId() + '/ledger/add-by-std', mainNode, {
  328. tender_id: mainNode.tender_id,
  329. stdType: stdType,
  330. stdLibId: stdNode.list_id,
  331. stdNode: stdTree.getNodeKey(stdNode)
  332. }, function (result) {
  333. treeOperationObj.refreshTree(mainSheet, result);
  334. treeOperationObj.refreshOperationValid(mainSheet);
  335. });
  336. });
  337. this.pathTree = createNewPathTree('base', this.treeSetting);
  338. }
  339. loadLib (listId) {
  340. const self = this;
  341. postData(this.url+'/get-data', {list_id: listId}, function (data) {
  342. self.pathTree.loadDatas(data);
  343. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'tree', self.pathTree);
  344. });
  345. }
  346. }
  347. class DealBills {
  348. constructor (selector, spreadSetting) {
  349. const self = this;
  350. this.loaded = false;
  351. this.obj = $(selector)[0];
  352. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  353. this.spreadSetting = spreadSetting;
  354. this.spread = SpreadJsObj.createNewSpread(this.obj);
  355. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  356. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  357. const dealSheet = info.sheet;
  358. const mainSheet = ledgerSpread.getActiveSheet();
  359. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  360. if (!dealBills) { return; }
  361. const mainTree = mainSheet.zh_tree;
  362. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  363. if (!mainNode || !mainTree) { return; }
  364. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  365. toast('非最底层项目下,不应添加清单', 'error');
  366. return;
  367. }
  368. postData('/tender/' + getTenderId() + '/ledger/add-by-deal', {
  369. id: mainNode.ledger_id,
  370. type: mainNode.code ? 'child' : 'next',
  371. dealBills: {
  372. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  373. unit_price: dealBills.unit_price,
  374. },
  375. }, function (result) {
  376. const refreshData = mainTree.loadPostData(result);
  377. treeOperationObj.refreshTree(mainSheet, refreshData);
  378. treeOperationObj.refreshOperationValid(mainSheet);
  379. });
  380. });
  381. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  382. }
  383. loadData () {
  384. if (this.loaded) return;
  385. const self = this;
  386. postData(this.url+'/get-data', {}, function (data) {
  387. self.data = data;
  388. //self.calculateData();
  389. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  390. self.loaded = true;
  391. });
  392. }
  393. calculateData () {
  394. if (this.data) {
  395. for (const d of this.data) {
  396. d.total_price = _.multiply(d.quantity, d.unit_price);
  397. }
  398. }
  399. }
  400. }
  401. class BatchInsertBillsPosObj {
  402. constructor (obj) {
  403. const self = this;
  404. this.obj = obj;
  405. this.billsCount = 6;
  406. this.posCount = 1000;
  407. // 初始化 清单编号窗口 参数
  408. this.qdSpreadSetting = {
  409. cols: [
  410. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  411. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  412. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  413. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  414. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  415. ],
  416. emptyRows: this.billsCount,
  417. headRows: 1,
  418. headRowHeight: [40],
  419. };
  420. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  421. // 初始化 部位数量复核表 参数
  422. this.posSpreadSetting = {
  423. cols: [
  424. {title: '部位', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  425. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  426. ],
  427. emptyRows: this.posCount,
  428. headRows: 1,
  429. headRowHeight: [40],
  430. };
  431. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  432. this.posSpreadSetting.cols.push(
  433. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  434. )
  435. }
  436. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  437. // 初始化 签约清单 参数
  438. this.dealSpreadSetting = {
  439. cols: [
  440. {title: '清单编号', field: 'code', width: 80, formatter: '@', readOnly: true},
  441. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true},
  442. {title: '单位', field: 'unit', width: 50, formatter: '@', readOnly: true},
  443. {title: '单价', field: 'unit_price', width: 50, readOnly: true},
  444. ],
  445. emptyRows: 0,
  446. headRows: 1,
  447. headRowHeight: [40],
  448. };
  449. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  450. // 初始化 清单编号、部位数量复核表 表格
  451. this.initView();
  452. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  453. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  454. // 拉取签约清单数据
  455. dealBills.loadData();
  456. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  457. // 双击签约清单,自动添加到清单编号窗口
  458. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  459. const deal = info.sheet.zh_data[info.row];
  460. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  461. const sel = qdSheet.getSelections()[0];
  462. qdSheet.getCell(sel.row, 0).value(deal.code);
  463. qdSheet.getCell(sel.row, 1).value(deal.name);
  464. qdSheet.getCell(sel.row, 2).value(deal.unit);
  465. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  466. if (sel.row + 1 === qdSheet.getRowCount()) {
  467. const count = sel.row + 2;
  468. qdSheet.setRowCount(count);
  469. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  470. const colCount = posSheet.getColumnCount() + 1
  471. posSheet.setColumnCount(colCount);
  472. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('数量' + count);
  473. }
  474. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  475. });
  476. this.obj.bind('shown.bs.modal', function () {
  477. self.qdSpread.refresh();
  478. self.posSpread.refresh();
  479. self.dealSpread.refresh();
  480. });
  481. $('#batch-ok').click(function () {
  482. const selection = billsSheet.getSelections();
  483. const row = selection[0].row;
  484. const select = billsTree.nodes[row];
  485. if (select) {
  486. const insertData = {};
  487. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  488. insertData.id = select[billsTree.setting.id];
  489. insertData.batchData = self.getBatchData();
  490. postData(window.location.pathname + '/batch-insert', insertData, function (data) {
  491. pos.updateDatas(data.pos);
  492. const result = billsTree.loadPostData(data.ledger);
  493. billsTreeSpreadObj.refreshTree(billsSheet, result);
  494. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  495. self.obj.modal('hide');
  496. });
  497. }
  498. });
  499. }
  500. // 初始化左侧表格
  501. initView () {
  502. // 初始化 清单编号
  503. const qdSheet = this.qdSpread.getActiveSheet();
  504. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  505. SpreadJsObj.refreshColumnAlign(qdSheet);
  506. // 清理原有数据
  507. SpreadJsObj.beginMassOperation(qdSheet);
  508. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  509. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  510. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  511. }
  512. qdSheet.setSelection(0, 0, 1 ,1);
  513. SpreadJsObj.endMassOperation(qdSheet);
  514. // 初始化 部位数量复核表
  515. const posSheet = this.posSpread.getActiveSheet();
  516. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  517. SpreadJsObj.refreshColumnAlign(posSheet);
  518. // 清理原有数据
  519. SpreadJsObj.beginMassOperation(posSheet);
  520. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  521. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  522. posSheet.setSelection(0, 0, 1 ,1);
  523. SpreadJsObj.endMassOperation(posSheet);
  524. // 检查签约清单数据,以工具栏数据为准
  525. if (dealBills) {
  526. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  527. }
  528. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  529. }
  530. // 获取界面数据
  531. getBatchData () {
  532. const result = [];
  533. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  534. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  535. if (qdSheet.getText(iRow, 0) === '') { continue; }
  536. const qd = {
  537. b_code: qdSheet.getText(iRow, 0),
  538. name: qdSheet.getText(iRow, 1),
  539. unit: qdSheet.getText(iRow, 2),
  540. price: _.toNumber(qdSheet.getText(iRow, 3)),
  541. pos: [],
  542. };
  543. result.push(qd);
  544. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  545. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  546. if (value !== 0 && !isNaN(value)) {
  547. qd.pos.push({
  548. name: posSheet.getText(iPosRow, 0),
  549. drawing_code: posSheet.getText(iPosRow, 1),
  550. quantity: value,
  551. });
  552. }
  553. }
  554. }
  555. return result;
  556. }
  557. }
  558. let stdChapter, stdBills, searchLedger;
  559. const dealBills = new DealBills('#deal-bills-spread', {
  560. cols: [
  561. {title: '清单编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  562. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  563. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  564. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  565. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  566. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  567. ],
  568. emptyRows: 0,
  569. headRows: 1,
  570. headRowHeight: [40],
  571. defaultRowHeight: 21,
  572. });
  573. $.divResizer({
  574. select: '#revise-right-spr',
  575. callback: function () {
  576. billsSpread.refresh();
  577. if (posSpread) {
  578. posSpread.refresh();
  579. }
  580. if (stdChapter) {
  581. stdChapter.spread.refresh();
  582. }
  583. if (stdBills) {
  584. stdBills.spread.refresh();
  585. }
  586. }
  587. });
  588. // 展开收起标准清单
  589. $('a', '#side-menu').bind('click', function (e) {
  590. e.preventDefault();
  591. const tab = $(this), tabPanel = $(tab.attr('content'));
  592. const showSideTools = function (show) {
  593. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  594. if (show) {
  595. right.show();
  596. autoFlashHeight();
  597. /**
  598. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  599. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  600. * 故需要通过最终的parent.width再计算一次left.width
  601. *
  602. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  603. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  604. *
  605. */
  606. //left.css('width', parent.width() - right.outerWidth());
  607. //left.css('width', parent.width() - right.outerWidth());
  608. const percent = 100 - right.outerWidth() /parent.width() * 100;
  609. left.css('width', percent + '%');
  610. } else {
  611. left.width(parent.width());
  612. right.hide();
  613. }
  614. };
  615. // 展开工具栏、切换标签
  616. if (!tab.hasClass('active')) {
  617. const close = $('.active', '#side-menu').length === 0;
  618. $('a', '#side-menu').removeClass('active');
  619. tab.addClass('active');
  620. $('.tab-content .tab-pane').removeClass('active');
  621. tabPanel.addClass('active');
  622. showSideTools(tab.hasClass('active'));
  623. if (tab.attr('content') === '#std-chapter') {
  624. if (!stdChapter) {
  625. stdChapter = new stdLib($('#std-chapter-spread')[0], 'chapter', {
  626. id: 'chapter_id',
  627. pid: 'pid',
  628. order: 'order',
  629. level: 'level',
  630. rootId: -1,
  631. keys: ['id', 'list_id', 'chapter_id'],
  632. }, {
  633. cols: [
  634. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  635. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  636. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  637. ],
  638. treeCol: 0,
  639. emptyRows: 0,
  640. headRows: 1,
  641. headRowHeight: [40],
  642. defaultRowHeight: 21,
  643. });
  644. stdChapter.loadLib(1);
  645. }
  646. stdChapter.spread.refresh();
  647. } else if (tab.attr('content') === '#std-bills') {
  648. if (!stdBills) {
  649. stdBills = new stdLib($('#std-bills-spread')[0], 'bills', {
  650. id: 'bill_id',
  651. pid: 'pid',
  652. order: 'order',
  653. level: 'level',
  654. rootId: -1,
  655. keys: ['id', 'list_id', 'bill_id']
  656. }, {
  657. cols: [
  658. {title: '清单编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  659. {title: '名称', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  660. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  661. ],
  662. treeCol: 0,
  663. emptyRows: 0,
  664. headRows: 1,
  665. headRowHeight: [40],
  666. defaultRowHeight: 21,
  667. });
  668. stdBills.loadLib(1);
  669. }
  670. stdBills.spread.refresh();
  671. } else if (tab.attr('content') === '#deal-bills') {
  672. dealBills.loadData();
  673. dealBills.spread.refresh();
  674. } else if (tab.attr('content') === '#search' && !searchLedger) {
  675. if (!searchLedger) {
  676. searchLedger = $.billsSearch({
  677. selector: '#search',
  678. searchSpread: billsSpread,
  679. resultSpreadSetting: {
  680. cols: [
  681. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  682. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  683. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  684. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  685. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  686. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  687. ],
  688. emptyRows: 0,
  689. headRows: 1,
  690. headRowHeight: [40],
  691. defaultRowHeight: 21,
  692. },
  693. afterLocated: function () {
  694. posSpreadObj.loadCurPosData();
  695. }
  696. });
  697. }
  698. searchLedger.spread.refresh();
  699. }
  700. }
  701. billsSpread.refresh();
  702. if (posSpread) {
  703. posSpread.refresh();
  704. }
  705. });
  706. // 修订详情 保存
  707. $('#save').click(function () {
  708. const content = $('textarea').val();
  709. postData('save', { content: content });
  710. });
  711. // 显示层次
  712. (function (select, sheet) {
  713. if (!sheet.zh_tree) return;
  714. $(select).click(function () {
  715. const tag = $(this).attr('tag');
  716. const tree = sheet.zh_tree;
  717. switch (tag) {
  718. case "1":
  719. case "2":
  720. case "3":
  721. case "4":
  722. case "5":
  723. tree.expandByLevel(parseInt(tag));
  724. SpreadJsObj.refreshTreeRowVisible(sheet);
  725. break;
  726. case "last":
  727. tree.expandByCustom(() => { return true; });
  728. SpreadJsObj.refreshTreeRowVisible(sheet);
  729. break;
  730. case "leafXmj":
  731. tree.expandToLeafXmj();
  732. SpreadJsObj.refreshTreeRowVisible(sheet);
  733. break;
  734. }
  735. });
  736. })('a[name=showLevel]', billsSheet);
  737. });