revise.js 124 KB

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