revise.js 69 KB

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