revise.js 145 KB

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