revise.js 120 KB

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