revise.js 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  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 = ledgerSpread.getActiveSheet();
  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. billsSpread.refresh();
  1213. if (posSpread) {
  1214. posSpread.refresh();
  1215. }
  1216. });
  1217. if (!readOnly) {
  1218. // 修订详情 保存
  1219. $('#save').click(function () {
  1220. const content = $('textarea').val();
  1221. postData('save', { content: content });
  1222. });
  1223. }
  1224. // 显示层次
  1225. (function (select, sheet) {
  1226. $(select).click(function () {
  1227. if (!sheet.zh_tree) return;
  1228. const tag = $(this).attr('tag');
  1229. const tree = sheet.zh_tree;
  1230. switch (tag) {
  1231. case "1":
  1232. case "2":
  1233. case "3":
  1234. case "4":
  1235. case "5":
  1236. tree.expandByLevel(parseInt(tag));
  1237. SpreadJsObj.refreshTreeRowVisible(sheet);
  1238. break;
  1239. case "last":
  1240. tree.expandByCustom(() => { return true; });
  1241. SpreadJsObj.refreshTreeRowVisible(sheet);
  1242. break;
  1243. case "leafXmj":
  1244. tree.expandToLeafXmj();
  1245. SpreadJsObj.refreshTreeRowVisible(sheet);
  1246. break;
  1247. }
  1248. });
  1249. })('a[name=showLevel]', billsSheet);
  1250. });