revise.js 119 KB

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