revise.js 115 KB

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