revise.js 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503
  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. posXmj: ['code'],
  16. };
  17. function getExprInfo (field) {
  18. const exprField = [
  19. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  20. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  21. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  22. ];
  23. return _.find(exprField, {qty: field});
  24. }
  25. function transExpr(expr) {
  26. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  27. }
  28. const copyBlockTag = 'zh.calc.copyBlock';
  29. $(document).ready(() => {
  30. let stdXmj, stdGcl, searchLedger;
  31. autoFlashHeight();
  32. // 初始化spread
  33. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  34. const billsSheet = billsSpread.getActiveSheet();
  35. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  36. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  37. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  38. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  39. const posSheet = posSpread.getActiveSheet();
  40. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  41. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  42. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  43. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  44. const errorList = $.cs_errorList({
  45. tabSelector: '#error-list-tab',
  46. selector: '#error-list',
  47. relaSpread: billsSpread,
  48. storeKey: 'revise-error-' + window.location.pathname.split('/')[2] + '-' + window.location.pathname.split('/')[4],
  49. afterLocated: function () {
  50. posSpreadObj.loadCurPosData();
  51. },
  52. afterShow: function () {
  53. billsSpread.refresh();
  54. if (posSpread) posSpread.refresh();
  55. },
  56. });
  57. // 初始化 节点树结构
  58. const treeSetting = {
  59. id: 'ledger_id',
  60. pid: 'ledger_pid',
  61. order: 'order',
  62. level: 'level',
  63. rootId: -1,
  64. keys: ['id', 'tender_id', 'ledger_id'],
  65. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  66. };
  67. if (!isTz) {
  68. treeSetting.calcFields.push('deal_tp');
  69. }
  70. treeSetting.calcFun = function (node) {
  71. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  72. };
  73. const billsTree = createNewPathTree('revise', treeSetting);
  74. // 初始化 计量单元
  75. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  76. // 清单 相关方法&绑定spreadjs事件
  77. const billsTreeSpreadObj = {
  78. loadExprToInput(sheet) {
  79. const sel = sheet.getSelections()[0];
  80. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  81. if (col && col.type === 'Number') {
  82. const data = SpreadJsObj.getSelectObject(sheet);
  83. if (data) {
  84. const exprInfo = getExprInfo(col.field);
  85. if (exprInfo) {
  86. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  87. .attr('field', col.field).attr('org', data[col.field]);
  88. } else {
  89. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  90. }
  91. if (col.field.indexOf('dgn') >= 0) {
  92. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== ''));
  93. } else if (col.field === 'unit_price') {
  94. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true));
  95. } else {
  96. const nodePos = pos.getLedgerPos(data.id);
  97. if (nodePos && nodePos.length > 0) {
  98. $('#bills-expr').val('').attr('readOnly', true);
  99. $('#bills-expr').removeAttr('data-row');
  100. } else {
  101. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0));
  102. }
  103. }
  104. $('#bills-expr').attr('data-row', sel.row);
  105. } else {
  106. $('#bills-expr').val('').attr('readOnly', true);
  107. $('#bills-expr').removeAttr('data-row');
  108. }
  109. } else {
  110. $('#bills-expr').val('').attr('readOnly', true);
  111. $('#bills-expr').removeAttr('data-row');
  112. }
  113. },
  114. getDefaultSelectInfo: function (sheet) {
  115. const tree = sheet.zh_tree;
  116. if (!tree) return;
  117. const sel = sheet.getSelections()[0];
  118. const node = sheet.zh_tree.nodes[sel.row];
  119. if (!node) return;
  120. let count = 1;
  121. if (sel.rowCount > 1) {
  122. for (let r = 1; r < sel.rowCount; r++) {
  123. const rNode = sheet.zh_tree.nodes[sel.row + r];
  124. if (rNode.level > node.level) continue;
  125. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  126. toastr.warning('请选择同一节点下的节点,进行该操作');
  127. return;
  128. }
  129. count += 1;
  130. }
  131. }
  132. return [tree, node, count];
  133. },
  134. /**
  135. * 刷新顶部按钮是否可用
  136. * @param sheet
  137. * @param selections
  138. */
  139. refreshOperationValid: function (sheet, selection) {
  140. const setObjEnable = function (obj, enable) {
  141. if (enable) {
  142. obj.removeClass('disabled');
  143. } else {
  144. obj.addClass('disabled');
  145. }
  146. };
  147. const invalidAll = function () {
  148. setObjEnable($('a[name=base-opr][type=add]'), false);
  149. setObjEnable($('a[name=base-opr][type=delete]'), false);
  150. setObjEnable($('a[name=base-opr][type=up-move]'), false);
  151. setObjEnable($('a[name=base-opr][type=down-move]'), false);
  152. setObjEnable($('a[name=base-opr][type=up-level]'), false);
  153. setObjEnable($('a[name=base-opr][type=down-level]'), false);
  154. };
  155. const sel = selection ? selection[0] : sheet.getSelections()[0];
  156. const row = sel ? sel.row : -1;
  157. const tree = sheet.zh_tree;
  158. if (!tree) {
  159. invalidAll();
  160. return;
  161. }
  162. const first = sheet.zh_tree.nodes[row];
  163. if (!first) {
  164. invalidAll();
  165. return;
  166. }
  167. let last = first, sameParent = true, nodeUsed = first.used;
  168. if (sel.rowCount > 1 && first) {
  169. for (let r = 1; r < sel.rowCount; r++) {
  170. const rNode = tree.nodes[sel.row + r];
  171. if (!rNode) {
  172. sameParent = false;
  173. break;
  174. }
  175. nodeUsed = nodeUsed || rNode.used;
  176. if (rNode.level > first.level) continue;
  177. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  178. sameParent = false;
  179. break;
  180. }
  181. last = rNode;
  182. }
  183. }
  184. const preNode = tree.getPreSiblingNode(first);
  185. const valid = !sheet.zh_setting.readOnly;
  186. setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1);
  187. setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed);
  188. setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode);
  189. setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
  190. const posRange = last ? pos.getLedgerPos(last.id) : [];
  191. setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  192. && first.level > 2 && ((!posRange || posRange.length === 0) || tree.isLastSibling(last)));
  193. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  194. setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
  195. && first.level > 1 && preNode && (!preNodePosRange || preNodePosRange.length === 0) && !preNode.used);
  196. setObjEnable($('#cut'), valid);
  197. setObjEnable($('#paste'), valid);
  198. },
  199. /**
  200. *
  201. * @param sheet
  202. * @param data
  203. */
  204. refreshTree: function (sheet, data) {
  205. SpreadJsObj.massOperationSheet(sheet, function () {
  206. const tree = sheet.zh_tree;
  207. // 处理删除
  208. if (data.delete) {
  209. data.delete.sort(function (a, b) {
  210. return b.deleteIndex - a.deleteIndex;
  211. });
  212. for (const d of data.delete) {
  213. sheet.deleteRows(d.deleteIndex, 1);
  214. }
  215. }
  216. // 处理新增
  217. if (data.create) {
  218. const newNodes = data.create;
  219. if (newNodes) {
  220. newNodes.sort(function (a, b) {
  221. return a.index - b.index;
  222. });
  223. for (const node of newNodes) {
  224. sheet.addRows(node.index, 1);
  225. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  226. }
  227. }
  228. }
  229. // 处理更新
  230. if (data.update) {
  231. const rows = [];
  232. for (const u of data.update) {
  233. rows.push(tree.nodes.indexOf(u));
  234. }
  235. SpreadJsObj.reLoadRowsData(sheet, rows);
  236. }
  237. // 处理展开
  238. if (data.expand) {
  239. const expanded = [];
  240. for (const e of data.expand) {
  241. if (expanded.indexOf(e) === -1) {
  242. const posterity = tree.getPosterity(e);
  243. for (const p of posterity) {
  244. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  245. expanded.push(p);
  246. }
  247. }
  248. }
  249. }
  250. });
  251. },
  252. selectionChanged: function (e, info) {
  253. if (info.newSelections) {
  254. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row) {
  255. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  256. SpreadJsObj.resetTopAndSelect(posSheet);
  257. posSpreadObj.loadCurPosData();
  258. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  259. posSearch.search($('#pos-keyword').val());
  260. }
  261. }
  262. billsTreeSpreadObj.loadExprToInput(info.sheet);
  263. },
  264. /**
  265. * 新增节点
  266. * @param spread
  267. */
  268. baseOpr: function (sheet, type, addCount = 1) {
  269. const self = this;
  270. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  271. if (!tree || !node || !count) return;
  272. if (type === 'delete') {
  273. const parent = tree.getParent(node);
  274. const children = parent ? parent.children : tree.children;
  275. const index = children.indexOf(node);
  276. for (let i = 0; i < count; i++) {
  277. const child = children[i+index];
  278. if (tree.checkNodeUsed(child, pos)) {
  279. toastr.warning('选中的节点已计量,不可删除');
  280. return;
  281. }
  282. }
  283. } else if (type === 'up-level') {
  284. const parent = tree.getParent(node);
  285. const children = parent ? parent.children : tree.children;
  286. const index = children.indexOf(node);
  287. for (let i = index; i < children.length; i++) {
  288. const child = children[index];
  289. if (tree.checkNodeUsed(child, pos)) {
  290. if (i >= index + count) {
  291. toastr.warning('其后节点已计量,选中的节点不可升级');
  292. } else {
  293. toastr.warning('选中的节点已计量,不可升级');
  294. }
  295. return;
  296. }
  297. }
  298. } else if (type === 'down-level') {
  299. const parent = tree.getParent(node);
  300. const children = parent ? parent.children : tree.children;
  301. const index = children.indexOf(node);
  302. for (let i = 0; i < count; i++) {
  303. const child = children[i+index];
  304. if (tree.checkNodeUsed(child, pos)) {
  305. toastr.warning('选中的节点已计量,不可降级');
  306. return;
  307. }
  308. }
  309. }
  310. if (type === 'delete') {
  311. deleteAfterHint(function () {
  312. postData(window.location.pathname + '/update', {
  313. postType: type,
  314. postData: {
  315. id: node.ledger_id,
  316. count: type === 'add' ? addCount : count,
  317. }
  318. }, function (result) {
  319. const refreshData = tree.loadPostData(result);
  320. self.refreshTree(sheet, refreshData);
  321. const sel = sheet.getSelections()[0];
  322. if (sel) {
  323. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  324. }
  325. self.refreshOperationValid(sheet);
  326. });
  327. });
  328. } else {
  329. postData(window.location.pathname + '/update', {
  330. postType: type,
  331. postData: {
  332. id: node.ledger_id,
  333. count: type === 'add' ? addCount : count,
  334. }
  335. }, function (result) {
  336. const refreshData = tree.loadPostData(result);
  337. self.refreshTree(sheet, refreshData);
  338. if (['up-move', 'down-move'].indexOf(type) > -1) {
  339. const sel = sheet.getSelections()[0];
  340. if (sel) {
  341. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  342. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  343. }
  344. } else if (type === 'add') {
  345. const sel = sheet.getSelections()[0];
  346. if (sel) {
  347. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  348. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
  349. }
  350. }
  351. self.refreshOperationValid(sheet);
  352. });
  353. }
  354. },
  355. /**
  356. * 编辑单元格响应事件
  357. * @param {Object} e
  358. * @param {Object} info
  359. */
  360. editEnded: function (e, info) {
  361. if (info.sheet.zh_setting) {
  362. const col = info.sheet.zh_setting.cols[info.col];
  363. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  364. const node = sortData[info.row];
  365. const data = {
  366. id: node.id,
  367. tender_id: node.tender_id,
  368. ledger_id: node.ledger_id
  369. };
  370. // 未改变值则不提交
  371. const orgValue = node[col.field];
  372. const newValue = trimInvalidChar(info.editingText);
  373. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  374. return;
  375. }
  376. // 台账模式,检查计量单元相关
  377. if (isTz) {
  378. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  379. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  380. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  381. if (!node.children || node.children.length ===0) {
  382. const lPos = pos.getLedgerPos(node.id);
  383. if (lPos && lPos.length > 0) {
  384. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  385. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  386. return;
  387. }
  388. }
  389. }
  390. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  391. const lPos = pos.getLedgerPos(node.id);
  392. if (lPos && lPos.length > 0) {
  393. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  394. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  395. return;
  396. }
  397. }
  398. }
  399. // 获取更新数据
  400. const exprInfo = getExprInfo(col.field);
  401. if (info.editingText) {
  402. const text = newValue;
  403. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  404. toastr.error('节点已计量,请勿删除编号');
  405. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  406. return;
  407. }
  408. if (col.type === 'Number') {
  409. const num = _.toNumber(text);
  410. if (_.isFinite(num)) {
  411. data[col.field] = num;
  412. if (exprInfo) {
  413. data[exprInfo.expr] = '';
  414. }
  415. } else {
  416. try {
  417. data[col.field] = math.evaluate(transExpr(text));
  418. if (exprInfo) {
  419. data[exprInfo.expr] = newValue;
  420. }
  421. } catch(err) {
  422. toastr.error('输入的表达式非法');
  423. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  424. return;
  425. }
  426. }
  427. } else {
  428. data[col.field] = text;
  429. }
  430. } else {
  431. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  432. toastr.error('节点已计量,请勿删除编号');
  433. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  434. return;
  435. }
  436. data[col.field] = null;
  437. if (exprInfo) {
  438. data[exprInfo.expr] = '';
  439. }
  440. }
  441. // 更新至服务器
  442. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  443. const refreshNode = billsTree.loadPostData(result);
  444. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  445. });
  446. }
  447. },
  448. clipboardPasting: function (e, info) {
  449. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  450. info.cancel = true;
  451. if (!setting || !tree) return;
  452. // const range = info.cellRange;
  453. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  454. // const node = tree.nodes[iRow];
  455. // if (tree.checkNodeUsed(node, pos)) {
  456. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  457. // return;
  458. // }
  459. // }
  460. const pasteData = info.pasteData.html
  461. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  462. : (info.pasteData.text === ''
  463. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  464. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  465. const hint = {
  466. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  467. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  468. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  469. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  470. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  471. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  472. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  473. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  474. sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  475. };
  476. const datas = [], filterNodes = [];
  477. let pid, level, filterRow = 0;
  478. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  479. const curRow = info.cellRange.row + iRow;
  480. const node = tree.nodes[curRow];
  481. if (!node) continue;
  482. if (!pid) pid = node.ledger_pid;
  483. if (!level) level = node.level;
  484. if (node.ledger_pid !== pid) {
  485. toastMessageUniq(hint.sameParent);
  486. filterRow+=1;
  487. continue;
  488. }
  489. if (node.level < level) break;
  490. let bPaste = false;
  491. const data = info.sheet.zh_tree.getNodeKeyData(node);
  492. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  493. const curCol = info.cellRange.col + iCol;
  494. const colSetting = info.sheet.zh_setting.cols[curCol];
  495. const value = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  496. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  497. toastMessageUniq(hint.parent);
  498. continue;
  499. }
  500. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  501. toastMessageUniq(hint.gcl);
  502. continue;
  503. }
  504. const lPos = pos.getLedgerPos(node.id);
  505. if (lPos && lPos.length > 0) {
  506. if (value === '' && colSetting.field === 'b_code') {
  507. toastMessageUniq(hint.posCode);
  508. continue;
  509. }
  510. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  511. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  512. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  513. toastMessageUniq(hint.posQty);
  514. continue;
  515. }
  516. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  517. toastMessageUniq(hint.posXmj);
  518. continue;
  519. }
  520. }
  521. if (tree.checkNodeUsed(node, pos) && col.field === 'unit_price') {
  522. toastMessageUniq (hint.usedUp);
  523. continue;
  524. }
  525. if (colSetting.type === 'Number') {
  526. const num = _.toNumber(value);
  527. if (num) {
  528. data[colSetting.field] = num;
  529. } else {
  530. try {
  531. data[colSetting.field] = math.evaluate(transExpr(value));
  532. const exprInfo = getExprInfo(colSetting.field);
  533. if (exprInfo) {
  534. data[exprInfo.expr] = value;
  535. }
  536. bPaste = true;
  537. } catch (err) {
  538. toastMessageUniq(hint.invalidExpr);
  539. continue;
  540. }
  541. }
  542. } else {
  543. if (node.used && (col.field === 'code' || col.field ==='b_code')
  544. && data[colSetting.field] !== '' && value === '') {
  545. toastMessageUniq(hint.usedCode);
  546. continue;
  547. }
  548. data[colSetting.field] = value;
  549. }
  550. bPaste = true;
  551. }
  552. if (bPaste) {
  553. datas.push(data);
  554. } else {
  555. filterNodes.push(node);
  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. clipboardPasted: function (e, info) {
  573. const hint = {
  574. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  575. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  576. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  577. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  578. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  579. };
  580. const tree = info.sheet.zh_tree;
  581. if (!tree) { return; }
  582. const sortData = info.sheet.zh_tree.nodes;
  583. const datas = [], filterNodes = [];
  584. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  585. let bPaste = false;
  586. const curRow = info.cellRange.row + iRow;
  587. const node = sortData[curRow];
  588. if (node) {
  589. const data = info.sheet.zh_tree.getNodeKeyData(node);
  590. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  591. const curCol = info.cellRange.col + iCol;
  592. const colSetting = info.sheet.zh_setting.cols[curCol];
  593. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  594. const lPos = pos.getLedgerPos(node.id);
  595. if (lPos && lPos.length > 0) {
  596. if (value === '' && colSetting.field === 'b_code') {
  597. toastMessageUniq(hint.posCode);
  598. continue;
  599. }
  600. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  601. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  602. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  603. toastMessageUniq(hint.posQty);
  604. continue;
  605. }
  606. }
  607. if (node.used && col.field === 'unit_price') {
  608. toastMessageUniq (hint.usedUp);
  609. continue;
  610. }
  611. if (colSetting.type === 'Number') {
  612. const num = _.toNumber(value);
  613. if (num) {
  614. data[colSetting.field] = num;
  615. } else {
  616. try {
  617. data[colSetting.field] = math.evaluate(transExpr(value));
  618. } catch (err) {
  619. toastMessageUniq(hint.invalidExpr);
  620. continue;
  621. }
  622. }
  623. } else {
  624. if (node.used && (col.field === 'code' || col.field ==='b_code')
  625. && data[colSetting.field] !== '' && value === '') {
  626. toastMessageUniq(hint.usedCode);
  627. continue;
  628. }
  629. data[colSetting.field] = value;
  630. }
  631. bPaste = true;
  632. }
  633. if (bPaste) {
  634. datas.push(data);
  635. } else {
  636. filterNodes.push(node);
  637. }
  638. }
  639. }
  640. if (datas.length > 0) {
  641. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  642. const refreshNode = tree.loadPostData(result);
  643. if (refreshNode.update) {
  644. refreshNode.update = refreshNode.update.concat(filterNodes);
  645. }
  646. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  647. }, function () {
  648. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  649. });
  650. } else {
  651. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  652. }
  653. },
  654. deletePress: function (sheet) {
  655. if (!sheet.zh_setting) return;
  656. const sel = sheet.getSelections()[0], datas = [];
  657. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  658. const node = sheet.zh_tree.nodes[iRow];
  659. if (sheet.zh_tree.checkNodeUsed(node, pos)) {
  660. toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  661. return;
  662. }
  663. const data = sheet.zh_tree.getNodeKeyData(node);
  664. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  665. const col = sheet.zh_setting.cols[iCol];
  666. data[col.field] = null;
  667. const exprInfo = getExprInfo(col.field);
  668. if (exprInfo) {
  669. data[exprInfo.expr] = '';
  670. }
  671. }
  672. datas.push(data);
  673. }
  674. if (datas.length > 0) {
  675. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  676. const refreshNode = sheet.zh_tree.loadPostData(result);
  677. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  678. billsTreeSpreadObj.loadExprToInput(sheet);
  679. });
  680. }
  681. },
  682. pasteBlock: function (spread, copyInfo) {
  683. const self = this;
  684. const sheet = spread.getActiveSheet();
  685. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  686. postData(window.location.pathname + '/update', {
  687. postType: 'paste-block',
  688. postData: {
  689. id: tree.getNodeKey(node),
  690. tid: copyInfo.tid,
  691. block: copyInfo.block,
  692. }
  693. }, function (data) {
  694. pos.updateDatas(data.pos);
  695. const result = tree.loadPostData(data.ledger);
  696. self.refreshTree(sheet, result);
  697. const sel = sheet.getSelections()[0];
  698. if (sel) {
  699. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  700. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  701. }
  702. self.refreshOperationValid(sheet);
  703. removeLocalCache(copyBlockTag);
  704. }, null, true);
  705. },
  706. topRowChanged: function (e, info) {
  707. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  708. },
  709. editStarting(e, info) {
  710. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  711. const col = info.sheet.zh_setting.cols[info.col];
  712. const node = info.sheet.zh_tree.nodes[info.row];
  713. if (!node) {
  714. info.cancel = true;
  715. return;
  716. }
  717. const exprInfo = getExprInfo(col.field);
  718. if (exprInfo) {
  719. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  720. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  721. }
  722. }
  723. switch (col.field) {
  724. case 'code':
  725. const posRange = pos.getLedgerPos(node.id);
  726. info.cancel = posRange && posRange.length > 0;
  727. break;
  728. case 'unit_price':
  729. info.cancel = (node.children && node.children.length > 0) || node.used;
  730. break;
  731. case 'sgfh_qty':
  732. case 'sgfh_tp':
  733. case 'sjcl_qty':
  734. case 'sjcl_tp':
  735. case 'qtcl_qty':
  736. case 'qtcl_tp':
  737. case 'deal_qty':
  738. case 'deal_tp':
  739. info.cancel = (node.children && node.children.length > 0);
  740. break;
  741. case 'dgn_qty1':
  742. case 'dgn_qty2':
  743. info.cancel = !_.isEmpty(node.b_code);
  744. break;
  745. }
  746. },
  747. cut: function (sheet, sel, callback) {
  748. if (!sheet || !sel) return;
  749. if (sel.colCount >= sheet.zh_setting.cols.length) {
  750. toastr.warning('请勿选中整行剪切');
  751. return;
  752. }
  753. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  754. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  755. const node = sortData[iRow];
  756. if (node) {
  757. const data = sheet.zh_tree.getNodeKeyData(node);
  758. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  759. const col = sheet.zh_setting.cols[iCol];
  760. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  761. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  762. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  763. const lPos = pos.getLedgerPos(node.id);
  764. if (lPos && lPos.length > 0) {
  765. toastr.error('不可剪切');
  766. return;
  767. }
  768. }
  769. const style = sheet.getStyle(iRow, iCol);
  770. if (style.locked) {
  771. toastr.error('不可剪切');
  772. return;
  773. }
  774. const colSetting = sheet.zh_setting.cols[iCol];
  775. data[colSetting.field] = null;
  776. const exprInfo = getExprInfo(colSetting.field);
  777. if (exprInfo) {
  778. data[exprInfo.expr] = '';
  779. }
  780. }
  781. datas.push(data);
  782. }
  783. }
  784. if (datas.length > 0) {
  785. callback();
  786. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  787. const refreshNode = sheet.zh_tree.loadPostData(result);
  788. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  789. });
  790. }
  791. },
  792. sortCode: function (sheet) {
  793. const tree = sheet.zh_tree;
  794. if (!tree) return;
  795. const select = SpreadJsObj.getSelectObject(sheet);
  796. if (!select || !select.code || select.code === '') return;
  797. const recursiveSortCode = function (data, parentCode, children) {
  798. if (!children || children.length === 0) return;
  799. for (const [i, child] of children.entries()) {
  800. if (!child.b_code || child.b_code === '') {
  801. const code = parentCode + '-' + (i + 1);
  802. const cData = tree.getNodeKeyData(child);
  803. cData.code = code;
  804. data.push(cData);
  805. if (!tree.isLeafXmj(child)) {
  806. recursiveSortCode(data, code, child.children);
  807. }
  808. }
  809. }
  810. };
  811. const data = [];
  812. recursiveSortCode(data, select.code, select.children);
  813. if (data.length > 0) {
  814. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  815. const refreshNode = tree.loadPostData(result);
  816. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  817. })
  818. }
  819. }
  820. };
  821. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  822. billsTreeSpreadObj.loadExprToInput(billsSheet);
  823. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  824. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  825. if (!readOnly) {
  826. // 增删上下移升降级
  827. $('a[name="base-opr"]').click(function () {
  828. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  829. });
  830. $('a[name=cpc]').click(function () {
  831. billsSpread.commandManager().execute({
  832. cmd: this.getAttribute('type'),
  833. sheetName: billsSheet.name()
  834. });
  835. });
  836. $('#bills-expr').bind('change onblur', function () {
  837. if (this.readOnly) return;
  838. const expr = $(this);
  839. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  840. const select = billsTree.getItemsByIndex(row);
  841. if (!select) return;
  842. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  843. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  844. const data = {
  845. id: select.id,
  846. tender_id: select.tender_id,
  847. ledger_id: select.ledger_id
  848. };
  849. const exprInfo = getExprInfo(field);
  850. if (newValue !== '') {
  851. const num = _.toNumber(newValue);
  852. if (num) {
  853. data[field] = num;
  854. if (exprInfo) {
  855. data[exprInfo.expr] = '';
  856. }
  857. } else {
  858. try {
  859. data[field] = math.evaluate(transExpr(newValue));
  860. if (exprInfo) {
  861. data[exprInfo.expr] = newValue;
  862. }
  863. } catch (err) {
  864. toastr.error('输入的表达式非法');
  865. return;
  866. }
  867. }
  868. } else {
  869. data[field] = null;
  870. if (exprInfo) {
  871. data[exprInfo.expr] = '';
  872. }
  873. }
  874. // 更新至服务器
  875. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  876. const refreshNode = billsTree.loadPostData(result);
  877. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  878. });
  879. });
  880. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  881. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  882. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  883. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  884. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  885. SpreadJsObj.Clipboard.setCopyData(copyText);
  886. });
  887. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  888. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  889. }
  890. // 右键菜单
  891. let batchInsertObj;
  892. $.contextMenu.types.batchInsert = function (item, opt, root) {
  893. const self = this;
  894. if ($.isFunction(item.icon)) {
  895. item._icon = item.icon.call(this, this, $t, key, item);
  896. } else {
  897. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  898. // to enable font awesome
  899. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  900. } else {
  901. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  902. }
  903. }
  904. this.addClass(item._icon);
  905. 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>')
  906. .appendTo(this);
  907. const $input = $obj.find('input');
  908. const event = () => {
  909. if (self.hasClass('context-menu-disabled')) return;
  910. item.batchInsert($input[0], root);
  911. };
  912. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  913. $input.click((e) => {e.stopPropagation();})
  914. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  915. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  916. };
  917. const billsContextMenuOptions = {
  918. selector: '#bills-spread',
  919. build: function ($trigger, e) {
  920. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  921. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  922. },
  923. items: {}
  924. };
  925. if (!readOnly) {
  926. billsContextMenuOptions.items.create = {
  927. name: '新增',
  928. icon: 'fa-sign-in',
  929. callback: function (key, opt) {
  930. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  931. },
  932. disabled: function (key, opt) {
  933. const sheet = billsSheet;
  934. const selection = sheet.getSelections();
  935. const sel = selection ? selection[0] : sheet.getSelections()[0];
  936. const row = sel ? sel.row : -1;
  937. const tree = sheet.zh_tree;
  938. if (!tree) return true;
  939. const first = sheet.zh_tree.nodes[row];
  940. const valid = !sheet.zh_setting.readOnly;
  941. return !(valid && first && first.level > 1);
  942. }
  943. };
  944. billsContextMenuOptions.items.delete = {
  945. name: '删除',
  946. icon: 'fa-remove',
  947. callback: function (key, opt) {
  948. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  949. },
  950. disabled: function (key, opt) {
  951. const sheet = billsSheet;
  952. const selection = sheet.getSelections();
  953. const sel = selection ? selection[0] : sheet.getSelections()[0];
  954. const row = sel ? sel.row : -1;
  955. const tree = sheet.zh_tree;
  956. if (!tree) return true;
  957. const first = sheet.zh_tree.nodes[row];
  958. let last = first, sameParent = true, nodeUsed = first.used;
  959. if (sel.rowCount > 1 && first) {
  960. for (let r = 1; r < sel.rowCount; r++) {
  961. const rNode = tree.nodes[sel.row + r];
  962. if (!rNode) {
  963. sameParent = false;
  964. break;
  965. }
  966. nodeUsed = nodeUsed || rNode.used;
  967. if (rNode.level > first.level) continue;
  968. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  969. sameParent = false;
  970. break;
  971. }
  972. last = rNode;
  973. }
  974. }
  975. const valid = !sheet.zh_setting.readOnly;
  976. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed);
  977. }
  978. };
  979. billsContextMenuOptions.items.sprBase = '-----------';
  980. }
  981. billsContextMenuOptions.items.copyBlock = {
  982. name: '复制整块',
  983. icon: 'fa-files-o',
  984. callback: function (key, opt) {
  985. const copyBlockList = [];
  986. const sheet = billsSheet;
  987. const sel = sheet.getSelections()[0];
  988. let iRow = sel.row;
  989. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  990. while (iRow < sel.row + sel.rowCount) {
  991. const node = sheet.zh_tree.nodes[iRow];
  992. if (node.ledger_pid !== pid) {
  993. toastr.error('仅可同时选中同层节点');
  994. return;
  995. }
  996. const posterity = sheet.zh_tree.getPosterity(node);
  997. iRow += posterity.length + 1;
  998. posterity.unshift(node);
  999. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1000. }
  1001. const tenderId = _.toInteger(getTenderId());
  1002. for (const cbl of copyBlockList) {
  1003. const posRange = pos.getLedgerPos(cbl.id);
  1004. if (posRange && posRange.length > 0) cbl.pos = posRange;
  1005. }
  1006. setLocalCache(copyBlockTag, JSON.stringify({tid: tenderId, block: copyBlockList}));
  1007. },
  1008. visible: function (key, opt) {
  1009. const sheet = billsSheet;
  1010. const selection = sheet.getSelections();
  1011. const row = selection[0].row;
  1012. const select = billsTree.nodes[row];
  1013. return select;
  1014. },
  1015. disabled: function (key, opt) {
  1016. const sheet = billsSheet;
  1017. const selection = sheet.getSelections();
  1018. const row = selection[0].row;
  1019. const select = billsTree.nodes[row];
  1020. return select && select.level <= 1;
  1021. }
  1022. };
  1023. if (!readOnly) {
  1024. billsContextMenuOptions.items.pasteBlock = {
  1025. name: '粘贴整块',
  1026. icon: 'fa-clipboard',
  1027. disabled: function (key, opt) {
  1028. //const block = treeOperationObj.block || [];
  1029. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1030. return !(copyInfo && copyInfo.tid && copyInfo.tid > 0 && copyInfo.block && copyInfo.block.length > 0);
  1031. },
  1032. callback: function (key, opt) {
  1033. //const block = treeOperationObj.block || [];
  1034. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1035. if (copyInfo.block.length > 0) {
  1036. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  1037. } else {
  1038. document.execCommand('paste');
  1039. }
  1040. },
  1041. visible: function (key, opt) {
  1042. return !readOnly;
  1043. }
  1044. };
  1045. billsContextMenuOptions.items.sprBlock = '-----------';
  1046. }
  1047. if (!readOnly) {
  1048. billsContextMenuOptions.items.batchInsert = {
  1049. name: '批量插入',
  1050. type: 'batchInsert',
  1051. value: '2',
  1052. icon: 'fa-sign-in',
  1053. batchInsert: function (obj, root) {
  1054. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1055. obj.value = obj.max;
  1056. toastr.warning('批量插入不可多于' + obj.max);
  1057. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1058. obj.value = obj.min;
  1059. toastr.warning('批量插入不可少于' + obj.min);
  1060. } else {
  1061. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  1062. root.$menu.trigger('contextmenu:hide');
  1063. }
  1064. },
  1065. disabled: function (key, opt) {
  1066. const sheet = billsSheet;
  1067. const selection = sheet.getSelections();
  1068. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1069. const row = sel ? sel.row : -1;
  1070. const tree = sheet.zh_tree;
  1071. if (!tree) return true;
  1072. const first = sheet.zh_tree.nodes[row];
  1073. const valid = !sheet.zh_setting.readOnly;
  1074. return !(valid && first && first.level > 1);
  1075. }
  1076. };
  1077. billsContextMenuOptions.items.batchInsertBillsPos = {
  1078. name: '批量插入清单-计量单元',
  1079. icon: 'fa-sign-in',
  1080. disabled: function (key, opt) {
  1081. if (!isTz) return true;
  1082. const select = SpreadJsObj.getSelectObject(billsSheet);
  1083. if (select) {
  1084. if (select.code && select.code !== '') {
  1085. return !billsTree.isLeafXmj(select);
  1086. } else {
  1087. const parent = billsTree.getParent(select);
  1088. return !(parent && billsTree.isLeafXmj(parent));
  1089. }
  1090. } else {
  1091. return false;
  1092. }
  1093. },
  1094. callback: function (key, opt) {
  1095. if (!batchInsertObj) {
  1096. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1097. } else {
  1098. batchInsertObj.initView();
  1099. }
  1100. $('#batch').modal('show');
  1101. }
  1102. };
  1103. billsContextMenuOptions.items.sprBatch = '-----------';
  1104. billsContextMenuOptions.items.importGclBills2Xmj = {
  1105. name: '导入工程量清单至项目节',
  1106. icon: 'fa-file-excel-o',
  1107. disabled: function (key, opt) {
  1108. const node = SpreadJsObj.getSelectObject(billsSheet);
  1109. return readOnly
  1110. || (node.children && node.children.length > 0)
  1111. || (!_.isNil(node.b_code) && node.b_code !== '')
  1112. || billsTree.checkNodeUsed(node, pos);
  1113. },
  1114. callback: function (key, opt) {
  1115. const node = SpreadJsObj.getSelectObject(billsSheet);
  1116. importExcel.doImport({
  1117. template: {
  1118. hint: '工程量清单',
  1119. url: '/template/导入工程量清单EXCEL格式.xls',
  1120. },
  1121. callback: function (sheet) {
  1122. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  1123. const sel = billsSheet.getSelections();
  1124. const refreshNode = billsTree.loadPostData(result);
  1125. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1126. if (refreshNode.create[0]) {
  1127. if (sel && sel[0]) {
  1128. billsSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  1129. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel[0].row, refreshNode.create[0].index]);
  1130. } else {
  1131. billsSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  1132. SpreadJsObj.reloadRowsBackColor(billsSheet, [refreshNode.create[0].index]);
  1133. }
  1134. }
  1135. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1136. }, null);
  1137. }
  1138. });
  1139. }
  1140. };
  1141. }
  1142. $.contextMenu(billsContextMenuOptions);
  1143. // 计量单元 相关方法&绑定spreadjs事件
  1144. const posSpreadObj = {
  1145. refreshOperationValid: function (sheet, selection) {
  1146. const setObjEnable = function (obj, enable) {
  1147. if (enable) {
  1148. obj.removeClass('disabled');
  1149. } else {
  1150. obj.addClass('disabled');
  1151. }
  1152. };
  1153. const invalidAll = function () {
  1154. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1155. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1156. };
  1157. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1158. const row = sel ? sel.row : -1;
  1159. const first = sheet.zh_data[row];
  1160. if (!first) {
  1161. invalidAll();
  1162. return;
  1163. }
  1164. let last = first;
  1165. if (sel.rowCount > 1 && first) {
  1166. for (let r = 1; r < sel.rowCount; r++) {
  1167. const rNode = sheet.zh_data[sel.row + r];
  1168. if (!rNode) break;
  1169. last = rNode;
  1170. }
  1171. }
  1172. const preNode = sheet.zh_data[row - 1];
  1173. const valid = !sheet.zh_setting.readOnly;
  1174. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode);
  1175. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1));
  1176. },
  1177. loadExprToInput: function () {
  1178. const sel = posSheet.getSelections()[0];
  1179. if (!sel) return;
  1180. const col = posSheet.zh_setting.cols[sel.col];
  1181. const cell = posSheet.getCell(sel.col, sel.col);
  1182. if (col && col.type === 'Number') {
  1183. const data = SpreadJsObj.getSelectObject(posSheet);
  1184. if (data) {
  1185. const exprInfo = getExprInfo(col.field);
  1186. const value = exprInfo
  1187. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1188. : data[col.field];
  1189. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1190. .attr('readOnly', readOnly || cell.locked()).attr('data-row', sel.row);
  1191. } else {
  1192. $('#pos-expr').val('').attr('readOnly', true);
  1193. $('#pos-expr').removeAttr('data-row');
  1194. }
  1195. } else {
  1196. $('#pos-expr').val('').attr('readOnly', true);
  1197. $('#pos-expr').removeAttr('data-row');
  1198. }
  1199. },
  1200. /**
  1201. * 加载计量单元 根据当前台账选择节点
  1202. */
  1203. loadCurPosData: function () {
  1204. const node = SpreadJsObj.getSelectObject(billsSheet);
  1205. if (node) {
  1206. const posData = pos.getLedgerPos(node.id) || [];
  1207. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  1208. } else {
  1209. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  1210. }
  1211. SpreadJsObj.resetFieldReadOnly(posSheet);
  1212. posSpreadObj.loadExprToInput();
  1213. posSpreadObj.refreshOperationValid(posSheet);
  1214. },
  1215. baseOpr: function (sheet, type) {
  1216. const data = {
  1217. postType: 'pos',
  1218. posPostType: type === 'delete' ? type : 'update',
  1219. postData: [],
  1220. };
  1221. const selection = sheet.getSelections();
  1222. const row = selection[0].row, count = selection[0].rowCount;
  1223. const first = sheet.zh_data[row];
  1224. if (type === 'delete') {
  1225. for (let iRow = 0; iRow < count; iRow++) {
  1226. const posData = sheet.zh_data[iRow + row];
  1227. if (posData) {
  1228. if (posData.used) {
  1229. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1230. return;
  1231. }
  1232. data.postData.push(sheet.zh_data[iRow + row].id);
  1233. }
  1234. }
  1235. } else if (type === 'up-move') {
  1236. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1237. for (let iRow = 0; iRow < count; iRow++) {
  1238. const posData = sheet.zh_data[iRow + row];
  1239. if (posData) {
  1240. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1241. preUpdate.porder = posData.porder;
  1242. }
  1243. }
  1244. data.postData.push(preUpdate);
  1245. } else if (type === 'down-move') {
  1246. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1247. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1248. const posData = sheet.zh_data[iRow + row];
  1249. if (posData) {
  1250. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  1251. nextUpdate.porder = posData.porder;
  1252. }
  1253. }
  1254. data.postData.push(nextUpdate);
  1255. }
  1256. if (data.postData.length > 0) {
  1257. postData(window.location.pathname + '/update', data, function (result) {
  1258. if (type === 'delete') {
  1259. pos.removeDatas(result.pos);
  1260. sheet.deleteRows(row, count);
  1261. const loadResult = billsTree.loadPostData(result.ledger);
  1262. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1263. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1264. posSpreadObj.refreshOperationValid(posSheet);
  1265. } else {
  1266. pos.updateDatas(result.pos);
  1267. const sel = selection[0];
  1268. if (sel) {
  1269. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1270. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1271. }
  1272. posSpreadObj.loadCurPosData();
  1273. }
  1274. });
  1275. }
  1276. },
  1277. editStarting: function (e, info) {
  1278. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1279. const sel = info.sheet.getSelections();
  1280. if (!sel || !sel[0]) return;
  1281. const col = info.sheet.zh_setting.cols[sel[0].col];
  1282. const node = SpreadJsObj.getSelectObject(info.sheet);
  1283. const exprInfo = getExprInfo(col.field);
  1284. if (exprInfo) {
  1285. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1286. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1287. }
  1288. }
  1289. },
  1290. /**
  1291. * 编辑单元格响应事件
  1292. * @param {Object} e
  1293. * @param {Object} info
  1294. */
  1295. editEnded: function (e, info) {
  1296. if (!info.sheet.zh_setting) {
  1297. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1298. return;
  1299. }
  1300. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1301. const col = info.sheet.zh_setting.cols[info.col];
  1302. const orgText = posData ? posData[col.field] : null;
  1303. const newText = trimInvalidChar(info.editingText);
  1304. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  1305. const node = posSpreadObj.billsNode;
  1306. if (!node) {
  1307. toastr.error('数据错误,请选择台账节点后再试');
  1308. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1309. return;
  1310. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1311. toastr.error('父节点不可插入计量单元');
  1312. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1313. return;
  1314. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1315. toastr.error('项目节不可插入计量单元');
  1316. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1317. return;
  1318. }
  1319. const data = {postType: 'pos'};
  1320. if (col.field === 'name') {
  1321. if (newText === '' && posData) {
  1322. toastr.error('部位名称不可为空', 'error');
  1323. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1324. return;
  1325. } else if (!posData) {
  1326. if (newText && newText !== '') {
  1327. data.posPostType = 'add';
  1328. const sortData = info.sheet.zh_data;
  1329. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1330. data.postData = { name: newText, lid: node.id, porder: order};
  1331. } else {
  1332. return;
  1333. }
  1334. } else {
  1335. data.posPostType = 'update';
  1336. data.postData = {id: posData.id, name: newText};
  1337. }
  1338. } else if (!posData) {
  1339. toastr.warning('新增计量单元请先输入名称');
  1340. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1341. return;
  1342. } else {
  1343. data.posPostType = 'update';
  1344. data.postData = {id: posData.id};
  1345. if (col.type === 'Number') {
  1346. const exprInfo = getExprInfo(col.field);
  1347. const num = _.toNumber(newText);
  1348. if (_.isFinite(num)) {
  1349. data.postData[col.field] = num;
  1350. if (exprInfo) {
  1351. data.postData[exprInfo.expr] = '';
  1352. }
  1353. } else {
  1354. try {
  1355. data.postData[col.field] = math.evaluate(transExpr(newText));
  1356. if (exprInfo) {
  1357. data.postData[exprInfo.expr] = newText;
  1358. }
  1359. } catch(err) {
  1360. toastr.error('输入的表达式非法');
  1361. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1362. return;
  1363. }
  1364. }
  1365. } else {
  1366. data.postData[col.field] = newText;
  1367. }
  1368. }
  1369. postData(window.location.pathname + '/update', data, function (result) {
  1370. const updateRst = pos.updateDatas(result.pos);
  1371. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1372. if (updateRst.create.length > 0) {
  1373. posSpreadObj.loadCurPosData();
  1374. } else {
  1375. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1376. }
  1377. const loadResult = billsTree.loadPostData(result.ledger);
  1378. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1379. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1380. }, function () {
  1381. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1382. });
  1383. },
  1384. /**
  1385. * 删除按钮响应事件
  1386. * @param sheet
  1387. */
  1388. deletePress: function (sheet) {
  1389. if (!sheet.zh_setting) return;
  1390. const sortData = sheet.zh_data;
  1391. const datas = [], posSelects = [];
  1392. const sel = sheet.getSelections()[0];
  1393. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1394. let bDel = false;
  1395. const node = sortData[iRow];
  1396. if (node) {
  1397. const data = {id: node.id};
  1398. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1399. const colSetting = sheet.zh_setting.cols[iCol];
  1400. if (colSetting.field === 'name') {
  1401. toastr.error('部位名称不能为空');
  1402. return;
  1403. }
  1404. const style = sheet.getStyle(iRow, iCol);
  1405. if (!style.locked) {
  1406. const colSetting = sheet.zh_setting.cols[iCol];
  1407. data[colSetting.field] = null;
  1408. const exprInfo = getExprInfo(colSetting.field);
  1409. if (exprInfo) {
  1410. data[exprInfo.expr] = '';
  1411. }
  1412. bDel = true;
  1413. }
  1414. }
  1415. if (bDel) {
  1416. datas.push(data);
  1417. posSelects.push(node);
  1418. }
  1419. }
  1420. }
  1421. if (datas.length > 0) {
  1422. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  1423. pos.updateDatas(result.pos);
  1424. posSpreadObj.loadCurPosData();
  1425. const loadResult = billsTree.loadPostData(result.ledger);
  1426. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1427. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1428. }, function () {
  1429. posSpreadObj.loadCurPosData();
  1430. });
  1431. }
  1432. },
  1433. /**
  1434. * 删除 计量单元
  1435. * @param sheet
  1436. */
  1437. deletePos: function (sheet) {
  1438. const selection = sheet.getSelections();
  1439. const data = {
  1440. postType: 'pos',
  1441. posPostType: 'delete',
  1442. postData: [],
  1443. };
  1444. const row = selection[0].row, count = selection[0].rowCount;
  1445. const sortData = sheet.zh_data;
  1446. for (let iRow = 0; iRow < count; iRow++) {
  1447. const posData = sortData[iRow + row];
  1448. if (posData) {
  1449. if (posData.used) {
  1450. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1451. return;
  1452. }
  1453. data.postData.push(sortData[iRow + row].id);
  1454. }
  1455. }
  1456. if (data.postData.length > 0) {
  1457. postData(window.location.pathname + '/update', data, function (result) {
  1458. pos.removeDatas(result.pos);
  1459. sheet.deleteRows(row, count);
  1460. const loadResult = billsTree.loadPostData(result.ledger);
  1461. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1462. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1463. });
  1464. }
  1465. },
  1466. clipboardPasting: function (e, info) {
  1467. if (!info.sheet.zh_setting) {
  1468. info.cancel = true;
  1469. return;
  1470. }
  1471. const range = info.cellRange;
  1472. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  1473. const posData = info.sheet.zh_data[iRow];
  1474. if (posData && posData.used) {
  1475. toastr.warning('"' + pos.name +'"已计量,请勿修改');
  1476. info.cancel = true;
  1477. return;
  1478. }
  1479. }
  1480. },
  1481. /**
  1482. * 粘贴单元格响应事件
  1483. * @param e
  1484. * @param info
  1485. */
  1486. clipboardPasted: function (e, info) {
  1487. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1488. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1489. }
  1490. const node = SpreadJsObj.getSelectObject(billsSheet);
  1491. if (node.code && (node.code !== '')) {
  1492. toastr.error('项目节不可含有节点明细');
  1493. posSpreadObj.loadCurPosData();
  1494. return;
  1495. }
  1496. if (node.children && (node.children.length > 0)) {
  1497. toastr.error('仅节点子项可以含有计量单元');
  1498. posSpreadObj.loadCurPosData();
  1499. return;
  1500. }
  1501. if (!info.sheet.zh_setting) {
  1502. posSpreadObj.loadCurPosData();
  1503. return;
  1504. }
  1505. const data = [];
  1506. const sortData = info.sheet.zh_data || [];
  1507. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1508. if (info.cellRange.col !== 0) {
  1509. toastr.warning('新增计量单元请先输入名称');
  1510. posSpreadObj.loadCurPosData();
  1511. return;
  1512. }
  1513. }
  1514. let bHint = false;
  1515. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1516. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1517. let bPaste = true;
  1518. const curRow = info.cellRange.row + iRow;
  1519. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  1520. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1521. const curCol = info.cellRange.col + iCol;
  1522. const colSetting = info.sheet.zh_setting.cols[curCol];
  1523. if (!colSetting) continue;
  1524. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1525. if (colSetting.type === 'Number') {
  1526. const num = _.toNumber(posData[colSetting.field]);
  1527. if (num) {
  1528. posData[colSetting.field] = num;
  1529. } else {
  1530. try {
  1531. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  1532. const exprInfo = getExprInfo(colSetting.field);
  1533. if (exprInfo) {
  1534. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1535. }
  1536. } catch (err) {
  1537. if (!bHint) {
  1538. toastr.warning('粘贴了非法表达式,已过滤');
  1539. bHint = true;
  1540. }
  1541. bPaste = false;
  1542. }
  1543. }
  1544. }
  1545. }
  1546. if (bPaste) {
  1547. data.push(posData);
  1548. }
  1549. }
  1550. if (data.length === 0) {
  1551. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1552. return;
  1553. }
  1554. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  1555. pos.updateDatas(result.pos);
  1556. posSpreadObj.loadCurPosData();
  1557. const loadResult = billsTree.loadPostData(result.ledger);
  1558. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1559. posSpreadObj.loadCurPosData();
  1560. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1561. }, function () {
  1562. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1563. });
  1564. },
  1565. selectionChanged: function (e, info) {
  1566. posSpreadObj.loadExprToInput();
  1567. posSpreadObj.refreshOperationValid(posSheet);
  1568. },
  1569. addPegs: function (pegs) {
  1570. if (!pegs || pegs.length <= 0) return;
  1571. const node = SpreadJsObj.getSelectObject(billsSheet);
  1572. if (!node) return;
  1573. const sheet = posSpread.getActiveSheet();
  1574. const sortData = sheet.zh_data || [];
  1575. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1576. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1577. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  1578. pos.updateDatas(result.pos);
  1579. posSpreadObj.loadCurPosData();
  1580. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1581. });
  1582. }
  1583. };
  1584. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  1585. if (!readOnly && isTz) {
  1586. $('a[name="pos-opr"]').click(function () {
  1587. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  1588. });
  1589. $('#pos-expr').bind('change onblur', function () {
  1590. if (this.readOnly) return;
  1591. const expr = $(this);
  1592. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1593. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  1594. if (!select) return;
  1595. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1596. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  1597. const data = {id: select.id};
  1598. const exprInfo = getExprInfo(field);
  1599. if (newValue !== '') {
  1600. const num = _.toNumber(newValue);
  1601. if (num) {
  1602. data[field] = num;
  1603. if (exprInfo) data[exprInfo.expr] = '';
  1604. } else {
  1605. try {
  1606. data[field] = math.evaluate(transExpr(newValue));
  1607. if (exprInfo) data[exprInfo.expr] = newValue;
  1608. } catch (err) {
  1609. toastr.error('输入的表达式非法');
  1610. return;
  1611. }
  1612. }
  1613. } else {
  1614. data[field] = null;
  1615. if (exprInfo) data[exprInfo.expr] = '';
  1616. }
  1617. // 更新至服务器
  1618. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  1619. const updateRst = pos.updateDatas(result.pos);
  1620. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1621. SpreadJsObj.reLoadRowData(posSheet, row);
  1622. const loadResult = billsTree.loadPostData(result.ledger);
  1623. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1624. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1625. });
  1626. });
  1627. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  1628. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  1629. posSpread.bind(spreadNS.Events.ClipboardPasting, posSpreadObj.clipboardPasting);
  1630. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  1631. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  1632. const mergePeg = NewMergePeg({ callback: posSpreadObj.addPegs });
  1633. $.contextMenu({
  1634. selector: '#pos-spread',
  1635. build: function ($trigger, e) {
  1636. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  1637. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1638. },
  1639. items: {
  1640. 'delete': {
  1641. name: '删除',
  1642. icon: 'fa-remove',
  1643. disabled: function (key, opt) {
  1644. if (posSheet.zh_data) {
  1645. const selection = posSheet.getSelections();
  1646. return posSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  1647. } else {
  1648. return true;
  1649. }
  1650. },
  1651. callback: function (key, opt) {
  1652. posSpreadObj.deletePos(posSheet);
  1653. }
  1654. },
  1655. 'merge-peg': {
  1656. name: '合并起讫桩号',
  1657. disabled: function (key, opt) {
  1658. const node = SpreadJsObj.getSelectObject(billsSheet);
  1659. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  1660. },
  1661. callback: function (key, opt) {
  1662. mergePeg.show();
  1663. },
  1664. visible: function (key, opt) {
  1665. return isTz;
  1666. }
  1667. }
  1668. }
  1669. });
  1670. }
  1671. // 加载清单&计量单元数据
  1672. postData(window.location.pathname + '/load', {}, function (result) {
  1673. billsTree.loadDatas(result.bills);
  1674. treeCalc.calculateAll(billsTree);
  1675. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  1676. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  1677. pos.loadDatas(result.pos);
  1678. posSpreadObj.loadCurPosData();
  1679. SpreadJsObj.resetTopAndSelect(posSheet);
  1680. }, null);
  1681. $.divResizer({
  1682. select: '#revise-resize',
  1683. callback: function () {
  1684. billsSpread.refresh();
  1685. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1686. $(".sp-wrap").height(bcontent-30);
  1687. posSpread.refresh();
  1688. }
  1689. });
  1690. class DealBills {
  1691. constructor (selector, spreadSetting) {
  1692. const self = this;
  1693. this.loaded = false;
  1694. this.obj = $(selector)[0];
  1695. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  1696. this.spreadSetting = spreadSetting;
  1697. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1698. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  1699. if (!readOnly) {
  1700. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1701. const dealSheet = info.sheet;
  1702. const mainSheet = billsSheet;
  1703. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  1704. if (!dealBills) { return; }
  1705. const mainTree = mainSheet.zh_tree;
  1706. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1707. if (!mainNode || !mainTree) { return; }
  1708. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1709. toastr.warning('非最底层项目下,不应添加节点');
  1710. return;
  1711. }
  1712. postData(window.location.pathname + '/update', {
  1713. postType: 'add-deal',
  1714. postData: {
  1715. id: mainNode.ledger_id,
  1716. type: mainNode.code ? 'child' : 'next',
  1717. dealBills: {
  1718. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  1719. unit_price: dealBills.unit_price,
  1720. }
  1721. },
  1722. }, function (result) {
  1723. const refreshData = mainTree.loadPostData(result);
  1724. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1725. const sel = mainSheet.getSelections()[0];
  1726. if (sel && refreshData.create[0]) {
  1727. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1728. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  1729. }
  1730. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1731. billsSpread.focus();
  1732. posSpreadObj.loadCurPosData();
  1733. });
  1734. });
  1735. }
  1736. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1737. }
  1738. loadData (callback) {
  1739. if (this.loaded) {
  1740. if (callback) callback();
  1741. return;
  1742. }
  1743. const self = this;
  1744. postData(this.url+'/get-data', {}, function (data) {
  1745. self.data = data;
  1746. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1747. self.loaded = true;
  1748. if (callback) callback();
  1749. });
  1750. }
  1751. calculateData () {
  1752. if (this.data) {
  1753. for (const d of this.data) {
  1754. d.total_price = _.multiply(d.quantity, d.unit_price);
  1755. }
  1756. }
  1757. }
  1758. }
  1759. class BgBills {
  1760. constructor (selector, spreadSetting) {
  1761. this.loaded = false;
  1762. this.obj = $(selector)[0];
  1763. this.spreadSetting = spreadSetting;
  1764. this.spread = SpreadJsObj.createNewSpread(this.obj);
  1765. this.sheet = this.spread.getActiveSheet();
  1766. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1767. if (!readOnly) {
  1768. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  1769. const dealSheet = info.sheet;
  1770. const mainSheet = billsSheet;
  1771. const bgBills = SpreadJsObj.getSelectObject(dealSheet);
  1772. if (!bgBills) { return; }
  1773. const mainTree = mainSheet.zh_tree;
  1774. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  1775. if (!mainNode || !mainTree) { return; }
  1776. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  1777. toastr.warning('非最底层项目下,不应添加变更清单');
  1778. return;
  1779. }
  1780. postData(window.location.pathname + '/update', {
  1781. postType: 'add-bg',
  1782. postData: {
  1783. id: mainNode.ledger_id,
  1784. type: mainNode.code ? 'child' : 'next',
  1785. dealBills: {
  1786. b_code: bgBills.code, name: bgBills.name, unit: bgBills.unit,
  1787. unit_price: bgBills.unit_price,
  1788. }
  1789. },
  1790. }, function (result) {
  1791. const refreshData = mainTree.loadPostData(result);
  1792. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  1793. const sel = mainSheet.getSelections()[0];
  1794. if (sel && refreshData.create[0]) {
  1795. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  1796. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  1797. }
  1798. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  1799. billsSpread.focus();
  1800. posSpreadObj.loadCurPosData();
  1801. });
  1802. });
  1803. }
  1804. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  1805. }
  1806. loadData () {
  1807. if (this.loaded) return;
  1808. const self = this;
  1809. postData('/tender/' + window.location.pathname.split('/')[2] +'/change/bills', {type: 'gather'}, function (data) {
  1810. self.data = data;
  1811. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  1812. self.loaded = true;
  1813. });
  1814. }
  1815. }
  1816. class BatchInsertBillsPosObj {
  1817. constructor (obj) {
  1818. const self = this;
  1819. this.obj = obj;
  1820. this.billsCount = 6;
  1821. this.posCount = 1000;
  1822. this.filter = getLocalCache('zh-calc-batch-filter');
  1823. if (!this.filter) {
  1824. this.filter = '1';
  1825. }
  1826. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  1827. // 初始化 清单编号窗口 参数
  1828. this.qdSpreadSetting = {
  1829. cols: [
  1830. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  1831. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  1832. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  1833. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  1834. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  1835. ],
  1836. emptyRows: this.billsCount,
  1837. headRows: 1,
  1838. headRowHeight: [32],
  1839. headerFont: '12px 微软雅黑',
  1840. font: '12px 微软雅黑',
  1841. };
  1842. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  1843. // 初始化 部位数量复核表 参数
  1844. this.posSpreadSetting = {
  1845. cols: [
  1846. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  1847. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  1848. ],
  1849. emptyRows: this.posCount,
  1850. headRows: 1,
  1851. headRowHeight: [32],
  1852. headerFont: '12px 微软雅黑',
  1853. font: '12px 微软雅黑',
  1854. };
  1855. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  1856. this.posSpreadSetting.cols.push(
  1857. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  1858. )
  1859. }
  1860. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  1861. // 初始化 签约节点 参数
  1862. this.dealSpreadSetting = {
  1863. cols: [
  1864. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  1865. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  1866. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1867. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  1868. ],
  1869. emptyRows: 0,
  1870. headRows: 1,
  1871. headRowHeight: [32],
  1872. headerFont: '12px 微软雅黑',
  1873. font: '12px 微软雅黑',
  1874. };
  1875. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  1876. // 初始化 清单编号、部位数量复核表 表格
  1877. this.initView();
  1878. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  1879. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  1880. // 拉取签约节点数据
  1881. dealBills.loadData(() => {
  1882. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  1883. });
  1884. // 双击签约节点,自动添加到清单编号窗口
  1885. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  1886. const deal = info.sheet.zh_data[info.row];
  1887. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  1888. const sel = qdSheet.getSelections()[0];
  1889. qdSheet.getCell(sel.row, 0).value(deal.code);
  1890. qdSheet.getCell(sel.row, 1).value(deal.name);
  1891. qdSheet.getCell(sel.row, 2).value(deal.unit);
  1892. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  1893. if (sel.row + 1 === qdSheet.getRowCount()) {
  1894. const count = sel.row + 2;
  1895. qdSheet.setRowCount(count);
  1896. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  1897. const colCount = posSheet.getColumnCount() + 1;
  1898. posSheet.setColumnCount(colCount);
  1899. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  1900. }
  1901. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  1902. qdSheet.getParent().focus();
  1903. });
  1904. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  1905. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  1906. const count = posSheet.getColumnCount() - 2;
  1907. if (billsCount > count) {
  1908. posSheet.setColumnCount(billsCount + 2);
  1909. for (let i = count + 1; i <= billsCount; i++) {
  1910. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  1911. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  1912. }
  1913. }
  1914. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  1915. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  1916. if (dealBills && dealBills.length > 0) {
  1917. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1918. const curRow = iRow + info.cellRange.row;
  1919. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  1920. if (bills) {
  1921. info.sheet.getCell(curRow, 1).value(bills.name);
  1922. info.sheet.getCell(curRow, 2).value(bills.unit);
  1923. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  1924. }
  1925. }
  1926. }
  1927. }
  1928. });
  1929. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  1930. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  1931. const count = qdSheet.getRowCount();
  1932. if (billsCount > count) {
  1933. qdSheet.setRowCount(billsCount);
  1934. for (let i = count + 1; i <= billsCount; i++) {
  1935. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  1936. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  1937. }
  1938. }
  1939. });
  1940. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  1941. if (info.col === 0) {
  1942. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  1943. if (dealBills && dealBills.length > 0) {
  1944. const bills = _.find(dealBills, {code: info.editingText});
  1945. if (bills) {
  1946. info.sheet.getCell(info.row, 1).value(bills.name);
  1947. info.sheet.getCell(info.row, 2).value(bills.unit);
  1948. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  1949. }
  1950. }
  1951. }
  1952. });
  1953. this.obj.bind('shown.bs.modal', function () {
  1954. self.qdSpread.refresh();
  1955. self.posSpread.refresh();
  1956. self.dealSpread.refresh();
  1957. });
  1958. $('#batch-ok').click(function () {
  1959. const selection = billsSheet.getSelections();
  1960. const sel = selection[0];
  1961. const row = selection[0].row;
  1962. const select = billsTree.nodes[row];
  1963. if (select) {
  1964. const insertData = {};
  1965. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  1966. insertData.id = select[billsTree.setting.id];
  1967. insertData.batchData = self.getBatchData();
  1968. if (insertData.batchData.length > 0) {
  1969. postData(window.location.pathname + '/update', {
  1970. postType: 'batch-insert',
  1971. postData: insertData
  1972. }, function (data) {
  1973. pos.updateDatas(data.pos);
  1974. const result = billsTree.loadPostData(data.ledger);
  1975. billsTreeSpreadObj.refreshTree(billsSheet, result);
  1976. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  1977. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  1978. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  1979. posSpreadObj.loadCurPosData();
  1980. self.obj.modal('hide');
  1981. }, null, true);
  1982. } else {
  1983. self.obj.modal('hide');
  1984. }
  1985. }
  1986. });
  1987. $('input[name=batch-filter]').change(function () {
  1988. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  1989. });
  1990. $.contextMenu({
  1991. selector: '.batch-l-t',
  1992. build: function ($trigger, e) {
  1993. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  1994. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1995. },
  1996. items: {
  1997. 'create': {
  1998. name: '新增行',
  1999. icon: 'fa-sign-in',
  2000. callback: function (key, opt) {
  2001. const qdSheet = self.qdSpread.getActiveSheet();
  2002. const posSheet = self.posSpread.getActiveSheet();
  2003. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2004. const index = qdSheet.getRowCount();
  2005. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2006. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2007. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2008. },
  2009. },
  2010. 'delete': {
  2011. name: '删除行',
  2012. icon: 'fa-remove',
  2013. callback: function (key, opt) {
  2014. const qdSheet = self.qdSpread.getActiveSheet();
  2015. const posSheet = self.posSpread.getActiveSheet();
  2016. const sel = qdSheet.getSelections()[0];
  2017. qdSheet.deleteRows(sel.row, sel.rowCount);
  2018. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2019. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2020. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2021. }
  2022. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2023. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2024. }
  2025. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2026. },
  2027. },
  2028. }
  2029. });
  2030. }
  2031. // 初始化左侧表格
  2032. initView () {
  2033. // 初始化 清单编号
  2034. const qdSheet = this.qdSpread.getActiveSheet();
  2035. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  2036. SpreadJsObj.refreshColumnAlign(qdSheet);
  2037. // 清理原有数据
  2038. SpreadJsObj.beginMassOperation(qdSheet);
  2039. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2040. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  2041. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  2042. }
  2043. qdSheet.setSelection(0, 0, 1 ,1);
  2044. SpreadJsObj.endMassOperation(qdSheet);
  2045. // 初始化 部位数量复核表
  2046. const posSheet = this.posSpread.getActiveSheet();
  2047. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  2048. SpreadJsObj.refreshColumnAlign(posSheet);
  2049. // 清理原有数据
  2050. SpreadJsObj.beginMassOperation(posSheet);
  2051. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  2052. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2053. posSheet.setSelection(0, 0, 1 ,1);
  2054. SpreadJsObj.endMassOperation(posSheet);
  2055. // 检查签约节点数据,以工具栏数据为准
  2056. if (dealBills) {
  2057. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2058. }
  2059. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  2060. }
  2061. // 获取界面数据
  2062. getBatchData () {
  2063. const result = [];
  2064. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  2065. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  2066. if (qdSheet.getText(iRow, 0) === '') { continue; }
  2067. const qd = {
  2068. b_code: qdSheet.getText(iRow, 0),
  2069. name: qdSheet.getText(iRow, 1),
  2070. unit: qdSheet.getText(iRow, 2),
  2071. price: _.toNumber(qdSheet.getText(iRow, 3)),
  2072. pos: [],
  2073. };
  2074. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  2075. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  2076. if (value !== 0 && !isNaN(value)) {
  2077. qd.pos.push({
  2078. name: posSheet.getText(iPosRow, 0),
  2079. drawing_code: posSheet.getText(iPosRow, 1),
  2080. quantity: value, porder: qd.pos.length + 1,
  2081. });
  2082. }
  2083. }
  2084. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  2085. }
  2086. return result;
  2087. }
  2088. }
  2089. const dealBills = new DealBills('#deal-bills-spread', {
  2090. cols: [
  2091. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2092. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2093. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2094. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2095. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2096. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2097. ],
  2098. emptyRows: 0,
  2099. headRows: 1,
  2100. headRowHeight: [32],
  2101. headColWidth: [30],
  2102. defaultRowHeight: 21,
  2103. headerFont: '12px 微软雅黑',
  2104. font: '12px 微软雅黑',
  2105. selectedBackColor: '#fffacd',
  2106. });
  2107. const bgBills = new BgBills('#bg-bills-spread', {
  2108. cols: [
  2109. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2110. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2111. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2112. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2113. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2114. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2115. ],
  2116. emptyRows: 0,
  2117. headRows: 1,
  2118. headRowHeight: [32],
  2119. headColWidth: [30],
  2120. defaultRowHeight: 21,
  2121. headerFont: '12px 微软雅黑',
  2122. font: '12px 微软雅黑',
  2123. selectedBackColor: '#fffacd',
  2124. });
  2125. $.divResizer({
  2126. select: '#revise-right-spr',
  2127. callback: function () {
  2128. billsSpread.refresh();
  2129. if (posSpread) {
  2130. posSpread.refresh();
  2131. }
  2132. if (stdXmj) {
  2133. stdXmj.spread.refresh();
  2134. }
  2135. if (stdGcl) {
  2136. stdGcl.spread.refresh();
  2137. }
  2138. if (dealBills) {
  2139. dealBills.spread.refresh();
  2140. }
  2141. if (bgBills) {
  2142. bgBills.spread.refresh();
  2143. }
  2144. if (searchLedger) {
  2145. searchLedger.spread.refresh();
  2146. }
  2147. }
  2148. });
  2149. $.subMenu({
  2150. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2151. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2152. key: 'menu.1.0.0',
  2153. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2154. callback: function (info) {
  2155. if (info.mini) {
  2156. $('.panel-title').addClass('fluid');
  2157. $('#sub-menu').removeClass('panel-sidebar');
  2158. } else {
  2159. $('.panel-title').removeClass('fluid');
  2160. $('#sub-menu').addClass('panel-sidebar');
  2161. }
  2162. autoFlashHeight();
  2163. billsSpread.refresh();
  2164. if (posSpread) {
  2165. posSpread.refresh();
  2166. }
  2167. if (stdXmj) {
  2168. stdXmj.spread.refresh();
  2169. }
  2170. if (stdGcl) {
  2171. stdGcl.spread.refresh();
  2172. }
  2173. if (dealBills) {
  2174. dealBills.spread.refresh();
  2175. }
  2176. if (bgBills) {
  2177. bgBills.spread.refresh();
  2178. }
  2179. if (searchLedger) {
  2180. searchLedger.spread.refresh();
  2181. }
  2182. }
  2183. });
  2184. $('#content-tab').addClass('active');
  2185. $('#xd-content').addClass('active');
  2186. showSideTools(true);
  2187. billsSpread.refresh();
  2188. if (posSpread) {
  2189. posSpread.refresh();
  2190. }
  2191. const stdLibCellDoubleClick = function (e, info) {
  2192. const stdSheet = info.sheet;
  2193. const mainSheet = billsSheet;
  2194. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  2195. const stdTree = stdSheet.zh_tree;
  2196. const stdNode = stdTree.nodes[info.row];
  2197. const mainTree = mainSheet.zh_tree;
  2198. const sel = mainSheet.getSelections()[0];
  2199. const mainNode = mainTree.nodes[sel.row];
  2200. if (!stdNode) return;
  2201. if (info.sheet.zh_setting.stdType === 'gcl') {
  2202. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2203. toastr.warning('非最底层项目下,不应添加节点');
  2204. return;
  2205. }
  2206. }
  2207. postData(window.location.pathname + '/update', {
  2208. postType: 'add-std',
  2209. postData: {
  2210. id: mainTree.getNodeKey(mainNode),
  2211. tender_id: mainNode.tender_id,
  2212. stdType: info.sheet.zh_setting.stdType,
  2213. stdLibId: stdNode.list_id,
  2214. stdNode: stdTree.getNodeKey(stdNode)
  2215. }
  2216. }, function (result) {
  2217. const refreshNode = mainTree.loadPostData(result);
  2218. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  2219. if (sel) {
  2220. if (refreshNode.create && refreshNode.create.length > 0) {
  2221. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  2222. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  2223. } else {
  2224. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  2225. if (node) {
  2226. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  2227. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  2228. }
  2229. }
  2230. }
  2231. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2232. billsSpread.focus();
  2233. posSpreadObj.loadCurPosData();
  2234. });
  2235. };
  2236. const stdXmjSetting = {
  2237. selector: '#std-xmj',
  2238. stdType: 'xmj',
  2239. treeSetting: {
  2240. id: 'chapter_id',
  2241. pid: 'pid',
  2242. order: 'order',
  2243. level: 'level',
  2244. rootId: -1,
  2245. keys: ['id', 'list_id', 'chapter_id'],
  2246. },
  2247. spreadSetting: {
  2248. cols: [
  2249. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2250. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2251. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2252. ],
  2253. treeCol: 0,
  2254. emptyRows: 0,
  2255. headRows: 1,
  2256. headRowHeight: [32],
  2257. defaultRowHeight: 21,
  2258. headerFont: '12px 微软雅黑',
  2259. font: '12px 微软雅黑',
  2260. headColWidth: [0],
  2261. selectedBackColor: '#fffacd',
  2262. },
  2263. cellDoubleClick: stdLibCellDoubleClick,
  2264. page: 'revise',
  2265. tid: window.location.pathname.split('/')[2],
  2266. };
  2267. const stdGclSetting = {
  2268. selector: '#std-gcl',
  2269. stdType: 'gcl',
  2270. treeSetting: {
  2271. id: 'bill_id',
  2272. pid: 'pid',
  2273. order: 'order',
  2274. level: 'level',
  2275. rootId: -1,
  2276. keys: ['id', 'list_id', 'bill_id']
  2277. },
  2278. spreadSetting: {
  2279. cols: [
  2280. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2281. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2282. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2283. ],
  2284. treeCol: 0,
  2285. emptyRows: 0,
  2286. headRows: 1,
  2287. headRowHeight: [32],
  2288. defaultRowHeight: 21,
  2289. headerFont: '12px 微软雅黑',
  2290. font: '12px 微软雅黑',
  2291. headColWidth: [0],
  2292. selectedBackColor: '#fffacd',
  2293. },
  2294. cellDoubleClick: stdLibCellDoubleClick,
  2295. page: 'revise',
  2296. tid: window.location.pathname.split('/')[2],
  2297. };
  2298. // 展开收起标准节点
  2299. $('a', '#side-menu').bind('click', function (e) {
  2300. e.preventDefault();
  2301. const tab = $(this), tabPanel = $(tab.attr('content'));
  2302. // 展开工具栏、切换标签
  2303. if (!tab.hasClass('active')) {
  2304. const close = $('.active', '#side-menu').length === 0;
  2305. $('a', '#side-menu').removeClass('active');
  2306. tab.addClass('active');
  2307. $('.tab-content .tab-pane').removeClass('active');
  2308. tabPanel.addClass('active');
  2309. showSideTools(tab.hasClass('active'));
  2310. if (tab.attr('content') === '#std-xmj') {
  2311. if (!stdXmj) {
  2312. stdXmj = new stdLib(stdXmjSetting);
  2313. }
  2314. stdXmj.spread.refresh();
  2315. } else if (tab.attr('content') === '#std-gcl') {
  2316. if (!stdGcl) {
  2317. stdGcl = new stdLib(stdGclSetting);
  2318. }
  2319. stdGcl.spread.refresh();
  2320. } else if (tab.attr('content') === '#deal-bills') {
  2321. dealBills.loadData();
  2322. dealBills.spread.refresh();
  2323. } else if (tab.attr('content') === '#bg-bills') {
  2324. bgBills.loadData();
  2325. bgBills.spread.refresh();
  2326. } else if (tab.attr('content') === '#search') {
  2327. if (!searchLedger) {
  2328. searchLedger = $.billsSearch({
  2329. selector: '#search',
  2330. searchSpread: billsSpread,
  2331. resultSpreadSetting: {
  2332. cols: [
  2333. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@', readOnly: true},
  2334. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2335. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@', readOnly: true},
  2336. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@', readOnly: true},
  2337. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2338. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2339. ],
  2340. emptyRows: 0,
  2341. headRows: 1,
  2342. headRowHeight: [32],
  2343. headColWidth: [30],
  2344. defaultRowHeight: 21,
  2345. headerFont: '12px 微软雅黑',
  2346. font: '12px 微软雅黑',
  2347. selectedBackColor: '#fffacd',
  2348. },
  2349. afterLocated: function () {
  2350. posSpreadObj.loadCurPosData();
  2351. }
  2352. });
  2353. }
  2354. searchLedger.spread.refresh();
  2355. } else if (tab.attr('content') === '#error-list') {
  2356. errorList.spread.refresh();
  2357. }
  2358. }
  2359. else {// 收起工具栏
  2360. tab.removeClass('active');
  2361. tabPanel.removeClass('active');
  2362. showSideTools(tab.hasClass('active'));
  2363. }
  2364. billsSpread.refresh();
  2365. if (posSpread) {
  2366. posSpread.refresh();
  2367. }
  2368. });
  2369. if (!readOnly) {
  2370. // 修订详情 保存
  2371. $('#save').click(function () {
  2372. const content = $('#content').val();
  2373. postData('save', { content: content }, function () {
  2374. $('#content').attr('org-value', content);
  2375. });
  2376. });
  2377. }
  2378. // 显示层次
  2379. (function (select, sheet) {
  2380. $(select).click(function () {
  2381. if (!sheet.zh_tree) return;
  2382. const tag = $(this).attr('tag');
  2383. const tree = sheet.zh_tree;
  2384. switch (tag) {
  2385. case "1":
  2386. case "2":
  2387. case "3":
  2388. case "4":
  2389. case "5":
  2390. tree.expandByLevel(parseInt(tag));
  2391. SpreadJsObj.refreshTreeRowVisible(sheet);
  2392. break;
  2393. case "last":
  2394. tree.expandByCustom(() => { return true; });
  2395. SpreadJsObj.refreshTreeRowVisible(sheet);
  2396. break;
  2397. case "leafXmj":
  2398. tree.expandToLeafXmj();
  2399. SpreadJsObj.refreshTreeRowVisible(sheet);
  2400. break;
  2401. }
  2402. });
  2403. })('a[name=showLevel]', billsSheet);
  2404. const dataChecker = DataChecker({
  2405. checkUrl: window.location.pathname + '/check',
  2406. completeData: function (data) {
  2407. pos.updateDatas({update: data.source.pos});
  2408. const loadResult = billsTree.loadPostData({update: data.source.bills});
  2409. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2410. posSpreadObj.loadCurPosData();
  2411. for (const e of data.error) {
  2412. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  2413. }
  2414. },
  2415. errorList: errorList,
  2416. });
  2417. $('[name=revise-start]').submit(function (e) {
  2418. if (checkAuditorFrom()) {
  2419. $(this).parent().parent().parent().modal('hide');
  2420. dataChecker.checkAndPost(this.action, {});
  2421. $('#hide-all').hide();
  2422. }
  2423. return false;
  2424. });
  2425. });