revise.js 59 KB

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