change_revise.js 196 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/revise-billsSelect';
  10. const invalidFields = {
  11. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price'],
  12. gcl: ['dgn_qty1', 'dgn_qty2'],
  13. posCode: ['b_code'],
  14. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp'],
  15. posXmj: ['code'],
  16. };
  17. function getExprInfo (field, 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('%', '/100');
  27. }
  28. const copyBlockTag = 'zh.calc.copyBlock';
  29. const dskCompilation = 'zh.calc.dskCompilation';
  30. const checkOption = {
  31. sibling: { enable: 1 },
  32. empty_code: { enable: 1 },
  33. calc: {
  34. enable: 1,
  35. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  36. },
  37. zero: { enable: 1 },
  38. zeroPos: { 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. let stdXmj, stdGcl, searchLedger;
  54. autoFlashHeight();
  55. billsSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', });
  56. if (!billsSpreadSetting.readOnly) {
  57. for (const col of billsSpreadSetting.cols) {
  58. if (!col.readOnly || col.readOnly === false)
  59. col.readOnly = 'readOnly.isChangeAdd';
  60. }
  61. }
  62. posSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', getValue: 'getValue.isChange' });
  63. if (!posSpreadSetting.readOnly) {
  64. for (const col of posSpreadSetting.cols) {
  65. if (!col.readOnly || col.readOnly === false)
  66. col.readOnly = 'readOnly.isChangeAdd';
  67. }
  68. }
  69. const billsCol = {
  70. readOnly: {
  71. isChangeAdd: function (data) {
  72. return !readOnly && !data.formc;
  73. },
  74. isChangeList: function (data) {
  75. if (!data) return true;
  76. let edit = !readOnly && !(data.is_leaf && data.b_code);
  77. if (!edit && data.id) {
  78. const lPos = pos.getLedgerPos(data.id);
  79. if (lPos && lPos.length > 0) {
  80. edit = true;
  81. }
  82. }
  83. return edit;
  84. }
  85. }
  86. };
  87. const posCol = {
  88. getValue: {
  89. isChange: function (data) {
  90. if (!data) return 0;
  91. if (!data.name) return 0;
  92. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  93. return cInfo ? 1 : 0;
  94. }
  95. },
  96. readOnly: {
  97. isChangeAdd: function (data) {
  98. return !readOnly && !data.formc && (data.settle_status && data.settle_status === settleStatus.finish);
  99. },
  100. isChangeList: function (data) {
  101. if (!data) return true;
  102. // console.log(data.name);
  103. return !readOnly && !data.name;
  104. }
  105. }
  106. };
  107. // 判断是否是已结算清单
  108. function checkIsSettle(data) {
  109. const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
  110. if (info && info.settle_status && info.settle_status === settleStatus.finish) {
  111. return true;
  112. }
  113. return false;
  114. }
  115. // 初始化spread
  116. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  117. const billsSheet = billsSpread.getActiveSheet();
  118. billsSpreadSetting.rowHeader = [
  119. {
  120. rowHeaderType: 'circle',
  121. setting: {
  122. size: 5,
  123. indent: 16,
  124. getColor: function (index, data) {
  125. if (!data) return;
  126. if(!data.formc && !data.cid) return;
  127. return '#dc3545';
  128. }
  129. },
  130. },
  131. ];
  132. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  133. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  134. return spreadColor.stage.settle;
  135. }
  136. if (data && data.is_change) {
  137. return '#c3e6cb';
  138. }
  139. return defaultColor;
  140. };
  141. billsSpreadSetting.localCache = {
  142. key: 'changes-ledger-spread',
  143. colWidth: true,
  144. };
  145. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  146. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  147. sjsSettingObj.setNodeTypeCol(billsSpreadSetting.cols, [{field: 'node_type'}]);
  148. SpreadJsObj.initSpreadSettingEvents(billsSpreadSetting, billsCol);
  149. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  150. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  151. const posSheet = posSpread.getActiveSheet();
  152. posSpreadSetting.rowHeader = [
  153. {
  154. rowHeaderType: 'circle',
  155. setting: {
  156. size: 5,
  157. indent: 16,
  158. getColor: function (index, data) {
  159. if (!data) return;
  160. if(!data.formc) return;
  161. return '#dc3545';
  162. }
  163. },
  164. },
  165. ];
  166. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  167. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  168. return spreadColor.stage.settle;
  169. }
  170. return defaultColor;
  171. };
  172. posSpreadSetting.localCache = {
  173. key: 'changes-pos-spread',
  174. colWidth: true,
  175. };
  176. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  177. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  178. SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  179. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  180. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  181. const errorList = $.cs_errorList({
  182. tabSelector: '#error-list-tab',
  183. selector: '#error-list',
  184. relaSpread: billsSpread,
  185. storeKey: 'change-revise-error-' + window.location.pathname.split('/')[2],
  186. afterLocated: function () {
  187. posSpreadObj.loadCurPosData();
  188. },
  189. afterShow: function () {
  190. billsSpread.refresh();
  191. if (posSpread) posSpread.refresh();
  192. },
  193. });
  194. const checkList = $.ledger_checkList({
  195. id: 'check-list',
  196. tabSelector: '#check-list-tab',
  197. selector: '#check-list',
  198. relaSpread: billsSpread,
  199. storeKey: 'change-revise-check-' + window.location.pathname.split('/')[2],
  200. checkType: getCheckType(checkOption),
  201. afterLocated: function () {
  202. posSpreadObj.loadCurPosData();
  203. },
  204. afterShow: function () {
  205. billsSpread.refresh();
  206. if (posSpread) posSpread.refresh();
  207. },
  208. });
  209. const sumLoadMiss = $.sumLoadMiss({
  210. tabSelector: '#sum-load-miss-tab',
  211. selector: '#sum-load-miss',
  212. relaSpread: billsSpread,
  213. storeKey: 'change-revise-slm-' + window.location.pathname.split('/')[2],
  214. id: 'revise-slm',
  215. afterLocated: function () {
  216. posSpreadObj.loadCurPosData();
  217. },
  218. afterShow: function () {
  219. billsSpread.refresh();
  220. if (posSpread) posSpread.refresh();
  221. },
  222. });
  223. // 初始化 节点树结构
  224. const treeSetting = {
  225. id: 'ledger_id',
  226. pid: 'ledger_pid',
  227. order: 'order',
  228. level: 'level',
  229. rootId: -1,
  230. keys: ['id', 'tender_id', 'ledger_id'],
  231. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  232. autoExpand: 3,
  233. markExpandKey: 'change-bills-expand',
  234. markExpandSubKey: window.location.pathname.split('/')[2],
  235. };
  236. if (!isTz) {
  237. treeSetting.calcFields.push('deal_tp');
  238. }
  239. treeSetting.calcFun = function (node) {
  240. if (node && node.b_code && isTz) {
  241. const posData = pos.getLedgerPos(node.id) || [];
  242. if (posData.length > 0) {
  243. let sgfh_qty = 0;
  244. let sjcl_qty = 0;
  245. let qtcl_qty = 0;
  246. for (const np of posData) {
  247. sgfh_qty = ZhCalc.add(sgfh_qty, np.sgfh_qty);
  248. sjcl_qty = ZhCalc.add(sjcl_qty, np.sjcl_qty);
  249. qtcl_qty = ZhCalc.add(qtcl_qty, np.qtcl_qty);
  250. }
  251. if (!_.isEqual(node.sgfh_qty, sgfh_qty) || !_.isEqual(node.sjcl_qty, sjcl_qty) || !_.isEqual(node.qtcl_qty, qtcl_qty)) {
  252. node.sgfh_qty = sgfh_qty;
  253. node.sjcl_qty = sjcl_qty;
  254. node.qtcl_qty = qtcl_qty;
  255. node.quantity = ZhCalc.sum([node.sgfh_qty, node.sjcl_qty, node.qtcl_qty]);
  256. node.sgfh_tp = ZhCalc.mul(sgfh_qty, node.unit_price, decimal.tp) || 0;
  257. node.sjcl_tp = ZhCalc.mul(sjcl_qty, node.unit_price, decimal.tp) || 0;
  258. node.qtcl_tp = ZhCalc.mul(qtcl_qty, node.unit_price, decimal.tp) || 0;
  259. node.total_price = ZhCalc.mul(node.quantity, node.unit_price, decimal.tp) || 0;
  260. }
  261. }
  262. }
  263. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  264. };
  265. const billsTree = createNewPathTree('revise', treeSetting);
  266. // 初始化 计量单元
  267. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  268. // 清单 相关方法&绑定spreadjs事件
  269. const billsTreeSpreadObj = {
  270. loadExprToInput(sheet) {
  271. const sel = sheet.getSelections()[0];
  272. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  273. if (col && col.type === 'Number') {
  274. const data = SpreadJsObj.getSelectObject(sheet);
  275. if (data) {
  276. const exprInfo = getExprInfo(col.field);
  277. if (exprInfo) {
  278. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  279. .attr('field', col.field).attr('org', data[col.field]);
  280. } else {
  281. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  282. }
  283. if (col.field.indexOf('dgn') >= 0) {
  284. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== '') || !data.formc);
  285. } else if (col.field === 'unit_price') {
  286. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true) || !data.formc);
  287. } else {
  288. const nodePos = pos.getLedgerPos(data.id);
  289. if (nodePos && nodePos.length > 0) {
  290. $('#bills-expr').val('').attr('readOnly', true);
  291. $('#bills-expr').removeAttr('data-row');
  292. } else {
  293. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || !data.formc);
  294. }
  295. }
  296. $('#bills-expr').attr('data-row', sel.row);
  297. } else {
  298. $('#bills-expr').val('').attr('readOnly', true);
  299. $('#bills-expr').removeAttr('data-row');
  300. }
  301. } else {
  302. $('#bills-expr').val('').attr('readOnly', true);
  303. $('#bills-expr').removeAttr('data-row');
  304. }
  305. },
  306. getDefaultSelectInfo: function (sheet) {
  307. const tree = sheet.zh_tree;
  308. if (!tree) return;
  309. const sel = sheet.getSelections()[0];
  310. const node = sheet.zh_tree.nodes[sel.row];
  311. if (!node) return;
  312. let count = 1;
  313. if (sel.rowCount > 1) {
  314. for (let r = 1; r < sel.rowCount; r++) {
  315. const rNode = sheet.zh_tree.nodes[sel.row + r];
  316. if (rNode.level > node.level) continue;
  317. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  318. toastr.warning('请选择同一节点下的节点,进行该操作');
  319. return;
  320. }
  321. count += 1;
  322. }
  323. }
  324. return [tree, node, count];
  325. },
  326. /**
  327. * 刷新顶部按钮是否可用
  328. * @param sheet
  329. * @param selections
  330. */
  331. refreshOperationValid: function (sheet, selection) {
  332. const setObjEnable = function (obj, enable) {
  333. if (enable) {
  334. obj.removeClass('disabled');
  335. } else {
  336. obj.addClass('disabled');
  337. }
  338. };
  339. const invalidAll = function () {
  340. setObjEnable($('a[name=base-opr][type=add]'), false);
  341. setObjEnable($('a[name=base-opr][type=delete]'), false);
  342. setObjEnable($('a[name=base-opr][type=up-move]'), false);
  343. setObjEnable($('a[name=base-opr][type=down-move]'), false);
  344. setObjEnable($('a[name=base-opr][type=up-level]'), false);
  345. setObjEnable($('a[name=base-opr][type=down-level]'), false);
  346. };
  347. const sel = selection ? selection[0] : sheet.getSelections()[0];
  348. const row = sel ? sel.row : -1;
  349. const tree = sheet.zh_tree;
  350. if (!tree) {
  351. invalidAll();
  352. return;
  353. }
  354. const first = sheet.zh_tree.nodes[row];
  355. if (!first) {
  356. invalidAll();
  357. return;
  358. }
  359. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  360. if (sel.rowCount > 1 && first) {
  361. for (let r = 1; r < sel.rowCount; r++) {
  362. const rNode = tree.nodes[sel.row + r];
  363. if (!rNode) {
  364. sameParent = false;
  365. break;
  366. }
  367. if (!rNode.formc) {
  368. sameParent = false;
  369. break;
  370. }
  371. nodeUsed = nodeUsed || rNode.used;
  372. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  373. if (rNode.level > first.level) continue;
  374. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  375. sameParent = false;
  376. break;
  377. }
  378. last = rNode;
  379. }
  380. }
  381. const preNode = tree.getPreSiblingNode(first);
  382. const siblings = tree.getChildren(tree.getParent(first));
  383. let upPower = true;
  384. for (let order = last.order; order < siblings.length - 1; order ++) {
  385. if (!siblings[order].formc) {
  386. upPower = false;
  387. break;
  388. }
  389. }
  390. const valid = !sheet.zh_setting.readOnly;
  391. setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  392. setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed && first.formc && !settleFinish);
  393. setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode && first.formc);
  394. setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last) && first.formc);
  395. const posRange = last ? pos.getLedgerPos(last.id) : [];
  396. setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  397. && first.level > 2 && ((!posRange || posRange.length === 0) || last.settle_status !== settleStatus.finish || tree.isLastSibling(last)) && upPower && first.formc);
  398. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  399. setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
  400. && first.level > 1 && preNode && (preNode.children.length > 0 || (preNode.children.length === 0 && preNode.formc && (!preNodePosRange || preNodePosRange.length === 0))) && !preNode.used && first.formc && preNode.settle_status !== settleStatus.finish);
  401. setObjEnable($('#cut'), valid);
  402. setObjEnable($('#paste'), valid);
  403. },
  404. /**
  405. *
  406. * @param sheet
  407. * @param data
  408. */
  409. refreshTree: function (sheet, data) {
  410. SpreadJsObj.massOperationSheet(sheet, function () {
  411. const tree = sheet.zh_tree;
  412. // 处理删除
  413. if (data.delete) {
  414. data.delete.sort(function (a, b) {
  415. return b.deleteIndex - a.deleteIndex;
  416. });
  417. for (const d of data.delete) {
  418. sheet.deleteRows(d.deleteIndex, 1);
  419. }
  420. }
  421. // 处理新增
  422. if (data.create) {
  423. const newNodes = data.create;
  424. if (newNodes) {
  425. newNodes.sort(function (a, b) {
  426. return a.index - b.index;
  427. });
  428. for (const node of newNodes) {
  429. sheet.addRows(node.index, 1);
  430. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  431. }
  432. }
  433. }
  434. // 处理更新
  435. if (data.update) {
  436. const rows = [];
  437. for (const u of data.update) {
  438. rows.push(tree.nodes.indexOf(u));
  439. }
  440. SpreadJsObj.reLoadRowsData(sheet, rows);
  441. }
  442. // 处理展开
  443. if (data.expand) {
  444. const expanded = [];
  445. for (const e of data.expand) {
  446. if (expanded.indexOf(e) === -1) {
  447. const posterity = tree.getPosterity(e);
  448. for (const p of posterity) {
  449. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  450. expanded.push(p);
  451. }
  452. }
  453. }
  454. }
  455. });
  456. },
  457. selectionChanged: function (e, info) {
  458. if (info.newSelections) {
  459. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  460. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  461. billsTreeSpreadObj.refreshPosData();
  462. }
  463. }
  464. billsTreeSpreadObj.loadExprToInput(info.sheet);
  465. },
  466. refreshPosData: function() {
  467. SpreadJsObj.resetTopAndSelect(posSheet);
  468. posSpreadObj.loadCurPosData();
  469. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  470. posSearch.search($('#pos-keyword').val());
  471. },
  472. /**
  473. * 新增节点
  474. * @param spread
  475. */
  476. baseOpr: function (sheet, type, addCount = 1) {
  477. const self = this;
  478. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  479. if (!tree || !node || !count) return;
  480. if (type === 'delete') {
  481. const parent = tree.getParent(node);
  482. const children = parent ? parent.children : tree.children;
  483. const index = children.indexOf(node);
  484. for (let i = 0; i < count; i++) {
  485. const child = children[i+index];
  486. if (tree.checkNodeUsed(child, pos)) {
  487. toastr.warning('选中的节点已计量,不可删除');
  488. return;
  489. }
  490. if (child.settle_status === settleStatus.finish) {
  491. toastr.warning('选中的节点已结算,不可删除');
  492. return;
  493. }
  494. }
  495. } else if (type === 'up-level') {
  496. const parent = tree.getParent(node);
  497. const children = parent ? parent.children : tree.children;
  498. const index = children.indexOf(node);
  499. const lastSelect = children[index + count - 1];
  500. if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) {
  501. toastr.warning('选中的节点已计量,不可升级');
  502. return;
  503. }
  504. if (lastSelect.settle_status === settleStatus.finish && (children.length > index + count)) {
  505. toastr.warning('选中的节点已结算,不可升级');
  506. return;
  507. }
  508. // for (let i = index; i < children.length; i++) {
  509. // const child = children[index];
  510. // if (tree.checkNodeUsed(child, pos)) {
  511. // if (i >= index + count) {
  512. // toastr.warning('其后节点已计量,选中的节点不可升级');
  513. // } else {
  514. // toastr.warning('选中的节点已计量,不可升级');
  515. // }
  516. // return;
  517. // }
  518. // }
  519. } else if (type === 'down-level') {
  520. const parent = tree.getParent(node);
  521. const children = parent ? parent.children : tree.children;
  522. const index = children.indexOf(node);
  523. if (index > 0 && children[index-1].used) {
  524. toastr.warning('其前节点已计量,选中的节点不可降级');
  525. return;
  526. }
  527. if (index > 0 && children[index-1].settle_status === settleStatus.finish) {
  528. toastr.warning('其前节点已结算,选中的节点不可降级');
  529. return;
  530. }
  531. for (let i = index; i < count; i++) {
  532. const child = children[i+index];
  533. if (tree.checkNodeUsed(child, pos)) {
  534. toastr.warning('选中的节点已计量,不可降级');
  535. return;
  536. }
  537. if (tree.settle_status === settleStatus.finish) {
  538. toastr.warning('选中的节点已结算,不可降级');
  539. return;
  540. }
  541. }
  542. } else if (type === 'add') {
  543. if (node.settle_status === settleStatus.finish) {
  544. toastr.warning('选中的节点已结算,不可新增子项');
  545. return;
  546. }
  547. }
  548. if (type === 'delete') {
  549. deleteAfterHint(function () {
  550. postData(window.location.pathname + '/update', {
  551. postType: type,
  552. postData: {
  553. id: node.ledger_id,
  554. count: type === 'add' ? addCount : count,
  555. }
  556. }, function (result) {
  557. changeList = result.changeList;
  558. const refreshData = tree.loadPostData(result);
  559. self.refreshTree(sheet, refreshData);
  560. const sel = sheet.getSelections()[0];
  561. if (sel) {
  562. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  563. billsTreeSpreadObj.refreshPosData();
  564. }
  565. self.refreshOperationValid(sheet);
  566. });
  567. });
  568. } else {
  569. postData(window.location.pathname + '/update', {
  570. postType: type,
  571. postData: {
  572. id: node.ledger_id,
  573. count: type === 'add' ? addCount : count,
  574. }
  575. }, function (result) {
  576. changeList = result.changeList;
  577. const refreshData = tree.loadPostData(result);
  578. self.refreshTree(sheet, refreshData);
  579. if (['up-move', 'down-move'].indexOf(type) > -1) {
  580. const sel = sheet.getSelections()[0];
  581. if (sel) {
  582. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  583. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  584. }
  585. } else if (type === 'add') {
  586. const sel = sheet.getSelections()[0];
  587. if (sel) {
  588. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  589. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
  590. billsTreeSpreadObj.refreshPosData();
  591. }
  592. }
  593. self.refreshOperationValid(sheet);
  594. });
  595. }
  596. },
  597. buttonClicked: function (e, info, v) {
  598. if (info.sheet.zh_setting) {
  599. const select = SpreadJsObj.getSelectObject(info.sheet);
  600. const col = info.sheet.zh_setting.cols[info.col];
  601. if (col.field === 'is_change') {
  602. if (billsCol.readOnly.isChangeList(select)) {
  603. return
  604. }
  605. if (info.sheet.isEditing()) {
  606. info.sheet.endEdit(true);
  607. }
  608. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  609. if (is_change) {
  610. makeGclGatherData();
  611. const gclInfo = _.find(gclGatherData, function (item) {
  612. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
  613. });
  614. const xmjInfo = gclInfo.leafXmjs[0];
  615. const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
  616. const data = {
  617. lid: select.id,
  618. code: gclInfo.b_code,
  619. name: gclInfo.name || '',
  620. unit: gclInfo.unit || '',
  621. unit_price: gclInfo.unit_price,
  622. oamount: xmjInfo.quantity,
  623. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  624. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  625. xmj_code: xmjInfo.code || '',
  626. xmj_jldy: xmjInfo.jldy || '',
  627. xmj_dwgc: xmjInfo.dwgc || '',
  628. xmj_fbgc: xmjInfo.fbgc || '',
  629. xmj_fxgc: xmjInfo.fxgc || '',
  630. gcl_id: select.id,
  631. mx_id: '',
  632. };
  633. if (oldCInfo) {
  634. data.detail = oldCInfo.detail;
  635. data.camount = oldCInfo.camount;
  636. data.spamount = oldCInfo.spamount;
  637. data.is_valuation = oldCInfo.is_valuation;
  638. data.delimit = oldCInfo.delimit;
  639. }
  640. // 更新至服务器
  641. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  642. changeList = result.changeList;
  643. select.is_change = 1;
  644. }, function () {
  645. info.sheet.setValue(info.row, info.col, 0);
  646. });
  647. console.log(data);
  648. } else {
  649. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.id }) !== -1) {
  650. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  651. info.sheet.setValue(info.row, info.col, 1);
  652. return
  653. }
  654. const cInfo = _.find(changeList, { gcl_id: select.id });
  655. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  656. toastr.warning('该清单计量单元已被使用,无法取消勾选');
  657. info.sheet.setValue(info.row, info.col, 1);
  658. return
  659. } else if (checkIsSettle(cInfo)) {
  660. toastr.warning('该清单计量单元已结算,无法取消勾选');
  661. info.sheet.setValue(info.row, info.col, 1);
  662. return
  663. } else {
  664. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  665. changeList = result.changeList;
  666. select.is_change = 0;
  667. }, function () {
  668. info.sheet.setValue(info.row, info.col, 1);
  669. });
  670. }
  671. }
  672. }
  673. }
  674. },
  675. /**
  676. * 编辑单元格响应事件
  677. * @param {Object} e
  678. * @param {Object} info
  679. */
  680. editEnded: function (e, info) {
  681. if (info.sheet.zh_setting) {
  682. const col = info.sheet.zh_setting.cols[info.col];
  683. if (col.field === 'is_change') {
  684. return;
  685. }
  686. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  687. const node = sortData[info.row];
  688. const data = {
  689. id: node.id,
  690. tender_id: node.tender_id,
  691. ledger_id: node.ledger_id
  692. };
  693. // 未改变值则不提交
  694. const orgValue = node[col.field];
  695. const newValue = trimInvalidChar(info.editingText);
  696. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  697. return;
  698. }
  699. // 台账模式,检查计量单元相关
  700. if (isTz) {
  701. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  702. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  703. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  704. if (!node.children || node.children.length ===0) {
  705. const lPos = pos.getLedgerPos(node.id);
  706. if (lPos && lPos.length > 0) {
  707. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  708. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  709. return;
  710. }
  711. }
  712. }
  713. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  714. const lPos = pos.getLedgerPos(node.id);
  715. if (lPos && lPos.length > 0) {
  716. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  717. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  718. return;
  719. }
  720. }
  721. }
  722. // 获取更新数据
  723. const exprInfo = getExprInfo(col.field);
  724. if (info.editingText) {
  725. const text = newValue;
  726. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  727. toastr.error('节点已计量,请勿删除编号');
  728. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  729. return;
  730. }
  731. if (col.type === 'Number') {
  732. const num = _.toNumber(text);
  733. if (_.isFinite(num)) {
  734. data[col.field] = num;
  735. if (exprInfo) {
  736. data[exprInfo.expr] = '';
  737. }
  738. } else {
  739. try {
  740. data[col.field] = math.evaluate(transExpr(text));
  741. if (exprInfo) {
  742. data[exprInfo.expr] = newValue;
  743. }
  744. } catch(err) {
  745. toastr.error('输入的表达式非法');
  746. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  747. return;
  748. }
  749. }
  750. } else {
  751. data[col.field] = text;
  752. }
  753. } else {
  754. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  755. toastr.error('节点已计量,请勿删除编号');
  756. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  757. return;
  758. }
  759. data[col.field] = null;
  760. if (exprInfo) {
  761. data[exprInfo.expr] = '';
  762. }
  763. }
  764. if (col.field === 'b_code' && newValue) {
  765. const ledgerData = _.filter(billsTree.nodes, function (item) {
  766. return item.b_code !== null && item.b_code !== '' && !item.formc;
  767. });
  768. const ledgerOneData = _.find(ledgerData, { b_code: newValue });
  769. if (ledgerOneData) {
  770. data.name = ledgerOneData.name;
  771. data.unit = ledgerOneData.unit;
  772. data.unit_price = ledgerOneData.unit_price;
  773. }
  774. }
  775. // 更新至服务器
  776. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  777. changeList = result.changeList;
  778. const refreshNode = billsTree.loadPostData(result);
  779. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  780. });
  781. }
  782. },
  783. clipboardPasting: function (e, info) {
  784. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  785. info.cancel = true;
  786. if (!setting || !tree) return;
  787. // const range = info.cellRange;
  788. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  789. // const node = tree.nodes[iRow];
  790. // if (tree.checkNodeUsed(node, pos)) {
  791. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  792. // return;
  793. // }
  794. // }
  795. const pasteData = info.pasteData.html
  796. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  797. : (info.pasteData.text === ''
  798. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  799. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  800. const hint = {
  801. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  802. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  803. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  804. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  805. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  806. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  807. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  808. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  809. // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  810. settle: {type: 'warning', msg: '已结算节点,不可修改数量、单价、金额'},
  811. };
  812. const datas = [], filterNodes = [];
  813. let pid, level, filterRow = 0;
  814. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  815. const curRow = info.cellRange.row + iRow;
  816. const node = tree.nodes[curRow];
  817. if (!node) continue;
  818. if (!pid) pid = node.ledger_pid;
  819. if (!level) level = node.level;
  820. // if (node.ledger_pid !== pid) {
  821. // toastMessageUniq(hint.sameParent);
  822. // filterRow+=1;
  823. // continue;
  824. // }
  825. if (node.level < level) break;
  826. let bPaste = false;
  827. const data = info.sheet.zh_tree.getNodeKeyData(node);
  828. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  829. const curCol = info.cellRange.col + iCol;
  830. const colSetting = info.sheet.zh_setting.cols[curCol];
  831. const value = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  832. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  833. toastMessageUniq(hint.parent);
  834. continue;
  835. }
  836. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  837. toastMessageUniq(hint.gcl);
  838. continue;
  839. }
  840. const lPos = pos.getLedgerPos(node.id);
  841. if (lPos && lPos.length > 0) {
  842. if (value === '' && colSetting.field === 'b_code') {
  843. toastMessageUniq(hint.posCode);
  844. continue;
  845. }
  846. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  847. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  848. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  849. toastMessageUniq(hint.posQty);
  850. continue;
  851. }
  852. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  853. toastMessageUniq(hint.posXmj);
  854. continue;
  855. }
  856. }
  857. if (tree.checkNodeUsed(node, pos) && colSetting.field === 'unit_price') {
  858. toastMessageUniq (hint.usedUp);
  859. continue;
  860. }
  861. if (colSetting.type === 'Number' && node.settle_status === settleStatus.finish) {
  862. toastMessageUniq(hint.settle);
  863. continue;
  864. }
  865. if (colSetting.type === 'Number') {
  866. const num = _.toNumber(value);
  867. if (num) {
  868. data[colSetting.field] = num;
  869. } else {
  870. try {
  871. data[colSetting.field] = math.evaluate(transExpr(value));
  872. const exprInfo = getExprInfo(colSetting.field);
  873. if (exprInfo) {
  874. data[exprInfo.expr] = value;
  875. }
  876. bPaste = true;
  877. } catch (err) {
  878. toastMessageUniq(hint.invalidExpr);
  879. continue;
  880. }
  881. }
  882. } else {
  883. if (node.used && (colSetting.field === 'code' || colSetting.field ==='b_code')
  884. && data[colSetting.field] !== '' && value === '') {
  885. toastMessageUniq(hint.usedCode);
  886. continue;
  887. }
  888. data[colSetting.field] = value;
  889. }
  890. if (colSetting.field === 'b_code' && value) {
  891. const ledgerData = _.filter(billsTree.nodes, function (item) {
  892. return item.b_code !== null && item.b_code !== '' && !item.formc;
  893. });
  894. const ledgerOneData = _.find(ledgerData, { b_code: value });
  895. if (ledgerOneData) {
  896. data.name = ledgerOneData.name;
  897. data.unit = ledgerOneData.unit;
  898. data.unit_price = ledgerOneData.unit_price;
  899. }
  900. }
  901. bPaste = true;
  902. }
  903. if (bPaste) {
  904. datas.push(data);
  905. } else {
  906. filterNodes.push(node);
  907. }
  908. }
  909. if (datas.length > 0) {
  910. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  911. changeList = result.changeList;
  912. const refreshNode = tree.loadPostData(result);
  913. if (refreshNode.update) {
  914. refreshNode.update = refreshNode.update.concat(filterNodes);
  915. }
  916. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  917. }, function () {
  918. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  919. });
  920. } else {
  921. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  922. }
  923. },
  924. clipboardPasted: function (e, info) {
  925. const hint = {
  926. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  927. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  928. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  929. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  930. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  931. };
  932. const tree = info.sheet.zh_tree;
  933. if (!tree) { return; }
  934. const sortData = info.sheet.zh_tree.nodes;
  935. const datas = [], filterNodes = [];
  936. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  937. let bPaste = false;
  938. const curRow = info.cellRange.row + iRow;
  939. const node = sortData[curRow];
  940. if (node) {
  941. const data = info.sheet.zh_tree.getNodeKeyData(node);
  942. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  943. const curCol = info.cellRange.col + iCol;
  944. const colSetting = info.sheet.zh_setting.cols[curCol];
  945. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  946. const lPos = pos.getLedgerPos(node.id);
  947. if (lPos && lPos.length > 0) {
  948. if (value === '' && colSetting.field === 'b_code') {
  949. toastMessageUniq(hint.posCode);
  950. continue;
  951. }
  952. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  953. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  954. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  955. toastMessageUniq(hint.posQty);
  956. continue;
  957. }
  958. }
  959. if (node.used && colSetting.field === 'unit_price') {
  960. toastMessageUniq (hint.usedUp);
  961. continue;
  962. }
  963. if (colSetting.type === 'Number') {
  964. const num = _.toNumber(value);
  965. if (num) {
  966. data[colSetting.field] = num;
  967. } else {
  968. try {
  969. data[colSetting.field] = math.evaluate(transExpr(value));
  970. } catch (err) {
  971. toastMessageUniq(hint.invalidExpr);
  972. continue;
  973. }
  974. }
  975. } else {
  976. if (node.used && (colSetting.field === 'code' || colSetting.field === 'b_code')
  977. && data[colSetting.field] !== '' && value === '') {
  978. toastMessageUniq(hint.usedCode);
  979. continue;
  980. }
  981. data[colSetting.field] = value;
  982. }
  983. if (colSetting.field === 'b_code' && value) {
  984. const ledgerData = _.filter(billsTree.nodes, function (item) {
  985. return item.b_code !== null && item.b_code !== '' && !item.formc;
  986. });
  987. const ledgerOneData = _.find(ledgerData, { b_code: value });
  988. if (ledgerOneData) {
  989. data.name = ledgerOneData.name;
  990. data.unit = ledgerOneData.unit;
  991. data.unit_price = ledgerOneData.unit_price;
  992. }
  993. }
  994. bPaste = true;
  995. }
  996. if (bPaste) {
  997. datas.push(data);
  998. } else {
  999. filterNodes.push(node);
  1000. }
  1001. }
  1002. }
  1003. if (datas.length > 0) {
  1004. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1005. changeList = result.changeList;
  1006. const refreshNode = tree.loadPostData(result);
  1007. if (refreshNode.update) {
  1008. refreshNode.update = refreshNode.update.concat(filterNodes);
  1009. }
  1010. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1011. }, function () {
  1012. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1013. });
  1014. } else {
  1015. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1016. }
  1017. },
  1018. deletePress: function (sheet) {
  1019. if (!sheet.zh_setting) return;
  1020. const sel = sheet.getSelections()[0], datas = [];
  1021. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1022. let bDel = false;
  1023. const node = sheet.zh_tree.nodes[iRow];
  1024. const data = sheet.zh_tree.getNodeKeyData(node);
  1025. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1026. const col = sheet.zh_setting.cols[iCol];
  1027. const style = sheet.getStyle(iRow, iCol);
  1028. if (style.locked || (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) >= 0 && node.b_code)) continue;
  1029. if (col.type === 'Number' && node.settle_status === settleStatus.finish) continue;
  1030. if (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) < 0 && sheet.zh_tree.checkNodeUsed(node, pos)) {
  1031. toastr.warning('"' + (node.code || '') + (node.b_code || '') + ' ' + node.name +'"已计量,请勿修改');
  1032. return;
  1033. }
  1034. data[col.field] = null;
  1035. const exprInfo = getExprInfo(col.field);
  1036. if (exprInfo) {
  1037. data[exprInfo.expr] = '';
  1038. }
  1039. bDel = true;
  1040. }
  1041. if (bDel) datas.push(data);
  1042. }
  1043. if (datas.length > 0) {
  1044. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1045. changeList = result.changeList;
  1046. const refreshNode = sheet.zh_tree.loadPostData(result);
  1047. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1048. billsTreeSpreadObj.loadExprToInput(sheet);
  1049. });
  1050. }
  1051. },
  1052. pasteBlock: function (spread, copyInfo) {
  1053. const self = this;
  1054. const sheet = spread.getActiveSheet();
  1055. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  1056. if (node.settle_status === settleStatus.finish) {
  1057. toastr.warning('选中的节点已结算,不可粘贴整块');
  1058. return;
  1059. }
  1060. postData(window.location.pathname + '/update', {
  1061. postType: 'paste-block',
  1062. postData: {
  1063. id: tree.getNodeKey(node),
  1064. tid: copyInfo.tid,
  1065. block: copyInfo.block,
  1066. }
  1067. }, function (data) {
  1068. changeList = data.changeList;
  1069. pos.updateDatas(data.pos);
  1070. const result = tree.loadPostData(data.ledger);
  1071. self.refreshTree(sheet, result);
  1072. const sel = sheet.getSelections()[0];
  1073. if (sel) {
  1074. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  1075. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  1076. }
  1077. self.refreshOperationValid(sheet);
  1078. removeLocalCache(copyBlockTag);
  1079. }, null, true);
  1080. },
  1081. topRowChanged: function (e, info) {
  1082. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1083. },
  1084. editStarting(e, info) {
  1085. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1086. const col = info.sheet.zh_setting.cols[info.col];
  1087. const node = info.sheet.zh_tree.nodes[info.row];
  1088. if (!node) {
  1089. info.cancel = true;
  1090. return;
  1091. }
  1092. const exprInfo = getExprInfo(col.field);
  1093. if (exprInfo) {
  1094. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1095. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1096. }
  1097. }
  1098. switch (col.field) {
  1099. case 'code':
  1100. const posRange = pos.getLedgerPos(node.id);
  1101. info.cancel = posRange && posRange.length > 0;
  1102. break;
  1103. case 'unit_price':
  1104. info.cancel = (node.children && node.children.length > 0) || node.used || node.settle_status === settleStatus.finish;
  1105. break;
  1106. case 'sgfh_qty':
  1107. case 'sgfh_tp':
  1108. case 'sjcl_qty':
  1109. case 'sjcl_tp':
  1110. case 'qtcl_qty':
  1111. case 'qtcl_tp':
  1112. case 'deal_qty':
  1113. case 'deal_tp':
  1114. info.cancel = (node.children && node.children.length > 0) || node.settle_status === settleStatus.finish;
  1115. break;
  1116. case 'dgn_qty1':
  1117. case 'dgn_qty2':
  1118. info.cancel = !_.isEmpty(node.b_code || node.settle_status === settleStatus.finish);
  1119. break;
  1120. }
  1121. },
  1122. cut: function (sheet, sel, callback) {
  1123. if (!sheet || !sel) return;
  1124. if (sel.colCount >= sheet.zh_setting.cols.length) {
  1125. toastr.warning('请勿选中整行剪切');
  1126. return;
  1127. }
  1128. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  1129. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1130. const node = sortData[iRow];
  1131. if (node) {
  1132. const data = sheet.zh_tree.getNodeKeyData(node);
  1133. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1134. const col = sheet.zh_setting.cols[iCol];
  1135. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  1136. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  1137. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  1138. const lPos = pos.getLedgerPos(node.id);
  1139. if (lPos && lPos.length > 0) {
  1140. toastr.error('不可剪切');
  1141. return;
  1142. }
  1143. }
  1144. const style = sheet.getStyle(iRow, iCol);
  1145. if (style.locked) {
  1146. toastr.error('不可剪切');
  1147. return;
  1148. }
  1149. const colSetting = sheet.zh_setting.cols[iCol];
  1150. data[colSetting.field] = null;
  1151. const exprInfo = getExprInfo(colSetting.field);
  1152. if (exprInfo) {
  1153. data[exprInfo.expr] = '';
  1154. }
  1155. }
  1156. datas.push(data);
  1157. }
  1158. }
  1159. if (datas.length > 0) {
  1160. callback();
  1161. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1162. changeList = result.changeList;
  1163. const refreshNode = sheet.zh_tree.loadPostData(result);
  1164. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1165. });
  1166. }
  1167. },
  1168. sortCode: function (sheet) {
  1169. const tree = sheet.zh_tree;
  1170. if (!tree) return;
  1171. const select = SpreadJsObj.getSelectObject(sheet);
  1172. if (!select || !select.code || select.code === '') return;
  1173. const recursiveSortCode = function (data, parentCode, children) {
  1174. if (!children || children.length === 0) return;
  1175. for (const [i, child] of children.entries()) {
  1176. if (!child.b_code || child.b_code === '') {
  1177. const code = parentCode + '-' + (i + 1);
  1178. const cData = tree.getNodeKeyData(child);
  1179. cData.code = code;
  1180. data.push(cData);
  1181. if (!tree.isLeafXmj(child)) {
  1182. recursiveSortCode(data, code, child.children);
  1183. }
  1184. }
  1185. }
  1186. };
  1187. const data = [];
  1188. recursiveSortCode(data, select.code, select.children);
  1189. if (data.length > 0) {
  1190. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1191. changeList = result.changeList;
  1192. const refreshNode = tree.loadPostData(result);
  1193. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1194. })
  1195. }
  1196. }
  1197. };
  1198. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1199. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1200. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  1201. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  1202. if (!readOnly) {
  1203. // 增删上下移升降级
  1204. $('a[name="base-opr"]').click(function () {
  1205. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  1206. });
  1207. $('a[name=cpc]').click(function () {
  1208. billsSpread.commandManager().execute({
  1209. cmd: this.getAttribute('type'),
  1210. sheetName: billsSheet.name()
  1211. });
  1212. });
  1213. $('#bills-expr').bind('change onblur', function () {
  1214. if (this.readOnly) return;
  1215. const expr = $(this);
  1216. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1217. const select = billsTree.getItemsByIndex(row);
  1218. if (!select) return;
  1219. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1220. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1221. const data = {
  1222. id: select.id,
  1223. tender_id: select.tender_id,
  1224. ledger_id: select.ledger_id
  1225. };
  1226. const exprInfo = getExprInfo(field);
  1227. if (newValue !== '') {
  1228. const num = _.toNumber(newValue);
  1229. if (num) {
  1230. data[field] = num;
  1231. if (exprInfo) {
  1232. data[exprInfo.expr] = '';
  1233. }
  1234. } else {
  1235. try {
  1236. data[field] = math.evaluate(transExpr(newValue));
  1237. if (exprInfo) {
  1238. data[exprInfo.expr] = newValue;
  1239. }
  1240. } catch (err) {
  1241. toastr.error('输入的表达式非法');
  1242. return;
  1243. }
  1244. }
  1245. } else {
  1246. data[field] = null;
  1247. if (exprInfo) {
  1248. data[exprInfo.expr] = '';
  1249. }
  1250. }
  1251. // 更新至服务器
  1252. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1253. changeList = result.changeList;
  1254. const refreshNode = billsTree.loadPostData(result);
  1255. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1256. });
  1257. });
  1258. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  1259. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  1260. billsSpread.bind(spreadNS.Events.ButtonClicked, billsTreeSpreadObj.buttonClicked);
  1261. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  1262. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  1263. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  1264. SpreadJsObj.Clipboard.setCopyData(copyText);
  1265. });
  1266. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  1267. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  1268. }
  1269. // 右键菜单
  1270. let batchInsertObj;
  1271. $.contextMenu.types.batchInsert = function (item, opt, root) {
  1272. const self = this;
  1273. if ($.isFunction(item.icon)) {
  1274. item._icon = item.icon.call(this, this, $t, key, item);
  1275. } else {
  1276. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1277. // to enable font awesome
  1278. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1279. } else {
  1280. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1281. }
  1282. }
  1283. this.addClass(item._icon);
  1284. 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>')
  1285. .appendTo(this);
  1286. const $input = $obj.find('input');
  1287. const event = () => {
  1288. if (self.hasClass('context-menu-disabled')) return;
  1289. item.batchInsert($input[0], root);
  1290. };
  1291. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  1292. $input.click((e) => {e.stopPropagation();})
  1293. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  1294. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  1295. };
  1296. const billsContextMenuOptions = {
  1297. selector: '#bills-spread',
  1298. build: function ($trigger, e) {
  1299. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  1300. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1301. },
  1302. items: {}
  1303. };
  1304. if (!readOnly) {
  1305. billsContextMenuOptions.items.create = {
  1306. name: '新增',
  1307. icon: 'fa-sign-in',
  1308. callback: function (key, opt) {
  1309. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  1310. },
  1311. disabled: function (key, opt) {
  1312. const sheet = billsSheet;
  1313. const selection = sheet.getSelections();
  1314. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1315. const row = sel ? sel.row : -1;
  1316. const tree = sheet.zh_tree;
  1317. if (!tree) return true;
  1318. const first = sheet.zh_tree.nodes[row];
  1319. const valid = !sheet.zh_setting.readOnly;
  1320. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  1321. }
  1322. };
  1323. billsContextMenuOptions.items.delete = {
  1324. name: '删除',
  1325. icon: 'fa-remove',
  1326. callback: function (key, opt) {
  1327. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  1328. },
  1329. disabled: function (key, opt) {
  1330. const sheet = billsSheet;
  1331. const selection = sheet.getSelections();
  1332. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1333. const row = sel ? sel.row : -1;
  1334. const tree = sheet.zh_tree;
  1335. if (!tree) return true;
  1336. const first = sheet.zh_tree.nodes[row];
  1337. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  1338. if (sel.rowCount > 1 && first) {
  1339. for (let r = 1; r < sel.rowCount; r++) {
  1340. const rNode = tree.nodes[sel.row + r];
  1341. if (!rNode) {
  1342. sameParent = false;
  1343. break;
  1344. }
  1345. if (!rNode.formc) {
  1346. return true;
  1347. }
  1348. nodeUsed = nodeUsed || rNode.used;
  1349. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  1350. if (rNode.level > first.level) continue;
  1351. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1352. sameParent = false;
  1353. break;
  1354. }
  1355. last = rNode;
  1356. }
  1357. }
  1358. const valid = !sheet.zh_setting.readOnly;
  1359. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed && first.formc && !settleFinish);
  1360. }
  1361. };
  1362. billsContextMenuOptions.items.sprBase = '----';
  1363. }
  1364. billsContextMenuOptions.items.copyBlock = {
  1365. name: '复制整块',
  1366. icon: 'fa-files-o',
  1367. callback: function (key, opt) {
  1368. const copyBlockList = [];
  1369. const sheet = billsSheet;
  1370. const sel = sheet.getSelections()[0];
  1371. let iRow = sel.row;
  1372. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1373. while (iRow < sel.row + sel.rowCount) {
  1374. const node = sheet.zh_tree.nodes[iRow];
  1375. if (node.ledger_pid !== pid) {
  1376. toastr.error('仅可同时选中同层节点');
  1377. return;
  1378. }
  1379. const posterity = sheet.zh_tree.getPosterity(node);
  1380. iRow += posterity.length + 1;
  1381. posterity.unshift(node);
  1382. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1383. }
  1384. for (const cbl of copyBlockList) {
  1385. for (const b of cbl) {
  1386. const posRange = pos.getLedgerPos(b.id);
  1387. if (posRange && posRange.length > 0) b.pos = posRange;
  1388. }
  1389. }
  1390. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1391. },
  1392. visible: function (key, opt) {
  1393. const sheet = billsSheet;
  1394. const selection = sheet.getSelections();
  1395. const row = selection[0].row;
  1396. const select = billsTree.nodes[row];
  1397. return select;
  1398. },
  1399. disabled: function (key, opt) {
  1400. const sheet = billsSheet;
  1401. const selection = sheet.getSelections();
  1402. const row = selection[0].row;
  1403. const select = billsTree.nodes[row];
  1404. return select && select.level <= 1;
  1405. }
  1406. };
  1407. billsContextMenuOptions.items.copyBlockXmj = {
  1408. name: '复制整块(只复制项目节)',
  1409. icon: 'fa-files-o',
  1410. callback: function (key, opt) {
  1411. const copyBlockList = [];
  1412. const sheet = billsSheet;
  1413. const sel = sheet.getSelections()[0];
  1414. let iRow = sel.row;
  1415. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1416. while (iRow < sel.row + sel.rowCount) {
  1417. const node = sheet.zh_tree.nodes[iRow];
  1418. if (node.ledger_pid !== pid) {
  1419. toastr.error('仅可同时选中同层节点');
  1420. return;
  1421. }
  1422. const posterity = sheet.zh_tree.getPosterity(node);
  1423. iRow += posterity.length + 1;
  1424. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  1425. copyPosterity.unshift(node);
  1426. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  1427. for (const p of copyData) {
  1428. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  1429. p.is_leaf = children.length === 0;
  1430. }
  1431. copyBlockList.push(copyData);
  1432. }
  1433. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  1434. },
  1435. visible: function (key, opt) {
  1436. const sheet = billsSheet;
  1437. const selection = sheet.getSelections();
  1438. const row = selection[0].row;
  1439. const select = billsTree.nodes[row];
  1440. return select;
  1441. },
  1442. disabled: function (key, opt) {
  1443. const sheet = billsSheet;
  1444. const selection = sheet.getSelections();
  1445. const row = selection[0].row;
  1446. const select = billsTree.nodes[row];
  1447. return select && select.level <= 1;
  1448. }
  1449. };
  1450. if (!readOnly) {
  1451. billsContextMenuOptions.items.pasteBlock = {
  1452. name: '粘贴整块',
  1453. icon: 'fa-clipboard',
  1454. disabled: function (key, opt) {
  1455. //const block = treeOperationObj.block || [];
  1456. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1457. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1458. },
  1459. callback: function (key, opt) {
  1460. //const block = treeOperationObj.block || [];
  1461. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1462. if (copyInfo.block.length > 0) {
  1463. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  1464. } else {
  1465. document.execCommand('paste');
  1466. }
  1467. },
  1468. visible: function (key, opt) {
  1469. return !readOnly;
  1470. }
  1471. };
  1472. billsContextMenuOptions.items.sprBlock = '----';
  1473. }
  1474. if (!readOnly) {
  1475. billsContextMenuOptions.items.batchInsert = {
  1476. name: '批量插入',
  1477. type: 'batchInsert',
  1478. value: '2',
  1479. icon: 'fa-sign-in',
  1480. batchInsert: function (obj, root) {
  1481. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1482. obj.value = obj.max;
  1483. toastr.warning('批量插入不可多于' + obj.max);
  1484. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1485. obj.value = obj.min;
  1486. toastr.warning('批量插入不可少于' + obj.min);
  1487. } else {
  1488. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  1489. root.$menu.trigger('contextmenu:hide');
  1490. }
  1491. },
  1492. disabled: function (key, opt) {
  1493. const sheet = billsSheet;
  1494. const selection = sheet.getSelections();
  1495. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1496. const row = sel ? sel.row : -1;
  1497. const tree = sheet.zh_tree;
  1498. if (!tree) return true;
  1499. const first = sheet.zh_tree.nodes[row];
  1500. const valid = !sheet.zh_setting.readOnly;
  1501. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  1502. }
  1503. };
  1504. billsContextMenuOptions.items.batchInsertBillsPos = {
  1505. name: '批量插入清单-计量单元',
  1506. icon: 'fa-sign-in',
  1507. visible: function (key, opt) {
  1508. return false;
  1509. },
  1510. disabled: function (key, opt) {
  1511. if (!isTz) return true;
  1512. const select = SpreadJsObj.getSelectObject(billsSheet);
  1513. if (select) {
  1514. if (select.code && select.code !== '') {
  1515. return !billsTree.isLeafXmj(select) || select.settle_status === settleStatus.finish;
  1516. } else {
  1517. const parent = billsTree.getParent(select);
  1518. return !(parent && billsTree.isLeafXmj(parent)) || !(parent && parent.settle_status === settleStatus.finish);
  1519. }
  1520. } else {
  1521. return false;
  1522. }
  1523. },
  1524. callback: function (key, opt) {
  1525. if (!batchInsertObj) {
  1526. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1527. } else {
  1528. batchInsertObj.initView();
  1529. }
  1530. $('#batch').modal('show');
  1531. }
  1532. };
  1533. }
  1534. billsContextMenuOptions.items.sprTag = '----';
  1535. billsContextMenuOptions.items.showLast = {
  1536. name: '显示至最底层',
  1537. callback: function (key, opt, menu, e) {
  1538. const node = SpreadJsObj.getSelectObject(billsSheet);
  1539. setTimeout(() => {
  1540. showWaitingView();
  1541. billsTree.expandByCustom(x => {
  1542. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1543. });
  1544. SpreadJsObj.refreshTreeRowVisible(billsSheet);
  1545. closeWaitingView();
  1546. }, 100);
  1547. },
  1548. };
  1549. $.contextMenu(billsContextMenuOptions);
  1550. // 计量单元 相关方法&绑定spreadjs事件
  1551. const posSpreadObj = {
  1552. refreshOperationValid: function (sheet, selection) {
  1553. const setObjEnable = function (obj, enable) {
  1554. if (enable) {
  1555. obj.removeClass('disabled');
  1556. } else {
  1557. obj.addClass('disabled');
  1558. }
  1559. };
  1560. const invalidAll = function () {
  1561. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1562. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1563. };
  1564. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1565. const row = sel ? sel.row : -1;
  1566. const first = sheet.zh_data[row];
  1567. if (!first) {
  1568. invalidAll();
  1569. return;
  1570. }
  1571. let last = first;
  1572. if (sel.rowCount > 1 && first) {
  1573. for (let r = 1; r < sel.rowCount; r++) {
  1574. const rNode = sheet.zh_data[sel.row + r];
  1575. if (!rNode) break;
  1576. last = rNode;
  1577. }
  1578. }
  1579. const preNode = sheet.zh_data[row - 1];
  1580. const valid = !sheet.zh_setting.readOnly;
  1581. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode && first.formc);
  1582. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1) && first.formc);
  1583. },
  1584. loadExprToInput: function () {
  1585. const sel = posSheet.getSelections()[0];
  1586. if (!sel) return;
  1587. const col = posSheet.zh_setting.cols[sel.col];
  1588. const cell = posSheet.getCell(sel.col, sel.col);
  1589. if (col && col.type === 'Number') {
  1590. const data = SpreadJsObj.getSelectObject(posSheet);
  1591. if (data) {
  1592. const exprInfo = getExprInfo(col.field);
  1593. const value = exprInfo
  1594. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1595. : data[col.field];
  1596. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1597. .attr('readOnly', readOnly || (!data.formc && cell.locked()) || data.settle_status === settleStatus.finish).attr('data-row', sel.row);
  1598. } else {
  1599. $('#pos-expr').val('').attr('readOnly', true);
  1600. $('#pos-expr').removeAttr('data-row');
  1601. }
  1602. } else {
  1603. $('#pos-expr').val('').attr('readOnly', true);
  1604. $('#pos-expr').removeAttr('data-row');
  1605. }
  1606. },
  1607. /**
  1608. * 加载计量单元 根据当前台账选择节点
  1609. */
  1610. loadCurPosData: function () {
  1611. const node = SpreadJsObj.getSelectObject(billsSheet);
  1612. // SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  1613. // SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  1614. if (node) {
  1615. const posData = pos.getLedgerPos(node.id) || [];
  1616. console.log(posData);
  1617. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  1618. posSheet.zh_setting.readOnly = readOnly || (node.used && posData.length === 0) || (node.settle_status && node.settle_status === settleStatus.finish);
  1619. } else {
  1620. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  1621. posSheet.zh_setting.readOnly = true;
  1622. }
  1623. SpreadJsObj.massOperationSheet(posSheet, function () {
  1624. if (posSheet.zh_setting) {
  1625. posSheet.zh_setting.cols.forEach(function (col, i) {
  1626. for (let iRow = 0; iRow < posSheet.getRowCount(); iRow++) {
  1627. if (i !== 0) {
  1628. posSheet.getCell(iRow, i).locked((posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].formc) || posSheet.zh_setting.readOnly || false);
  1629. } else {
  1630. let lock = false;
  1631. if (!posSheet.zh_data[iRow]) {
  1632. lock = true;
  1633. }
  1634. posSheet.getCell(iRow, i).locked(lock || (posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].name) || posSheet.zh_setting.readOnly || false);
  1635. }
  1636. }
  1637. });
  1638. }
  1639. });
  1640. // SpreadJsObj.refreshSheetReadOnly(posSheet);
  1641. posSpreadObj.loadExprToInput();
  1642. posSpreadObj.refreshOperationValid(posSheet);
  1643. },
  1644. baseOpr: function (sheet, type) {
  1645. const data = {
  1646. postType: 'pos',
  1647. posPostType: type === 'delete' ? type : 'update',
  1648. postData: [],
  1649. };
  1650. const selection = sheet.getSelections();
  1651. const row = selection[0].row, count = selection[0].rowCount;
  1652. const first = sheet.zh_data[row];
  1653. if (type === 'delete') {
  1654. for (let iRow = 0; iRow < count; iRow++) {
  1655. const posData = sheet.zh_data[iRow + row];
  1656. if (posData) {
  1657. if (posData.used) {
  1658. toastr.error('"' + posData.name + '"已计量,请勿删除');
  1659. return;
  1660. }
  1661. if (posData.settle_status) {
  1662. toastr.error('"' + posData.name + '"已结算,请勿删除');
  1663. return;
  1664. }
  1665. data.postData.push(sheet.zh_data[iRow + row].id);
  1666. }
  1667. }
  1668. } else if (type === 'up-move') {
  1669. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1670. for (let iRow = 0; iRow < count; iRow++) {
  1671. const posData = sheet.zh_data[iRow + row];
  1672. if (posData) {
  1673. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1674. preUpdate.porder = posData.porder;
  1675. }
  1676. }
  1677. data.postData.push(preUpdate);
  1678. } else if (type === 'down-move') {
  1679. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1680. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1681. const posData = sheet.zh_data[iRow + row];
  1682. if (posData) {
  1683. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  1684. nextUpdate.porder = posData.porder;
  1685. }
  1686. }
  1687. data.postData.push(nextUpdate);
  1688. } else if (type === 'add') {
  1689. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1690. if (billsNode.settle_status === settleStatus.finish) {
  1691. toastr.warning('清单已结算,不可新增计量单元');
  1692. return;
  1693. }
  1694. }
  1695. if (data.postData.length > 0) {
  1696. postData(window.location.pathname + '/update', data, function (result) {
  1697. changeList = result.changeList;
  1698. if (type === 'delete') {
  1699. pos.removeDatas(result.pos);
  1700. sheet.deleteRows(row, count);
  1701. const loadResult = billsTree.loadPostData(result.ledger);
  1702. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1703. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1704. posSpreadObj.refreshOperationValid(posSheet);
  1705. } else {
  1706. pos.updateDatas(result.pos);
  1707. const sel = selection[0];
  1708. if (sel) {
  1709. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1710. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1711. }
  1712. posSpreadObj.loadCurPosData();
  1713. }
  1714. });
  1715. }
  1716. },
  1717. editStarting: function (e, info) {
  1718. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1719. const sel = info.sheet.getSelections();
  1720. if (!sel || !sel[0]) return;
  1721. const col = info.sheet.zh_setting.cols[sel[0].col];
  1722. const node = SpreadJsObj.getSelectObject(info.sheet);
  1723. const exprInfo = getExprInfo(col.field);
  1724. if (node && exprInfo) {
  1725. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1726. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1727. }
  1728. }
  1729. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  1730. info.cancel = true;
  1731. }
  1732. },
  1733. buttonClicked: function (e, info) {
  1734. if (info.sheet.zh_setting) {
  1735. const select = SpreadJsObj.getSelectObject(info.sheet);
  1736. const col = info.sheet.zh_setting.cols[info.col];
  1737. if (col.field === 'is_change') {
  1738. if (posCol.readOnly.isChangeList(select)) {
  1739. info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
  1740. return
  1741. }
  1742. if (info.sheet.isEditing()) {
  1743. info.sheet.endEdit(true);
  1744. }
  1745. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  1746. if (is_change) {
  1747. makeGclGatherData();
  1748. const gclInfo = _.find(gclGatherData, function (item) {
  1749. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
  1750. });
  1751. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
  1752. const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
  1753. const data = {
  1754. lid: select.lid,
  1755. code: gclInfo.b_code,
  1756. name: gclInfo.name || '',
  1757. unit: gclInfo.unit || '',
  1758. unit_price: gclInfo.unit_price,
  1759. oamount: xmjInfo.quantity,
  1760. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  1761. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  1762. xmj_code: xmjInfo.code || '',
  1763. xmj_jldy: xmjInfo.jldy || '',
  1764. xmj_dwgc: xmjInfo.dwgc || '',
  1765. xmj_fbgc: xmjInfo.fbgc || '',
  1766. xmj_fxgc: xmjInfo.fxgc || '',
  1767. gcl_id: select.lid,
  1768. mx_id: select.id,
  1769. }
  1770. if (oldCInfo) {
  1771. data.detail = oldCInfo.detail;
  1772. data.camount = oldCInfo.camount;
  1773. data.spamount = oldCInfo.spamount;
  1774. data.is_valuation = oldCInfo.is_valuation;
  1775. data.delimit = oldCInfo.delimit;
  1776. }
  1777. // 更新至服务器
  1778. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  1779. changeList = result.changeList;
  1780. select.is_change = 1;
  1781. if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
  1782. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1783. billsNode.is_change = 1;
  1784. const loadResult = { update: [billsNode] };
  1785. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1786. }
  1787. }, function () {
  1788. info.sheet.setValue(info.row, info.col, 0);
  1789. });
  1790. } else {
  1791. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.lid, mx_id: select.id }) !== -1) {
  1792. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  1793. info.sheet.setValue(info.row, info.col, 1);
  1794. return
  1795. }
  1796. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  1797. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  1798. toastr.warning('该计量单元已被使用,无法取消变更');
  1799. info.sheet.setValue(info.row, info.col, 1);
  1800. return
  1801. } else if (checkIsSettle(cInfo)) {
  1802. toastr.warning('该计量单元已结算,无法取消变更');
  1803. info.sheet.setValue(info.row, info.col, 1);
  1804. return
  1805. } else {
  1806. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  1807. changeList = result.changeList;
  1808. select.is_change = 0;
  1809. // 判断是否只剩一个,并同步去勾
  1810. if (_.findIndex(changeList, { gcl_id: select.lid }) === -1) {
  1811. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1812. billsNode.is_change = 0;
  1813. const loadResult = { update: [billsNode] };
  1814. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1815. }
  1816. }, function () {
  1817. info.sheet.setValue(info.row, info.col, 1);
  1818. });
  1819. }
  1820. }
  1821. }
  1822. }
  1823. },
  1824. /**
  1825. * 编辑单元格响应事件
  1826. * @param {Object} e
  1827. * @param {Object} info
  1828. */
  1829. editEnded: function (e, info) {
  1830. if (!info.sheet.zh_setting) {
  1831. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1832. return;
  1833. }
  1834. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1835. const col = info.sheet.zh_setting.cols[info.col];
  1836. if (col.field === 'is_change') {
  1837. return;
  1838. }
  1839. const orgText = posData ? posData[col.field] : null;
  1840. const newText = trimInvalidChar(info.editingText);
  1841. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  1842. const node = posSpreadObj.billsNode;
  1843. if (!node) {
  1844. toastr.error('数据错误,请选择台账节点后再试');
  1845. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1846. return;
  1847. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1848. toastr.error('父节点不可插入计量单元');
  1849. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1850. return;
  1851. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1852. toastr.error('项目节不可插入计量单元');
  1853. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1854. return;
  1855. }
  1856. const data = {postType: 'pos'};
  1857. if (col.field === 'name') {
  1858. if (newText === '' && posData) {
  1859. toastr.error('部位名称不可为空', 'error');
  1860. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1861. return;
  1862. } else if (!posData) {
  1863. if (newText && newText !== '') {
  1864. data.posPostType = 'add';
  1865. const sortData = info.sheet.zh_data;
  1866. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1867. data.postData = { name: newText, lid: node.id, porder: order};
  1868. if (node.settle_status === settleStatus.finish) {
  1869. toastr.error('已结算清单不可插入计量单元');
  1870. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1871. return;
  1872. }
  1873. } else {
  1874. return;
  1875. }
  1876. } else {
  1877. data.posPostType = 'update';
  1878. data.postData = {id: posData.id, name: newText};
  1879. if (col.type === 'Number' && posData.settle_status === settleStatus.finish) {
  1880. toastr.error('计量单元已结算,不可修改');
  1881. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1882. return;
  1883. }
  1884. }
  1885. } else if (!posData) {
  1886. toastr.warning('新增计量单元请先输入名称');
  1887. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1888. return;
  1889. } else {
  1890. data.posPostType = 'update';
  1891. data.postData = {id: posData.id};
  1892. if (col.type === 'Number') {
  1893. const exprInfo = getExprInfo(col.field);
  1894. const num = _.toNumber(newText);
  1895. if (_.isFinite(num)) {
  1896. data.postData[col.field] = num;
  1897. if (exprInfo) {
  1898. data.postData[exprInfo.expr] = '';
  1899. }
  1900. } else {
  1901. try {
  1902. data.postData[col.field] = math.evaluate(transExpr(newText));
  1903. if (exprInfo) {
  1904. data.postData[exprInfo.expr] = newText;
  1905. }
  1906. } catch(err) {
  1907. toastr.error('输入的表达式非法');
  1908. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1909. return;
  1910. }
  1911. }
  1912. } else if (col.field.indexOf('_expr') > 0) {
  1913. const exprInfo = getExprInfo(col.field, true);
  1914. if (!exprInfo) return;
  1915. if (newText) {
  1916. try {
  1917. data.postData[exprInfo.qty] = math.evaluate(transExpr(newText));
  1918. data.postData[exprInfo.expr] = newText;
  1919. } catch(err) {
  1920. toastr.error('输入的表达式非法');
  1921. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1922. return;
  1923. }
  1924. } else {
  1925. data.postData[exprInfo.qty] = 0;
  1926. data.postData[exprInfo.expr] = '';
  1927. }
  1928. } else {
  1929. data.postData[col.field] = newText;
  1930. }
  1931. }
  1932. postData(window.location.pathname + '/update', data, function (result) {
  1933. changeList = result.changeList;
  1934. const updateRst = pos.updateDatas(result.pos);
  1935. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1936. if (updateRst.create.length > 0) {
  1937. posSpreadObj.loadCurPosData();
  1938. } else {
  1939. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1940. }
  1941. const loadResult = billsTree.loadPostData(result.ledger);
  1942. // 判断是否只剩一个,并同步去勾
  1943. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  1944. billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  1945. if (loadResult.update) {
  1946. const r = _.find(loadResult.update, { id: billsNode.id });
  1947. r.is_change = billsNode.is_change;
  1948. } else {
  1949. loadResult.update = [billsNode];
  1950. }
  1951. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  1952. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1953. }, function () {
  1954. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1955. });
  1956. },
  1957. /**
  1958. * 删除按钮响应事件
  1959. * @param sheet
  1960. */
  1961. deletePress: function (sheet) {
  1962. if (!sheet.zh_setting) return;
  1963. const sortData = sheet.zh_data;
  1964. const datas = [], posSelects = [];
  1965. const sel = sheet.getSelections()[0];
  1966. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1967. let bDel = false;
  1968. const node = sortData[iRow];
  1969. if (node) {
  1970. const data = {id: node.id};
  1971. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1972. const colSetting = sheet.zh_setting.cols[iCol];
  1973. if (colSetting.field === 'name') {
  1974. toastr.error('部位名称不能为空');
  1975. return;
  1976. }
  1977. const style = sheet.getStyle(iRow, iCol);
  1978. if (!style.locked) {
  1979. const colSetting = sheet.zh_setting.cols[iCol];
  1980. if (colSetting.field.indexOf('_expr') > 0) {
  1981. const exprInfo = getExprInfo(colSetting.field, true);
  1982. if (!exprInfo) continue;
  1983. data[exprInfo.expr] = '';
  1984. data[exprInfo.qty] = 0;
  1985. } else {
  1986. data[colSetting.field] = null;
  1987. const exprInfo = getExprInfo(colSetting.field);
  1988. if (exprInfo) data[exprInfo.expr] = '';
  1989. }
  1990. bDel = true;
  1991. }
  1992. }
  1993. if (bDel) {
  1994. datas.push(data);
  1995. posSelects.push(node);
  1996. }
  1997. }
  1998. }
  1999. if (datas.length > 0) {
  2000. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  2001. changeList = result.changeList;
  2002. pos.updateDatas(result.pos);
  2003. posSpreadObj.loadCurPosData();
  2004. const loadResult = billsTree.loadPostData(result.ledger);
  2005. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2006. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2007. }, function () {
  2008. posSpreadObj.loadCurPosData();
  2009. });
  2010. }
  2011. },
  2012. /**
  2013. * 删除 计量单元
  2014. * @param sheet
  2015. */
  2016. deletePos: function (sheet) {
  2017. const selection = sheet.getSelections();
  2018. const data = {
  2019. postType: 'pos',
  2020. posPostType: 'delete',
  2021. postData: [],
  2022. };
  2023. const row = selection[0].row, count = selection[0].rowCount;
  2024. const sortData = sheet.zh_data;
  2025. for (let iRow = 0; iRow < count; iRow++) {
  2026. const posData = sortData[iRow + row];
  2027. if (posData) {
  2028. if (posData.used) {
  2029. toastr.error('"' + posData.name + '"已计量,请勿删除');
  2030. return;
  2031. }
  2032. if (posData.settle_status === settleStatus.finish) {
  2033. toastr.error(`"${posData.name}"已计量,请勿删除`);
  2034. return;
  2035. }
  2036. data.postData.push(sortData[iRow + row].id);
  2037. }
  2038. }
  2039. if (data.postData.length > 0) {
  2040. postData(window.location.pathname + '/update', data, function (result) {
  2041. changeList = result.changeList;
  2042. pos.removeDatas(result.pos);
  2043. sheet.deleteRows(row, count);
  2044. const loadResult = billsTree.loadPostData(result.ledger);
  2045. // 判断是否只剩一个,并同步去勾
  2046. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2047. billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  2048. if (loadResult.update) {
  2049. const r = _.find(loadResult.update, { id: billsNode.id });
  2050. r.is_change = billsNode.is_change;
  2051. } else {
  2052. loadResult.update = [billsNode];
  2053. }
  2054. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2055. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2056. });
  2057. }
  2058. },
  2059. /**
  2060. * 粘贴单元格响应事件
  2061. * @param e
  2062. * @param info
  2063. */
  2064. clipboardPasted: function (e, info) {
  2065. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2066. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2067. }
  2068. const node = SpreadJsObj.getSelectObject(billsSheet);
  2069. if (node.code && (node.code !== '')) {
  2070. toastr.error('项目节不可含有节点明细');
  2071. posSpreadObj.loadCurPosData();
  2072. return;
  2073. }
  2074. if (node.children && (node.children.length > 0)) {
  2075. toastr.error('仅节点子项可以含有计量单元');
  2076. posSpreadObj.loadCurPosData();
  2077. return;
  2078. }
  2079. if (node.settle_status === settleStatus.finish) {
  2080. toastr.error('清单已结算,请勿修改计量单元数据');
  2081. posSpread.loadCurPosData();
  2082. return;
  2083. }
  2084. if (!info.sheet.zh_setting) {
  2085. posSpreadObj.loadCurPosData();
  2086. return;
  2087. }
  2088. const data = [];
  2089. const sortData = info.sheet.zh_data || [];
  2090. const hint = {
  2091. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2092. settle: {type: 'warning', msg: '计量单元已结算,不可修改台账数据,已过滤'},
  2093. };
  2094. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  2095. const nameCol = info.sheet.zh_setting.cols.findIndex(x => { return x.field === 'name'; });
  2096. if (info.cellRange.col > nameCol || info.cellRange.col + info.cellRange.colCount < nameCol) {
  2097. toastr.warning('新增计量单元请先输入名称');
  2098. posSpreadObj.loadCurPosData();
  2099. return;
  2100. }
  2101. }
  2102. let bHint = false;
  2103. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2104. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2105. let bPaste = true;
  2106. const curRow = info.cellRange.row + iRow;
  2107. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  2108. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2109. const curCol = info.cellRange.col + iCol;
  2110. const colSetting = info.sheet.zh_setting.cols[curCol];
  2111. if (!colSetting) continue;
  2112. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2113. if (posData.id && colSetting.type === 'Number' && sortData[curRow].settle_status === settleStatus.finish) {
  2114. bPaste = false;
  2115. toastMessageUniq(hint.settle);
  2116. continue;
  2117. }
  2118. if (colSetting.type === 'Number') {
  2119. const num = _.toNumber(posData[colSetting.field]);
  2120. if (num) {
  2121. posData[colSetting.field] = num;
  2122. } else {
  2123. try {
  2124. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  2125. const exprInfo = getExprInfo(colSetting.field);
  2126. if (exprInfo) {
  2127. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2128. }
  2129. } catch (err) {
  2130. if (!bHint) {
  2131. toastr.warning('粘贴了非法表达式,已过滤');
  2132. bHint = true;
  2133. }
  2134. bPaste = false;
  2135. }
  2136. }
  2137. } else if (colSetting.field.indexOf('_expr') > 0) {
  2138. try {
  2139. const exprInfo = getExprInfo(colSetting.field, true);
  2140. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2141. if (posData[exprInfo.expr] || !posData[exprInfo.qty]) {
  2142. posData[exprInfo.qty] = math.evaluate(transExpr(posData[exprInfo.expr]));
  2143. }
  2144. bPaste = true;
  2145. } catch (err) {
  2146. toastMessageUniq(hint.expr);
  2147. }
  2148. } else {
  2149. bPaste = true;
  2150. }
  2151. }
  2152. if (bPaste) {
  2153. data.push(posData);
  2154. }
  2155. }
  2156. if (data.length === 0) {
  2157. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2158. return;
  2159. }
  2160. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  2161. changeList = result.changeList;
  2162. pos.updateDatas(result.pos);
  2163. posSpreadObj.loadCurPosData();
  2164. const loadResult = billsTree.loadPostData(result.ledger);
  2165. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2166. posSpreadObj.loadCurPosData();
  2167. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2168. }, function () {
  2169. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2170. });
  2171. },
  2172. selectionChanged: function (e, info) {
  2173. posSpreadObj.loadExprToInput();
  2174. posSpreadObj.refreshOperationValid(posSheet);
  2175. },
  2176. addPegs: function (pegs) {
  2177. if (!pegs || pegs.length <= 0) return;
  2178. const node = SpreadJsObj.getSelectObject(billsSheet);
  2179. if (!node) return;
  2180. const sheet = posSpread.getActiveSheet();
  2181. const sortData = sheet.zh_data || [];
  2182. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2183. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2184. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  2185. changeList = result.changeList;
  2186. pos.updateDatas(result.pos);
  2187. posSpreadObj.loadCurPosData();
  2188. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2189. });
  2190. }
  2191. };
  2192. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  2193. if (!readOnly && isTz) {
  2194. $('a[name="pos-opr"]').click(function () {
  2195. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  2196. });
  2197. $('#pos-expr').bind('change onblur', function () {
  2198. if (this.readOnly) return;
  2199. const expr = $(this);
  2200. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2201. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2202. if (!select) return;
  2203. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  2204. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  2205. const data = {id: select.id};
  2206. const exprInfo = getExprInfo(field);
  2207. if (newValue !== '') {
  2208. const num = _.toNumber(newValue);
  2209. if (num) {
  2210. data[field] = num;
  2211. if (exprInfo) data[exprInfo.expr] = '';
  2212. } else {
  2213. try {
  2214. data[field] = math.evaluate(transExpr(newValue));
  2215. if (exprInfo) data[exprInfo.expr] = newValue;
  2216. } catch (err) {
  2217. toastr.error('输入的表达式非法');
  2218. return;
  2219. }
  2220. }
  2221. } else {
  2222. data[field] = null;
  2223. if (exprInfo) data[exprInfo.expr] = '';
  2224. }
  2225. // 更新至服务器
  2226. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  2227. changeList = result.changeList;
  2228. const updateRst = pos.updateDatas(result.pos);
  2229. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  2230. SpreadJsObj.reLoadRowData(posSheet, row);
  2231. const loadResult = billsTree.loadPostData(result.ledger);
  2232. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2233. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2234. });
  2235. });
  2236. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  2237. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  2238. posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
  2239. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  2240. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  2241. $.contextMenu({
  2242. selector: '#pos-spread',
  2243. build: function ($trigger, e) {
  2244. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  2245. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2246. },
  2247. items: {
  2248. 'delete': {
  2249. name: '删除',
  2250. icon: 'fa-remove',
  2251. disabled: function (key, opt) {
  2252. if (posSheet.zh_data) {
  2253. const selection = posSheet.getSelections();
  2254. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2255. const row = sel ? sel.row : -1;
  2256. const rowCount = sel.rowCount;
  2257. let settleFinish = false;
  2258. for (let i = row; i < row + rowCount; i++) {
  2259. if (!posSheet.zh_data[i]) continue;
  2260. settleFinish = settleFinish || posSheet.zh_data[i].settle_status === settleStatus.finish;
  2261. }
  2262. return (posSheet.zh_data.length < selection[0].row + selection[0].rowCount) || (posSheet.zh_data[selection[0].row] && !posSheet.zh_data[selection[0].row].formc) || settleFinish;
  2263. } else {
  2264. return true;
  2265. }
  2266. },
  2267. callback: function (key, opt) {
  2268. posSpreadObj.deletePos(posSheet);
  2269. }
  2270. },
  2271. }
  2272. });
  2273. }
  2274. // 加载清单&计量单元数据
  2275. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  2276. let gclGatherData;
  2277. postData(preUrl + '/defaultBills', { from: 'revise' }, function (result) {
  2278. for (const b of result.bills) {
  2279. if (!(b.is_leaf && b.b_code)) {
  2280. b.is_change = 0;
  2281. } else {
  2282. const cInfo = _.find(changeList, { gcl_id: b.id });
  2283. b.is_change = cInfo ? 1 : 0;
  2284. }
  2285. }
  2286. billsTree.loadDatas(result.bills);
  2287. pos.loadDatas(result.pos);
  2288. treeCalc.calculateAll(billsTree);
  2289. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  2290. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  2291. checkShowLast(result.bills.length);
  2292. posSpreadObj.loadCurPosData();
  2293. SpreadJsObj.resetTopAndSelect(posSheet);
  2294. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2295. billsTreeSpreadObj.loadExprToInput(billsSheet);
  2296. checkList.loadHisCheckData();
  2297. console.log(billsTree);
  2298. }, null);
  2299. $.divResizer({
  2300. select: '#revise-resize',
  2301. callback: function () {
  2302. billsSpread.refresh();
  2303. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2304. $(".sp-wrap").height(bcontent-30);
  2305. posSpread.refresh();
  2306. }
  2307. });
  2308. function makeGclGatherData() {
  2309. gclGatherModel.loadLedgerData(billsTree.datas);
  2310. gclGatherModel.loadPosData(pos.datas);
  2311. gclGatherData = gclGatherModel.gatherGclData();
  2312. gclGatherData = _.filter(gclGatherData, function (item) {
  2313. return item.leafXmjs && item.leafXmjs.length !== 0;
  2314. });
  2315. gclGatherData = gclGatherData.sort(sortByCode);
  2316. console.log(gclGatherData);
  2317. }
  2318. class DealBills {
  2319. constructor (selector, spreadSetting) {
  2320. const self = this;
  2321. this.loaded = false;
  2322. this.obj = $(selector)[0];
  2323. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2324. this.spreadSetting = spreadSetting;
  2325. this.spread = SpreadJsObj.createNewSpread(this.obj);
  2326. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2327. if (!readOnly) {
  2328. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2329. const dealSheet = info.sheet;
  2330. const mainSheet = billsSheet;
  2331. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2332. if (!dealBills) { return; }
  2333. const mainTree = mainSheet.zh_tree;
  2334. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2335. if (!mainNode || !mainTree) { return; }
  2336. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2337. toastr.warning('非最底层项目下,不应添加节点');
  2338. return;
  2339. }
  2340. if (mainNode.settle_status === settleStatus.finish) {
  2341. toastr.warning('已结算节点下,不应添加签约清单');
  2342. return;
  2343. }
  2344. postData(window.location.pathname + '/update', {
  2345. postType: 'add-deal',
  2346. postData: {
  2347. id: mainNode.ledger_id,
  2348. type: mainNode.code ? 'child' : 'next',
  2349. dealBills: {
  2350. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2351. unit_price: dealBills.unit_price,
  2352. }
  2353. },
  2354. }, function (result) {
  2355. changeList = result.changeList;
  2356. const refreshData = mainTree.loadPostData(result);
  2357. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2358. const sel = mainSheet.getSelections()[0];
  2359. if (sel && refreshData.create[0]) {
  2360. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2361. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2362. }
  2363. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2364. billsSpread.focus();
  2365. posSpreadObj.loadCurPosData();
  2366. });
  2367. });
  2368. }
  2369. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2370. }
  2371. loadData (callback) {
  2372. if (this.loaded) {
  2373. if (callback) callback();
  2374. return;
  2375. }
  2376. const self = this;
  2377. postData(this.url+'/get-data', {}, function (data) {
  2378. self.data = data;
  2379. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  2380. self.loaded = true;
  2381. if (callback) callback();
  2382. });
  2383. }
  2384. calculateData () {
  2385. if (this.data) {
  2386. for (const d of this.data) {
  2387. d.total_price = _.multiply(d.quantity, d.unit_price);
  2388. }
  2389. }
  2390. }
  2391. }
  2392. class BatchInsertBillsPosObj {
  2393. constructor (obj) {
  2394. const self = this;
  2395. this.obj = obj;
  2396. this.billsCount = 6;
  2397. this.posCount = 1000;
  2398. this.filter = getLocalCache('zh-calc-batch-filter');
  2399. if (!this.filter) {
  2400. this.filter = '1';
  2401. }
  2402. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  2403. // 初始化 清单编号窗口 参数
  2404. this.qdSpreadSetting = {
  2405. cols: [
  2406. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  2407. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2408. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2409. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2410. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  2411. ],
  2412. emptyRows: this.billsCount,
  2413. headRows: 1,
  2414. headRowHeight: [32],
  2415. headerFont: '12px 微软雅黑',
  2416. font: '12px 微软雅黑',
  2417. };
  2418. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  2419. // 初始化 部位数量复核表 参数
  2420. this.posSpreadSetting = {
  2421. cols: [
  2422. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  2423. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  2424. ],
  2425. emptyRows: this.posCount,
  2426. headRows: 1,
  2427. headRowHeight: [32],
  2428. headerFont: '12px 微软雅黑',
  2429. font: '12px 微软雅黑',
  2430. };
  2431. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  2432. this.posSpreadSetting.cols.push(
  2433. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  2434. )
  2435. }
  2436. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  2437. // 初始化 签约节点 参数
  2438. this.dealSpreadSetting = {
  2439. cols: [
  2440. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  2441. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  2442. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2443. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  2444. ],
  2445. emptyRows: 0,
  2446. headRows: 1,
  2447. headRowHeight: [32],
  2448. headerFont: '12px 微软雅黑',
  2449. font: '12px 微软雅黑',
  2450. };
  2451. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  2452. // 初始化 清单编号、部位数量复核表 表格
  2453. this.initView();
  2454. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  2455. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  2456. // 拉取签约节点数据
  2457. dealBills.loadData(() => {
  2458. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2459. });
  2460. // 双击签约节点,自动添加到清单编号窗口
  2461. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  2462. const deal = info.sheet.zh_data[info.row];
  2463. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  2464. const sel = qdSheet.getSelections()[0];
  2465. qdSheet.getCell(sel.row, 0).value(deal.code);
  2466. qdSheet.getCell(sel.row, 1).value(deal.name);
  2467. qdSheet.getCell(sel.row, 2).value(deal.unit);
  2468. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  2469. if (sel.row + 1 === qdSheet.getRowCount()) {
  2470. const count = sel.row + 2;
  2471. qdSheet.setRowCount(count);
  2472. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  2473. const colCount = posSheet.getColumnCount() + 1;
  2474. posSheet.setColumnCount(colCount);
  2475. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  2476. }
  2477. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  2478. qdSheet.getParent().focus();
  2479. });
  2480. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2481. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  2482. const count = posSheet.getColumnCount() - 2;
  2483. if (billsCount > count) {
  2484. posSheet.setColumnCount(billsCount + 2);
  2485. for (let i = count + 1; i <= billsCount; i++) {
  2486. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2487. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2488. }
  2489. }
  2490. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  2491. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2492. if (dealBills && dealBills.length > 0) {
  2493. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2494. const curRow = iRow + info.cellRange.row;
  2495. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  2496. if (bills) {
  2497. info.sheet.getCell(curRow, 1).value(bills.name);
  2498. info.sheet.getCell(curRow, 2).value(bills.unit);
  2499. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  2500. }
  2501. }
  2502. }
  2503. }
  2504. });
  2505. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  2506. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  2507. const count = qdSheet.getRowCount();
  2508. if (billsCount > count) {
  2509. qdSheet.setRowCount(billsCount);
  2510. for (let i = count + 1; i <= billsCount; i++) {
  2511. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  2512. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  2513. }
  2514. }
  2515. });
  2516. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  2517. if (info.col === 0) {
  2518. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  2519. if (dealBills && dealBills.length > 0) {
  2520. const bills = _.find(dealBills, {code: info.editingText});
  2521. if (bills) {
  2522. info.sheet.getCell(info.row, 1).value(bills.name);
  2523. info.sheet.getCell(info.row, 2).value(bills.unit);
  2524. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  2525. }
  2526. }
  2527. }
  2528. });
  2529. this.obj.bind('shown.bs.modal', function () {
  2530. self.qdSpread.refresh();
  2531. self.posSpread.refresh();
  2532. self.dealSpread.refresh();
  2533. });
  2534. $('#batch-ok').click(function () {
  2535. const selection = billsSheet.getSelections();
  2536. const sel = selection[0];
  2537. const row = selection[0].row;
  2538. const select = billsTree.nodes[row];
  2539. if (select) {
  2540. const insertData = {};
  2541. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  2542. insertData.id = select[billsTree.setting.id];
  2543. insertData.batchData = self.getBatchData();
  2544. if (insertData.batchData.length > 0) {
  2545. postData(window.location.pathname + '/update', {
  2546. postType: 'batch-insert',
  2547. postData: insertData
  2548. }, function (data) {
  2549. changeList = result.changeList;
  2550. pos.updateDatas(data.pos);
  2551. const result = billsTree.loadPostData(data.ledger);
  2552. billsTreeSpreadObj.refreshTree(billsSheet, result);
  2553. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  2554. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  2555. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  2556. posSpreadObj.loadCurPosData();
  2557. self.obj.modal('hide');
  2558. }, null, true);
  2559. } else {
  2560. self.obj.modal('hide');
  2561. }
  2562. }
  2563. });
  2564. $('input[name=batch-filter]').change(function () {
  2565. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  2566. });
  2567. $.contextMenu({
  2568. selector: '.batch-l-t',
  2569. build: function ($trigger, e) {
  2570. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  2571. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2572. },
  2573. items: {
  2574. 'create': {
  2575. name: '新增行',
  2576. icon: 'fa-sign-in',
  2577. callback: function (key, opt) {
  2578. const qdSheet = self.qdSpread.getActiveSheet();
  2579. const posSheet = self.posSpread.getActiveSheet();
  2580. qdSheet.addRows(qdSheet.getRowCount(), 1);
  2581. const index = qdSheet.getRowCount();
  2582. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  2583. posSheet.addColumns(posSheet.getColumnCount(), 1);
  2584. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  2585. },
  2586. },
  2587. 'delete': {
  2588. name: '删除行',
  2589. icon: 'fa-remove',
  2590. callback: function (key, opt) {
  2591. const qdSheet = self.qdSpread.getActiveSheet();
  2592. const posSheet = self.posSpread.getActiveSheet();
  2593. const sel = qdSheet.getSelections()[0];
  2594. qdSheet.deleteRows(sel.row, sel.rowCount);
  2595. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  2596. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  2597. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  2598. }
  2599. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  2600. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  2601. }
  2602. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  2603. },
  2604. },
  2605. }
  2606. });
  2607. }
  2608. // 初始化左侧表格
  2609. initView () {
  2610. // 初始化 清单编号
  2611. const qdSheet = this.qdSpread.getActiveSheet();
  2612. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  2613. SpreadJsObj.refreshColumnAlign(qdSheet);
  2614. // 清理原有数据
  2615. SpreadJsObj.beginMassOperation(qdSheet);
  2616. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2617. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  2618. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  2619. }
  2620. qdSheet.setSelection(0, 0, 1 ,1);
  2621. SpreadJsObj.endMassOperation(qdSheet);
  2622. // 初始化 部位数量复核表
  2623. const posSheet = this.posSpread.getActiveSheet();
  2624. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  2625. SpreadJsObj.refreshColumnAlign(posSheet);
  2626. // 清理原有数据
  2627. SpreadJsObj.beginMassOperation(posSheet);
  2628. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  2629. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  2630. posSheet.setSelection(0, 0, 1 ,1);
  2631. SpreadJsObj.endMassOperation(posSheet);
  2632. // 检查签约节点数据,以工具栏数据为准
  2633. if (dealBills) {
  2634. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  2635. }
  2636. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  2637. }
  2638. // 获取界面数据
  2639. getBatchData () {
  2640. const result = [];
  2641. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  2642. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  2643. if (qdSheet.getText(iRow, 0) === '') { continue; }
  2644. const qd = {
  2645. b_code: qdSheet.getText(iRow, 0),
  2646. name: qdSheet.getText(iRow, 1),
  2647. unit: qdSheet.getText(iRow, 2),
  2648. price: _.toNumber(qdSheet.getText(iRow, 3)),
  2649. pos: [],
  2650. };
  2651. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  2652. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  2653. if (value !== 0 && !isNaN(value)) {
  2654. qd.pos.push({
  2655. name: posSheet.getText(iPosRow, 0),
  2656. drawing_code: posSheet.getText(iPosRow, 1),
  2657. quantity: value, porder: qd.pos.length + 1,
  2658. });
  2659. }
  2660. }
  2661. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  2662. }
  2663. return result;
  2664. }
  2665. }
  2666. const dealBills = new DealBills('#deal-bills-spread', {
  2667. cols: [
  2668. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2669. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2670. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  2671. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  2672. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  2673. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2674. ],
  2675. emptyRows: 0,
  2676. headRows: 1,
  2677. headRowHeight: [32],
  2678. headColWidth: [30],
  2679. defaultRowHeight: 21,
  2680. headerFont: '12px 微软雅黑',
  2681. font: '12px 微软雅黑',
  2682. selectedBackColor: '#fffacd',
  2683. });
  2684. class Jlzf {
  2685. constructor (selector, spreadSetting) {
  2686. const self = this;
  2687. this.loaded = false;
  2688. this.obj = $(selector);
  2689. const relaSelect = {
  2690. showLevel: `cb-${spreadSetting.stdType}-sl`,
  2691. searchText: `cb-${spreadSetting.stdType}-st`,
  2692. searchResult: `cb-${spreadSetting.stdType}-sr`,
  2693. searchPre: `cb-${spreadSetting.stdType}-sp`,
  2694. searchNext: `cb-${spreadSetting.stdType}-sn`,
  2695. searchClose: `cb-${spreadSetting.stdType}-sc`,
  2696. };
  2697. this.obj.html(
  2698. '<div class="sjs-bar d-flex">\n' +
  2699. ' <div class="ml-1">\n' +
  2700. ' <div class="px-2 border-primary border-1 d-flex">\n' +
  2701. ' <div class="d-inline-block">\n' +
  2702. ' <div class="input-group input-group-sm mr-1">' +
  2703. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  2704. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  2705. ' <div class="input-group-append" >\n' +
  2706. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  2707. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  2708. ' </div>\n' +
  2709. ' </div>\n' +
  2710. ' </div>\n' +
  2711. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  2712. ' </div>\n' +
  2713. ' </div>' +
  2714. '</div>\n' +
  2715. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  2716. );
  2717. autoFlashHeight();
  2718. const sh = `.cb-${spreadSetting.stdType}-sh`;
  2719. function getObjHeight(select) {
  2720. return select.length > 0 ? select.height() : 0;
  2721. }
  2722. const cHeader = getObjHeight($(".c-header"));
  2723. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  2724. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2725. this.spreadSetting = spreadSetting;
  2726. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  2727. const searchSheet = this.spread.getActiveSheet();
  2728. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  2729. if (!readOnly) {
  2730. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2731. const dealSheet = info.sheet;
  2732. const mainSheet = billsSheet;
  2733. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2734. if (!dealBills) { return; }
  2735. const mainTree = mainSheet.zh_tree;
  2736. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2737. if (!mainNode || !mainTree) { return; }
  2738. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2739. toastr.warning('非最底层项目下,不应添加节点');
  2740. return;
  2741. }
  2742. if (mainNode.settle_status === settleStatus.finish) {
  2743. toastr.warning('已结算节点下,不应添加签约清单');
  2744. return;
  2745. }
  2746. postData(window.location.pathname + '/update', {
  2747. postType: 'add-deal',
  2748. postData: {
  2749. id: mainNode.ledger_id,
  2750. type: mainNode.code ? 'child' : 'next',
  2751. dealBills: {
  2752. b_code: dealBills.b_code, code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  2753. unit_price: dealBills.unit_price,
  2754. }
  2755. },
  2756. }, function (result) {
  2757. changeList = result.changeList;
  2758. const refreshData = mainTree.loadPostData(result);
  2759. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2760. const sel = mainSheet.getSelections()[0];
  2761. if (sel && refreshData.create[0]) {
  2762. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2763. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2764. }
  2765. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2766. billsSpread.focus();
  2767. posSpreadObj.loadCurPosData();
  2768. });
  2769. });
  2770. }
  2771. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2772. const searchObj = {
  2773. result: [],
  2774. cur: 0,
  2775. searchStdNode: function() {
  2776. const keyword = $(`#${relaSelect.searchText}`).val();
  2777. const sortData = SpreadJsObj.getSortData(searchSheet);
  2778. searchObj.result = keyword ? sortData.filter(x => {
  2779. return (x.code && x.code.indexOf(keyword) >= 0) || (x.b_code && x.b_code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  2780. }) : [];
  2781. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  2782. searchObj.cur = 0;
  2783. if (searchObj.result.length > 0) {
  2784. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2785. }
  2786. },
  2787. searchPre: function () {
  2788. if (searchObj.result.length === 0) return;
  2789. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  2790. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2791. },
  2792. searchNext: function () {
  2793. if (searchObj.result.length === 0) return;
  2794. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  2795. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  2796. },
  2797. clear: function () {
  2798. $(`#${relaSelect.searchText}`).val('');
  2799. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  2800. searchObj.result = [];
  2801. searchObj.cur = 0;
  2802. }
  2803. };
  2804. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  2805. $(`#${relaSelect.searchPre}`).click(function (e) {
  2806. searchObj.searchPre();
  2807. e.stopPropagation();
  2808. });
  2809. $(`#${relaSelect.searchNext}`).click(function (e) {
  2810. searchObj.searchNext();
  2811. e.stopPropagation();
  2812. });
  2813. $(`#${relaSelect.searchClose}`).click(function (e) {
  2814. searchObj.clear();
  2815. e.stopPropagation();
  2816. });
  2817. };
  2818. loadData (callback) {
  2819. // if (this.loaded) {
  2820. // if (callback) callback();
  2821. // return;
  2822. // }
  2823. const self = this;
  2824. const datas = billsTree.nodes.filter(node => node.is_leaf === 1 && !node.code && node.ccid !== undefined && node.ccid !== '');
  2825. const showDatas = [];
  2826. for (const d of datas) {
  2827. if (_.findIndex(showDatas, { b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price }) === -1) {
  2828. showDatas.push({ code: d.code, b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price });
  2829. }
  2830. }
  2831. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', _.uniqWith(showDatas, _.isEqual).sort(sortByCode));
  2832. // self.loaded = true;
  2833. if (callback) callback();
  2834. }
  2835. }
  2836. const jlzfBills = new Jlzf('#jlzf-spread', {
  2837. cols: [
  2838. // {title: '项目节编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  2839. {title: '清单编号', field: 'b_code', hAlign: 0, width: 100, formatter: '@'},
  2840. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  2841. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2842. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2843. ],
  2844. emptyRows: 0,
  2845. headRows: 1,
  2846. headRowHeight: [32],
  2847. headColWidth: [30],
  2848. defaultRowHeight: 21,
  2849. headerFont: '12px 微软雅黑',
  2850. font: '12px 微软雅黑',
  2851. selectedBackColor: '#fffacd',
  2852. readOnly: true,
  2853. stdType: 'jlzf',
  2854. });
  2855. class Dsk {
  2856. constructor (selector, spreadSetting) {
  2857. const self = this;
  2858. this.loaded = false;
  2859. this.obj = $(selector);
  2860. const dskProjectHtml = spreadSetting.libs.map(l => {
  2861. return `<option value="${l.pid}" ${spreadSetting.select_lib === l.pid ? 'selected' : ''}>${l.name}</option>`;
  2862. });
  2863. const relaSelect = {
  2864. showLevel: `cb-${spreadSetting.stdType}-sl`,
  2865. searchText: `cb-${spreadSetting.stdType}-st`,
  2866. searchResult: `cb-${spreadSetting.stdType}-sr`,
  2867. searchPre: `cb-${spreadSetting.stdType}-sp`,
  2868. searchNext: `cb-${spreadSetting.stdType}-sn`,
  2869. searchClose: `cb-${spreadSetting.stdType}-sc`,
  2870. };
  2871. this.obj.html(
  2872. '<div class="sjs-bar d-flex">\n' +
  2873. ' <div class="dropdown mr-1">\n' +
  2874. ' <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  2875. ' <i class="fa fa-list-ol"></i> 显示层级\n' +
  2876. ' </button>\n' +
  2877. ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
  2878. ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
  2879. ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
  2880. ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
  2881. ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
  2882. ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
  2883. ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
  2884. ' </div>\n' +
  2885. ' </div>' +
  2886. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project">${dskProjectHtml.join('')}</select></div>\n` +
  2887. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project-tree"></select></div>\n` +
  2888. ' <div class="ml-1">\n' +
  2889. ' <div class="dropdown">\n' +
  2890. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  2891. ' <i class="fa fa-search"></i>\n' +
  2892. ' </button>\n' +
  2893. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  2894. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  2895. ' <div class="d-inline-block">\n' +
  2896. ' <div class="input-group input-group-sm mr-1">' +
  2897. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  2898. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  2899. ' <div class="input-group-append" >\n' +
  2900. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  2901. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  2902. ' </div>\n' +
  2903. ' </div>\n' +
  2904. ' </div>\n' +
  2905. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  2906. ' </div>\n' +
  2907. ' </div>\n' +
  2908. ' </div>\n' +
  2909. ' </div>' +
  2910. '</div>\n' +
  2911. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  2912. );
  2913. autoFlashHeight();
  2914. const sh = `.cb-${spreadSetting.stdType}-sh`;
  2915. function getObjHeight(select) {
  2916. return select.length > 0 ? select.height() : 0;
  2917. }
  2918. const cHeader = getObjHeight($(".c-header"));
  2919. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  2920. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  2921. this.spreadSetting = spreadSetting;
  2922. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  2923. const searchSheet = this.spread.getActiveSheet();
  2924. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  2925. (function (select, sheet) {
  2926. $(select).click(function () {
  2927. if (!sheet.zh_tree) return;
  2928. const tag = $(this).attr('tag');
  2929. const tree = sheet.zh_tree;
  2930. setTimeout(() => {
  2931. switch (tag) {
  2932. case "1":
  2933. case "2":
  2934. case "3":
  2935. case "4":
  2936. case "5":
  2937. tree.expandByLevel(parseInt(tag));
  2938. SpreadJsObj.refreshTreeRowVisible(sheet);
  2939. break;
  2940. case "last":
  2941. tree.expandByCustom(() => { return true; });
  2942. SpreadJsObj.refreshTreeRowVisible(sheet);
  2943. break;
  2944. }
  2945. }, 100);
  2946. });
  2947. })(`a[name=${relaSelect.showLevel}]`, searchSheet);
  2948. if (!readOnly) {
  2949. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  2950. const dealSheet = info.sheet;
  2951. const mainSheet = billsSheet;
  2952. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  2953. if (!dealBills) { return; }
  2954. const mainTree = mainSheet.zh_tree;
  2955. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  2956. if (!mainNode || !mainTree) { return; }
  2957. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2958. toastr.warning('非最底层项目下,不应添加节点');
  2959. return;
  2960. }
  2961. if (mainNode.settle_status === settleStatus.finish) {
  2962. toastr.warning('已结算节点下,不应添加签约清单');
  2963. return;
  2964. }
  2965. const is_bill = dealBills.kind === 4;
  2966. const oneBills = {
  2967. b_code: is_bill ? dealBills.code : null, code: !is_bill ? dealBills.code : null, name: dealBills.name, unit: dealBills.unit,
  2968. unit_price: is_bill ? dealBills.unitPrice : null, quantity: is_bill ? dealBills.quantity : null, total_price: is_bill ? dealBills.totalPrice : null,
  2969. sgfh_qty: is_bill ? dealBills.quantity : null, sgfh_tp: is_bill ? dealBills.totalPrice : null,
  2970. };
  2971. postData(window.location.pathname + '/update', {
  2972. postType: 'add-deal',
  2973. postData: {
  2974. id: mainNode.ledger_id,
  2975. type: mainNode.code ? 'child' : 'next',
  2976. dealBills: oneBills,
  2977. },
  2978. }, function (result) {
  2979. changeList = result.changeList;
  2980. const refreshData = mainTree.loadPostData(result);
  2981. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  2982. const sel = mainSheet.getSelections()[0];
  2983. if (sel && refreshData.create[0]) {
  2984. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  2985. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  2986. }
  2987. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  2988. billsSpread.focus();
  2989. posSpreadObj.loadCurPosData();
  2990. });
  2991. });
  2992. }
  2993. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  2994. const searchObj = {
  2995. result: [],
  2996. cur: 0,
  2997. searchStdNode: function() {
  2998. const keyword = $(`#${relaSelect.searchText}`).val();
  2999. searchObj.result = keyword ? dskProjectBills2Tree.tenderTree.nodes.filter(x => {
  3000. return (x.code && x.code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  3001. }) : [];
  3002. // searchObj.result = [];
  3003. // for (const x of pathTree.nodes) {
  3004. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  3005. // searchObj.result.push(x);
  3006. // }
  3007. // }
  3008. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  3009. searchObj.cur = 0;
  3010. if (searchObj.result.length > 0) {
  3011. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]));
  3012. }
  3013. },
  3014. searchPre: function () {
  3015. if (searchObj.result.length === 0) return;
  3016. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  3017. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  3018. },
  3019. searchNext: function () {
  3020. if (searchObj.result.length === 0) return;
  3021. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  3022. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  3023. },
  3024. clear: function () {
  3025. $(`#${relaSelect.searchText}`).val('');
  3026. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  3027. searchObj.result = [];
  3028. searchObj.cur = 0;
  3029. }
  3030. };
  3031. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  3032. $(`#${relaSelect.searchPre}`).click(function (e) {
  3033. searchObj.searchPre();
  3034. e.stopPropagation();
  3035. });
  3036. $(`#${relaSelect.searchNext}`).click(function (e) {
  3037. searchObj.searchNext();
  3038. e.stopPropagation();
  3039. });
  3040. $(`#${relaSelect.searchClose}`).click(function (e) {
  3041. searchObj.clear();
  3042. e.stopPropagation();
  3043. });
  3044. };
  3045. loadData (callback) {
  3046. if (this.loaded) {
  3047. if (callback) callback();
  3048. return;
  3049. }
  3050. const self = this;
  3051. if (dskAccountData && dskAccountData.select_project) {
  3052. self.loaded = true;
  3053. changeDskProject(dskAccountData.select_project);
  3054. } else {
  3055. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', []);
  3056. self.loaded = true;
  3057. }
  3058. if (callback) callback();
  3059. }
  3060. }
  3061. $('body').on('change', '#change-dsk-project', function () {
  3062. const pid = $(this).val();
  3063. changeDskProject(pid);
  3064. });
  3065. $('body').on('change', '#change-dsk-project-tree', function () {
  3066. const treeId = $(this).val();
  3067. const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project });
  3068. changeDskProjectTree(projectInfo, treeId);
  3069. });
  3070. function setDskProjectTreeSelect(trees) {
  3071. let html = '';
  3072. for (const tree of trees) {
  3073. html += `<option value="${tree.ID}" ${tree.ID === dskAccountData.select_tree ? 'selected' : ''}>${tree.name}</option>`;
  3074. }
  3075. $('#change-dsk-project-tree').html(html);
  3076. }
  3077. function changeDskProject(pid) {
  3078. const projectInfo = _.find(dskProjects, { pid });
  3079. if (!projectInfo) {
  3080. dskAccountData.select_project = null;
  3081. dskAccountData.select_tree = null;
  3082. const tree = dskProjectBills2Tree.convert([]);
  3083. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3084. return;
  3085. }
  3086. postData('/profile/dsk/api', { type: 'project_tree', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, projectId: projectInfo.pid }, function (datas) {
  3087. const trees = _.filter(datas, x => x.type === 4);
  3088. dskAccountData.select_project = projectInfo.pid;
  3089. setDskProjectTreeSelect(trees);
  3090. changeDskProjectTree(projectInfo, trees.length > 0 ? trees[0].ID : null);
  3091. });
  3092. }
  3093. function changeDskProjectTree(projectInfo, treeId) {
  3094. dskAccountData.select_tree = treeId;
  3095. if (!treeId) {
  3096. const tree = dskProjectBills2Tree.convert([]);
  3097. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3098. return;
  3099. }
  3100. postData('/profile/dsk/api', { type: 'project_bills', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, treeId }, function (result) {
  3101. const tree = dskProjectBills2Tree.convert(result);
  3102. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  3103. });
  3104. }
  3105. const dskBills = new Dsk('#dsk-spread', {
  3106. cols: [
  3107. {title: '编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  3108. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  3109. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3110. {title: '单价', field: 'unitPrice', hAlign: 2, width: 80, formatter: '@'},
  3111. {title: '数量', field: 'quantity', hAlign: 2, width: 80, formatter: '@'},
  3112. ],
  3113. emptyRows: 0,
  3114. headRows: 1,
  3115. headRowHeight: [32],
  3116. headColWidth: [30],
  3117. defaultRowHeight: 21,
  3118. headerFont: '12px 微软雅黑',
  3119. font: '12px 微软雅黑',
  3120. selectedBackColor: '#fffacd',
  3121. readOnly: true,
  3122. stdType: 'dsk',
  3123. libs: dskProjects,
  3124. select_lib: dskAccountData.select_project ? dskAccountData.select_project : null,
  3125. });
  3126. const dskProjectBills2Tree = (function () {
  3127. const treeSetting = {
  3128. id: 'dpb_id',
  3129. pid: 'dpb_pid',
  3130. order: 'seq',
  3131. level: 'level',
  3132. rootId: '-1',
  3133. fullPath: 'full_path',
  3134. };
  3135. const tenderTree = createNewPathTree('gather', treeSetting);
  3136. function setChildrenNode(node, dxs, files, tenders) {
  3137. const dxchildren = _.filter(dxs, { parentID: node.bid });
  3138. const children = _.filter(files, { parentID: node.bid });
  3139. const tenderChildren = _.filter(tenders, { parentID: node.bid });
  3140. const checkChildren = _.orderBy([...dxchildren, ...children, ...tenderChildren], ['seq', 'asc']);
  3141. for (const t of checkChildren) {
  3142. const child = {
  3143. bid: t.ID,
  3144. parentID: t.parentID,
  3145. name: t.name,
  3146. kind: t.kind,
  3147. code: t.code,
  3148. quantity: t.quantity,
  3149. quantity2: t.quantity2,
  3150. unit: t.unit,
  3151. unitPrice: t.unitPrice,
  3152. totalPrice: t.totalPrice,
  3153. formulaCode: t.formulaCode,
  3154. flag: t.flag,
  3155. remark: t.remark,
  3156. };
  3157. tenderTree.addNode(child, node);
  3158. setChildrenNode(child, dxs, files, tenders);
  3159. }
  3160. }
  3161. function convert (projects) {
  3162. tenderTree.clearDatas();
  3163. // 区分文件夹及项目
  3164. const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
  3165. const dxs = _.filter(projects, { kind: 1 });
  3166. const files = _.filter(projects, { kind: 4 });
  3167. const tenders = _.filter(projects, { kind: 8 });
  3168. for (const t of topLevel) {
  3169. const node = {
  3170. bid: t.ID,
  3171. parentID: t.parentID,
  3172. name: t.name,
  3173. kind: t.kind,
  3174. code: t.code,
  3175. quantity: t.quantity,
  3176. quantity2: t.quantity2,
  3177. unit: t.unit,
  3178. unitPrice: t.unitPrice,
  3179. totalPrice: t.totalPrice,
  3180. formulaCode: t.formulaCode,
  3181. flag: t.flag,
  3182. remark: t.remark,
  3183. };
  3184. tenderTree.addNode(node, null);
  3185. setChildrenNode(node, dxs, files, tenders);
  3186. }
  3187. tenderTree.sortTreeNode(true);
  3188. return tenderTree;
  3189. }
  3190. return { tenderTree, convert }
  3191. })();
  3192. $.divResizer({
  3193. select: '#revise-right-spr',
  3194. callback: function () {
  3195. billsSpread.refresh();
  3196. if (posSpread) posSpread.refresh();
  3197. if (stdXmj) stdXmj.spread.refresh();
  3198. if (stdGcl) stdGcl.spread.refresh();
  3199. if (dealBills) dealBills.spread.refresh();
  3200. if (searchLedger) searchLedger.spread.refresh();
  3201. if (errorList) errorList.spread.refresh();
  3202. if (checkList) checkList.spread.refresh();
  3203. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3204. if (jlzfBills) jlzfBills.spread.refresh();
  3205. if (dskBills) dskBills.spread.refresh();
  3206. }
  3207. });
  3208. $.subMenu({
  3209. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  3210. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  3211. key: 'menu.1.0.0',
  3212. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  3213. callback: function (info) {
  3214. if (info.mini) {
  3215. $('.panel-title').addClass('fluid');
  3216. $('#sub-menu').removeClass('panel-sidebar');
  3217. } else {
  3218. $('.panel-title').removeClass('fluid');
  3219. $('#sub-menu').addClass('panel-sidebar');
  3220. }
  3221. autoFlashHeight();
  3222. billsSpread.refresh();
  3223. if (posSpread) posSpread.refresh();
  3224. if (stdXmj) stdXmj.spread.refresh();
  3225. if (stdGcl) stdGcl.spread.refresh();
  3226. if (dealBills) dealBills.spread.refresh();
  3227. if (searchLedger) searchLedger.spread.refresh();
  3228. if (errorList) errorList.spread.refresh();
  3229. if (checkList) checkList.spread.refresh();
  3230. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3231. if (jlzfBills) jlzfBills.spread.refresh();
  3232. if (dskBills) dskBills.spread.refresh();
  3233. }
  3234. });
  3235. // showSideTools(true);
  3236. billsSpread.refresh();
  3237. if (posSpread) posSpread.refresh();
  3238. const stdLibCellDoubleClick = function (updateData, stdNode, stdTree) {
  3239. const mainSheet = billsSheet;
  3240. if (!stdTree || !mainSheet.zh_tree) { return; }
  3241. const mainTree = mainSheet.zh_tree;
  3242. const sel = mainSheet.getSelections()[0];
  3243. const mainNode = mainTree.nodes[sel.row];
  3244. if (!stdNode) return;
  3245. if (updateData.postData.stdType === 'gcl') {
  3246. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3247. toastr.warning('非最底层项目下,不应添加节点');
  3248. return;
  3249. }
  3250. if (mainNode.settle_status === settleStatus.finish) {
  3251. toastr.warning('已结算节点下,不可添加工程量清单');
  3252. return;
  3253. }
  3254. } else {
  3255. const stdNodes = stdTree.getAllParents(stdNode);
  3256. for (const node of stdNodes) {
  3257. const parent = mainTree.datas.find(x => { return x.code === node.code && x.name === node.name; });
  3258. if (parent && parent.settle_status === settleStatus.finish) {
  3259. toastr.warning('项目节父项已结算,不可添加节点');
  3260. return;
  3261. }
  3262. }
  3263. }
  3264. postData(window.location.pathname + '/update', {
  3265. postType: 'add-std',
  3266. postData: {
  3267. id: mainTree.getNodeKey(mainNode),
  3268. tender_id: mainNode.tender_id,
  3269. stdType: updateData.postData.stdType,
  3270. stdLibId: stdNode.list_id,
  3271. stdNode: stdTree.getNodeKey(stdNode)
  3272. }
  3273. }, function (result) {
  3274. changeList = result.changeList;
  3275. const refreshNode = mainTree.loadPostData(result);
  3276. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  3277. if (sel) {
  3278. if (refreshNode.create && refreshNode.create.length > 0) {
  3279. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  3280. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  3281. } else {
  3282. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  3283. if (node) {
  3284. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  3285. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  3286. }
  3287. }
  3288. }
  3289. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3290. billsSpread.focus();
  3291. posSpreadObj.loadCurPosData();
  3292. });
  3293. };
  3294. const stdXmjSetting = {
  3295. selector: '#std-xmj',
  3296. stdType: 'xmj',
  3297. libs: stdChapters,
  3298. treeSetting: {
  3299. id: 'chapter_id',
  3300. pid: 'pid',
  3301. order: 'order',
  3302. level: 'level',
  3303. rootId: -1,
  3304. keys: ['id', 'list_id', 'chapter_id'],
  3305. },
  3306. spreadSetting: {
  3307. cols: [
  3308. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  3309. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3310. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  3311. ],
  3312. treeCol: 0,
  3313. emptyRows: 0,
  3314. headRows: 1,
  3315. headRowHeight: [32],
  3316. defaultRowHeight: 21,
  3317. headerFont: '12px 微软雅黑',
  3318. font: '12px 微软雅黑',
  3319. headColWidth: [30],
  3320. selectedBackColor: '#fffacd',
  3321. },
  3322. cellDoubleClick: stdLibCellDoubleClick,
  3323. page: 'revise',
  3324. tid: window.location.pathname.split('/')[2],
  3325. };
  3326. const stdGclSetting = {
  3327. selector: '#std-gcl',
  3328. stdType: 'gcl',
  3329. libs: stdBills,
  3330. treeSetting: {
  3331. id: 'bill_id',
  3332. pid: 'pid',
  3333. order: 'order',
  3334. level: 'level',
  3335. rootId: -1,
  3336. keys: ['id', 'list_id', 'bill_id']
  3337. },
  3338. spreadSetting: {
  3339. cols: [
  3340. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  3341. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3342. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  3343. ],
  3344. treeCol: 0,
  3345. emptyRows: 0,
  3346. headRows: 1,
  3347. headRowHeight: [32],
  3348. defaultRowHeight: 21,
  3349. headerFont: '12px 微软雅黑',
  3350. font: '12px 微软雅黑',
  3351. headColWidth: [30],
  3352. selectedBackColor: '#fffacd',
  3353. },
  3354. cellDoubleClick: stdLibCellDoubleClick,
  3355. page: 'revise',
  3356. tid: window.location.pathname.split('/')[2],
  3357. };
  3358. // 展开收起标准节点
  3359. $('a', '#side-menu').bind('click', function (e) {
  3360. e.preventDefault();
  3361. const tab = $(this), tabPanel = $(tab.attr('content'));
  3362. // 展开工具栏、切换标签
  3363. if (!tab.hasClass('active')) {
  3364. const close = $('.active', '#side-menu').length === 0;
  3365. $('a', '#side-menu').removeClass('active');
  3366. tab.addClass('active');
  3367. $('.tab-content .tab-pane').removeClass('active');
  3368. tabPanel.addClass('active');
  3369. showSideTools(tab.hasClass('active'));
  3370. if (tab.attr('content') === '#std-xmj') {
  3371. if (!stdXmj) {
  3372. stdXmj = $.stdLib(stdXmjSetting);
  3373. }
  3374. stdXmj.spread.refresh();
  3375. } else if (tab.attr('content') === '#std-gcl') {
  3376. if (!stdGcl) {
  3377. stdGcl = $.stdLib(stdGclSetting);
  3378. }
  3379. stdGcl.spread.refresh();
  3380. } else if (tab.attr('content') === '#deal-bills') {
  3381. dealBills.loadData();
  3382. dealBills.spread.refresh();
  3383. } else if (tab.attr('content') === '#search') {
  3384. if (!searchLedger) {
  3385. searchLedger = $.billsSearch({
  3386. selector: '#search',
  3387. searchSpread: billsSpread,
  3388. searchOver: true,
  3389. searchEmpty: true,
  3390. resultSpreadSetting: {
  3391. cols: [
  3392. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3393. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3394. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3395. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3396. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3397. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3398. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  3399. ],
  3400. emptyRows: 0,
  3401. headRows: 1,
  3402. headRowHeight: [32],
  3403. headColWidth: [30],
  3404. defaultRowHeight: 21,
  3405. headerFont: '12px 微软雅黑',
  3406. font: '12px 微软雅黑',
  3407. selectedBackColor: '#fffacd',
  3408. readOnly: true,
  3409. },
  3410. afterLocated: function () {
  3411. posSpreadObj.loadCurPosData();
  3412. },
  3413. customSearch: [
  3414. {
  3415. key: 'revise', title: '新增部位', valid: true, parent: true,
  3416. check: function (node) {
  3417. if (node.formc || node.cid) {
  3418. return true;
  3419. } else {
  3420. return false;
  3421. }
  3422. }
  3423. }
  3424. ],
  3425. });
  3426. }
  3427. searchLedger.spread.refresh();
  3428. } else if (tab.attr('content') === '#error-list') {
  3429. errorList.spread.refresh();
  3430. } else if (tab.attr('content') === '#check-list') {
  3431. checkList.spread.refresh();
  3432. } else if (tab.attr('content') === '#sum-load-miss') {
  3433. sumLoadMiss.spread.refresh();
  3434. } else if (tab.attr('content') === '#dsk-list') {
  3435. const dskActiveTab = $('#dsk-tab a[class*="active"]').attr('href');
  3436. $(dskActiveTab).addClass('active');
  3437. if (dskActiveTab === '#jlzf-spread') {
  3438. $('#get-dsk-btn').hide();
  3439. $('#get-dsk-bills-btn').hide();
  3440. jlzfBills.loadData();
  3441. jlzfBills.spread.refresh();
  3442. } else if (dskActiveTab === '#dsk-spread') {
  3443. $('#get-dsk-btn').show();
  3444. $('#get-dsk-bills-btn').show();
  3445. dskBills.loadData();
  3446. dskBills.spread.refresh();
  3447. }
  3448. }
  3449. }
  3450. else {// 收起工具栏
  3451. tab.removeClass('active');
  3452. tabPanel.removeClass('active');
  3453. showSideTools(tab.hasClass('active'));
  3454. }
  3455. billsSpread.refresh();
  3456. if (posSpread) posSpread.refresh();
  3457. });
  3458. // 新增清单切换tab
  3459. $('#dsk-tab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  3460. e.preventDefault();
  3461. const dskActiveTab = $(this).attr('href');
  3462. if (dskActiveTab === '#jlzf-spread') {
  3463. $('#get-dsk-btn').hide();
  3464. $('#get-dsk-bills-btn').hide();
  3465. jlzfBills.loadData();
  3466. jlzfBills.spread.refresh();
  3467. } else if (dskActiveTab === '#dsk-spread') {
  3468. $('#get-dsk-btn').show();
  3469. $('#get-dsk-bills-btn').show();
  3470. dskBills.loadData();
  3471. dskBills.spread.refresh();
  3472. }
  3473. });
  3474. // 显示层次
  3475. (function (select, sheet) {
  3476. $(select).click(function () {
  3477. if (!sheet.zh_tree) return;
  3478. const tag = $(this).attr('tag');
  3479. const tree = sheet.zh_tree;
  3480. setTimeout(() => {
  3481. showWaitingView();
  3482. switch (tag) {
  3483. case "1":
  3484. case "2":
  3485. case "3":
  3486. case "4":
  3487. case "5":
  3488. tree.expandByLevel(parseInt(tag));
  3489. SpreadJsObj.refreshTreeRowVisible(sheet);
  3490. break;
  3491. case "last":
  3492. tree.expandByCustom(() => { return true; });
  3493. SpreadJsObj.refreshTreeRowVisible(sheet);
  3494. break;
  3495. case "leafXmj":
  3496. tree.expandToLeafXmj();
  3497. SpreadJsObj.refreshTreeRowVisible(sheet);
  3498. break;
  3499. }
  3500. closeWaitingView();
  3501. }, 100);
  3502. });
  3503. })('a[name=showLevel]', billsSheet);
  3504. if (openRevise) {
  3505. const dataChecker = DataChecker({
  3506. checkUrl: window.location.pathname + '/check',
  3507. completeData: function (data) {
  3508. pos.updateDatas({update: data.source.pos});
  3509. const loadResult = billsTree.loadPostData({update: data.source.bills});
  3510. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3511. posSpreadObj.loadCurPosData();
  3512. for (const e of data.error) {
  3513. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  3514. }
  3515. },
  3516. errorList: errorList,
  3517. });
  3518. $('#ledger-check2').click(() => {
  3519. ledgerCheck2({
  3520. ledgerTree: billsTree,
  3521. ledgerPos: pos,
  3522. checkList: checkList,
  3523. decimal: decimal,
  3524. checkOption: checkOption,
  3525. }).then(result => {
  3526. check2Viewing({
  3527. extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
  3528. randomWait: true,
  3529. prefix: 'check2-',
  3530. checks: result,
  3531. checkList: checkList,
  3532. });
  3533. });
  3534. });
  3535. if (isYb) {
  3536. let compilationList = [];
  3537. $('#get-dsk-btn').click(function () {
  3538. // 判断是否已绑定dsk用户
  3539. postData('/profile/dsk/api', {type: 'hadbind'}, function (result) {
  3540. if (result === 1) {
  3541. $('#error-dsk .modal-body').find('h5').eq(0).show();
  3542. $('#error-dsk .modal-body').find('h5').eq(1).hide();
  3543. $('#error-dsk').modal('show');
  3544. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定手机');
  3545. } else if (result === 2) {
  3546. $('#error-dsk .modal-body').find('h5').eq(1).show();
  3547. $('#error-dsk .modal-body').find('h5').eq(0).hide();
  3548. $('#error-dsk').modal('show');
  3549. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定账号');
  3550. } else {
  3551. postData('/profile/dsk/api', {
  3552. type: 'compilation',
  3553. getProject: 1,
  3554. compilationId: getLocalCache(dskCompilation)
  3555. }, function (result) {
  3556. let html = '';
  3557. for (const data of result.compilation) {
  3558. html += `<option value="${data.ID}" ${result.select_compilation === data.ID ? 'selected' : ''}>${data.name}</option>`;
  3559. }
  3560. dskAccountData = result.dskAccountData;
  3561. compilationList = result.compilation;
  3562. console.log(compilationList);
  3563. $('#dsk-compilation-list').html(html);
  3564. $('#add-dsk').modal('show');
  3565. setLocalCache(dskCompilation, result.select_compilation);
  3566. makeDskProjectSjsHtml(result.project);
  3567. });
  3568. }
  3569. })
  3570. });
  3571. $('#get-dsk-bills-btn').click(function () {
  3572. const projectInfo = _.find(dskProjects, {pid: dskAccountData.select_project ? dskAccountData.select_project : null});
  3573. changeDskProjectTree(projectInfo, dskAccountData.select_tree ? dskAccountData.select_tree : null);
  3574. });
  3575. $('body').on('change', '#dsk-compilation-list', function () {
  3576. const compilationId = $(this).val();
  3577. setLocalCache(dskCompilation, compilationId);
  3578. dskProjectSpreadObj.refreshSourceTree();
  3579. });
  3580. $('.hide-dsk-modal').click(function () {
  3581. $('#error-dsk').modal('hide');
  3582. });
  3583. let dp = false;
  3584. let gsObj = {
  3585. setting: null,
  3586. gsSheet: null,
  3587. grSheet: null,
  3588. tenderSourceTree: null,
  3589. grArray: dskProjects ? dskProjects : [],
  3590. orgSelect: null,
  3591. };
  3592. function makeDskProjectSjsHtml(datas) {
  3593. if (!dp) {
  3594. initDskProjectTree();
  3595. dp = true;
  3596. }
  3597. gsObj.tenderSourceTree = dskProject2Tree.convert(datas);
  3598. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  3599. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  3600. if (datas.length === 0) {
  3601. $('#show-project-0').show();
  3602. } else {
  3603. $('#show-project-0').hide();
  3604. }
  3605. }
  3606. const dskProjectSpreadObj = {
  3607. _addTender: function (tender) {
  3608. const gr = gsObj.grArray.find(function (x) {
  3609. return x.pid === tender.pid;
  3610. });
  3611. const c_id = getLocalCache(dskCompilation);
  3612. const t = {
  3613. pid: tender.pid,
  3614. name: tender.name,
  3615. compilationId: c_id,
  3616. compilationName: _.find(compilationList, {ID: c_id}).name
  3617. };
  3618. if (!gr) gsObj.grArray.push(t);
  3619. return t;
  3620. },
  3621. _removeTender: function (tender) {
  3622. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  3623. return x.pid === tender.pid;
  3624. });
  3625. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  3626. },
  3627. reloadResultData: function () {
  3628. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  3629. },
  3630. refreshSourceTree: function () {
  3631. const c_id = getLocalCache(dskCompilation);
  3632. if (c_id) {
  3633. postData('/profile/dsk/api', {type: 'project', compilationId: c_id}, function (result) {
  3634. makeDskProjectSjsHtml(result);
  3635. });
  3636. }
  3637. },
  3638. gsButtonClicked: function (e, info) {
  3639. if (!info.sheet.zh_setting) return;
  3640. const col = info.sheet.zh_setting.cols[info.col];
  3641. if (col.field !== 'selected') return;
  3642. const node = SpreadJsObj.getSelectObject(info.sheet);
  3643. node.selected = !node.selected;
  3644. if (node.children && node.children.length > 0) {
  3645. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  3646. for (const p of posterity) {
  3647. p.selected = node.selected;
  3648. if ((!p.children || p.children.length === 0) && p.type === 2) {
  3649. if (p.selected) {
  3650. dskProjectSpreadObj._addTender(p);
  3651. } else {
  3652. dskProjectSpreadObj._removeTender(p);
  3653. }
  3654. }
  3655. }
  3656. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  3657. } else if (node.type === 2) {
  3658. if (node.selected) {
  3659. dskProjectSpreadObj._addTender(node);
  3660. } else {
  3661. dskProjectSpreadObj._removeTender(node);
  3662. }
  3663. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  3664. }
  3665. dskProjectSpreadObj.reloadResultData();
  3666. },
  3667. deleteGr: function () {
  3668. if (gsObj.grArray.length === 0) return;
  3669. if (gsObj.grSheet.getSelections().length === 0) return;
  3670. const selections = gsObj.grSheet.getSelections();
  3671. const sel = selections ? selections[0] : gsObj.grSheet.getSelections()[0];
  3672. const row = sel && sel.row !== undefined ? sel.row : -1;
  3673. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  3674. return false;
  3675. }
  3676. const delList = [];
  3677. for (let r = 0; r < sel.rowCount; r++) {
  3678. const select = gsObj.grArray[row + r];
  3679. delList.push(select);
  3680. }
  3681. _.pullAll(gsObj.grArray, delList);
  3682. dskProjectSpreadObj.reloadResultData();
  3683. dskProjectSpreadObj.refreshSourceTree();
  3684. },
  3685. };
  3686. const initDskProjectTree = function () {
  3687. const gsSpread = SpreadJsObj.createNewSpread($('#dsk-project-source-spread')[0]);
  3688. gsObj.gsSheet = gsSpread.getActiveSheet();
  3689. const gsSpreadSetting = {
  3690. cols: [
  3691. {
  3692. title: '选择',
  3693. field: 'selected',
  3694. hAlign: 1,
  3695. width: 40,
  3696. formatter: '@',
  3697. cellType: 'checkbox',
  3698. readOnly: true,
  3699. },
  3700. {
  3701. title: '名称',
  3702. field: 'name',
  3703. hAlign: 0,
  3704. width: 400,
  3705. formatter: '@',
  3706. readOnly: true,
  3707. folderCell: true,
  3708. cellType: 'tree'
  3709. },
  3710. ],
  3711. emptyRows: 0,
  3712. headRows: 1,
  3713. headRowHeight: [32],
  3714. defaultRowHeight: 21,
  3715. headerFont: '12px 微软雅黑',
  3716. font: '12px 微软雅黑',
  3717. headColWidth: [0],
  3718. selectedBackColor: '#fffacd',
  3719. };
  3720. SpreadJsObj.initSheet(gsObj.gsSheet, gsSpreadSetting);
  3721. gsSpread.bind(spreadNS.Events.ButtonClicked, dskProjectSpreadObj.gsButtonClicked);
  3722. const grSpread = SpreadJsObj.createNewSpread($('#dsk-project-result-spread')[0]);
  3723. gsObj.grSheet = grSpread.getActiveSheet();
  3724. const grSpreadSetting = {
  3725. cols: [
  3726. {
  3727. title: '名称',
  3728. colSpan: '1',
  3729. rowSpan: '1',
  3730. field: 'name',
  3731. hAlign: 0,
  3732. width: 250,
  3733. formatter: '@',
  3734. readOnly: true,
  3735. cellType: 'ellipsisAutoTip',
  3736. scrollHeightClass: '.modal-height-500'
  3737. },
  3738. {
  3739. title: '所属编办',
  3740. colSpan: '1',
  3741. rowSpan: '1',
  3742. field: 'compilationName',
  3743. hAlign: 0,
  3744. width: 150,
  3745. formatter: '@',
  3746. readOnly: true
  3747. },
  3748. ],
  3749. emptyRows: 0,
  3750. headRows: 1,
  3751. headRowHeight: [32],
  3752. defaultRowHeight: 21,
  3753. headerFont: '12px 微软雅黑',
  3754. font: '12px 微软雅黑',
  3755. headColWidth: []
  3756. };
  3757. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  3758. // 右键删除已选项目
  3759. const gsContextMenuOptions = {
  3760. selector: '#dsk-project-result-spread',
  3761. build: function ($trigger, e) {
  3762. const target = SpreadJsObj.safeRightClickSelection($trigger, e, grSpread);
  3763. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3764. },
  3765. items: {
  3766. delete: {
  3767. name: '删除',
  3768. icon: 'fa-remove',
  3769. callback: function (key, opt) {
  3770. dskProjectSpreadObj.deleteGr();
  3771. },
  3772. disabled: function (key, opt) {
  3773. const selection = gsObj.grSheet.getSelections();
  3774. const sel = selection ? selection[0] : gsObj.grSheet.getSelections()[0];
  3775. const row = sel && sel.row !== undefined ? sel.row : -1;
  3776. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  3777. return true;
  3778. }
  3779. return false;
  3780. }
  3781. },
  3782. }
  3783. };
  3784. $.contextMenu(gsContextMenuOptions);
  3785. $('#add-dsk').bind('shown.bs.modal', function () {
  3786. if (gsSpread) gsSpread.refresh();
  3787. if (grSpread) grSpread.refresh();
  3788. });
  3789. };
  3790. const dskProject2Tree = (function () {
  3791. const treeSetting = {
  3792. id: 'tmt_id',
  3793. pid: 'tmt_pid',
  3794. order: 'seq',
  3795. level: 'level',
  3796. rootId: '-1',
  3797. fullPath: 'full_path',
  3798. };
  3799. const tenderTree = createNewPathTree('gather', treeSetting);
  3800. function setChildrenNode(node, files, tenders) {
  3801. const children = _.filter(files, {parentID: node.pid});
  3802. const tenderChildren = _.filter(tenders, {parentID: node.pid});
  3803. const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
  3804. for (const c of checkChildren) {
  3805. // if (c.type === 1 && _.filter(files, { parentID: c.ID }).length === 0 && _.filter(tenders, { parentID: c.ID }).length === 0) {
  3806. // // 判断文件夹下有无东西,没有就不插入
  3807. // continue;
  3808. // }
  3809. const child = {
  3810. pid: c.ID,
  3811. parentID: c.parentID,
  3812. name: c.name,
  3813. type: c.type,
  3814. selected: _.findIndex(gsObj.grArray, {pid: c.ID}) >= 0
  3815. };
  3816. tenderTree.addNode(child, node);
  3817. if (c.type === 1) setChildrenNode(child, files, tenders);
  3818. }
  3819. }
  3820. function convert(projects) {
  3821. tenderTree.clearDatas();
  3822. const result = filterFolders(projects);
  3823. const topLevel = _.orderBy(_.filter(result, {parentID: '-1'}), ['seq', 'asc']);
  3824. const files = _.filter(result, {type: 1});
  3825. const tenders = _.filter(result, {type: 2});
  3826. for (const t of topLevel) {
  3827. const node = {
  3828. pid: t.ID,
  3829. parentID: t.parentID,
  3830. name: t.name,
  3831. type: t.type,
  3832. selected: t.type === 2 ? _.findIndex(gsObj.grArray, {pid: t.ID}) >= 0 : false,
  3833. };
  3834. tenderTree.addNode(node, null);
  3835. if (t.type === 1) setChildrenNode(node, files, tenders);
  3836. }
  3837. tenderTree.sortTreeNode(true);
  3838. return tenderTree;
  3839. }
  3840. return {tenderTree, convert}
  3841. })();
  3842. function filterFolders(data) {
  3843. // 构建ID到节点的映射
  3844. const idMap = data.reduce((map, node) => {
  3845. map[node.ID] = node;
  3846. return map;
  3847. }, {});
  3848. // 建立父子关系映射
  3849. const parentMap = data.reduce((map, node) => {
  3850. if (node.parentID !== '-1') {
  3851. if (!map[node.parentID]) {
  3852. map[node.parentID] = [];
  3853. }
  3854. map[node.parentID].push(node.ID);
  3855. }
  3856. return map;
  3857. }, {});
  3858. // 检查节点及其子节点是否包含清单(type=1)
  3859. const hasChecklist = (id) => {
  3860. const node = idMap[id];
  3861. if (node.type === 2) {
  3862. return true;
  3863. }
  3864. if (!parentMap[id]) {
  3865. return false;
  3866. }
  3867. return parentMap[id].some(childID => hasChecklist(childID));
  3868. };
  3869. // 过滤节点
  3870. const filteredIDs = new Set();
  3871. data.forEach(node => {
  3872. if (node.type === 2 || hasChecklist(node.ID)) {
  3873. let currentID = node.ID;
  3874. while (currentID !== '-1') {
  3875. filteredIDs.add(currentID);
  3876. currentID = idMap[currentID].parentID;
  3877. }
  3878. }
  3879. });
  3880. // 返回过滤后的数据
  3881. return data.filter(node => filteredIDs.has(node.ID));
  3882. }
  3883. $('#set-dsk-project').click(function () {
  3884. postData('/profile/dsk/api', {
  3885. type: 'save_projects',
  3886. tid: window.location.pathname.split('/')[2],
  3887. project_list: gsObj.grArray
  3888. }, function (result) {
  3889. // dskAccountData.select_project = result;
  3890. dskProjects = gsObj.grArray;
  3891. if (!dskAccountData.select_project || dskAccountData.select_project !== result) {
  3892. dskAccountData.select_project = result;
  3893. changeDskProject(result);
  3894. dskBills.spread.refresh();
  3895. }
  3896. setDskProjectSelect(gsObj.grArray);
  3897. $('#add-dsk').modal('hide');
  3898. });
  3899. });
  3900. $('#add-dsk').on('hide.bs.modal', function () {
  3901. $('#autoTip').hide();
  3902. });
  3903. function setDskProjectSelect(projects) {
  3904. let html = '';
  3905. for (const project of projects) {
  3906. html += `<option value="${project.pid}" ${project.pid === dskAccountData.select_project ? 'selected' : ''}>${project.name}</option>`;
  3907. }
  3908. $('#change-dsk-project').html(html);
  3909. }
  3910. // 选中所有新增部位/清单
  3911. $('#add-all-revise').click(function() {
  3912. const this_cid = window.location.pathname.split('/')[4];
  3913. makeGclGatherData();
  3914. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  3915. type: 'get-revise-list',
  3916. }, function (result) {
  3917. const addDatas = [];
  3918. for (const ggd in gclGatherData) {
  3919. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  3920. let hadcid = 0;
  3921. for (const xmj of gclGatherData[ggd].leafXmjs) {
  3922. const changeLedger = _.find(result.changeLedgerList, {id: xmj.gcl_id});
  3923. const changePos = _.find(result.changePosList, {id: xmj.mx_id, lid: xmj.gcl_id});
  3924. if (changeLedger || changePos) {
  3925. xmj.cid = 1;
  3926. xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
  3927. hadcid = 1;
  3928. }
  3929. }
  3930. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  3931. }
  3932. for (const gclInfo of _.filter(gclGatherData, {cid: 1})) {
  3933. const leafXmjs = _.filter(gclInfo.leafXmjs, {ccid: this_cid});
  3934. if (leafXmjs.length > 0) {
  3935. gclInfo.is_change = 1;
  3936. for (const xmj of leafXmjs) {
  3937. if (_.findIndex(changeList, function (item) {
  3938. return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
  3939. }) === -1) {
  3940. addDatas.push({
  3941. lid: xmj.gcl_id,
  3942. code: gclInfo.code,
  3943. name: gclInfo.name || '',
  3944. unit: gclInfo.unit || '',
  3945. unit_price: gclInfo.unit_price,
  3946. oamount: xmj.quantity,
  3947. oamount2: xmj.quantity,
  3948. bwmx: xmj.bwmx || xmj.jldy || '',
  3949. xmj_code: xmj.code || '',
  3950. xmj_jldy: xmj.jldy || '',
  3951. xmj_dwgc: xmj.dwgc || '',
  3952. xmj_fbgc: xmj.fbgc || '',
  3953. xmj_fxgc: xmj.fxgc || '',
  3954. gcl_id: xmj.gcl_id,
  3955. mx_id: xmj.mx_id || '',
  3956. });
  3957. }
  3958. }
  3959. }
  3960. }
  3961. console.log(addDatas);
  3962. if (addDatas.length > 0) {
  3963. // 更新至服务器
  3964. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  3965. type: 'add-change-list',
  3966. postData: addDatas,
  3967. }, function (result) {
  3968. toastr.success('已新增当前变更令新增的所有部位/清单');
  3969. changeList = result.changeList;
  3970. const sortData = SpreadJsObj.getSortData(billsSheet);
  3971. const billsNodes = _.filter(sortData, function (item) {
  3972. return _.findIndex(addDatas, {gcl_id: item.id}) !== -1;
  3973. });
  3974. for (const billsNode of billsNodes) {
  3975. billsNode.is_change = 1;
  3976. }
  3977. const loadResult = { update: billsNodes };
  3978. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3979. posSpreadObj.loadCurPosData();
  3980. });
  3981. } else {
  3982. toastr.warning('未存在当前变更令新增的部位/清单');
  3983. }
  3984. });
  3985. });
  3986. }
  3987. }
  3988. });
  3989. // 编号排序,多重判断
  3990. function sortByCode(a, b, code = 'b_code') {
  3991. let code1 = a[code].split('-');
  3992. let code2 = b[code].split('-');
  3993. let code1length = code1.length;
  3994. let code2length = code2.length;
  3995. for (let i = 0; i < code1length; i ++) {
  3996. if (i+1 <= code2length) {
  3997. if (code1[i] != code2[i]) {
  3998. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  3999. return parseInt(code1[i]) - parseInt(code2[i]);
  4000. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  4001. return 1;
  4002. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  4003. return -1;
  4004. } else {
  4005. const str1length = code1[i].length;
  4006. const str2length = code2[i].length;
  4007. for (let j = 0; j < str1length; j++) {
  4008. if (j+1 <= str2length) {
  4009. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  4010. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  4011. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  4012. if (str1length == str2length) {
  4013. return 0;
  4014. } else {
  4015. return str1length - str2length;
  4016. }
  4017. }
  4018. } else {
  4019. if (j+1 >= str1length) {
  4020. return 1;
  4021. } else {
  4022. return -1;
  4023. }
  4024. }
  4025. }
  4026. }
  4027. } else if (i+1 == code1length && code1[i] == code2[i]) {
  4028. if (code1length == code2length) {
  4029. return 0;
  4030. } else {
  4031. return code1length - code2length;
  4032. }
  4033. }
  4034. } else {
  4035. if (i+1 >= code1length) {
  4036. return 1;
  4037. } else {
  4038. return -1;
  4039. }
  4040. }
  4041. }
  4042. }