revise.js 118 KB

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