revise.js 124 KB

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