revise.js 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  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. const self = this;
  747. if ($.isFunction(item.icon)) {
  748. item._icon = item.icon.call(this, this, $t, key, item);
  749. } else {
  750. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  751. // to enable font awesome
  752. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  753. } else {
  754. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  755. }
  756. }
  757. this.addClass(item._icon);
  758. 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>')
  759. .appendTo(this);
  760. const $input = $obj.find('input');
  761. const event = () => {
  762. if (self.hasClass('context-menu-disabled')) return;
  763. item.batchInsert($input[0], root);
  764. };
  765. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  766. $input.click((e) => {e.stopPropagation();})
  767. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  768. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  769. };
  770. // 右键菜单
  771. $.contextMenu({
  772. selector: '#bills-spread',
  773. build: function ($trigger, e) {
  774. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  775. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  776. },
  777. items: {
  778. 'create': {
  779. name: '新增',
  780. icon: 'fa-sign-in',
  781. callback: function (key, opt) {
  782. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  783. },
  784. disabled: function (key, opt) {
  785. const sheet = billsSheet;
  786. const selection = sheet.getSelections();
  787. const sel = selection ? selection[0] : sheet.getSelections()[0];
  788. const row = sel ? sel.row : -1;
  789. const tree = sheet.zh_tree;
  790. if (!tree) return true;
  791. const first = sheet.zh_tree.nodes[row];
  792. const valid = !sheet.zh_setting.readOnly;
  793. return !(valid && first && first.level > 1);
  794. }
  795. },
  796. 'delete': {
  797. name: '删除',
  798. icon: 'fa-remove',
  799. callback: function (key, opt) {
  800. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  801. },
  802. disabled: function (key, opt) {
  803. const sheet = billsSheet;
  804. const selection = sheet.getSelections();
  805. const sel = selection ? selection[0] : sheet.getSelections()[0];
  806. const row = sel ? sel.row : -1;
  807. const tree = sheet.zh_tree;
  808. if (!tree) return true;
  809. const first = sheet.zh_tree.nodes[row];
  810. let last = first, sameParent = true, nodeUsed = first.used;
  811. if (sel.rowCount > 1 && first) {
  812. for (let r = 1; r < sel.rowCount; r++) {
  813. const rNode = tree.nodes[sel.row + r];
  814. if (!rNode) {
  815. sameParent = false;
  816. break;
  817. }
  818. nodeUsed = nodeUsed || rNode.used;
  819. if (rNode.level > first.level) continue;
  820. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  821. sameParent = false;
  822. break;
  823. }
  824. last = rNode;
  825. }
  826. }
  827. const valid = !sheet.zh_setting.readOnly;
  828. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed);
  829. }
  830. },
  831. 'batchInsert': {
  832. name: '批量插入',
  833. type: 'batchInsert',
  834. value: '2',
  835. icon: 'fa-sign-in',
  836. batchInsert: function (obj, root) {
  837. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  838. obj.value = obj.max;
  839. toastr.warning('批量插入不可多于' + obj.max);
  840. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  841. obj.value = obj.min;
  842. toastr.warning('批量插入不可少于' + obj.min);
  843. } else {
  844. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  845. root.$menu.trigger('contextmenu:hide');
  846. }
  847. },
  848. disabled: function (key, opt) {
  849. const sheet = billsSheet;
  850. const selection = sheet.getSelections();
  851. const sel = selection ? selection[0] : sheet.getSelections()[0];
  852. const row = sel ? sel.row : -1;
  853. const tree = sheet.zh_tree;
  854. if (!tree) return true;
  855. const first = sheet.zh_tree.nodes[row];
  856. const valid = !sheet.zh_setting.readOnly;
  857. return !(valid && first && first.level > 1);
  858. }
  859. },
  860. 'batchInsertBillsPos': {
  861. name: '批量插入清单-计量单元',
  862. icon: 'fa-sign-in',
  863. disabled: function (key, opt) {
  864. if (!isTz) return true;
  865. const select = SpreadJsObj.getSelectObject(billsSheet);
  866. if (select) {
  867. if (select.code && select.code !== '') {
  868. return !billsTree.isLeafXmj(select);
  869. } else {
  870. const parent = billsTree.getParent(select);
  871. return !(parent && billsTree.isLeafXmj(parent));
  872. }
  873. } else {
  874. return false;
  875. }
  876. },
  877. callback: function (key, opt) {
  878. if (!batchInsertObj) {
  879. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  880. } else {
  881. batchInsertObj.initView();
  882. }
  883. $('#batch').modal('show');
  884. }
  885. }
  886. }
  887. });
  888. }
  889. const posSpreadObj = {
  890. /**
  891. * 加载计量单元 根据当前台账选择节点
  892. */
  893. loadCurPosData: function () {
  894. const node = SpreadJsObj.getSelectObject(billsSheet);
  895. if (node) {
  896. const posData = pos.getLedgerPos(node.id) || [];
  897. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  898. } else {
  899. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  900. }
  901. SpreadJsObj.resetFieldReadOnly(posSheet);
  902. },
  903. editStarting: function (e, info) {
  904. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  905. },
  906. /**
  907. * 编辑单元格响应事件
  908. * @param {Object} e
  909. * @param {Object} info
  910. */
  911. editEnded: function (e, info) {
  912. if (!info.sheet.zh_setting) {
  913. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  914. return;
  915. }
  916. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  917. const col = info.sheet.zh_setting.cols[info.col];
  918. const orgText = posData ? posData[col.field] : null;
  919. const newText = trimInvalidChar(info.sheet.getCell(info.row, info.col).text());
  920. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  921. const node = posSpreadObj.billsNode;
  922. if (!node) {
  923. toastr.error('数据错误,请选择台账节点后再试');
  924. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  925. return;
  926. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  927. toastr.error('父节点不可插入计量单元');
  928. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  929. return;
  930. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  931. toastr.error('项目节不可插入计量单元');
  932. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  933. return;
  934. }
  935. const data = {postType: 'pos'};
  936. if (col.field === 'name') {
  937. if (newText === '' && posData) {
  938. toastr.error('部位名称不可为空', 'error');
  939. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  940. return;
  941. } else if (!posData) {
  942. if (newText && newText !== '') {
  943. data.posPostType = 'add';
  944. const sortData = info.sheet.zh_data;
  945. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  946. data.postData = { name: newText, lid: node.id, porder: order};
  947. } else {
  948. return;
  949. }
  950. } else {
  951. data.posPostType = 'update';
  952. data.postData = {id: posData.id, name: newText};
  953. }
  954. } else if (!posData) {
  955. toastr.warning('新增部位请先输入名称');
  956. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  957. return;
  958. } else {
  959. data.posPostType = 'update';
  960. data.postData = {id: posData.id};
  961. if (col.type === 'Number') {
  962. const num = _.toNumber(newText);
  963. if (_.isFinite(num)) {
  964. data.postData[col.field] = num;
  965. } else {
  966. try {
  967. data.postData[col.field] = math.evaluate(transExpr(newText));
  968. } catch(err) {
  969. toastr.error('输入的表达式非法');
  970. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  971. return;
  972. }
  973. }
  974. } else {
  975. data.postData[col.field] = newText;
  976. }
  977. }
  978. postData(window.location.pathname + '/update', data, function (result) {
  979. const updateRst = pos.updateDatas(result.pos);
  980. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  981. if (updateRst.create.length > 0) {
  982. posSpreadObj.loadCurPosData();
  983. } else {
  984. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  985. }
  986. const loadResult = billsTree.loadPostData(result.ledger);
  987. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  988. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  989. }, function () {
  990. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  991. });
  992. },
  993. /**
  994. * 删除按钮响应事件
  995. * @param sheet
  996. */
  997. deletePress: function (sheet) {
  998. if (!sheet.zh_settting) return;
  999. const sortData = sheet.zh_data;
  1000. const datas = [], posSelects = [];
  1001. const sel = sheet.getSelections()[0];
  1002. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1003. let bDel = false;
  1004. const node = sortData[iRow];
  1005. if (node) {
  1006. const data = {id: node.id};
  1007. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1008. const colSetting = sheet.zh_setting.cols[iCol];
  1009. if (colSetting.field === 'name') {
  1010. toastr.error('部位名称不能为空');
  1011. return;
  1012. }
  1013. const style = sheet.getStyle(iRow, iCol);
  1014. if (!style.locked) {
  1015. const colSetting = sheet.zh_setting.cols[iCol];
  1016. data[colSetting.field] = null;
  1017. bDel = true;
  1018. }
  1019. }
  1020. if (bDel) {
  1021. datas.push(data);
  1022. posSelects.push(node);
  1023. }
  1024. }
  1025. }
  1026. if (datas.length > 0) {
  1027. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  1028. pos.updateDatas(result.pos);
  1029. posSpreadObj.loadCurPosData();
  1030. const loadResult = billsTree.loadPostData(result.ledger);
  1031. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1032. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1033. }, function () {
  1034. posSpreadObj.loadCurPosData();
  1035. });
  1036. }
  1037. },
  1038. /**
  1039. * 删除 计量单元
  1040. * @param sheet
  1041. */
  1042. deletePos: function (sheet) {
  1043. const selection = sheet.getSelections();
  1044. const data = {
  1045. postType: 'pos',
  1046. posPostType: 'delete',
  1047. postData: [],
  1048. };
  1049. const row = selection[0].row, count = selection[0].rowCount;
  1050. const sortData = sheet.zh_data;
  1051. for (let iRow = 0; iRow < count; iRow++) {
  1052. const posData = sortData[iRow + row];
  1053. if (posData) {
  1054. if (posData.used) {
  1055. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1056. return;
  1057. }
  1058. data.postData.push(sortData[iRow + row].id);
  1059. }
  1060. }
  1061. if (data.postData.length > 0) {
  1062. postData(window.location.pathname + '/update', data, function (result) {
  1063. pos.removeDatas(result.pos);
  1064. sheet.deleteRows(row, count);
  1065. const loadResult = billsTree.loadPostData(result.ledger);
  1066. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1067. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1068. });
  1069. }
  1070. },
  1071. clipboardPasting: function (e, info) {
  1072. if (!info.sheet.zh_setting) {
  1073. info.cancel = true;
  1074. return;
  1075. }
  1076. const range = info.cellRange;
  1077. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  1078. const posData = info.sheet.zh_data[iRow];
  1079. if (posData && posData.used) {
  1080. toastr.warning('"' + pos.name +'"已计量,请勿修改');
  1081. info.cancel = true;
  1082. return;
  1083. }
  1084. }
  1085. },
  1086. /**
  1087. * 粘贴单元格响应事件
  1088. * @param e
  1089. * @param info
  1090. */
  1091. clipboardPasted: function (e, info) {
  1092. const node = SpreadJsObj.getSelectObject(billsSheet);
  1093. if (node.code && (node.code !== '')) {
  1094. toastr.error('项目节不可含有节点明细');
  1095. posSpreadObj.loadCurPosData();
  1096. return;
  1097. }
  1098. if (node.children && (node.children.length > 0)) {
  1099. toastr.error('仅节点子项可以含有计量单元');
  1100. posSpreadObj.loadCurPosData();
  1101. return;
  1102. }
  1103. if (!info.sheet.zh_setting) {
  1104. posSpreadObj.loadCurPosData();
  1105. return;
  1106. }
  1107. const data = [];
  1108. const sortData = info.sheet.zh_data || [];
  1109. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1110. if (info.cellRange.col !== 0) {
  1111. toastr.warning('新增部位请先输入名称');
  1112. posSpreadObj.loadCurPosData();
  1113. return;
  1114. }
  1115. }
  1116. let bHint = false;
  1117. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1118. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1119. let bPaste = true;
  1120. const curRow = info.cellRange.row + iRow;
  1121. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  1122. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1123. const curCol = info.cellRange.col + iCol;
  1124. const colSetting = info.sheet.zh_setting.cols[curCol];
  1125. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1126. if (colSetting.type === 'Number') {
  1127. const num = _.toNumber(posData[colSetting.field]);
  1128. if (num) {
  1129. posData[colSetting.field] = num;
  1130. } else {
  1131. try {
  1132. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  1133. } catch (err) {
  1134. if (!bHint) {
  1135. toastr.warning('粘贴了非法表达式,已过滤');
  1136. bHint = true;
  1137. }
  1138. bPaste = false;
  1139. }
  1140. }
  1141. }
  1142. }
  1143. if (bPaste) {
  1144. data.push(posData);
  1145. }
  1146. }
  1147. if (data.length === 0) {
  1148. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1149. return;
  1150. }
  1151. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  1152. pos.updateDatas(result.pos);
  1153. posSpreadObj.loadCurPosData();
  1154. const loadResult = billsTree.loadPostData(result.ledger);
  1155. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1156. posSpreadObj.loadCurPosData();
  1157. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1158. }, function () {
  1159. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1160. });
  1161. },
  1162. selectionChanged: function (e, info) {
  1163. const col = info.sheet.zh_setting.cols[info.newSelections[0].col];
  1164. const cell = info.sheet.getCell(info.newSelections[0].col, info.newSelections[0].col);
  1165. if (col && col.type === 'Number') {
  1166. const data = SpreadJsObj.getSelectObject(info.sheet);
  1167. if (data) {
  1168. $('#pos-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field])
  1169. .attr('row', info.newSelections[0].row).attr('readOnly', readOnly || cell.locked());
  1170. } else {
  1171. $('#pos-expr').val('').attr('readOnly', true);
  1172. }
  1173. } else {
  1174. $('#pos-expr').val('').attr('readOnly', true);
  1175. }
  1176. },
  1177. addPegs: function (pegs) {
  1178. if (!pegs || pegs.length <= 0) return;
  1179. const node = SpreadJsObj.getSelectObject(billsSheet);
  1180. if (!node) return;
  1181. const sheet = posSpread.getActiveSheet();
  1182. const sortData = sheet.zh_data || [];
  1183. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1184. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1185. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  1186. pos.updateDatas(result.pos);
  1187. posSpreadObj.loadCurPosData();
  1188. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1189. });
  1190. }
  1191. };
  1192. posSpreadObj.loadCurPosData();
  1193. SpreadJsObj.resetTopAndSelect(posSheet);
  1194. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  1195. if (!readOnly) {
  1196. $('#pos-expr').bind('change mouseleave', function () {
  1197. if (this.readOnly) return;
  1198. const expr = $(this);
  1199. const select = SpreadJsObj.getSelectObject(posSheet);
  1200. const row = posSheet.getSelections()[0].row;
  1201. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1202. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1203. const data = {id: select.id};
  1204. if (newValue !== '') {
  1205. const num = _.toNumber(newValue);
  1206. if (num) {
  1207. data[field] = num;
  1208. } else {
  1209. try {
  1210. data[field] = math.evaluate(transExpr(newValue));
  1211. } catch (err) {
  1212. toastr.error('输入的表达式非法');
  1213. return;
  1214. }
  1215. }
  1216. } else {
  1217. data[field] = null;
  1218. }
  1219. // 更新至服务器
  1220. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  1221. const updateRst = pos.updateDatas(result.pos);
  1222. expr.val(select[field]);
  1223. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1224. SpreadJsObj.reLoadRowData(posSheet, row);
  1225. const loadResult = billsTree.loadPostData(result.ledger);
  1226. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1227. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1228. });
  1229. });
  1230. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  1231. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  1232. posSpread.bind(spreadNS.Events.ClipboardPasting, posSpreadObj.clipboardPasting);
  1233. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  1234. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  1235. const mergePeg = NewMergePeg({ callback: posSpreadObj.addPegs });
  1236. $.contextMenu({
  1237. selector: '#pos-spread',
  1238. build: function ($trigger, e) {
  1239. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  1240. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1241. },
  1242. items: {
  1243. 'delete': {
  1244. name: '删除',
  1245. icon: 'fa-remove',
  1246. disabled: function (key, opt) {
  1247. if (posSheet.zh_data) {
  1248. const selection = posSheet.getSelections();
  1249. return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1250. } else {
  1251. return true;
  1252. }
  1253. },
  1254. callback: function (key, opt) {
  1255. posSpreadObj.deletePos(posSheet);
  1256. }
  1257. },
  1258. 'merge-peg': {
  1259. name: '合并起讫桩号',
  1260. disabled: function (key, opt) {
  1261. const node = SpreadJsObj.getSelectObject(billsSheet);
  1262. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1263. },
  1264. callback: function (key, opt) {
  1265. mergePeg.show();
  1266. }
  1267. }
  1268. }
  1269. });
  1270. }
  1271. $.divResizer({
  1272. select: '#revise-resize',
  1273. callback: function () {
  1274. billsSpread.refresh();
  1275. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1276. $(".sp-wrap").height(bcontent-40);
  1277. posSpread.refresh();
  1278. }
  1279. });
  1280. class DealBills {
  1281. constructor (selector, spreadSetting) {
  1282. const self = this;
  1283. this.loaded = false;
  1284. this.obj = $(selector)[0];
  1285. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  1286. this.spreadSetting = spreadSetting;
  1287. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1288. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1289. if (!readOnly) {
  1290. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1291. const dealSheet = info.sheet;
  1292. const mainSheet = billsSheet;
  1293. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  1294. if (!dealBills) { return; }
  1295. const mainTree = mainSheet.zh_tree;
  1296. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1297. if (!mainNode || !mainTree) { return; }
  1298. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1299. toastr.warning('非最底层项目下,不应添加节点');
  1300. return;
  1301. }
  1302. postData(window.location.pathname + '/update', {
  1303. postType: 'add-deal',
  1304. postData: {
  1305. id: mainNode.ledger_id,
  1306. type: mainNode.code ? 'child' : 'next',
  1307. dealBills: {
  1308. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  1309. unit_price: dealBills.unit_price,
  1310. }
  1311. },
  1312. }, function (result) {
  1313. const refreshData = mainTree.loadPostData(result);
  1314. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1315. const sel = mainSheet.getSelections()[0];
  1316. if (sel && refreshData.create[0]) {
  1317. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1318. }
  1319. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1320. billsSpread.focus();
  1321. posSpreadObj.loadCurPosData();
  1322. });
  1323. });
  1324. }
  1325. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1326. }
  1327. loadData (callback) {
  1328. if (this.loaded) {
  1329. if (callback) callback();
  1330. return;
  1331. }
  1332. const self = this;
  1333. postData(this.url+'/get-data', {}, function (data) {
  1334. self.data = data;
  1335. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1336. self.loaded = true;
  1337. if (callback) callback();
  1338. });
  1339. }
  1340. calculateData () {
  1341. if (this.data) {
  1342. for (const d of this.data) {
  1343. d.total_price = _.multiply(d.quantity, d.unit_price);
  1344. }
  1345. }
  1346. }
  1347. }
  1348. class BgBills {
  1349. constructor (selector, spreadSetting) {
  1350. this.loaded = false;
  1351. this.obj = $(selector)[0];
  1352. this.spreadSetting = spreadSetting;
  1353. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1354. this.sheet = this.spread.getActiveSheet();
  1355. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1356. if (!readOnly) {
  1357. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1358. const dealSheet = info.sheet;
  1359. const mainSheet = billsSheet;
  1360. const bgBills = SpreadJsObj.getSelectObject(dealSheet);
  1361. if (!bgBills) { return; }
  1362. const mainTree = mainSheet.zh_tree;
  1363. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1364. if (!mainNode || !mainTree) { return; }
  1365. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1366. toastr.warning('非最底层项目下,不应添加变更清单');
  1367. return;
  1368. }
  1369. postData(window.location.pathname + '/update', {
  1370. postType: 'add-bg',
  1371. postData: {
  1372. id: mainNode.ledger_id,
  1373. type: mainNode.code ? 'child' : 'next',
  1374. dealBills: {
  1375. b_code: bgBills.code, name: bgBills.name, unit: bgBills.unit,
  1376. unit_price: bgBills.unit_price,
  1377. }
  1378. },
  1379. }, function (result) {
  1380. const refreshData = mainTree.loadPostData(result);
  1381. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1382. const sel = mainSheet.getSelections()[0];
  1383. if (sel && refreshData.create[0]) {
  1384. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1385. }
  1386. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1387. billsSpread.focus();
  1388. posSpreadObj.loadCurPosData();
  1389. });
  1390. });
  1391. }
  1392. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1393. }
  1394. loadData () {
  1395. if (this.loaded) return;
  1396. const self = this;
  1397. postData('/tender/' + window.location.pathname.split('/')[2] +'/change/bills', {type: 'gather'}, function (data) {
  1398. self.data = data;
  1399. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1400. self.loaded = true;
  1401. });
  1402. }
  1403. }
  1404. class BatchInsertBillsPosObj {
  1405. constructor (obj) {
  1406. const self = this;
  1407. this.obj = obj;
  1408. this.billsCount = 6;
  1409. this.posCount = 1000;
  1410. // 初始化 清单编号窗口 参数
  1411. this.qdSpreadSetting = {
  1412. cols: [
  1413. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  1414. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  1415. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  1416. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1417. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  1418. ],
  1419. emptyRows: this.billsCount,
  1420. headRows: 1,
  1421. headRowHeight: [32],
  1422. headerFont: '12px 微软雅黑',
  1423. font: '12px 微软雅黑',
  1424. };
  1425. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  1426. // 初始化 部位数量复核表 参数
  1427. this.posSpreadSetting = {
  1428. cols: [
  1429. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  1430. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  1431. ],
  1432. emptyRows: this.posCount,
  1433. headRows: 1,
  1434. headRowHeight: [32],
  1435. headerFont: '12px 微软雅黑',
  1436. font: '12px 微软雅黑',
  1437. };
  1438. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  1439. this.posSpreadSetting.cols.push(
  1440. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  1441. )
  1442. }
  1443. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  1444. // 初始化 签约节点 参数
  1445. this.dealSpreadSetting = {
  1446. cols: [
  1447. {title: '清单编号', field: 'code', width: 80, formatter: '@', readOnly: true},
  1448. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true},
  1449. {title: '单位', field: 'unit', width: 50, formatter: '@', readOnly: true},
  1450. {title: '单价', field: 'unit_price', width: 50, readOnly: true},
  1451. ],
  1452. emptyRows: 0,
  1453. headRows: 1,
  1454. headRowHeight: [32],
  1455. headerFont: '12px 微软雅黑',
  1456. font: '12px 微软雅黑',
  1457. };
  1458. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  1459. // 初始化 清单编号、部位数量复核表 表格
  1460. this.initView();
  1461. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  1462. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  1463. // 拉取签约节点数据
  1464. dealBills.loadData(() => {
  1465. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1466. });
  1467. // 双击签约节点,自动添加到清单编号窗口
  1468. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1469. const deal = info.sheet.zh_data[info.row];
  1470. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  1471. const sel = qdSheet.getSelections()[0];
  1472. qdSheet.getCell(sel.row, 0).value(deal.code);
  1473. qdSheet.getCell(sel.row, 1).value(deal.name);
  1474. qdSheet.getCell(sel.row, 2).value(deal.unit);
  1475. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  1476. if (sel.row + 1 === qdSheet.getRowCount()) {
  1477. const count = sel.row + 2;
  1478. qdSheet.setRowCount(count);
  1479. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  1480. const colCount = posSheet.getColumnCount() + 1;
  1481. posSheet.setColumnCount(colCount);
  1482. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('数量' + count);
  1483. }
  1484. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  1485. qdSheet.getParent().focus();
  1486. });
  1487. this.obj.bind('shown.bs.modal', function () {
  1488. self.qdSpread.refresh();
  1489. self.posSpread.refresh();
  1490. self.dealSpread.refresh();
  1491. });
  1492. $('#batch-ok').click(function () {
  1493. const selection = billsSheet.getSelections();
  1494. const row = selection[0].row;
  1495. const select = billsTree.nodes[row];
  1496. if (select) {
  1497. const insertData = {};
  1498. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  1499. insertData.id = select[billsTree.setting.id];
  1500. insertData.batchData = self.getBatchData();
  1501. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  1502. pos.updateDatas(data.pos);
  1503. const result = billsTree.loadPostData(data.ledger);
  1504. billsTreeSpreadObj.refreshTree(billsSheet, result);
  1505. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  1506. self.obj.modal('hide');
  1507. }, null, true);
  1508. }
  1509. });
  1510. }
  1511. // 初始化左侧表格
  1512. initView () {
  1513. // 初始化 清单编号
  1514. const qdSheet = this.qdSpread.getActiveSheet();
  1515. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  1516. SpreadJsObj.refreshColumnAlign(qdSheet);
  1517. // 清理原有数据
  1518. SpreadJsObj.beginMassOperation(qdSheet);
  1519. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1520. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  1521. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  1522. }
  1523. qdSheet.setSelection(0, 0, 1 ,1);
  1524. SpreadJsObj.endMassOperation(qdSheet);
  1525. // 初始化 部位数量复核表
  1526. const posSheet = this.posSpread.getActiveSheet();
  1527. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  1528. SpreadJsObj.refreshColumnAlign(posSheet);
  1529. // 清理原有数据
  1530. SpreadJsObj.beginMassOperation(posSheet);
  1531. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  1532. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  1533. posSheet.setSelection(0, 0, 1 ,1);
  1534. SpreadJsObj.endMassOperation(posSheet);
  1535. // 检查签约节点数据,以工具栏数据为准
  1536. if (dealBills) {
  1537. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1538. }
  1539. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  1540. }
  1541. // 获取界面数据
  1542. getBatchData () {
  1543. const result = [];
  1544. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  1545. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  1546. if (qdSheet.getText(iRow, 0) === '') { continue; }
  1547. const qd = {
  1548. b_code: qdSheet.getText(iRow, 0),
  1549. name: qdSheet.getText(iRow, 1),
  1550. unit: qdSheet.getText(iRow, 2),
  1551. price: _.toNumber(qdSheet.getText(iRow, 3)),
  1552. pos: [],
  1553. };
  1554. result.push(qd);
  1555. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  1556. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  1557. if (value !== 0 && !isNaN(value)) {
  1558. qd.pos.push({
  1559. name: posSheet.getText(iPosRow, 0),
  1560. drawing_code: posSheet.getText(iPosRow, 1),
  1561. quantity: value,
  1562. });
  1563. }
  1564. }
  1565. }
  1566. return result;
  1567. }
  1568. }
  1569. const dealBills = new DealBills('#deal-bills-spread', {
  1570. cols: [
  1571. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1572. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1573. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1574. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1575. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1576. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1577. ],
  1578. emptyRows: 0,
  1579. headRows: 1,
  1580. headRowHeight: [32],
  1581. defaultRowHeight: 21,
  1582. headerFont: '12px 微软雅黑',
  1583. font: '12px 微软雅黑',
  1584. });
  1585. const bgBills = new BgBills('#bg-bills-spread', {
  1586. cols: [
  1587. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  1588. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1589. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1590. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1591. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1592. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  1593. ],
  1594. emptyRows: 0,
  1595. headRows: 1,
  1596. headRowHeight: [32],
  1597. defaultRowHeight: 21,
  1598. headerFont: '12px 微软雅黑',
  1599. font: '12px 微软雅黑',
  1600. });
  1601. $.divResizer({
  1602. select: '#revise-right-spr',
  1603. callback: function () {
  1604. billsSpread.refresh();
  1605. if (posSpread) {
  1606. posSpread.refresh();
  1607. }
  1608. if (stdXmj) {
  1609. stdXmj.spread.refresh();
  1610. }
  1611. if (stdGcl) {
  1612. stdGcl.spread.refresh();
  1613. }
  1614. if (dealBills) {
  1615. dealBills.spread.refresh();
  1616. }
  1617. if (bgBills) {
  1618. bgBills.spread.refresh();
  1619. }
  1620. if (searchLedger) {
  1621. searchLedger.spread.refresh();
  1622. }
  1623. }
  1624. });
  1625. $.subMenu({
  1626. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1627. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1628. key: 'menu.1.0.0',
  1629. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1630. callback: function (info) {
  1631. if (info.mini) {
  1632. $('.panel-title').addClass('fluid');
  1633. $('#sub-menu').removeClass('panel-sidebar');
  1634. } else {
  1635. $('.panel-title').removeClass('fluid');
  1636. $('#sub-menu').addClass('panel-sidebar');
  1637. }
  1638. autoFlashHeight();
  1639. billsSpread.refresh();
  1640. if (posSpread) {
  1641. posSpread.refresh();
  1642. }
  1643. if (stdXmj) {
  1644. stdXmj.spread.refresh();
  1645. }
  1646. if (stdGcl) {
  1647. stdGcl.spread.refresh();
  1648. }
  1649. if (dealBills) {
  1650. dealBills.spread.refresh();
  1651. }
  1652. if (bgBills) {
  1653. bgBills.spread.refresh();
  1654. }
  1655. if (searchLedger) {
  1656. searchLedger.spread.refresh();
  1657. }
  1658. }
  1659. });
  1660. const showSideTools = function (show) {
  1661. const left = $('#left-view'), right = $('#right-view'), parent = left.parent();
  1662. if (show) {
  1663. right.show();
  1664. autoFlashHeight();
  1665. /**
  1666. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  1667. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  1668. * 故需要通过最终的parent.width再计算一次left.width
  1669. *
  1670. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  1671. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  1672. *
  1673. */
  1674. //left.css('width', parent.width() - right.outerWidth());
  1675. //left.css('width', parent.width() - right.outerWidth());
  1676. const percent = 100 - right.outerWidth() /parent.width() * 100;
  1677. left.css('width', percent + '%');
  1678. } else {
  1679. left.width(parent.width());
  1680. right.hide();
  1681. }
  1682. };
  1683. $('#content-tab').addClass('active');
  1684. $('#xd-content').addClass('active');
  1685. showSideTools(true);
  1686. billsSpread.refresh();
  1687. if (posSpread) {
  1688. posSpread.refresh();
  1689. }
  1690. const stdLibCellDoubleClick = function (e, info) {
  1691. const stdSheet = info.sheet;
  1692. const mainSheet = billsSheet;
  1693. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  1694. const stdTree = stdSheet.zh_tree;
  1695. const stdNode = stdTree.nodes[info.row];
  1696. const mainTree = mainSheet.zh_tree;
  1697. const sel = mainSheet.getSelections()[0];
  1698. const mainNode = mainTree.nodes[sel.row];
  1699. if (!stdNode) return;
  1700. if (info.sheet.zh_setting.stdType === 'gcl') {
  1701. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1702. toastr.warning('非最底层项目下,不应添加节点');
  1703. return;
  1704. }
  1705. }
  1706. postData(window.location.pathname + '/update', {
  1707. postType: 'add-std',
  1708. postData: {
  1709. id: mainTree.getNodeKey(mainNode),
  1710. tender_id: mainNode.tender_id,
  1711. stdType: info.sheet.zh_setting.stdType,
  1712. stdLibId: stdNode.list_id,
  1713. stdNode: stdTree.getNodeKey(stdNode)
  1714. }
  1715. }, function (result) {
  1716. const refreshNode = mainTree.loadPostData(result);
  1717. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  1718. if (sel) {
  1719. if (refreshNode.create && refreshNode.create.length > 0) {
  1720. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  1721. } else {
  1722. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  1723. if (node) {
  1724. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  1725. }
  1726. }
  1727. }
  1728. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1729. billsSpread.focus();
  1730. posSpreadObj.loadCurPosData();
  1731. });
  1732. };
  1733. const stdXmjSetting = {
  1734. selector: '#std-xmj',
  1735. stdType: 'xmj',
  1736. treeSetting: {
  1737. id: 'chapter_id',
  1738. pid: 'pid',
  1739. order: 'order',
  1740. level: 'level',
  1741. rootId: -1,
  1742. keys: ['id', 'list_id', 'chapter_id'],
  1743. },
  1744. spreadSetting: {
  1745. cols: [
  1746. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1747. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1748. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1749. ],
  1750. treeCol: 0,
  1751. emptyRows: 0,
  1752. headRows: 1,
  1753. headRowHeight: [32],
  1754. defaultRowHeight: 21,
  1755. headerFont: '12px 微软雅黑',
  1756. font: '12px 微软雅黑',
  1757. headColWidth: [0],
  1758. },
  1759. cellDoubleClick: stdLibCellDoubleClick,
  1760. page: 'revise',
  1761. tid: window.location.pathname.split('/')[2],
  1762. };
  1763. const stdGclSetting = {
  1764. selector: '#std-gcl',
  1765. stdType: 'gcl',
  1766. treeSetting: {
  1767. id: 'bill_id',
  1768. pid: 'pid',
  1769. order: 'order',
  1770. level: 'level',
  1771. rootId: -1,
  1772. keys: ['id', 'list_id', 'bill_id']
  1773. },
  1774. spreadSetting: {
  1775. cols: [
  1776. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1777. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1778. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  1779. ],
  1780. treeCol: 0,
  1781. emptyRows: 0,
  1782. headRows: 1,
  1783. headRowHeight: [32],
  1784. defaultRowHeight: 21,
  1785. headerFont: '12px 微软雅黑',
  1786. font: '12px 微软雅黑',
  1787. headColWidth: [0],
  1788. },
  1789. cellDoubleClick: stdLibCellDoubleClick,
  1790. page: 'revise',
  1791. tid: window.location.pathname.split('/')[2],
  1792. };
  1793. // 展开收起标准节点
  1794. $('a', '#side-menu').bind('click', function (e) {
  1795. e.preventDefault();
  1796. const tab = $(this), tabPanel = $(tab.attr('content'));
  1797. // 展开工具栏、切换标签
  1798. if (!tab.hasClass('active')) {
  1799. const close = $('.active', '#side-menu').length === 0;
  1800. $('a', '#side-menu').removeClass('active');
  1801. tab.addClass('active');
  1802. $('.tab-content .tab-pane').removeClass('active');
  1803. tabPanel.addClass('active');
  1804. showSideTools(tab.hasClass('active'));
  1805. if (tab.attr('content') === '#std-xmj') {
  1806. if (!stdXmj) {
  1807. stdXmj = new stdLib(stdXmjSetting);
  1808. }
  1809. stdXmj.spread.refresh();
  1810. } else if (tab.attr('content') === '#std-gcl') {
  1811. if (!stdGcl) {
  1812. stdGcl = new stdLib(stdGclSetting);
  1813. }
  1814. stdGcl.spread.refresh();
  1815. } else if (tab.attr('content') === '#deal-bills') {
  1816. dealBills.loadData();
  1817. dealBills.spread.refresh();
  1818. } else if (tab.attr('content') === '#bg-bills') {
  1819. bgBills.loadData();
  1820. bgBills.spread.refresh();
  1821. } else if (tab.attr('content') === '#search' && !searchLedger) {
  1822. if (!searchLedger) {
  1823. searchLedger = $.billsSearch({
  1824. selector: '#search',
  1825. searchSpread: billsSpread,
  1826. resultSpreadSetting: {
  1827. cols: [
  1828. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1829. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  1830. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  1831. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  1832. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  1833. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  1834. ],
  1835. emptyRows: 0,
  1836. headRows: 1,
  1837. headRowHeight: [32],
  1838. defaultRowHeight: 21,
  1839. headerFont: '12px 微软雅黑',
  1840. font: '12px 微软雅黑',
  1841. },
  1842. afterLocated: function () {
  1843. posSpreadObj.loadCurPosData();
  1844. }
  1845. });
  1846. }
  1847. searchLedger.spread.refresh();
  1848. }
  1849. }
  1850. else {// 收起工具栏
  1851. tab.removeClass('active');
  1852. tabPanel.removeClass('active');
  1853. showSideTools(tab.hasClass('active'));
  1854. }
  1855. billsSpread.refresh();
  1856. if (posSpread) {
  1857. posSpread.refresh();
  1858. }
  1859. });
  1860. if (!readOnly) {
  1861. // 修订详情 保存
  1862. $('#save').click(function () {
  1863. const content = $('#content').val();
  1864. postData('save', { content: content }, function () {
  1865. $('#content').attr('org-value', content);
  1866. });
  1867. });
  1868. }
  1869. // 显示层次
  1870. (function (select, sheet) {
  1871. $(select).click(function () {
  1872. if (!sheet.zh_tree) return;
  1873. const tag = $(this).attr('tag');
  1874. const tree = sheet.zh_tree;
  1875. switch (tag) {
  1876. case "1":
  1877. case "2":
  1878. case "3":
  1879. case "4":
  1880. case "5":
  1881. tree.expandByLevel(parseInt(tag));
  1882. SpreadJsObj.refreshTreeRowVisible(sheet);
  1883. break;
  1884. case "last":
  1885. tree.expandByCustom(() => { return true; });
  1886. SpreadJsObj.refreshTreeRowVisible(sheet);
  1887. break;
  1888. case "leafXmj":
  1889. tree.expandToLeafXmj();
  1890. SpreadJsObj.refreshTreeRowVisible(sheet);
  1891. break;
  1892. }
  1893. });
  1894. })('a[name=showLevel]', billsSheet);
  1895. });