revise.js 88 KB

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