ledger.js 217 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741
  1. /**
  2. * 台账相关js
  3. *
  4. * @author Mai
  5. * @date 2018/02/05
  6. * @version
  7. */
  8. const ckBillsSpread = window.location.pathname + '-billsSelect';
  9. function checkTzMeasureType () {
  10. return tender.measure_type === measureType.tz.value;
  11. }
  12. function getTenderId() {
  13. return window.location.pathname.split('/')[2];
  14. }
  15. const copyBlockTag = 'zh.calc.copyBlock';
  16. const invalidFields = {
  17. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price'],
  18. gcl: ['dgn_qty1', 'dgn_qty2'],
  19. posCode: ['b_code'],
  20. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp'],
  21. posXmj: ['code'],
  22. };
  23. function getExprInfo (field, converse = false) {
  24. const exprField = [
  25. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  26. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  27. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  28. ];
  29. if (converse) return _.find(exprField, { expr: field });
  30. return _.find(exprField, {qty: field});
  31. }
  32. function transExpr(expr) {
  33. return expr.replace('=', '').replace('%', '/100');
  34. }
  35. const checkOption = {
  36. sibling: { enable: 1 },
  37. empty_code: { enable: 1 },
  38. calc: {
  39. enable: 1,
  40. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  41. },
  42. zero: { enable: 1 },
  43. zeroPos: { enable: 1 },
  44. pos_drawingCode: { enable: 1 },
  45. tp: {
  46. enable: 1,
  47. fields: [
  48. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  49. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  50. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  51. {qty: 'quantity', tp: 'total_price'},
  52. {qty: 'deal_qty', tp: 'deal_tp'},
  53. ],
  54. },
  55. same_code: { enable: 1 },
  56. };
  57. $(document).ready(function() {
  58. let stdXmj, stdGcl, dealBills, searchLedger;
  59. autoFlashHeight();
  60. // 初始化台账
  61. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  62. const ledgerSheet = ledgerSpread.getActiveSheet();
  63. removeLocalCache('bills-fold');
  64. const treeSetting = {
  65. id: 'ledger_id',
  66. pid: 'ledger_pid',
  67. order: 'order',
  68. level: 'level',
  69. rootId: -1,
  70. keys: ['id', 'tender_id', 'ledger_id'],
  71. preUrl: '/tender/' + getTenderId() + '/ledger',
  72. //treeCacheKey: 'ledger_bills_fold' + '_' + getTenderId(),
  73. autoExpand: 3,
  74. // markFoldKey: 'bills-fold',
  75. // markFoldSubKey: window.location.pathname.split('/')[2],
  76. markExpandKey: 'bills-expand',
  77. markExpandSubKey: window.location.pathname.split('/')[2],
  78. calcFields: ['deal_tp', 'sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price'],
  79. };
  80. treeSetting.calcFun = function (node) {
  81. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  82. };
  83. const ledgerTree = createNewPathTree('ledger', treeSetting);
  84. //初始化所有附件列表
  85. getAllList();
  86. // 初始化 计量单元
  87. const pos = new PosData({
  88. id: 'id', ledgerId: 'lid',
  89. });
  90. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  91. // 初始化 附属工程量
  92. const ancGcl = createAncillaryGcl({ id: 'id', masterId: 'lid', sort: [['g_order', 'asc']] });
  93. const ancGclSpread = SpreadJsObj.createNewSpread($('#anc-gcl-spread')[0]);
  94. const ancGclSheet = ancGclSpread.getActiveSheet();
  95. const billsTag = $.billsTag({
  96. selector: '#bills-tag',
  97. relaSpread: ledgerSpread,
  98. relaPosSpread: posSpread,
  99. updateUrl: window.location.pathname + '/tag',
  100. afterModify: function (nodes) {
  101. SpreadJsObj.repaintNodesRowHeader(ledgerSpread.getActiveSheet(), nodes);
  102. },
  103. afterLocated: function (lid, pos_id) {
  104. posOperationObj.loadCurPosData();
  105. ancGclObj.loadCurAncillaryGcl();
  106. if (pos_id) {
  107. const posSheet = posSpread.getActiveSheet();
  108. const relaPos = posSheet.zh_data.find(x => { return x.id === pos_id; });
  109. SpreadJsObj.locateData(posSheet, relaPos);
  110. }
  111. },
  112. afterShow: function () {
  113. ledgerSpread.refresh();
  114. if (posSpread) posSpread.refresh();
  115. if (ancGclSpread) ancGclSpread.refresh();
  116. },
  117. });
  118. const errorList = $.cs_errorList({
  119. tabSelector: '#error-list-tab',
  120. selector: '#error-list',
  121. relaSpread: ledgerSpread,
  122. storeKey: 'ledger-error-' + getTenderId(),
  123. afterLocated: function () {
  124. posOperationObj.loadCurPosData();
  125. ancGclObj.loadCurAncillaryGcl();
  126. },
  127. afterShow: function () {
  128. ledgerSpread.refresh();
  129. if (posSpread) posSpread.refresh();
  130. if (ancGclSpread) ancGclSpread.refresh();
  131. },
  132. });
  133. const checkList = $.ledger_checkList({
  134. id: 'check-list',
  135. tabSelector: '#check-list-tab',
  136. selector: '#check-list',
  137. relaSpread: ledgerSpread,
  138. storeKey: 'ledger-check-' + getTenderId(),
  139. checkType: getCheckType(checkOption),
  140. afterLocated: function () {
  141. posOperationObj.loadCurPosData();
  142. ancGclObj.loadCurAncillaryGcl();
  143. },
  144. afterShow: function () {
  145. ledgerSpread.refresh();
  146. if (posSpread) posSpread.refresh();
  147. if (ancGclSpread) ancGclSpread.refresh();
  148. },
  149. });
  150. const gclGather = $.cs_gclGather({
  151. selector: '#gcl-gather',
  152. id: 'gcl-gather',
  153. relaSheet: ledgerSpread.getActiveSheet(),
  154. });
  155. $.subMenu({
  156. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  157. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  158. key: 'menu.1.0.0',
  159. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  160. callback: function (info) {
  161. if (info.mini) {
  162. $('.panel-title').addClass('fluid');
  163. $('#sub-menu').removeClass('panel-sidebar');
  164. } else {
  165. $('.panel-title').removeClass('fluid');
  166. $('#sub-menu').addClass('panel-sidebar');
  167. }
  168. autoFlashHeight();
  169. ledgerSpread.refresh();
  170. if (posSpread) posSpread.refresh();
  171. if (ancGclSpread) ancGclSpread.refresh();
  172. if (stdXmj) stdXmj.spread.refresh();
  173. if (stdGcl) stdGcl.spread.refresh();
  174. if (dealBills) dealBills.spread.refresh();
  175. if (searchLedger) searchLedger.spread.refresh();
  176. if (errorList) errorList.spread.refresh();
  177. if (checkList) checkList.spread.refresh();
  178. if (gclGather) gclGather.spread.refresh();
  179. }
  180. });
  181. // 定义事件
  182. const treeOperationObj = {
  183. loadExprToInput(sheet) {
  184. const sel = sheet.getSelections()[0];
  185. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  186. if (col && col.type === 'Number') {
  187. const data = SpreadJsObj.getSelectObject(sheet);
  188. if (data) {
  189. const exprInfo = getExprInfo(col.field);
  190. if (exprInfo) {
  191. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  192. .attr('field', col.field).attr('org', data[col.field]);
  193. } else {
  194. $('#bills-expr').val(data[col.field])
  195. .attr('field', col.field).attr('org', data[col.field]);
  196. }
  197. if (col.field.indexOf('dgn') >= 0) {
  198. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== ''));
  199. } else {
  200. const nodePos = pos.getLedgerPos(data.id);
  201. if (nodePos && nodePos.length > 0) {
  202. $('#bills-expr').val('').attr('readOnly', true);
  203. $('#bills-expr').removeAttr('data-row');
  204. } else {
  205. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0));
  206. }
  207. }
  208. $('#bills-expr').attr('data-row', sel.row);
  209. } else {
  210. $('#bills-expr').val('').attr('readOnly', true);
  211. $('#bills-expr').removeAttr('data-row');
  212. }
  213. } else {
  214. $('#bills-expr').val('').attr('readOnly', true);
  215. $('#bills-expr').removeAttr('data-row');
  216. }
  217. },
  218. getSelectNode: function (sheet) {
  219. if (!sheet || !sheet.zh_tree) {
  220. return null;
  221. } else {
  222. const sel = sheet.getSelections()[0];
  223. return sheet.zh_tree.nodes[sel.row];
  224. }
  225. },
  226. getDefaultSelectInfo: function (sheet) {
  227. const tree = sheet.zh_tree;
  228. if (!tree) return;
  229. const sel = sheet.getSelections()[0];
  230. const node = sheet.zh_tree.nodes[sel.row];
  231. if (!node) return;
  232. let count = 1;
  233. if (sel.rowCount > 1) {
  234. for (let r = 1; r < sel.rowCount; r++) {
  235. const rNode = sheet.zh_tree.nodes[sel.row + r];
  236. if (rNode.level > node.level) continue;
  237. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  238. toastr.error('请选择同一清单下的节点,进行该操作');
  239. return;
  240. }
  241. count += 1;
  242. }
  243. }
  244. return [tree, node, count];
  245. },
  246. /**
  247. * 刷新顶部按钮是否可用
  248. * @param sheet
  249. * @param selections
  250. */
  251. refreshOperationValid: function (sheet, selection) {
  252. const setObjEnable = function (obj, enable) {
  253. if (enable) {
  254. obj.removeClass('disabled');
  255. } else {
  256. obj.addClass('disabled');
  257. }
  258. };
  259. const invalidAll = function () {
  260. setObjEnable($('#insert'), false);
  261. setObjEnable($('#delete'), false);
  262. setObjEnable($('#up-move'), false);
  263. setObjEnable($('#down-move'), false);
  264. setObjEnable($('#up-level'), false);
  265. setObjEnable($('#down-level'), false);
  266. };
  267. const sel = selection ? selection[0] : sheet.getSelections()[0];
  268. const row = sel ? sel.row : -1;
  269. const tree = sheet.zh_tree;
  270. if (!tree) {
  271. invalidAll();
  272. return;
  273. }
  274. const first = sheet.zh_tree.nodes[row];
  275. if (!first) {
  276. invalidAll();
  277. return;
  278. }
  279. let last = first, sameParent = true;
  280. if (sel.rowCount > 1 && first) {
  281. for (let r = 1; r < sel.rowCount; r++) {
  282. const rNode = tree.nodes[row + r];
  283. if (!rNode) {
  284. sameParent = false;
  285. break;
  286. }
  287. if (rNode.level > first.level) continue;
  288. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  289. sameParent = false;
  290. break;
  291. }
  292. last = rNode;
  293. }
  294. }
  295. const preNode = tree.getPreSiblingNode(first);
  296. const valid = !sheet.zh_setting.readOnly;
  297. setObjEnable($('#insert'), valid && first && first.level > 1);
  298. setObjEnable($('#delete'), valid && first && sameParent && !(first.level === 1 && first.node_type));
  299. setObjEnable($('#up-move'), valid && first && sameParent && first.level > 1 && preNode);
  300. setObjEnable($('#down-move'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last));
  301. if (checkTzMeasureType()) {
  302. const posRange = last ? pos.getLedgerPos(last.id) : [];
  303. setObjEnable($('#up-level'), valid && first && sameParent && tree.getParent(first) && first.level > 2 && ((!posRange || posRange.length === 0) || tree.isLastSibling(last)));
  304. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  305. setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode && (!preNodePosRange || preNodePosRange.length === 0));
  306. } else {
  307. setObjEnable($('#up-level'), valid && first && sameParent && first.level > 2 && tree.getParent(first));
  308. setObjEnable($('#down-level'), valid && first && sameParent && first.level > 1 && preNode);
  309. }
  310. setObjEnable($('#cut'), valid);
  311. setObjEnable($('#paste'), valid);
  312. },
  313. refreshTree: function (sheet, data) {
  314. SpreadJsObj.massOperationSheet(sheet, function () {
  315. const tree = sheet.zh_tree;
  316. // 处理删除
  317. if (data.delete) {
  318. data.delete.sort(function (x, y) {
  319. return y.deleteIndex - x.deleteIndex;
  320. });
  321. for (const d of data.delete) {
  322. sheet.deleteRows(d.deleteIndex, 1);
  323. }
  324. }
  325. // 处理新增
  326. if (data.create) {
  327. const newNodes = data.create;
  328. if (newNodes) {
  329. newNodes.sort(function (a, b) {
  330. return a.index - b.index;
  331. });
  332. for (const node of newNodes) {
  333. sheet.addRows(node.index, 1);
  334. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  335. }
  336. }
  337. }
  338. // 处理更新
  339. if (data.update) {
  340. const rows = [];
  341. for (const u of data.update) {
  342. rows.push(tree.nodes.indexOf(u));
  343. billsTag.refreshBillsTagView(u);
  344. }
  345. SpreadJsObj.reLoadRowsData(sheet, rows);
  346. }
  347. // 处理展开
  348. if (data.expand) {
  349. const expanded = [];
  350. for (const e of data.expand) {
  351. if (expanded.indexOf(e) === -1) {
  352. const posterity = tree.getPosterity(e);
  353. for (const p of posterity) {
  354. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  355. expanded.push(p);
  356. }
  357. }
  358. }
  359. }
  360. });
  361. },
  362. /**
  363. * 新增节点
  364. * @param spread
  365. */
  366. addNode: function (sheet, count = 1) {
  367. const self = this;
  368. const sel = sheet.getSelections()[0];
  369. const row = sheet.getSelections()[0].row;
  370. const tree = sheet.zh_tree;
  371. if (!tree) { return; }
  372. const node = sheet.zh_tree.nodes[row];
  373. if (!node) { return; }
  374. postData(window.location.pathname + '/update', {
  375. postType: 'add',
  376. postData: {
  377. id: tree.getNodeKey(node),
  378. count: count,
  379. }
  380. }, function (result) {
  381. const refreshNode = tree.loadPostData(result);
  382. self.refreshTree(sheet, refreshNode);
  383. sheet.setSelection(refreshNode.create[0].index, sel.col, sel.rowCount, sel.colCount);
  384. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, refreshNode.create[0].index]);
  385. self.refreshOperationValid(sheet);
  386. });
  387. },
  388. /**
  389. * 删除选中节点
  390. * @param spread
  391. */
  392. deleteNode: function (sheet) {
  393. const self = this;
  394. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  395. if (tree && node && count) {
  396. const data = {
  397. postType: 'delete',
  398. postData: {
  399. id: tree.getNodeKey(node),
  400. count: count
  401. }
  402. };
  403. deleteAfterHint(function () {
  404. postData(window.location.pathname + '/update', data, function (result) {
  405. const refreshNode = tree.loadPostData(result);
  406. for (const d of refreshNode.delete) {
  407. pos.removeDatasByMasterId(d.id);
  408. ancGcl.removeDatasByMasterId(d.id);
  409. }
  410. self.refreshTree(sheet, refreshNode);
  411. self.refreshOperationValid(sheet);
  412. posOperationObj.loadCurPosData();
  413. ancGclObj.loadCurAncillaryGcl();
  414. billsTag.afterDeleteBills(refreshNode.delete);
  415. });
  416. });
  417. }
  418. },
  419. /**
  420. * 上移选中节点
  421. * @param spread
  422. */
  423. upMove: function (sheet) {
  424. const self = this;
  425. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  426. if (tree && node && count) {
  427. const data = {
  428. postType: 'up-move',
  429. postData: {
  430. id: tree.getNodeKey(node),
  431. count: count
  432. }
  433. };
  434. postData(window.location.pathname + '/update', data, function (result) {
  435. const refreshNode = tree.loadPostData(result);
  436. self.refreshTree(sheet, refreshNode);
  437. const sel = sheet.getSelections()[0];
  438. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  439. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  440. self.refreshOperationValid(sheet);
  441. });
  442. }
  443. },
  444. /**
  445. * 下移选中节点
  446. * @param spread
  447. */
  448. downMove: function (sheet) {
  449. const self = this;
  450. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  451. if (tree && node && count) {
  452. const data = {
  453. postType: 'down-move',
  454. postData: {
  455. id: tree.getNodeKey(node),
  456. count: count
  457. }
  458. };
  459. postData(window.location.pathname + '/update', data, function (result) {
  460. const refreshNode = tree.loadPostData(result);
  461. self.refreshTree(sheet, refreshNode);
  462. const sel = sheet.getSelections()[0];
  463. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  464. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  465. self.refreshOperationValid(sheet);
  466. });
  467. }
  468. },
  469. /**
  470. * 升级选中节点
  471. * @param spread
  472. */
  473. upLevel: function (sheet) {
  474. const self = this;
  475. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  476. if (tree && node && count) {
  477. const data = {
  478. postType: 'up-level',
  479. postData: {
  480. id: tree.getNodeKey(node),
  481. count: count
  482. }
  483. };
  484. postData(window.location.pathname + '/update', data, function (result) {
  485. const refreshNode = tree.loadPostData(result);
  486. self.refreshTree(sheet, refreshNode);
  487. self.refreshOperationValid(sheet);
  488. });
  489. }
  490. },
  491. /**
  492. * 降级选中节点
  493. * @param spread
  494. */
  495. downLevel: function (sheet) {
  496. const self = this;
  497. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  498. if (tree && node && count) {
  499. const data = {
  500. postType: 'down-level',
  501. postData: {
  502. id: tree.getNodeKey(node),
  503. count: count
  504. }
  505. };
  506. postData(window.location.pathname + '/update', data, function (result) {
  507. const refreshNode = tree.loadPostData(result);
  508. self.refreshTree(sheet, refreshNode);
  509. self.refreshOperationValid(sheet);
  510. });
  511. }
  512. },
  513. /**
  514. * 编辑单元格响应事件
  515. * @param {Object} e
  516. * @param {Object} info
  517. */
  518. editEnded: function (e, info) {
  519. if (info.sheet.zh_setting) {
  520. const col = info.sheet.zh_setting.cols[info.col];
  521. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  522. const node = sortData[info.row];
  523. const data = {
  524. id: node.id,
  525. tender_id: node.tender_id,
  526. ledger_id: node.ledger_id
  527. };
  528. // 未改变值则不提交
  529. const orgValue = node[col.field];
  530. const newValue = trimInvalidChar(info.editingText);
  531. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  532. return;
  533. }
  534. // 台账模式,检查计量单元相关
  535. if (checkTzMeasureType()) {
  536. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  537. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  538. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  539. if (!node.children || node.children.length ===0) {
  540. const lPos = pos.getLedgerPos(node.id);
  541. if (lPos && lPos.length > 0) {
  542. toastr.error('清单含有计量单元,请在计量单元输入数量');
  543. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  544. return;
  545. }
  546. }
  547. }
  548. if (col.field === 'b_code' && (info.editingText === '' || !info.editingText)) {
  549. const lPos = pos.getLedgerPos(node.id);
  550. if (lPos && lPos.length > 0) {
  551. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  552. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  553. return;
  554. }
  555. }
  556. }
  557. if (col.field === 'node_type' && newValue && newValue !== '0' && newValue !== '19') {
  558. const sameNodeType = sortData.find(x => { return x.node_type == newValue; });
  559. if (sameNodeType) {
  560. toastr.error('已存在该费用类别,请勿重复选择');
  561. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  562. return;
  563. }
  564. }
  565. // 获取更新数据
  566. if (col.type === 'Number') {
  567. const exprInfo = getExprInfo(col.field);
  568. if (newValue) {
  569. const num = _.toNumber(newValue);
  570. if (_.isFinite(num)) {
  571. data[col.field] = num;
  572. } else {
  573. try {
  574. data[col.field] = math.evaluate(transExpr(newValue));
  575. if (exprInfo) {
  576. data[exprInfo.expr] = newValue;
  577. }
  578. } catch(err) {
  579. toastr.error('输入的表达式非法');
  580. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  581. return;
  582. }
  583. }
  584. } else {
  585. data[col.field] = null;
  586. if (exprInfo) {
  587. data[exprInfo.expr] = '';
  588. }
  589. }
  590. } else {
  591. data[col.field] = newValue;
  592. }
  593. // 更新至服务器
  594. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  595. const refreshNode = ledgerTree.loadPostData(result);
  596. treeOperationObj.refreshTree(info.sheet, refreshNode);
  597. });
  598. }
  599. },
  600. /**
  601. * 粘贴单元格响应事件
  602. * @param e
  603. * @param info
  604. */
  605. clipboardPasted: function (e, info) {
  606. if (info.sheet.zh_setting && info.sheet.zh_dataType === 'tree') {
  607. const tree = info.sheet.zh_tree;
  608. if (!tree) { return; }
  609. const sortData = info.sheet.zh_tree.nodes;
  610. const datas = [], filterNodes = [];
  611. let bHint = false, bPaste;
  612. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  613. bPaste = false;
  614. const curRow = info.cellRange.row + iRow;
  615. const node = sortData[curRow];
  616. if (node) {
  617. const data = info.sheet.zh_tree.getNodeKeyData(node);
  618. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  619. const curCol = info.cellRange.col + iCol;
  620. const colSetting = info.sheet.zh_setting.cols[curCol];
  621. const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
  622. const lPos = pos.getLedgerPos(node.id);
  623. if (lPos && lPos.length > 0) {
  624. if (value === '' && colSetting.field === 'b_code') {
  625. if (!bHint) {
  626. toastr.warning('清单含有计量单元,请先删除计量单元,再删除清单编号');
  627. bHint = true;
  628. }
  629. continue;
  630. }
  631. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  632. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  633. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp') {
  634. if (!bHint) {
  635. toastr.warning('清单含有计量单元,数量金额根据计量单元汇总计算所得,不可编辑');
  636. bHint = true;
  637. }
  638. continue;
  639. }
  640. }
  641. if (colSetting.type === 'Number') {
  642. const num = _.toNumber(value);
  643. if (num) {
  644. data[colSetting.field] = num;
  645. bPaste = true;
  646. } else {
  647. try {
  648. data[colSetting.field] = math.evaluate(transExpr(value));
  649. bPaste = true;
  650. } catch(err) {
  651. delete data[colSetting.field];
  652. if (!bHint) {
  653. toastr.warning('输入的表达式非法');
  654. bHint = true;
  655. }
  656. }
  657. }
  658. } else {
  659. data[colSetting.field] = value;
  660. bPaste = true;
  661. }
  662. }
  663. if (bPaste) {
  664. datas.push(data);
  665. } else {
  666. filterNodes.push(node);
  667. }
  668. }
  669. }
  670. if (datas.length > 0) {
  671. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  672. const refreshNode = tree.loadPostData(result);
  673. if (refreshNode.update) {
  674. refreshNode.update = refreshNode.update.concat(filterNodes);
  675. }
  676. treeOperationObj.refreshTree(info.sheet, refreshNode);
  677. }, function () {
  678. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  679. });
  680. } else {
  681. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  682. }
  683. }
  684. },
  685. clipboardPasting: function (e, info) {
  686. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  687. info.cancel = true;
  688. if (!setting || !tree) return;
  689. const pasteData = info.pasteData.html
  690. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  691. : (info.pasteData.text === ''
  692. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  693. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  694. const hint = {
  695. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  696. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  697. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  698. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  699. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  700. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  701. // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  702. };
  703. const datas = [], filterNodes = [];
  704. let pid, level, filterRow = 0;
  705. for (let iRow = 0; iRow < info.cellRange.rowCount + filterRow; iRow++) {
  706. const curRow = info.cellRange.row + iRow;
  707. const node = tree.nodes[curRow];
  708. if (!node) continue;
  709. if (!pid) pid = node.ledger_pid;
  710. if (!level) level = node.level;
  711. // if (node.ledger_pid !== pid) {
  712. // toastMessageUniq(hint.sameParent);
  713. // filterRow+=1;
  714. // continue;
  715. // }
  716. if (node.level < level) break;
  717. let bPaste = false;
  718. const data = info.sheet.zh_tree.getNodeKeyData(node);
  719. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  720. const curCol = info.cellRange.col + iCol;
  721. const colSetting = info.sheet.zh_setting.cols[curCol];
  722. const value = trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  723. const lPos = pos.getLedgerPos(node.id);
  724. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  725. toastMessageUniq(hint.parent);
  726. continue;
  727. }
  728. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  729. toastMessageUniq(hint.gcl);
  730. continue;
  731. }
  732. if (lPos && lPos.length > 0) {
  733. if (value === '' && invalidFields.posCode.indexOf(colSetting.field) >= 0) {
  734. toastMessageUniq(hint.posCode);
  735. continue;
  736. }
  737. if (invalidFields.posCalc.indexOf(colSetting.field) >= 0) {
  738. toastMessageUniq(hint.posQty);
  739. continue;
  740. }
  741. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  742. toastMessageUniq(hint.posXmj);
  743. continue;
  744. }
  745. }
  746. if (colSetting.type === 'Number') {
  747. const num = _.toNumber(value);
  748. if (num) {
  749. data[colSetting.field] = num;
  750. bPaste = true;
  751. } else {
  752. try {
  753. data[colSetting.field] = math.evaluate(transExpr(value));
  754. const exprInfo = getExprInfo(colSetting.field);
  755. if (exprInfo) {
  756. data[exprInfo.expr] = value;
  757. bPaste = true;
  758. }
  759. } catch(err) {
  760. toastMessageUniq(hint.invalidExpr);
  761. }
  762. }
  763. } else {
  764. data[colSetting.field] = value;
  765. bPaste = true;
  766. }
  767. }
  768. if (bPaste) {
  769. datas.push(data);
  770. } else {
  771. filterNodes.push(node);
  772. }
  773. }
  774. if (datas.length > 0) {
  775. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  776. const refreshNode = tree.loadPostData(result);
  777. if (refreshNode.update) {
  778. refreshNode.update = refreshNode.update.concat(filterNodes);
  779. }
  780. treeOperationObj.refreshTree(info.sheet, refreshNode);
  781. }, function () {
  782. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  783. });
  784. } else {
  785. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  786. }
  787. },
  788. /**
  789. * 删除按钮响应事件
  790. * @param sheet
  791. */
  792. deletePress: function (sheet) {
  793. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  794. const tree = sheet.zh_tree;
  795. if (!tree) { return; }
  796. const sortData = sheet.zh_tree.nodes;
  797. const datas = [], nodes = [];
  798. const sel = sheet.getSelections()[0];
  799. let bHint = false;
  800. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  801. const node = sortData[iRow];
  802. if (node) {
  803. let bDel = false;
  804. const data = sheet.zh_tree.getNodeKeyData(node);
  805. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  806. const col = sheet.zh_setting.cols[iCol];
  807. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  808. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  809. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  810. const lPos = pos.getLedgerPos(node.id);
  811. if (lPos && lPos.length > 0) {
  812. if (!bHint) {
  813. if (col.field === 'code') {
  814. toastr.warning('清单含有计量单元,请先删除计量单元,再删除清单编号');
  815. } else {
  816. toastr.warning('清单含有计量单元,数量金额根据计量单元汇总计算所得,不可删除');
  817. }
  818. bHint = true;
  819. }
  820. continue;
  821. }
  822. }
  823. const style = sheet.getStyle(iRow, iCol);
  824. if (!style.locked) {
  825. const colSetting = sheet.zh_setting.cols[iCol];
  826. data[colSetting.field] = null;
  827. const exprInfo = getExprInfo(colSetting.field);
  828. if (exprInfo) {
  829. data[exprInfo.expr] = '';
  830. }
  831. bDel = true;
  832. }
  833. }
  834. if (bDel) {
  835. datas.push(data);
  836. nodes.push(node);
  837. }
  838. }
  839. }
  840. if (datas.length > 0) {
  841. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  842. const refreshNode = tree.loadPostData(result);
  843. treeOperationObj.refreshTree(sheet, refreshNode);
  844. treeOperationObj.loadExprToInput(sheet);
  845. });
  846. }
  847. }
  848. },
  849. /**
  850. * 粘贴整块
  851. * @param spread
  852. * @param block
  853. */
  854. pasteBlock: function (spread, copyInfo) {
  855. const self = this;
  856. const sheet = spread.getActiveSheet();
  857. const sel = sheet.getSelections()[0];
  858. const row = sel.row;
  859. const tree = sheet.zh_tree;
  860. if (!tree) { return; }
  861. const node = tree.nodes[row];
  862. if (!node) { return; }
  863. postData(window.location.pathname + '/update', {
  864. postType: 'paste-block',
  865. postData: {
  866. id: tree.getNodeKey(node),
  867. tid: copyInfo.tid,
  868. block: copyInfo.block,
  869. }
  870. }, function (data) {
  871. pos.updateDatas(data.pos);
  872. if (data.ancGcl) ancGcl.updateDatas(data.ancGcl);
  873. const result = tree.loadPostData(data.ledger);
  874. self.refreshTree(sheet, result);
  875. sheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  876. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, result.create[0].index]);
  877. self.refreshOperationValid(sheet);
  878. removeLocalCache(copyBlockTag);
  879. }, null, true);
  880. },
  881. loadRelaData: function () {
  882. posOperationObj.loadCurPosData();
  883. ancGclObj.loadCurAncillaryGcl();
  884. posSearch.search($('#pos-keyword').val());
  885. treeOperationObj.loadExprToInput(ledgerSpread.getActiveSheet());
  886. },
  887. selectionChanged: function (e, info) {
  888. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  889. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  890. treeOperationObj.loadRelaData();
  891. // 全选去除
  892. $('#dqjiedian').find('.check-all-file').prop('checked', false);
  893. }
  894. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  895. },
  896. topRowChanged(e, info) {
  897. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  898. },
  899. cut: function (sheet, sel, callback) {
  900. if (!sheet || !sel) return;
  901. if (sel.colCount >= sheet.zh_setting.cols.length) {
  902. toastr.warning('请勿选中整行剪切');
  903. return;
  904. }
  905. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  906. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  907. const node = sortData[iRow];
  908. if (node) {
  909. const data = sheet.zh_tree.getNodeKeyData(node);
  910. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  911. const col = sheet.zh_setting.cols[iCol];
  912. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  913. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  914. col.field === 'qtcl_qty' || col.field === 'qtcl_tp') {
  915. const lPos = pos.getLedgerPos(node.id);
  916. if (lPos && lPos.length > 0) {
  917. toastr.error('不可剪切');
  918. return;
  919. }
  920. }
  921. const style = sheet.getStyle(iRow, iCol);
  922. if (style.locked) {
  923. toastr.error('不可剪切');
  924. return;
  925. }
  926. const colSetting = sheet.zh_setting.cols[iCol];
  927. data[colSetting.field] = null;
  928. const exprInfo = getExprInfo(colSetting.field);
  929. if (exprInfo) {
  930. data[exprInfo.expr] = '';
  931. }
  932. }
  933. datas.push(data);
  934. }
  935. }
  936. if (datas.length > 0) {
  937. callback();
  938. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  939. const refreshNode = sheet.zh_tree.loadPostData(result);
  940. treeOperationObj.refreshTree(sheet, refreshNode);
  941. });
  942. }
  943. },
  944. editStarting(e, info) {
  945. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  946. const tree = info.sheet.zh_tree;
  947. const col = info.sheet.zh_setting.cols[info.col];
  948. const node = info.sheet.zh_tree.nodes[info.row];
  949. if (!node) {
  950. info.cancel = true;
  951. return;
  952. }
  953. const exprInfo = getExprInfo(col.field);
  954. if (exprInfo) {
  955. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  956. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  957. }
  958. }
  959. switch (col.field) {
  960. case 'code':
  961. const posRange = pos.getLedgerPos(node.id);
  962. info.cancel = posRange && posRange.length > 0;
  963. break;
  964. case 'unit_price':
  965. case 'sgfh_qty':
  966. case 'sgfh_tp':
  967. case 'sjcl_qty':
  968. case 'sjcl_tp':
  969. case 'qtcl_qty':
  970. case 'qtcl_tp':
  971. case 'deal_qty':
  972. case 'deal_tp':
  973. info.cancel = node.children && node.children.length > 0;
  974. break;
  975. case 'dgn_qty1':
  976. case 'dgn_qty2':
  977. info.cancel = !_.isEmpty(node.b_code);
  978. break;
  979. case 'node_type':
  980. const parent = tree.getParent(node);
  981. if (parent) {
  982. info.cancel = false;
  983. // const topParent = tree.getTopParent(node);
  984. // info.cancel = [1, 5].indexOf(topParent.node_type) < 0;
  985. } else {
  986. info.cancel = true;
  987. }
  988. break;
  989. }
  990. },
  991. sortCode: function (sheet) {
  992. const tree = sheet.zh_tree;
  993. if (!tree) return;
  994. const select = SpreadJsObj.getSelectObject(sheet);
  995. if (!select || !select.code) return;
  996. const getChildSort = function (i, split) {
  997. if (i <= 0) throw '参数错误';
  998. switch(split) {
  999. case '0':
  1000. return i < 10 ? split + i : i + '';
  1001. case '-':
  1002. default:
  1003. return split + i;
  1004. }
  1005. };
  1006. const recursiveSortCode = function (data, parentCode, children, split) {
  1007. if (!children || children.length === 0) return;
  1008. for (const [i, child] of children.entries()) {
  1009. if (!child.b_code || child.b_code === '') {
  1010. const code = parentCode + getChildSort(i + 1, split);
  1011. const cData = tree.getNodeKeyData(child);
  1012. cData.code = code;
  1013. data.push(cData);
  1014. if (!tree.isLeafXmj(child)) {
  1015. recursiveSortCode(data, code, child.children, split);
  1016. }
  1017. }
  1018. }
  1019. };
  1020. const data = [];
  1021. recursiveSortCode(data, select.code, select.children, tree.getCodeSplit());
  1022. if (data.length > 0) {
  1023. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1024. const refreshNode = tree.loadPostData(result);
  1025. treeOperationObj.refreshTree(sheet, refreshNode);
  1026. })
  1027. }
  1028. },
  1029. };
  1030. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  1031. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  1032. ledgerTreeCol.initSpreadSetting(ledgerSpreadSetting);
  1033. ledgerSpreadSetting.headColWidth = [50];
  1034. ledgerSpreadSetting.rowHeader = [
  1035. {
  1036. rowHeaderType: 'tag',
  1037. setting: {
  1038. indent: 14,
  1039. tagSize: 0.8,
  1040. tagFont: '8px 微软雅黑',
  1041. getColor: function (index, data) {
  1042. if (!data) return;
  1043. return billsTag.getBillsTagsColor(data.id);
  1044. },
  1045. getTagHtml: function (index, data) {
  1046. if (!data) return;
  1047. const getHtml = function (list) {
  1048. if (!list || list.length === 0) return '';
  1049. const html = [];
  1050. for (const l of list) {
  1051. html.push('<div class="row mr-1">');
  1052. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  1053. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  1054. html.push('</div>');
  1055. }
  1056. return html.join('');
  1057. };
  1058. return getHtml(billsTag.getBillsTagsInfo(data.id));
  1059. }
  1060. },
  1061. },
  1062. ];
  1063. // ledgerSpreadSetting.cols.push(
  1064. // {title: 'ledger_id', colSpan: '1', rowSpan: '2', field: 'ledger_id', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1065. // {title: 'ledger_pid', colSpan: '1', rowSpan: '2', field: 'ledger_pid', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1066. // {title: 'level', colSpan: '1', rowSpan: '2', field: 'level', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1067. // {title: 'order', colSpan: '1', rowSpan: '2', field: 'order', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1068. // {title: 'is_leaf', colSpan: '1', rowSpan: '2', field: 'is_leaf', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1069. // {title: 'full_path', colSpan: '1', rowSpan: '2', field: 'full_path', hAlign: 2, width: 60, type: 'Number', readOnly: true},
  1070. // {title: 'node_type', colSpan: '1', rowSpan: '2', field: 'node_type', hAlign: 2, width: 60, type: 'Number', readOnly: true}
  1071. // );
  1072. sjsSettingObj.setNodeTypeCol(ledgerSpreadSetting.cols, [{ field: 'node_type' }]);
  1073. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  1074. SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());
  1075. // 绑定事件
  1076. ledgerSpread.bind(spreadNS.Events.SelectionChanged, treeOperationObj.selectionChanged);
  1077. ledgerSpread.bind(spreadNS.Events.TopRowChanged, treeOperationObj.topRowChanged);
  1078. ledgerSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  1079. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  1080. SpreadJsObj.Clipboard.setCopyData(copyText);
  1081. });
  1082. if (!ledgerSpreadSetting.readOnly) {
  1083. ledgerSpread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  1084. treeOperationObj.refreshOperationValid(info.sheet, info.newSelections);
  1085. });
  1086. ledgerSpread.bind(spreadNS.Events.EditEnded, treeOperationObj.editEnded);
  1087. SpreadJsObj.addDeleteBind(ledgerSpread, treeOperationObj.deletePress);
  1088. ledgerSpread.bind(spreadNS.Events.ClipboardPasting, treeOperationObj.clipboardPasting);
  1089. ledgerSpread.bind(spreadNS.Events.EditStarting, treeOperationObj.editStarting);
  1090. SpreadJsObj.addCutEvents(ledgerSpread, treeOperationObj.cut);
  1091. // 绑定 删除等 顶部按钮
  1092. $('#insert').click(() => {
  1093. treeOperationObj.addNode(ledgerSpread.getActiveSheet());
  1094. });
  1095. $('#delete').click(function () {
  1096. treeOperationObj.deleteNode(ledgerSpread.getActiveSheet());
  1097. });
  1098. $('#up-move').click(function () {
  1099. treeOperationObj.upMove(ledgerSpread.getActiveSheet());
  1100. });
  1101. $('#down-move').click(function () {
  1102. treeOperationObj.downMove(ledgerSpread.getActiveSheet());
  1103. });
  1104. $('#up-level').click(function () {
  1105. treeOperationObj.upLevel(ledgerSpread.getActiveSheet());
  1106. });
  1107. $('#down-level').click(function () {
  1108. treeOperationObj.downLevel(ledgerSpread.getActiveSheet());
  1109. });
  1110. $('#copy').click(function () {
  1111. ledgerSpread.commandManager().execute({
  1112. cmd: 'copy',
  1113. sheetName: ledgerSpread.getActiveSheet().name()
  1114. });
  1115. });
  1116. $('#paste').click(function () {
  1117. ledgerSpread.commandManager().execute({
  1118. cmd: 'paste',
  1119. sheetName: ledgerSpread.getActiveSheet().name()
  1120. });
  1121. });
  1122. $('#cut').click(function () {
  1123. ledgerSpread.commandManager().execute({
  1124. cmd: 'cut',
  1125. sheetName: ledgerSpread.getActiveSheet().name()
  1126. });
  1127. });
  1128. $('#bills-expr').bind('change onblur', function () {
  1129. const expr = $(this);
  1130. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1131. const select = ledgerTree.getItemsByIndex(row);
  1132. if (!select) return;
  1133. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1134. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1135. // 台账模式,检查计量单元相关
  1136. if (checkTzMeasureType()) {
  1137. if (field === 'sgfh_qty' || field === 'sgfh_tp' ||
  1138. field === 'sjcl_qty' || field === 'sjcl_tp' ||
  1139. field === 'qtcl_qty' || field === 'qtcl_tp') {
  1140. if (!select.children || select.children.length === 0) {
  1141. const lPos = pos.getLedgerPos(select.id);
  1142. if (lPos && lPos.length > 0) {
  1143. toastr.error('清单含有计量单元,请在计量单元输入数量');
  1144. expr.val('');
  1145. return;
  1146. }
  1147. }
  1148. }
  1149. }
  1150. const data = {
  1151. id: select.id,
  1152. tender_id: select.tender_id,
  1153. ledger_id: select.ledger_id
  1154. };
  1155. const exprInfo = getExprInfo(field);
  1156. if (newValue !== '') {
  1157. const num = _.toNumber(newValue);
  1158. if (num) {
  1159. data[field] = num;
  1160. if (exprInfo) {
  1161. data[exprInfo.expr] = '';
  1162. }
  1163. } else {
  1164. try {
  1165. data[field] = math.evaluate(transExpr(newValue));
  1166. if (exprInfo) {
  1167. data[exprInfo.expr] = newValue;
  1168. }
  1169. } catch (err) {
  1170. toastr.error('输入的表达式非法');
  1171. return;
  1172. }
  1173. }
  1174. } else {
  1175. data[field] = null;
  1176. if (exprInfo) {
  1177. data[exprInfo.expr] = '';
  1178. }
  1179. }
  1180. // 更新至服务器
  1181. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1182. const refreshNode = ledgerTree.loadPostData(result);
  1183. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  1184. });
  1185. });
  1186. }
  1187. let batchInsertObj, contractExprObj;
  1188. $.contextMenu.types.batchInsert = function (item, opt, root) {
  1189. const self = this;
  1190. if ($.isFunction(item.icon)) {
  1191. item._icon = item.icon.call(this, this, $t, key, item);
  1192. } else {
  1193. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1194. // to enable font awesome
  1195. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1196. } else {
  1197. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1198. }
  1199. }
  1200. this.addClass(item._icon);
  1201. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="100" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  1202. .appendTo(this);
  1203. const $input = $obj.find('input');
  1204. const event = () => {
  1205. if (self.hasClass('context-menu-disabled')) return;
  1206. item.batchInsert($input[0], root);
  1207. };
  1208. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  1209. $input.click((e) => {e.stopPropagation();})
  1210. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  1211. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  1212. };
  1213. // $.contextMenu.types.switch = function (item, opt, root) {
  1214. // const self = this;
  1215. // if ($.isFunction(item.icon)) {
  1216. // item._icon = item.icon.call(this, this, $t, key, item);
  1217. // } else {
  1218. // if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1219. // // to enable font awesome
  1220. // item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1221. // } else {
  1222. // item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1223. // }
  1224. // }
  1225. // const html = [];
  1226. // html.push('<div>');
  1227. // html.push('</div>');
  1228. // const $obj = $('<div>' + item.name +)
  1229. // };
  1230. // 右键菜单
  1231. const addTag = newTag({ledgerSheet: ledgerSpread.getActiveSheet(), posSheet: posSpread.getActiveSheet(), billsTag});
  1232. const billsContextMenuOptions = {
  1233. selector: '#ledger-spread',
  1234. build: function ($trigger, e) {
  1235. const target = SpreadJsObj.safeRightClickSelection($trigger, e, ledgerSpread);
  1236. treeOperationObj.loadRelaData();
  1237. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1238. },
  1239. items: {},
  1240. };
  1241. if (!readOnly) {
  1242. billsContextMenuOptions.items.create = {
  1243. name: '新增',
  1244. icon: 'fa-sign-in',
  1245. callback: function (key, opt) {
  1246. treeOperationObj.addNode(ledgerSpread.getActiveSheet());
  1247. },
  1248. disabled: function (key, opt) {
  1249. const sheet = ledgerSpread.getActiveSheet();
  1250. const selection = sheet.getSelections();
  1251. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1252. const row = sel ? sel.row : -1;
  1253. const tree = sheet.zh_tree;
  1254. if (!tree) return true;
  1255. const first = sheet.zh_tree.nodes[row];
  1256. let last = first, sameParent = true;
  1257. if (sel.rowCount > 1) {
  1258. for (let r = 1; r < sel.rowCount; r++) {
  1259. const rNode = tree.nodes[sel.row + r];
  1260. if (rNode.level > first.level) continue;
  1261. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1262. sameParent = false;
  1263. break;
  1264. }
  1265. last = rNode;
  1266. }
  1267. }
  1268. const valid = !sheet.zh_setting.readOnly;
  1269. return !(valid && first && first.level > 1);
  1270. },
  1271. visible: function (key, opt) {
  1272. return !readOnly;
  1273. }
  1274. };
  1275. billsContextMenuOptions.items.delete = {
  1276. name: '删除',
  1277. icon: 'fa-remove',
  1278. callback: function (key, opt) {
  1279. treeOperationObj.deleteNode(ledgerSpread.getActiveSheet());
  1280. },
  1281. disabled: function (key, opt) {
  1282. const sheet = ledgerSpread.getActiveSheet();
  1283. const selection = sheet.getSelections();
  1284. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1285. const row = sel ? sel.row : -1;
  1286. const tree = sheet.zh_tree;
  1287. if (!tree) return true;
  1288. const first = sheet.zh_tree.nodes[row];
  1289. let last = first, sameParent = true;
  1290. if (sel.rowCount > 1) {
  1291. for (let r = 1; r < sel.rowCount; r++) {
  1292. const rNode = tree.nodes[sel.row + r];
  1293. if (rNode.level > first.level) continue;
  1294. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1295. sameParent = false;
  1296. break;
  1297. }
  1298. last = rNode;
  1299. }
  1300. }
  1301. const valid = !sheet.zh_setting.readOnly;
  1302. return !(valid && first && sameParent && !(first.level === 1 && first.node_type));
  1303. },
  1304. visible: function (key, opt) {
  1305. return !readOnly;
  1306. }
  1307. };
  1308. billsContextMenuOptions.items.sprBase = '----';
  1309. }
  1310. if (!readOnly) {
  1311. billsContextMenuOptions.items.batchInsert = {
  1312. name: '批量插入',
  1313. type: 'batchInsert',
  1314. value: '2',
  1315. icon: 'fa-sign-in',
  1316. batchInsert: function (obj, root) {
  1317. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  1318. obj.value = obj.max;
  1319. toastr.warning('批量插入不可多于' + obj.max);
  1320. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  1321. obj.value = obj.min;
  1322. toastr.warning('批量插入不可少于' + obj.min);
  1323. } else {
  1324. treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  1325. root.$menu.trigger('contextmenu:hide');
  1326. }
  1327. },
  1328. disabled: function (key, opt) {
  1329. const sheet = ledgerSpread.getActiveSheet();
  1330. const selection = sheet.getSelections();
  1331. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1332. const row = sel ? sel.row : -1;
  1333. const tree = sheet.zh_tree;
  1334. if (!tree) return true;
  1335. const first = sheet.zh_tree.nodes[row];
  1336. let last = first, sameParent = true;
  1337. if (sel.rowCount > 1) {
  1338. for (let r = 1; r < sel.rowCount; r++) {
  1339. const rNode = tree.nodes[sel.row + r];
  1340. if (rNode.level > first.level) continue;
  1341. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  1342. sameParent = false;
  1343. break;
  1344. }
  1345. last = rNode;
  1346. }
  1347. }
  1348. const valid = !sheet.zh_setting.readOnly;
  1349. return !(valid && first && first.level > 1);
  1350. },
  1351. visible: function (key, opt) {
  1352. return !readOnly;
  1353. }
  1354. };
  1355. billsContextMenuOptions.items.batchInsertBillsPos = {
  1356. name: '批量插入清单-计量单元',
  1357. icon: 'fa-sign-in',
  1358. disabled: function (key, opt) {
  1359. if (!checkTzMeasureType()) return true;
  1360. const sheet = ledgerSpread.getActiveSheet();
  1361. const selection = sheet.getSelections();
  1362. const row = selection[0].row;
  1363. const select = ledgerTree.nodes[row];
  1364. if (select) {
  1365. if (select.code && select.code !== '') {
  1366. return !ledgerTree.isLeafXmj(select);
  1367. } else {
  1368. const parent = ledgerTree.getParent(select);
  1369. return !(parent && ledgerTree.isLeafXmj(parent));
  1370. }
  1371. } else {
  1372. return true;
  1373. }
  1374. },
  1375. callback: function (key, opt) {
  1376. if (!batchInsertObj) {
  1377. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  1378. } else {
  1379. batchInsertObj.initView();
  1380. }
  1381. $('#batch').modal('show');
  1382. },
  1383. visible: function (key, opt) {
  1384. return !readOnly;
  1385. }
  1386. };
  1387. billsContextMenuOptions.items.sprBatch = '----';
  1388. }
  1389. billsContextMenuOptions.items.copyBlock = {
  1390. name: '复制整块',
  1391. icon: 'fa-files-o',
  1392. callback: function (key, opt) {
  1393. /*ledgerSpread.commandManager().execute({
  1394. cmd:"copy",
  1395. sheetName:ledgerSpread.getActiveSheet().name()
  1396. });*/
  1397. treeOperationObj.block = [];
  1398. const copyBlockList = [];
  1399. const sheet = ledgerSpread.getActiveSheet();
  1400. const sel = sheet.getSelections()[0];
  1401. let iRow = sel.row;
  1402. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1403. while (iRow < sel.row + sel.rowCount) {
  1404. const node = sheet.zh_tree.nodes[iRow];
  1405. if (node.ledger_pid !== pid) {
  1406. toastr.error('仅可同时选中同层节点');
  1407. return;
  1408. }
  1409. const posterity = sheet.zh_tree.getPosterity(node);
  1410. iRow += posterity.length + 1;
  1411. posterity.unshift(node);
  1412. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  1413. }
  1414. for (const cbl of copyBlockList) {
  1415. for (const b of cbl) {
  1416. const posRange = pos.getLedgerPos(b.id);
  1417. if (posRange && posRange.length > 0) b.pos = posRange;
  1418. const gclRange = ancGcl.getPartData(b.id);
  1419. if (gclRange && gclRange.length > 0) b.ancGcl = gclRange;
  1420. }
  1421. }
  1422. setLocalCache(copyBlockTag, JSON.stringify({block: copyBlockList}));
  1423. },
  1424. visible: function (key, opt) {
  1425. const sheet = ledgerSpread.getActiveSheet();
  1426. const selection = sheet.getSelections();
  1427. const row = selection[0].row;
  1428. const select = ledgerTree.nodes[row];
  1429. return select;
  1430. },
  1431. disabled: function (key, opt) {
  1432. const sheet = ledgerSpread.getActiveSheet();
  1433. const selection = sheet.getSelections();
  1434. const row = selection[0].row;
  1435. const select = ledgerTree.nodes[row];
  1436. return select && select.level <= 1;
  1437. }
  1438. };
  1439. billsContextMenuOptions.items.copyBlockXmj = {
  1440. name: '复制整块(只复制项目节)',
  1441. icon: 'fa-files-o',
  1442. callback: function (key, opt) {
  1443. treeOperationObj.block = [];
  1444. const copyBlockList = [];
  1445. const sheet = ledgerSpread.getActiveSheet();
  1446. const sel = sheet.getSelections()[0];
  1447. let iRow = sel.row;
  1448. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  1449. while (iRow < sel.row + sel.rowCount) {
  1450. const node = sheet.zh_tree.nodes[iRow];
  1451. if (node.ledger_pid !== pid) {
  1452. toastr.error('仅可同时选中同层节点');
  1453. return;
  1454. }
  1455. const posterity = sheet.zh_tree.getPosterity(node);
  1456. iRow += posterity.length + 1;
  1457. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  1458. copyPosterity.unshift(node);
  1459. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  1460. for (const p of copyData) {
  1461. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  1462. p.is_leaf = children.length === 0;
  1463. }
  1464. copyBlockList.push(copyData);
  1465. }
  1466. setLocalCache(copyBlockTag, JSON.stringify({block: copyBlockList}));
  1467. },
  1468. visible: function (key, opt) {
  1469. const sheet = ledgerSpread.getActiveSheet();
  1470. const selection = sheet.getSelections();
  1471. const row = selection[0].row;
  1472. const select = ledgerTree.nodes[row];
  1473. return select;
  1474. },
  1475. disabled: function (key, opt) {
  1476. const sheet = ledgerSpread.getActiveSheet();
  1477. const selection = sheet.getSelections();
  1478. const row = selection[0].row;
  1479. const select = ledgerTree.nodes[row];
  1480. return select && select.level <= 1;
  1481. }
  1482. };
  1483. if (!readOnly) {
  1484. billsContextMenuOptions.items.pasteBlock = {
  1485. name: '粘贴整块',
  1486. icon: 'fa-clipboard',
  1487. disabled: function (key, opt) {
  1488. //const block = treeOperationObj.block || [];
  1489. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1490. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  1491. },
  1492. callback: function (key, opt) {
  1493. //const block = treeOperationObj.block || [];
  1494. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  1495. if (copyInfo.block.length > 0) {
  1496. treeOperationObj.pasteBlock(ledgerSpread, copyInfo);
  1497. } else {
  1498. document.execCommand('paste');
  1499. }
  1500. },
  1501. visible: function (key, opt) {
  1502. return !readOnly;
  1503. }
  1504. };
  1505. }
  1506. billsContextMenuOptions.items.sprBlock = '----';
  1507. if (!readOnly) {
  1508. billsContextMenuOptions.items.sortChildren = {
  1509. name: '顺序重排子项编号',
  1510. icon: 'fa-sort-numeric-asc',
  1511. disabled: function (key, opt) {
  1512. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1513. return !node || !node.code || !node.children || node.children === 0 || node.code.length < 3;
  1514. },
  1515. callback: function (key, opt) {
  1516. treeOperationObj.sortCode(ledgerSpread.getActiveSheet());
  1517. },
  1518. visible: function (key, opt) {
  1519. return !readOnly;
  1520. }
  1521. };
  1522. if (!checkTzMeasureType()) {
  1523. billsContextMenuOptions.items.applyDeal2Sgfh = {
  1524. name: '填设计量',
  1525. icon: 'fa-pencil',
  1526. callback: function (key, opt) {
  1527. postData(window.location.pathname + '/deal2sgfh', null, function (result) {
  1528. ledgerTree.loadDatas(result.bills);
  1529. treeCalc.calculateAll(ledgerTree);
  1530. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1531. });
  1532. }
  1533. };
  1534. }
  1535. billsContextMenuOptions.items.sprSort = '----';
  1536. }
  1537. if (!readOnly) {
  1538. const tenderSelect = TenderSelect({
  1539. type: 'ledger',
  1540. afterLoad: function (result) {
  1541. const ledgerSheet = ledgerSpread.getActiveSheet();
  1542. const refreshNode = ledgerTree.loadPostData(result);
  1543. treeOperationObj.refreshTree(ledgerSheet, refreshNode);
  1544. treeOperationObj.refreshOperationValid(ledgerSheet);
  1545. }
  1546. });
  1547. billsContextMenuOptions.items.importExcel = {
  1548. name: '导入分项清单Excel',
  1549. icon: 'fa-file-excel-o',
  1550. disabled: function (key, opt) {
  1551. return readOnly;
  1552. },
  1553. callback: function (key, opt) {
  1554. importExcel.doImport({
  1555. template: {
  1556. hint: '0号台账',
  1557. url: 'https://jl-assets.oss-cn-shenzhen.aliyuncs.com/template/A/导入分项清单EXCEL格式.xlsx',
  1558. },
  1559. filter: true,
  1560. callback: function (sheet, filter) {
  1561. postDataCompress(window.location.pathname + '/upload-excel/tz', {sheet, filter}, function (result) {
  1562. ledgerTree.loadDatas(result.bills);
  1563. treeCalc.calculateAll(ledgerTree);
  1564. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1565. pos.loadDatas(result.pos);
  1566. posOperationObj.loadCurPosData();
  1567. ancGclObj.loadCurAncillaryGcl();
  1568. checkShowLast(result.bills.length);
  1569. }, null);
  1570. },
  1571. // callback: function (file, select) {
  1572. // const formData = new FormData();
  1573. // formData.append('file', file.files[0]);
  1574. // postDataWithFileProgress(window.location.pathname + '/upload-excel?ueType=tz&sheetName=' + select, formData, function (result) {
  1575. // ledgerTree.loadDatas(result.bills);
  1576. // treeCalc.calculateAll(ledgerTree);
  1577. // SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  1578. // pos.loadDatas(result.pos);
  1579. // posOperationObj.loadCurPosData();
  1580. // }, null);
  1581. // }
  1582. //u_type: importExcel.uploadType.file,
  1583. });
  1584. }
  1585. };
  1586. billsContextMenuOptions.items.importGclBills2Xmj = {
  1587. name: '导入工程量清单至项目节',
  1588. icon: 'fa-file-excel-o',
  1589. disabled: function (key, opt) {
  1590. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1591. return readOnly || !node
  1592. || (node.children && node.children.length > 0)
  1593. || (!_.isNil(node.b_code) && node.b_code !== '');
  1594. },
  1595. callback: function (key, opt) {
  1596. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1597. importExcel.doImport({
  1598. template: {
  1599. hint: '工程量清单',
  1600. url: '/template/导入工程量清单EXCEL格式.xls',
  1601. },
  1602. callback: function (sheet) {
  1603. postDataCompress(window.location.pathname + '/upload-excel/gcl2xmj', {id: node.id, sheet: sheet}, function (result) {
  1604. const ledgerSheet = ledgerSpread.getActiveSheet();
  1605. const sel = ledgerSheet.getSelections();
  1606. const refreshNode = ledgerTree.loadPostData(result);
  1607. treeOperationObj.refreshTree(ledgerSheet, refreshNode);
  1608. if (refreshNode.create[0]) {
  1609. if (sel && sel[0]) {
  1610. ledgerSheet.setSelection(refreshNode.create[0].index, sel[0].col, sel[0].rowCount, sel[0].colCount);
  1611. SpreadJsObj.reloadRowsBackColor(ledgerSheet, [sel[0].row, refreshNode.create[0].index]);
  1612. } else {
  1613. ledgerSheet.setSelection(refreshNode.create[0].index, 0, 1, 1);
  1614. SpreadJsObj.reloadRowsBackColor(ledgerSheet, [refreshNode.create[0].index]);
  1615. }
  1616. }
  1617. treeOperationObj.refreshOperationValid(ledgerSheet);
  1618. }, null);
  1619. }
  1620. });
  1621. }
  1622. };
  1623. billsContextMenuOptions.items.importOtherTender = {
  1624. name: '导入(其他标段)工程量清单至项目节',
  1625. icon: 'fa-link',
  1626. disabled: function (key, opt) {
  1627. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1628. return readOnly || !node
  1629. || (node.children && node.children.length > 0)
  1630. || !ledgerTree.isLeafXmj(node);
  1631. },
  1632. callback: function (key, opt) {
  1633. tenderSelect.showSelect(SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet()));
  1634. }
  1635. };
  1636. billsContextMenuOptions.items.sprImport = '----';
  1637. }
  1638. billsContextMenuOptions.items.tag = {
  1639. name: '书签',
  1640. callback: function (key, opt, menu, e) {
  1641. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1642. addTag.do(node);
  1643. },
  1644. disabled: function (key, opt) {
  1645. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1646. return !node;
  1647. }
  1648. };
  1649. billsContextMenuOptions.items.sprTag = '----';
  1650. billsContextMenuOptions.items.showLast = {
  1651. name: '显示至最底层',
  1652. callback: function (key, opt, menu, e) {
  1653. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1654. setTimeout(() => {
  1655. showWaitingView();
  1656. ledgerTree.expandByCustom(x => {
  1657. return x.expanded ||(x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1658. });
  1659. SpreadJsObj.refreshTreeRowVisible(ledgerSpread.getActiveSheet());
  1660. closeWaitingView();
  1661. }, 100);
  1662. },
  1663. };
  1664. billsContextMenuOptions.items.exportJSON = {
  1665. name: '导出后台标准表json',
  1666. callback: function (key, opt, menu, e) {
  1667. const result = [];
  1668. for (const node of ledgerTree.nodes) {
  1669. result.push({
  1670. id: node.ledger_id, pid: node.ledger_pid, level: node.level, order: node.order,
  1671. is_leaf: !node.children || node.children.length === 0, full_path: node.full_path,
  1672. code: node.code || '', b_code: node.b_code || '', name: node.name || '', unit: node.unit || '',
  1673. node_type: node.node_type,
  1674. });
  1675. }
  1676. const blob = new Blob([JSON.stringify(result, '', '\t')], { type: 'application/text'});
  1677. saveAs(blob, "台账分解.json");
  1678. },
  1679. visible: function() {
  1680. return is_debug;
  1681. }
  1682. };
  1683. if (contractExpr && readOnly) {
  1684. billsContextMenuOptions.items.exprTag = '----';
  1685. billsContextMenuOptions.items.contractExpr = {
  1686. name: '预设本期合同计量公式',
  1687. callback: function (key, opt, menu, e) {
  1688. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1689. if (!contractExprObj) {
  1690. contractExprObj = new ContractExpr({ sourceTree: ledgerTree });
  1691. }
  1692. contractExprObj.initView(node);
  1693. $('#contract_expr').modal('show');
  1694. },
  1695. visible: function (key, opt) {
  1696. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1697. if (node.children && node.children.length > 0) return false;
  1698. const posRange = pos.getLedgerPos(node.id);
  1699. if (posRange && posRange.length > 0) return false;
  1700. return true;
  1701. }
  1702. };
  1703. }
  1704. $.contextMenu(billsContextMenuOptions);
  1705. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  1706. // 台账模式加载计量单元数据
  1707. if (checkTzMeasureType()) {
  1708. $.divResizer({
  1709. select: '#main-resize',
  1710. callback: function () {
  1711. ledgerSpread.refresh();
  1712. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1713. $(".sp-wrap").height(bcontent-30);
  1714. posSpread.refresh();
  1715. if (ancGclSpread) ancGclSpread.refresh();
  1716. }
  1717. });
  1718. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  1719. }
  1720. posSpreadSetting.headColWidth = [50];
  1721. posSpreadSetting.rowHeader = [
  1722. {
  1723. rowHeaderType: 'tag',
  1724. setting: {
  1725. indent: 14,
  1726. tagSize: 0.8,
  1727. tagFont: '8px 微软雅黑',
  1728. getColor: function (index, data) {
  1729. if (!data) return;
  1730. return billsTag.getPosTagsColor(data.lid, data.id);
  1731. },
  1732. getTagHtml: function (index, data) {
  1733. if (!data) return;
  1734. const getHtml = function (list) {
  1735. if (!list || list.length === 0) return '';
  1736. const html = [];
  1737. for (const l of list) {
  1738. html.push('<div class="row mr-1">');
  1739. html.push(`<div class="col-auto pr-1 ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  1740. html.push('<div class="col p-0">', '<p>', l.comment, '</p>', '</div>');
  1741. html.push('</div>');
  1742. }
  1743. return html.join('');
  1744. };
  1745. return getHtml(billsTag.getPosTagsInfo(data.lid, data.id));
  1746. }
  1747. },
  1748. },
  1749. ];
  1750. SpreadJsObj.initSheet(posSpread.getActiveSheet(), posSpreadSetting);
  1751. //绑定计量单元编辑事件
  1752. const posOperationObj = {
  1753. /**
  1754. * 刷新顶部按钮是否可用
  1755. * @param sheet
  1756. * @param selections
  1757. */
  1758. refreshOperationValid: function (sheet, selection) {
  1759. const setObjEnable = function (obj, enable) {
  1760. if (enable) {
  1761. obj.removeClass('disabled');
  1762. } else {
  1763. obj.addClass('disabled');
  1764. }
  1765. };
  1766. const invalidAll = function () {
  1767. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  1768. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  1769. };
  1770. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1771. const row = sel ? sel.row : -1;
  1772. const first = sheet.zh_data[row];
  1773. if (!first) {
  1774. invalidAll();
  1775. return;
  1776. }
  1777. let last = first;
  1778. if (sel.rowCount > 1 && first) {
  1779. for (let r = 1; r < sel.rowCount; r++) {
  1780. const rNode = sheet.zh_data[sel.row + r];
  1781. if (!rNode) break;
  1782. last = rNode;
  1783. }
  1784. }
  1785. const preNode = sheet.zh_data[row - 1];
  1786. const valid = !sheet.zh_setting.readOnly;
  1787. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode);
  1788. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1));
  1789. },
  1790. editStarting: function (e, info) {
  1791. posOperationObj.ledgerTreeNode = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  1792. const sel = info.sheet.getSelections();
  1793. if (!sel || !sel[0]) return;
  1794. const col = info.sheet.zh_setting.cols[sel[0].col];
  1795. const node = SpreadJsObj.getSelectObject(info.sheet);
  1796. const exprInfo = getExprInfo(col.field);
  1797. if (exprInfo) {
  1798. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1799. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1800. }
  1801. }
  1802. },
  1803. loadExprToInput: function () {
  1804. const sheet = posSpread.getActiveSheet();
  1805. const sel = sheet.getSelections()[0];
  1806. if (!sel || !sheet.zh_setting) return;
  1807. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1808. if (col && col.type === 'Number') {
  1809. const data = SpreadJsObj.getSelectObject(sheet);
  1810. if (data) {
  1811. const exprInfo = getExprInfo(col.field);
  1812. const value = exprInfo
  1813. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  1814. : data[col.field];
  1815. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1816. .attr('readOnly', readOnly || cell.locked()).attr('data-row', sel.row);
  1817. } else {
  1818. $('#pos-expr').val('').attr('readOnly', true);
  1819. $('#pos-expr').removeAttr('data-row');
  1820. }
  1821. } else {
  1822. $('#pos-expr').val('').attr('readOnly', true);
  1823. $('#pos-expr').removeAttr('data-row');
  1824. }
  1825. },
  1826. /**
  1827. * 加载计量单元 根据当前台账选择节点
  1828. */
  1829. loadCurPosData: function () {
  1830. //spreadJsObj.reinitSheet(posSpread.getActiveSheet());
  1831. const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  1832. if (node) {
  1833. const posData = pos.ledgerPos[itemsPre + node.id] || [];
  1834. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', posData);
  1835. getNodeList(node.id);
  1836. } else {
  1837. SpreadJsObj.loadSheetData(posSpread.getActiveSheet(), 'data', []);
  1838. }
  1839. posOperationObj.loadExprToInput();
  1840. posOperationObj.refreshOperationValid(posSpread.getActiveSheet());
  1841. },
  1842. baseOpr: function (sheet, type) {
  1843. const data = {
  1844. updateType: type === 'delete' ? type : 'update',
  1845. updateData: [],
  1846. };
  1847. const selection = sheet.getSelections();
  1848. const row = selection[0].row, count = selection[0].rowCount;
  1849. const first = sheet.zh_data[row];
  1850. if (type === 'delete') {
  1851. for (let iRow = 0; iRow < count; iRow++) {
  1852. const posData = sheet.zh_data[iRow + row];
  1853. if (posData) {
  1854. data.updateData.push(sheet.zh_data[iRow + row].id);
  1855. }
  1856. }
  1857. } else if (type === 'up-move') {
  1858. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  1859. for (let iRow = 0; iRow < count; iRow++) {
  1860. const posData = sheet.zh_data[iRow + row];
  1861. if (posData) {
  1862. data.updateData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  1863. preUpdate.porder = posData.porder;
  1864. }
  1865. }
  1866. data.updateData.push(preUpdate);
  1867. } else if (type === 'down-move') {
  1868. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  1869. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1870. const posData = sheet.zh_data[iRow + row];
  1871. if (posData) {
  1872. data.updateData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  1873. nextUpdate.porder = posData.porder;
  1874. }
  1875. }
  1876. data.updateData.push(nextUpdate);
  1877. }
  1878. if (data.updateData.length > 0) {
  1879. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1880. if (type === 'delete') {
  1881. for (const p of result.pos) {
  1882. const posInfo = pos.getPos(p);
  1883. billsTag.afterDeletePos(posInfo);
  1884. }
  1885. pos.removeDatas(result.pos);
  1886. sheet.deleteRows(row, count);
  1887. const loadResult = ledgerTree.loadPostData(result.ledger);
  1888. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1889. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1890. } else {
  1891. const updateRst = pos.updateDatas(result.pos);
  1892. billsTag.refreshPosTagView(updateRst.update);
  1893. const sel = selection[0];
  1894. if (sel) {
  1895. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  1896. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  1897. }
  1898. posOperationObj.loadCurPosData();
  1899. }
  1900. });
  1901. }
  1902. },
  1903. /**
  1904. * 编辑单元格响应事件
  1905. * @param {Object} e
  1906. * @param {Object} info
  1907. */
  1908. editEnded: function (e, info) {
  1909. if (info.sheet.zh_setting) {
  1910. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1911. const col = info.sheet.zh_setting.cols[info.col];
  1912. const orgText = posData ? posData[col.field] : null;
  1913. const newText = trimInvalidChar(info.editingText);
  1914. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) {
  1915. return;
  1916. }
  1917. const node = posOperationObj.ledgerTreeNode;
  1918. if (!node) {
  1919. toastr.error('数据错误,请选择台账节点后再试');
  1920. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1921. return;
  1922. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  1923. toastr.error('父节点不可插入计量单元');
  1924. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1925. return;
  1926. }else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  1927. toastr.error('项目节不可插入计量单元');
  1928. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1929. return;
  1930. }
  1931. const data = { updateType: posData ? 'update' : 'add' };
  1932. if (!posData) {
  1933. const sortData = info.sheet.zh_data;
  1934. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1935. data.updateData = { lid: node.id, tid: tender.id, porder: order };
  1936. } else {
  1937. data.updateData = { id: posData.id };
  1938. }
  1939. if (col.type === 'Number') {
  1940. const exprInfo = getExprInfo(col.field);
  1941. const num = _.toNumber(newText);
  1942. if (_.isFinite(num)) {
  1943. data.updateData[col.field] = num;
  1944. if (exprInfo) {
  1945. data.updateData[exprInfo.expr] = '';
  1946. }
  1947. } else {
  1948. try {
  1949. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1950. if (exprInfo) {
  1951. data.updateData[exprInfo.expr] = newText;
  1952. }
  1953. } catch(err) {
  1954. toastr.error('输入的表达式非法');
  1955. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1956. return;
  1957. }
  1958. }
  1959. } else if (col.field.indexOf('_expr') > 0) {
  1960. const exprInfo = getExprInfo(col.field, true);
  1961. if (!exprInfo) return;
  1962. if (newText) {
  1963. try {
  1964. data.updateData[exprInfo.qty] = math.evaluate(transExpr(newText));
  1965. data.updateData[exprInfo.expr] = newText;
  1966. } catch(err) {
  1967. toastr.error('输入的表达式非法');
  1968. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1969. return;
  1970. }
  1971. } else {
  1972. data.updateData[exprInfo.qty] = 0;
  1973. data.updateData[exprInfo.expr] = '';
  1974. }
  1975. } else {
  1976. data.updateData[col.field] = newText;
  1977. }
  1978. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  1979. const updateRst = pos.updateDatas(result.pos);
  1980. billsTag.refreshPosTagView(updateRst.update);
  1981. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  1982. if (updateRst.create.length > 0) {
  1983. // info.sheet.addRows(info.row, 1);
  1984. // if (info.sheet.zh_data.length === 0) {
  1985. // info.sheet.zh_data = pos.ledgerPos[itemsPre + node.id] || [];
  1986. // }
  1987. // SpreadJsObj.reLoadRowData(info.sheet, info.sheet.zh_data.length - 1);
  1988. posOperationObj.loadCurPosData();
  1989. } else {
  1990. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1991. }
  1992. const loadResult = ledgerTree.loadPostData(result.ledger);
  1993. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  1994. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  1995. }, function () {
  1996. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1997. });
  1998. }
  1999. },
  2000. /**
  2001. * 删除按钮响应事件
  2002. * @param sheet
  2003. */
  2004. deletePress: function (sheet) {
  2005. const self = this;
  2006. if (sheet.zh_setting) {
  2007. const sortData = sheet.zh_data;
  2008. const datas = [], posSelects = [];
  2009. const sel = sheet.getSelections()[0];
  2010. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2011. let bDel = false;
  2012. const node = sortData[iRow];
  2013. if (node) {
  2014. const data = {id: node.id};
  2015. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2016. const colSetting = sheet.zh_setting.cols[iCol];
  2017. const style = sheet.getStyle(iRow, iCol);
  2018. if (!style.locked) {
  2019. const colSetting = sheet.zh_setting.cols[iCol];
  2020. if (colSetting.field.indexOf('_expr') > 0) {
  2021. const exprInfo = getExprInfo(colSetting.field, true);
  2022. if (!exprInfo) continue;
  2023. data[exprInfo.expr] = '';
  2024. data[exprInfo.qty] = 0;
  2025. } else {
  2026. data[colSetting.field] = null;
  2027. const exprInfo = getExprInfo(colSetting.field);
  2028. if (exprInfo) data[exprInfo.expr] = '';
  2029. }
  2030. bDel = true;
  2031. }
  2032. }
  2033. if (bDel) {
  2034. datas.push(data);
  2035. posSelects.push(node);
  2036. }
  2037. }
  2038. }
  2039. if (datas.length > 0) {
  2040. postData('/tender/' + getTenderId() + '/pos/update', {updateType: 'update', updateData: datas}, function (result) {
  2041. const updateRst = pos.updateDatas(result.pos);
  2042. billsTag.refreshPosTagView(updateRst.update);
  2043. posOperationObj.loadCurPosData();
  2044. const loadResult = ledgerTree.loadPostData(result.ledger);
  2045. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2046. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2047. }, function () {
  2048. posOperationObj.loadCurPosData();
  2049. });
  2050. }
  2051. }
  2052. },
  2053. /**
  2054. * 删除 计量单元
  2055. * @param sheet
  2056. */
  2057. deletePos: function (sheet) {
  2058. const selection = sheet.getSelections();
  2059. const data = {
  2060. updateType: 'delete',
  2061. updateData: [],
  2062. };
  2063. const row = selection[0].row, count = selection[0].rowCount;
  2064. const sortData = sheet.zh_data;
  2065. for (let iRow = 0; iRow < count; iRow++) {
  2066. if (sortData[iRow + row]) {
  2067. data.updateData.push(sortData[iRow + row].id);
  2068. }
  2069. }
  2070. if (data.updateData.length > 0) {
  2071. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  2072. for (const p of result.pos) {
  2073. const posInfo = pos.getPos(p);
  2074. billsTag.afterDeletePos(posInfo);
  2075. }
  2076. pos.removeDatas(result.pos);
  2077. sheet.deleteRows(row, count);
  2078. const loadResult = ledgerTree.loadPostData(result.ledger);
  2079. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2080. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2081. });
  2082. }
  2083. },
  2084. insertPos: function (sheet) {
  2085. const selection = sheet.getSelections();
  2086. const sortData = sheet.zh_data;
  2087. const row = selection[0].row;
  2088. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2089. const select = SpreadJsObj.getSelectObject(sheet);
  2090. const porder = select ? select.porder : sortData.length + 1;
  2091. const data = {
  2092. updateType: 'insert',
  2093. updateData: [ { lid: node.id, tid: tender.id, porder } ],
  2094. };
  2095. postData('/tender/' + getTenderId() + '/pos/update', data, function (result) {
  2096. const updateRst = pos.updateDatas(result.pos);
  2097. posOperationObj.loadCurPosData();
  2098. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2099. });
  2100. },
  2101. /**
  2102. * 粘贴单元格响应事件
  2103. * @param e
  2104. * @param info
  2105. */
  2106. clipboardPasted: function (e, info) {
  2107. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2108. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2109. }
  2110. const node = treeOperationObj.getSelectNode(ledgerSpread.getActiveSheet());
  2111. if (node.code && (node.code !== '')) {
  2112. toastr.error('项目节不可含有清单明细');
  2113. posOperationObj.loadCurPosData();
  2114. return;
  2115. }
  2116. if (node.children && (node.children.length > 0)) {
  2117. toastr.error('仅清单子项可以含有计量单元');
  2118. posOperationObj.loadCurPosData();
  2119. return;
  2120. }
  2121. const hint = {
  2122. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2123. };
  2124. if (info.sheet.zh_setting) {
  2125. const data = [];
  2126. const sortData = info.sheet.zh_data || [];
  2127. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  2128. if (info.cellRange.col !== 0) {
  2129. toastr.warning('新增计量单元请先输入名称');
  2130. posOperationObj.loadCurPosData();
  2131. return;
  2132. }
  2133. }
  2134. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2135. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2136. let bPaste = false;
  2137. const curRow = info.cellRange.row + iRow;
  2138. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  2139. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2140. const curCol = info.cellRange.col + iCol;
  2141. const colSetting = info.sheet.zh_setting.cols[curCol];
  2142. if (!colSetting) continue;
  2143. posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2144. if (colSetting.type === 'Number') {
  2145. const num = _.toNumber(posData[colSetting.field]);
  2146. if (num) {
  2147. posData[colSetting.field] = num;
  2148. bPaste = true;
  2149. } else {
  2150. try {
  2151. posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
  2152. const exprInfo = getExprInfo(colSetting.field);
  2153. if (exprInfo) {
  2154. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2155. }
  2156. bPaste = true;
  2157. } catch (err) {
  2158. delete posData[colSetting.field];
  2159. toastMessageUniq(hint.expr);
  2160. }
  2161. }
  2162. } else if (colSetting.field.indexOf('_expr') > 0) {
  2163. try {
  2164. const exprInfo = getExprInfo(colSetting.field, true);
  2165. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2166. posData[exprInfo.qty] = math.evaluate(transExpr(posData[exprInfo.expr]));
  2167. bPaste = true;
  2168. } catch (err) {
  2169. toastMessageUniq(hint.expr);
  2170. }
  2171. } else {
  2172. bPaste = true;
  2173. }
  2174. }
  2175. if (bPaste) {
  2176. data.push(posData);
  2177. }
  2178. }
  2179. if (data.length > 0) {
  2180. postData('/tender/' + getTenderId() + '/pos/paste', data, function (result) {
  2181. const updateRst = pos.updateDatas(result.pos);
  2182. billsTag.refreshPosTagView(updateRst.update);
  2183. posOperationObj.loadCurPosData();
  2184. const loadResult = ledgerTree.loadPostData(result.ledger);
  2185. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2186. posOperationObj.loadCurPosData();
  2187. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2188. }, function () {
  2189. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2190. });
  2191. } else {
  2192. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2193. }
  2194. }
  2195. },
  2196. selectionChanged: function (e, info) {
  2197. posOperationObj.loadExprToInput();
  2198. posOperationObj.refreshOperationValid(posSpread.getActiveSheet());
  2199. },
  2200. addPegs: function (pegs) {
  2201. if (!pegs || pegs.length <= 0) return;
  2202. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2203. if (!node) return;
  2204. const sheet = posSpread.getActiveSheet();
  2205. const sortData = sheet.zh_data || [];
  2206. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2207. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2208. postData('/tender/' + getTenderId() + '/pos/paste', pegs, function (result) {
  2209. pos.updateDatas(result.pos);
  2210. posOperationObj.loadCurPosData();
  2211. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2212. });
  2213. }
  2214. };
  2215. posSpread.bind(spreadNS.Events.SelectionChanged, posOperationObj.selectionChanged);
  2216. if (!posSpreadSetting.readOnly) {
  2217. $('a[name="pos-opr"]').click(function () {
  2218. posOperationObj.baseOpr(posSpread.getActiveSheet(), this.getAttribute('type'));
  2219. });
  2220. $('#pos-expr').bind('change onblur', function () {
  2221. const expr = $(this);
  2222. const posSheet = posSpread.getActiveSheet();
  2223. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2224. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2225. if (!select) return;
  2226. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2227. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2228. const data = {id: select.id};
  2229. const exprInfo = getExprInfo(field);
  2230. if (newValue !== '') {
  2231. const num = _.toNumber(newValue);
  2232. if (num) {
  2233. data[field] = num;
  2234. if (exprInfo) {
  2235. data[exprInfo.expr] = '';
  2236. }
  2237. } else {
  2238. try {
  2239. data[field] = math.evaluate(transExpr(newValue));
  2240. if (exprInfo) {
  2241. data[exprInfo.expr] = newValue;
  2242. }
  2243. } catch (err) {
  2244. toastr.error('输入的表达式非法');
  2245. return;
  2246. }
  2247. }
  2248. } else {
  2249. data[field] = null;
  2250. if (exprInfo) {
  2251. data[exprInfo.expr] = '';
  2252. }
  2253. }
  2254. // 更新至服务器
  2255. postData('/tender/' + getTenderId() + '/pos/update', {updateType: 'update', updateData: data}, function (result) {
  2256. const updateRst = pos.updateDatas(result.pos);
  2257. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2258. const loadResult = ledgerTree.loadPostData(result.ledger);
  2259. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  2260. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2261. });
  2262. });
  2263. SpreadJsObj.addDeleteBind(posSpread, posOperationObj.deletePress);
  2264. posSpread.bind(spreadNS.Events.EditStarting, posOperationObj.editStarting);
  2265. posSpread.bind(spreadNS.Events.EditEnded, posOperationObj.editEnded);
  2266. posSpread.bind(spreadNS.Events.ClipboardPasted, posOperationObj.clipboardPasted);
  2267. }
  2268. const mergePeg = NewMergePeg({ callback: posOperationObj.addPegs });
  2269. // 右键菜单
  2270. $.contextMenu({
  2271. selector: '#pos-spread',
  2272. build: function ($trigger, e) {
  2273. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  2274. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2275. },
  2276. items: {
  2277. 'insert': {
  2278. name: '插入',
  2279. icon: 'fa-plus',
  2280. disabled: function (key, opt) {
  2281. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2282. return node && node.children && node.children.length > 0;
  2283. },
  2284. callback: function (key, opt) {
  2285. posOperationObj.insertPos(posSpread.getActiveSheet());
  2286. },
  2287. visible: function(key, opt) {
  2288. return !readOnly;
  2289. }
  2290. },
  2291. 'delete': {
  2292. name: '删除',
  2293. icon: 'fa-remove',
  2294. disabled: function (key, opt) {
  2295. const sheet = posSpread.getActiveSheet();
  2296. if (sheet.zh_data) {
  2297. const selection = sheet.getSelections();
  2298. return sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2299. } else {
  2300. return true;
  2301. }
  2302. },
  2303. callback: function (key, opt) {
  2304. posOperationObj.deletePos(posSpread.getActiveSheet());
  2305. },
  2306. visible: function(key, opt) {
  2307. return !readOnly;
  2308. }
  2309. },
  2310. 'merge-peg': {
  2311. name: '合并起讫桩号',
  2312. disabled: function (key, opt) {
  2313. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2314. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '';
  2315. },
  2316. callback: function (key, opt) {
  2317. mergePeg.show();
  2318. },
  2319. visible: function(key, opt) {
  2320. return !readOnly;
  2321. }
  2322. },
  2323. tag: {
  2324. name: '书签',
  2325. disabled: function(key, opt) {
  2326. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2327. const pos = SpreadJsObj.getSelectObject(posSpread.getActiveSheet());
  2328. return _.isNil(node) || _.isNil(pos);
  2329. },
  2330. callback: function(key, opt) {
  2331. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2332. const pos = SpreadJsObj.getSelectObject(posSpread.getActiveSheet());
  2333. addTag.do(node, pos);
  2334. }
  2335. }
  2336. }
  2337. });
  2338. // 附属工程量相关
  2339. const ancGclSpreadSetting = {
  2340. cols: [
  2341. {title: '辅材', colSpan: '1', rowSpan: '1', field: 'is_aux', hAlign: 1, width: 40, cellType: 'checkbox'},
  2342. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  2343. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 40, formatter: '@', cellType: 'unit'},
  2344. {title: '设计量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  2345. {title: '设计量公式', colSpan: '1', rowSpan: '1', field: 'expr', hAlign: 0, width: 80, formatter: '@'},
  2346. {title: '图册号', colSpan: '1', rowSpan: '1', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  2347. {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 80, formatter: '@'},
  2348. ],
  2349. emptyRows: 3,
  2350. headRows: 1,
  2351. headRowHeight: [32],
  2352. headColWidth: [30],
  2353. defaultRowHeight: 21,
  2354. headerFont: '12px 微软雅黑',
  2355. font: '12px 微软雅黑',
  2356. };
  2357. SpreadJsObj.initSheet(ancGclSheet, ancGclSpreadSetting);
  2358. const ancGclObj = {
  2359. loadCurAncillaryGcl: function () {
  2360. const node = treeOperationObj.getSelectNode(ledgerSheet);
  2361. const gclData = node ? ancGcl.getPartData(node.id) || [] : [];
  2362. SpreadJsObj.loadSheetData(ancGclSheet, SpreadJsObj.DataType.Data, gclData);
  2363. },
  2364. baseOpr: function (type) {
  2365. const data = {};
  2366. const gclRange = ancGclSheet.zh_data;
  2367. if (type !== 'insert' && (!gclRange || gclRange.length === 0)) return;
  2368. const sel = ancGclSheet.getSelections();
  2369. if (!sel[0]) return;
  2370. const row = sel[0].row, count = sel[0].rowCount;
  2371. const first = gclRange[row];
  2372. if (type === 'insert') {
  2373. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  2374. data.add = [{ lid: node.id, g_order: gclRange.length + 1 }];
  2375. } else if (type === 'delete') {
  2376. data.del = [];
  2377. for (let iRow = 0; iRow < count; iRow++) {
  2378. const gclData = gclRange[row + iRow];
  2379. if (!gclData) continue;
  2380. data.del.push(gclData.id);
  2381. }
  2382. if (data.del.length === 0) return;
  2383. } else if (type === 'up-move') {
  2384. data.update = [];
  2385. const pre = gclRange[row - 1];
  2386. if (!pre) return;
  2387. const preUpdate = { id: pre.id };
  2388. for (let iRow = 0; iRow < count; iRow++) {
  2389. const gclData = gclRange[iRow + row];
  2390. if (!gclData) continue;
  2391. data.update.push({ id: gclData.id, g_order: gclRange[iRow + row - 1].g_order });
  2392. preUpdate.g_order = gclData.g_order;
  2393. }
  2394. data.update.push(preUpdate);
  2395. if (data.update <= 1) return;
  2396. } else if (type === 'down-move') {
  2397. data.update = [];
  2398. const next = gclRange[row + count];
  2399. if (!next) return;
  2400. const nextUpdate = { id: next.id };
  2401. for (let iRow = count - 1; iRow >= 0; iRow--) {
  2402. const gclData = gclRange[iRow + row];
  2403. if (!gclData) continue;
  2404. data.update.push({ id: gclData.id, g_order: gclRange[iRow + row + 1].g_order});
  2405. nextUpdate.g_order = gclData.g_order;
  2406. }
  2407. data.update.push(nextUpdate);
  2408. if (data.update <= 1) return;
  2409. }
  2410. postData('/tender/' + getTenderId() + '/anc-gcl/update', data, function(result) {
  2411. ancGcl.updateDatas(result);
  2412. ancGclObj.loadCurAncillaryGcl();
  2413. if (type !== 'delete') SpreadJsObj.locateData(ancGclSheet, first);
  2414. });
  2415. },
  2416. editStarting: function (e, info) {
  2417. ancGclObj.ledgerTreeNode = SpreadJsObj.getSelectObject(ledgerSheet);
  2418. },
  2419. editEnded: function (e, info) {
  2420. const setting = info.sheet.zh_setting;
  2421. if (!setting) return;
  2422. const gclData = SpreadJsObj.getSelectObject(info.sheet);
  2423. const col = setting.cols[info.col];
  2424. const orgText = gclData ? gclData[col.field] : '', newText = trimInvalidChar(info.editingText);
  2425. if (orgText === newText || (!orgText && !newText)) return;
  2426. const node = ancGclObj.ledgerTreeNode;
  2427. if (!node) {
  2428. toastr.error('数据错误,请选择台账节点后再试');
  2429. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2430. return;
  2431. }
  2432. if (!!newText && node.children && node.children.length > 0) {
  2433. toastr.error('父节点不可添加附属工程量');
  2434. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2435. return;
  2436. }
  2437. if (!!newText && (!node.b_code || node.b_code === '')) {
  2438. toastr.error('项目节不可插入附属工程量');
  2439. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2440. return;
  2441. }
  2442. const data = {};
  2443. if (gclData) {
  2444. const updateData = { id: gclData.id };
  2445. if (col.type === 'Number') {
  2446. const num = _.toNumber(newText);
  2447. if (!_.isFinite(num)) {
  2448. toastr.error('输入的数字非法');
  2449. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2450. return;
  2451. }
  2452. updateData[col.field] = num;
  2453. if (gclData.expr) updateData.expr = '';
  2454. } else if (col.field === 'expr') {
  2455. try {
  2456. updateData.expr = newText;
  2457. updateData.quantity = math.evaluate(transExpr(newText));
  2458. } catch(err) {
  2459. toastr.error('输入的计算式非法');
  2460. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2461. return;
  2462. }
  2463. } else {
  2464. updateData[col.field] = newText;
  2465. }
  2466. data.update = [ updateData ];
  2467. } else {
  2468. const sortData = info.sheet.zh_data;
  2469. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].g_order + 1, sortData.length + 1);
  2470. const addData = { lid: node.id, g_order: order };
  2471. if (col.type === 'Number') {
  2472. const num = _.toNumber(newText);
  2473. if (!_.isFinite(num)) {
  2474. toastr.error('输入的数字非法');
  2475. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2476. return;
  2477. }
  2478. addData[col.field] = num;
  2479. if (gclData.expr) addData.expr = '';
  2480. } else if (col.field === 'expr') {
  2481. try {
  2482. addData.expr = newText;
  2483. addData.quantity = math.evaluate(transExpr(newText));
  2484. } catch(err) {
  2485. toastr.error('输入的计算式非法');
  2486. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2487. return;
  2488. }
  2489. } else {
  2490. addData[col.field] = newText;
  2491. }
  2492. data.add = [addData];
  2493. }
  2494. postData('/tender/' + getTenderId() + '/anc-gcl/update', data, function (result) {
  2495. ancGcl.updateDatas(result);
  2496. ancGclObj.loadCurAncillaryGcl();
  2497. }, function () {
  2498. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2499. });
  2500. },
  2501. deletePress: function (sheet) {
  2502. const setting = sheet.zh_setting;
  2503. if (!setting) return;
  2504. const sortData = sheet.zh_data;
  2505. if (!sortData || sortData.length === 0) return;
  2506. const sel = sheet.getSelections()[0];
  2507. const data = { update: [] };
  2508. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2509. let bDel = false;
  2510. const node = sortData[iRow];
  2511. if (!node) continue;
  2512. const updateData = { id: node.id };
  2513. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2514. const style = sheet.getStyle(iRow, iCol);
  2515. if (style.locked) continue;
  2516. const col = setting.cols[iCol];
  2517. if (col.field === 'expr') {
  2518. updateData.expr = '';
  2519. updateData.quantity = 0;
  2520. } else {
  2521. updateData[col.field] = col.type === 'Number' ? 0 : '';
  2522. if (col.field === 'quantity') updateDataexpr = '';
  2523. }
  2524. bDel = true;
  2525. }
  2526. if (bDel) data.update.push(updateData);
  2527. }
  2528. if (data.update.length === 0) return;
  2529. postData('/tender/' + getTenderId() + '/anc-gcl/update', data, function (result) {
  2530. ancGcl.updateDatas(result);
  2531. ancGclObj.loadCurAncillaryGcl();
  2532. }, function () {
  2533. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2534. });
  2535. },
  2536. clipboardPasting: function(e, info) {
  2537. info.cancel = true;
  2538. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  2539. if (!node) {
  2540. toastr.error('数据错误,请选择台账节点后再试');
  2541. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2542. return;
  2543. }
  2544. if (node.children && node.children.length > 0) {
  2545. toastr.error('父节点不可添加附属工程量');
  2546. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2547. return;
  2548. }
  2549. if ((!node.b_code || node.b_code === '')) {
  2550. toastr.error('项目节不可插入附属工程量');
  2551. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2552. return;
  2553. }
  2554. const hint = {
  2555. expr: {type: 'warning', msg: '输入的 计算式 非法,已过滤'},
  2556. num: {type: 'warning', msg: '输入的 数字 非法,已过滤'},
  2557. };
  2558. const setting = info.sheet.zh_setting;
  2559. const sortData = info.sheet.zh_data || [];
  2560. const pasteData = SpreadJsObj.analysisPasteText(info.pasteData.text);
  2561. const data = {};
  2562. const analysisData = function(pasteRow, targetData) {
  2563. pasteRow.forEach((value, iCol) => {
  2564. const col = setting.cols[info.cellRange.col + iCol];
  2565. if (col.field === 'expr') {
  2566. try {
  2567. targetData.expr = trimInvalidChar(value);
  2568. targetData.quantity = math.evaluate(transExpr(targetData.expr));
  2569. } catch(err) {
  2570. toastMessageUniq(hint.expr);
  2571. targetData.expr = '';
  2572. return;
  2573. }
  2574. } else if (col.type === 'Number') {
  2575. const num = _.toNumber(value);
  2576. if (!_.isFinite(num)) {
  2577. toastMessageUniq(hint.num);
  2578. return;
  2579. }
  2580. targetData[col.field] = num;
  2581. if (col.field === 'quantity') targetData.expr = '';
  2582. } else {
  2583. targetData[col.field] = value;
  2584. }
  2585. });
  2586. };
  2587. for (let iRow = 0; iRow < pasteData.length; iRow++) {
  2588. const curRow = iRow + info.cellRange.row;
  2589. const gclData = sortData[curRow];
  2590. if (gclData) {
  2591. if (!data.update) data.update = [];
  2592. const updateData = { id: gclData.id };
  2593. analysisData(pasteData[iRow], updateData);
  2594. data.update.push(updateData);
  2595. } else {
  2596. if (!data.add) data.add = [];
  2597. const addData = { lid: node.id, g_order: curRow + 1};
  2598. analysisData(pasteData[iRow], addData);
  2599. data.add.push(addData);
  2600. }
  2601. }
  2602. if ((!data.update || data.update.length === 0) && (!data.add || data.add.length === 0)) return;
  2603. postData('/tender/' + getTenderId() + '/anc-gcl/update', data, function (result) {
  2604. ancGcl.updateDatas(result);
  2605. ancGclObj.loadCurAncillaryGcl();
  2606. }, function () {
  2607. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2608. });
  2609. },
  2610. buttonClicked: function (e, info) {
  2611. const setting = info.sheet.zh_setting;
  2612. if (!setting) return;
  2613. const node = SpreadJsObj.getSelectObject(info.sheet);
  2614. if (!node) {
  2615. toastr.warning('请先添加附属工程量再设置辅材');
  2616. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2617. return;
  2618. }
  2619. const col = setting.cols[info.col];
  2620. const updateData = { id: node.id };
  2621. updateData[col.field] = node[col.field] ? 0 : 1;
  2622. postData('/tender/' + getTenderId() + '/anc-gcl/update', { update: [updateData]}, function (result) {
  2623. ancGcl.updateDatas(result);
  2624. ancGclObj.loadCurAncillaryGcl();
  2625. }, function () {
  2626. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2627. });
  2628. },
  2629. };
  2630. SpreadJsObj.addDeleteBind(ancGclSpread, ancGclObj.deletePress);
  2631. ancGclSpread.bind(spreadNS.Events.EditStarting, ancGclObj.editStarting);
  2632. ancGclSpread.bind(spreadNS.Events.EditEnded, ancGclObj.editEnded);
  2633. ancGclSpread.bind(spreadNS.Events.ClipboardPasting, ancGclObj.clipboardPasting);
  2634. ancGclSpread.bind(spreadNS.Events.ButtonClicked, ancGclObj.buttonClicked);
  2635. $.contextMenu({
  2636. selector: '#anc-gcl-spread',
  2637. build: function ($trigger, e) {
  2638. const target = SpreadJsObj.safeRightClickSelection($trigger, e, ancGclSpread);
  2639. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2640. },
  2641. items: {
  2642. 'insert': {
  2643. name: '插入',
  2644. icon: 'fa-plus',
  2645. disabled: function (key, opt) {
  2646. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  2647. return !node || !node.b_code || (node.children && node.children.length > 0);
  2648. },
  2649. callback: function (key, opt) {
  2650. ancGclObj.baseOpr('insert');
  2651. }
  2652. },
  2653. 'delete': {
  2654. name: '删除',
  2655. icon: 'fa-remove',
  2656. disabled: function (key, opt) {
  2657. const gclData = SpreadJsObj.getSelectObject(ancGclSheet);
  2658. return !gclData;
  2659. },
  2660. callback: function (key, opt) {
  2661. ancGclObj.baseOpr('delete');
  2662. }
  2663. },
  2664. 'down-move': {
  2665. name: '下移',
  2666. icon: 'fa-arrow-down',
  2667. disabled: function(key, opt) {
  2668. const sel = ancGclSheet.getSelections()[0];
  2669. const row = sel ? sel.row : -1;
  2670. const first = ancGclSheet.zh_data[row];
  2671. const next = ancGclSheet.zh_data[sel.row + sel.rowCount];
  2672. return !first || !next;
  2673. },
  2674. callback: function(key, opt) {
  2675. ancGclObj.baseOpr('down-move');
  2676. }
  2677. },
  2678. 'up-move': {
  2679. name: '上移',
  2680. icon: 'fa-arrow-up',
  2681. disabled: function(key, opt) {
  2682. const sel = ancGclSheet.getSelections()[0];
  2683. const row = sel ? sel.row : -1;
  2684. const first = ancGclSheet.zh_data[row];
  2685. const preNode = ancGclSheet.zh_data[row - 1];
  2686. return !first || !preNode;
  2687. },
  2688. callback: function(key, opt) {
  2689. ancGclObj.baseOpr('up-move');
  2690. }
  2691. },
  2692. }
  2693. });
  2694. $('#filter-anc-gcl').change(function() {
  2695. if (this.checked) {
  2696. const condition = {};
  2697. condition[this.getAttribute('name')] = parseInt(this.value);
  2698. ancGcl.filter = condition;
  2699. } else {
  2700. ancGcl.filter = null;
  2701. }
  2702. ancGclObj.loadCurAncillaryGcl();
  2703. });
  2704. postData(window.location.pathname + '/load', {}, function (data) {
  2705. ledgerTree.loadDatas(data.bills);
  2706. treeCalc.calculateAll(ledgerTree);
  2707. checkShowLast(data.bills.length);
  2708. pos.loadDatas(data.pos);
  2709. ancGcl.loadDatas(data.ancGcl);
  2710. for (const t of data.tags) {
  2711. t.node = ledgerTree.datas.find(x => { return x.id === t.lid; });
  2712. if (t.pos_id) {
  2713. const posRange = pos.getLedgerPos(t.lid) || [];
  2714. t.pos = posRange.find(x => { return x.id === t.pos_id; });
  2715. }
  2716. }
  2717. billsTag.loadDatas(data.tags);
  2718. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  2719. SpreadJsObj.loadTopAndSelect(ledgerSpread.getActiveSheet(), ckBillsSpread);
  2720. posOperationObj.loadCurPosData();
  2721. SpreadJsObj.resetTopAndSelect(posSpread.getActiveSheet());
  2722. ancGclObj.loadCurAncillaryGcl();
  2723. SpreadJsObj.resetTopAndSelect(ancGclSheet);
  2724. treeOperationObj.refreshOperationValid(ledgerSpread.getActiveSheet());
  2725. treeOperationObj.loadExprToInput(ledgerSpread.getActiveSheet());
  2726. checkList.loadHisCheckData();
  2727. }, null, true);
  2728. $.divResizer({
  2729. select: '#right-spr',
  2730. callback: function () {
  2731. ledgerSpread.refresh();
  2732. if (posSpread) posSpread.refresh();
  2733. if (ancGclSpread) ancGclSpread.refresh();
  2734. if (stdXmj) stdXmj.spread.refresh();
  2735. if (stdGcl) stdGcl.spread.refresh();
  2736. if (dealBills) dealBills.spread.refresh();
  2737. if (searchLedger) searchLedger.spread.refresh();
  2738. if (errorList) errorList.spread.refresh();
  2739. if (checkList) checkList.spread.refresh();
  2740. if (gclGather) gclGather.spread.refresh();
  2741. }
  2742. });
  2743. const stdLibCellDoubleClick = function (e, info) {
  2744. const stdSheet = info.sheet;
  2745. const mainSheet = ledgerSpread.getActiveSheet();
  2746. if (!stdSheet.zh_setting || !stdSheet.zh_tree || !mainSheet.zh_tree) { return; }
  2747. const stdTree = stdSheet.zh_tree;
  2748. const stdNode = stdTree.nodes[info.row];
  2749. const mainTree = mainSheet.zh_tree;
  2750. const sel = mainSheet.getSelections()[0];
  2751. const mainNode = mainTree.nodes[sel.row];
  2752. if (!stdNode) { return; }
  2753. if (info.sheet.zh_setting.stdType === 'gcl') {
  2754. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  2755. toastr.warning('非最底层项目下,不应添加清单');
  2756. return;
  2757. }
  2758. }
  2759. postData(window.location.pathname + '/update', {
  2760. postType: 'add-std',
  2761. postData: {
  2762. id: ledgerTree.getNodeKey(mainNode),
  2763. tender_id: mainNode.tender_id,
  2764. stdType: info.sheet.zh_setting.stdType,
  2765. stdLibId: stdNode.list_id,
  2766. stdNode: stdTree.getNodeKey(stdNode)
  2767. }
  2768. }, function (result) {
  2769. const refreshNode = mainTree.loadPostData(result);
  2770. treeOperationObj.refreshTree(mainSheet, refreshNode);
  2771. if (refreshNode.create && refreshNode.create.length > 0) {
  2772. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  2773. const refreshRow = [sel.row, refreshNode.create[refreshNode.create.length - 1].index];
  2774. const curIndex = mainTree.nodes.indexOf(mainNode);
  2775. if (sel.row !== curIndex && curIndex >= 0) refreshRow.push(curIndex);
  2776. SpreadJsObj.reloadRowsBackColor(mainSheet, refreshRow);
  2777. } else {
  2778. const node = _.find(ledgerTree.nodes, {code: stdNode.code, name: stdNode.name});
  2779. if (node) {
  2780. mainSheet.setSelection(ledgerTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  2781. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, ledgerTree.nodes.indexOf(node)]);
  2782. }
  2783. }
  2784. treeOperationObj.refreshOperationValid(mainSheet);
  2785. ledgerSpread.focus();
  2786. posOperationObj.loadCurPosData();
  2787. ancGclObj.loadCurAncillaryGcl();
  2788. });
  2789. };
  2790. const stdXmjSetting = {
  2791. selector: '#std-xmj',
  2792. stdType: 'xmj',
  2793. libs: stdChapters,
  2794. treeSetting: {
  2795. id: 'chapter_id',
  2796. pid: 'pid',
  2797. order: 'order',
  2798. level: 'level',
  2799. rootId: -1,
  2800. keys: ['id', 'list_id', 'chapter_id'],
  2801. },
  2802. spreadSetting: {
  2803. cols: [
  2804. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2805. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2806. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2807. ],
  2808. treeCol: 0,
  2809. emptyRows: 0,
  2810. headRows: 1,
  2811. headRowHeight: [32],
  2812. defaultRowHeight: 21,
  2813. headerFont: '12px 微软雅黑',
  2814. font: '12px 微软雅黑',
  2815. headColWidth: [30],
  2816. selectedBackColor: '#fffacd',
  2817. },
  2818. cellDoubleClick: stdLibCellDoubleClick,
  2819. page: 'ledger',
  2820. tid: getTenderId(),
  2821. };
  2822. const stdGclSetting = {
  2823. selector: '#std-gcl',
  2824. stdType: 'gcl',
  2825. libs: stdBills,
  2826. treeSetting: {
  2827. id: 'bill_id',
  2828. pid: 'pid',
  2829. order: 'order',
  2830. level: 'level',
  2831. rootId: -1,
  2832. keys: ['id', 'list_id', 'bill_id']
  2833. },
  2834. spreadSetting: {
  2835. cols: [
  2836. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  2837. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  2838. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  2839. ],
  2840. treeCol: 0,
  2841. emptyRows: 0,
  2842. headRows: 1,
  2843. headRowHeight: [32],
  2844. defaultRowHeight: 21,
  2845. headerFont: '12px 微软雅黑',
  2846. font: '12px 微软雅黑',
  2847. headColWidth: [30],
  2848. selectedBackColor: '#fffacd',
  2849. },
  2850. cellDoubleClick: stdLibCellDoubleClick,
  2851. page: 'ledger',
  2852. tid: getTenderId(),
  2853. };
  2854. // 展开收起标准清单
  2855. $('a', '#side-menu').bind('click', function (e) {
  2856. e.preventDefault();
  2857. const tab = $(this), tabPanel = $(tab.attr('content'));
  2858. // 展开工具栏、切换标签
  2859. if (!tab.hasClass('active')) {
  2860. // const close = $('.active', '#side-menu').length === 0;
  2861. $('a', '#side-menu').removeClass('active');
  2862. $('.tab-content .tab-select-show.tab-pane.active').removeClass('active');
  2863. tab.addClass('active');
  2864. tabPanel.addClass('active');
  2865. // $('.tab-content .tab-pane').removeClass('active');
  2866. showSideTools(tab.hasClass('active'));
  2867. if (tab.attr('content') === '#std-xmj') {
  2868. if (!stdXmj) {
  2869. stdXmj = $.stdLib(stdXmjSetting);
  2870. }
  2871. stdXmj.spread.refresh();
  2872. } else if (tab.attr('content') === '#std-gcl') {
  2873. if (!stdGcl) {
  2874. stdGcl = $.stdLib(stdGclSetting);
  2875. }
  2876. stdGcl.spread.refresh();
  2877. } else if (tab.attr('content') === '#deal-bills') {
  2878. if (!dealBills) {
  2879. dealBills = new DealBills('#deal-bills-spread', {
  2880. cols: [
  2881. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  2882. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  2883. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  2884. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2885. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2886. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  2887. ],
  2888. emptyRows: 3,
  2889. headRows: 1,
  2890. headRowHeight: [32],
  2891. defaultRowHeight: 21,
  2892. headerFont: '12px 微软雅黑',
  2893. font: '12px 微软雅黑',
  2894. headColWidth: [30],
  2895. selectedBackColor: '#fffacd',
  2896. readOnly: true,
  2897. });
  2898. dealBills.loadData();
  2899. }
  2900. dealBills.spread.refresh();
  2901. } else if (tab.attr('content') === '#search') {
  2902. if (!searchLedger) {
  2903. searchLedger = $.billsSearch({
  2904. selector: '#search',
  2905. searchSpread: ledgerSpread,
  2906. resultSpreadSetting: {
  2907. cols: [
  2908. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  2909. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  2910. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  2911. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  2912. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  2913. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  2914. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  2915. ],
  2916. emptyRows: 0,
  2917. headRows: 1,
  2918. headRowHeight: [32],
  2919. headColWidth: [30],
  2920. defaultRowHeight: 21,
  2921. headerFont: '12px 微软雅黑',
  2922. font: '12px 微软雅黑',
  2923. selectedBackColor: '#fffacd',
  2924. readOnly: true,
  2925. },
  2926. afterLocated: function () {
  2927. posOperationObj.loadCurPosData();
  2928. ancGclObj.loadCurAncillaryGcl();
  2929. },
  2930. calcSum: function (result) {
  2931. const sum = { name: '合计' };
  2932. for (const r of result) {
  2933. sum.quantity = ZhCalc.add(r.quantity, sum.quantity);
  2934. }
  2935. return sum;
  2936. }
  2937. });
  2938. }
  2939. searchLedger.spread.refresh();
  2940. } else if (tab.attr('content') === '#bills-tag') {
  2941. // do something
  2942. } else if (tab.attr('content') === '#error-list') {
  2943. errorList.spread.refresh();
  2944. } else if (tab.attr('content') === '#check-list') {
  2945. checkList.spread.refresh();
  2946. } else if (tab.attr('content') === '#fujian') {
  2947. $('#showAttachment').hide();
  2948. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  2949. getNodeList(node.id);
  2950. getAllList();
  2951. } else if (tab.attr('content') === '#gcl-gather') {
  2952. gclGather.spread.refresh();
  2953. }
  2954. } else { // 收起工具栏
  2955. tab.removeClass('active');
  2956. tabPanel.removeClass('active');
  2957. showSideTools(tab.hasClass('active'));
  2958. }
  2959. ledgerSpread.refresh();
  2960. if (posSpread) {
  2961. posSpread.refresh();
  2962. }
  2963. if (ancGclSpread) ancGclSpread.refresh();
  2964. });
  2965. class DealBills {
  2966. constructor (selector, spreadSetting) {
  2967. const self = this;
  2968. this.obj = $(selector)[0];
  2969. this.url = '/tender/' + getTenderId() + '/deal';
  2970. this.spreadSetting = spreadSetting;
  2971. this.spread = SpreadJsObj.createNewSpread(this.obj);
  2972. this.sheet = this.spread.getActiveSheet();
  2973. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2974. this.OprObj = {
  2975. /**
  2976. * 删除按钮响应事件
  2977. * @param sheet
  2978. */
  2979. deletePress: function (sheet) {
  2980. if (!sheet.zh_setting || sheet.zh_setting.readOnly) return;
  2981. const sortData = sheet.zh_data;
  2982. const datas = [];
  2983. const sels = sheet.getSelections();
  2984. if (!sels || !sels[0]) return;
  2985. for (let iRow = sels[0].row; iRow < sels[0].row + sels[0].rowCount; iRow++) {
  2986. let bDel = false;
  2987. const node = sortData[iRow];
  2988. if (node) {
  2989. const data = {id: node.id};
  2990. for (let iCol = sels[0].col; iCol < sels[0].col + sels[0].colCount; iCol++) {
  2991. const colSetting = sheet.zh_setting.cols[iCol];
  2992. if (colSetting.field === 'code') {
  2993. toastr.error('清单编号不能为空,如需删除签约清单请使用右键删除');
  2994. return;
  2995. }
  2996. const style = sheet.getStyle(iRow, iCol);
  2997. if (!style.locked) {
  2998. const colSetting = sheet.zh_setting.cols[iCol];
  2999. data[colSetting.field] = null;
  3000. bDel = true;
  3001. }
  3002. }
  3003. if (bDel) {
  3004. datas.push(data);
  3005. }
  3006. }
  3007. }
  3008. if (datas.length > 0) {
  3009. postData(self.url + '/update', {update: datas}, function (result) {
  3010. self.loadUpdateData(result);
  3011. SpreadJsObj.reLoadSheetData(sheet);
  3012. }, function () {
  3013. SpreadJsObj.reLoadSheetData(sheet);
  3014. });
  3015. }
  3016. },
  3017. delete: function (sheet) {
  3018. if (!sheet.zh_setting || sheet.zh_setting.readOnly) return;
  3019. const sortData = sheet.zh_data;
  3020. const datas = [];
  3021. const sels = sheet.getSelections();
  3022. if (!sels || !sels[0]) return;
  3023. for (let iRow = sels[0].row, iLen = sels[0].row + sels[0].rowCount; iRow < iLen; iRow++) {
  3024. const node = sortData[iRow];
  3025. datas.push(node.id);
  3026. }
  3027. if (datas.length > 0) {
  3028. postData(self.url + '/update', {del: datas}, function (result) {
  3029. self.loadUpdateData(result);
  3030. SpreadJsObj.reLoadSheetData(sheet);
  3031. }, function () {
  3032. SpreadJsObj.reLoadSheetData(sheet);
  3033. });
  3034. }
  3035. },
  3036. editEnded: function (e, info) {
  3037. if (!info.sheet.zh_setting || !info.sheet.zh_data || info.sheet.zh_setting.readOnly) return;
  3038. const node = info.sheet.zh_data[info.row];
  3039. const col = info.sheet.zh_setting.cols[info.col];
  3040. const data = {};
  3041. if (node) {
  3042. data.update = {};
  3043. data.update.id = node.id;
  3044. const oldValue = node ? node[col.field] : null;
  3045. const newValue = trimInvalidChar(info.editingText);
  3046. if (oldValue == info.editingText || ((!oldValue || oldValue === '') && (newValue === ''))) {
  3047. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3048. return;
  3049. }
  3050. data.update[col.field] = newValue;
  3051. } else {
  3052. if (col.field !== 'code') {
  3053. toastr.warning('新增签约清单,请先输入清单编号');
  3054. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3055. return;
  3056. }
  3057. data.add = {};
  3058. data.add.order = info.row + 1;
  3059. data.add.code = trimInvalidChar(info.editingText);
  3060. }
  3061. postData(self.url + '/update', data, function (result) {
  3062. self.loadUpdateData(result);
  3063. SpreadJsObj.reLoadSheetData(info.sheet);
  3064. }, function () {
  3065. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3066. });
  3067. },
  3068. clipboardPasting(e, info) {
  3069. const setting = info.sheet.zh_setting, sortData = info.sheet.zh_data;
  3070. info.cancel = true;
  3071. if (!setting || !sortData || setting.readOnly) return;
  3072. const pasteData = info.pasteData.html
  3073. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  3074. : (info.pasteData.text === ''
  3075. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  3076. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  3077. const hint = {
  3078. code: {type: 'warning', msg: '签约清单编号不可为空,已过滤'},
  3079. unit_price: {type: 'warning', msg: '输入的 单价 非法,已过滤'},
  3080. quantity: {type: 'warning', msg: '输入的 数量 非法,已过滤'},
  3081. };
  3082. const uDatas = [], iDatas = [];
  3083. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3084. const curRow = info.cellRange.row + iRow;
  3085. const node = sortData[curRow];
  3086. let bPaste = false;
  3087. const data = {};
  3088. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  3089. const curCol = info.cellRange.col + iCol;
  3090. const colSetting = setting.cols[curCol];
  3091. const value = trimInvalidChar(pasteData[iRow][iCol]);
  3092. if (colSetting.field === 'code' && (!value || value === '')) {
  3093. toastMessageUniq(hint.code);
  3094. break;
  3095. }
  3096. if (colSetting.type === 'Number') {
  3097. const num = _.toNumber(value);
  3098. if (num) {
  3099. data[colSetting.field] = num;
  3100. bPaste = true;
  3101. } else if (colSetting.field === 'unit_price') {
  3102. toastMessageUniq(hint.unit_price);
  3103. } else if (colSetting.field === 'quantity') {
  3104. toastMessageUniq(hint.quantity);
  3105. }
  3106. } else {
  3107. data[colSetting.field] = value;
  3108. bPaste = true;
  3109. }
  3110. }
  3111. if (bPaste) {
  3112. if (node) {
  3113. data.id = node.id;
  3114. uDatas.push(data);
  3115. } else {
  3116. data.order = curRow + 1;
  3117. iDatas.push(data);
  3118. }
  3119. }
  3120. }
  3121. const updateData = {};
  3122. if (uDatas.length > 0) updateData.update = uDatas;
  3123. if (iDatas.length > 0) updateData.add = iDatas;
  3124. if (uDatas.length > 0 || iDatas.length > 0) {
  3125. postData(self.url + '/update', updateData, function (result) {
  3126. self.loadUpdateData(result);
  3127. SpreadJsObj.reLoadSheetData(info.sheet);
  3128. });
  3129. } else {
  3130. SpreadJsObj.reLoadSheetData(info.sheet);
  3131. }
  3132. },
  3133. };
  3134. if (!readOnly) {
  3135. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3136. const dealSheet = info.sheet;
  3137. if (!dealSheet.zh_setting.readOnly) return;
  3138. const mainSheet = ledgerSpread.getActiveSheet();
  3139. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  3140. if (!dealBills) { return; }
  3141. const mainTree = mainSheet.zh_tree;
  3142. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  3143. if (!mainNode || !mainTree) { return; }
  3144. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3145. toastr.error('非最底层项目下,不应添加清单');
  3146. return;
  3147. }
  3148. postData(window.location.pathname + '/update', {
  3149. postType: 'add-deal',
  3150. postData: {
  3151. id: mainNode.ledger_id,
  3152. type: mainNode.code ? 'child' : 'next',
  3153. dealBills: {
  3154. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  3155. unit_price: dealBills.unit_price,
  3156. }
  3157. },
  3158. }, function (result) {
  3159. const refreshData = mainTree.loadPostData(result);
  3160. treeOperationObj.refreshTree(mainSheet, refreshData);
  3161. const sel = mainSheet.getSelections()[0];
  3162. mainSheet.setSelection(refreshData.create[0].index, sel.col, sel.rowCount, sel.colCount);
  3163. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshData.create[0].index]);
  3164. treeOperationObj.refreshOperationValid(mainSheet);
  3165. ledgerSpread.focus();
  3166. posOperationObj.loadCurPosData();
  3167. ancGclObj.loadCurAncillaryGcl();
  3168. });
  3169. });
  3170. }
  3171. const dealBillsPermission = $('[href="#upload-deal"]').length > 0;
  3172. if (!readOnly || dealBillsPermission) {
  3173. this.spread.bind(spreadNS.Events.EditEnded, this.OprObj.editEnded);
  3174. this.spread.bind(spreadNS.Events.ClipboardPasting, this.OprObj.clipboardPasting);
  3175. SpreadJsObj.addDeleteBind(this.spread, this.OprObj.deletePress);
  3176. $.contextMenu({
  3177. selector: selector,
  3178. build: function ($trigger, e) {
  3179. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.spread);
  3180. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3181. },
  3182. items: {
  3183. edit: {
  3184. name: '进入编辑模式',
  3185. icon: 'fa-edit',
  3186. visible: function (key, opt) {
  3187. return self.sheet.zh_setting.readOnly;
  3188. },
  3189. callback: function (key, opt) {
  3190. self.sheet.zh_setting.readOnly = false;
  3191. SpreadJsObj.refreshSheetReadOnly(self.sheet);
  3192. },
  3193. },
  3194. read: {
  3195. name: '退出编辑模式',
  3196. icon: 'fa-sign-out',
  3197. visible: function (key, opt) {
  3198. return !self.sheet.zh_setting.readOnly;
  3199. },
  3200. callback: function (key, opt) {
  3201. self.sheet.zh_setting.readOnly = true;
  3202. SpreadJsObj.refreshSheetReadOnly(self.sheet);
  3203. },
  3204. },
  3205. del: {
  3206. name: '删除',
  3207. icon: 'fa-times',
  3208. visible: function (key, opt) {
  3209. return !self.sheet.zh_setting.readOnly;
  3210. },
  3211. disabled: function (key, opt) {
  3212. const select = SpreadJsObj.getSelectObject(self.sheet);
  3213. return !select;
  3214. },
  3215. callback: function (key, opt) {
  3216. self.OprObj.delete(self.sheet);
  3217. },
  3218. },
  3219. sprEdit: '----',
  3220. apply: {
  3221. name: '应用全部清单单价至台账',
  3222. icon: 'fa-magic',
  3223. disabled: function (key, opt) {
  3224. const sheet = self.spread.getActiveSheet();
  3225. return sheet.getRowCount() === 0 || readOnly;
  3226. },
  3227. callback: function (key, opt) {
  3228. const datas = [], sourceData = self.spread.getActiveSheet().zh_data;
  3229. for (const db of sourceData) {
  3230. const targets = ledgerTree.nodes.filter(function (x) {
  3231. return x.b_code === db.code && x.name === db.name && x.unit === db.unit;
  3232. });
  3233. for (const t of targets) {
  3234. if (t.children && t.children.length > 0) continue;
  3235. const data = ledgerTree.getNodeKeyData(t);
  3236. data.unit_price = db.unit_price;
  3237. datas.push(data);
  3238. }
  3239. }
  3240. if (datas.length > 0) {
  3241. doAfterHint({
  3242. fun: function() {
  3243. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  3244. const refreshNode = ledgerTree.loadPostData(result);
  3245. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);
  3246. });
  3247. },
  3248. hint: '此操作会替换台账里所有同编号、名称、单位的清单,请谨慎操作',
  3249. });
  3250. } else {
  3251. toastr.warning('没有可应用的清单。');
  3252. }
  3253. },
  3254. }
  3255. }
  3256. });
  3257. }
  3258. $('#upload-deal-bills').click(function () {
  3259. const file = $('#deal-bills-file')[0];
  3260. const formData = new FormData();
  3261. formData.append('file', file.files[0]);
  3262. postDataWithFile(self.url+'/upload-excel', formData, function (data) {
  3263. self.data = data;
  3264. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  3265. $('#upload-deal').modal('hide');
  3266. }, function () {
  3267. $('#upload-deal').modal('hide');
  3268. });
  3269. });
  3270. this.initDealBillsSearch();
  3271. }
  3272. search(keyword) {
  3273. this.searchResult = [];
  3274. this.searchCur = 0;
  3275. if (keyword) {
  3276. for (const [i, d] of this.data.entries()) {
  3277. if (d.code.indexOf(keyword) >= 0 || d.name.indexOf(keyword) >= 0) this.searchResult.push(d);
  3278. }
  3279. }
  3280. $('#dbs-count').html(`结果:${this.searchResult.length}`);
  3281. if (this.searchResult.length > 0) SpreadJsObj.locateData(this.sheet, this.searchResult[0]);
  3282. }
  3283. searchPre() {
  3284. this.searchCur = this.searchCur - 1;
  3285. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  3286. SpreadJsObj.locateData(this.sheet, this.searchResult[this.searchCur]);
  3287. }
  3288. searchNext() {
  3289. this.searchCur = this.searchCur + 1;
  3290. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  3291. SpreadJsObj.locateData(this.sheet, this.searchResult[this.searchCur]);
  3292. }
  3293. searchClear() {
  3294. $('#dbs-keyword').val('');
  3295. this.searchResult = [];
  3296. this.searchCur = 0;
  3297. $('#dbs-count').html(`结果:${this.searchResult.length}`);
  3298. }
  3299. initDealBillsSearch() {
  3300. const self = this;
  3301. $('#dbs-keyword').change(function () { self.search(this.value); });
  3302. $('#dbs-pre').click(function (e) {
  3303. self.searchPre();
  3304. e.stopPropagation();
  3305. });
  3306. $('#dbs-next').click(function (e) {
  3307. self.searchNext();
  3308. e.stopPropagation();
  3309. });
  3310. $('#dbs-clear').click(function (e) {
  3311. self.searchClear();
  3312. e.stopPropagation();
  3313. });
  3314. }
  3315. loadData () {
  3316. const self = this;
  3317. postData(this.url+'/get-data', {}, function (data) {
  3318. self.data = data;
  3319. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  3320. if (data.length > 0) self.spread.getActiveSheet().setSelection(0, 0, 1, 1);
  3321. });
  3322. }
  3323. calculateData () {
  3324. if (this.data) {
  3325. for (const d of this.data) {
  3326. d.total_price = _.multiply(d.quantity, d.unit_price);
  3327. }
  3328. }
  3329. }
  3330. loadUpdateData(updateData) {
  3331. if (updateData.add) {
  3332. for (const a of updateData.add) {
  3333. this.data.push(a);
  3334. }
  3335. }
  3336. if (updateData.update) {
  3337. for (const u of updateData.update) {
  3338. const d = this.data.find(function (x) {
  3339. return u.id === x.id;
  3340. });
  3341. if (d) {
  3342. _.assign(d, u);
  3343. } else {
  3344. this.data.push(d);
  3345. }
  3346. }
  3347. }
  3348. if (updateData.del) {
  3349. _.remove(this.data, function (d) {
  3350. return updateData.del.indexOf(d.id) >= 0;
  3351. });
  3352. }
  3353. }
  3354. }
  3355. class BatchInsertBillsPosObj {
  3356. constructor (obj) {
  3357. const self = this;
  3358. this.obj = obj;
  3359. this.billsCount = 6;
  3360. this.posCount = 1000;
  3361. this.filter = getLocalCache('zh-calc-batch-filter');
  3362. if (!this.filter) {
  3363. this.filter = '1';
  3364. }
  3365. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  3366. // 初始化 清单编号窗口 参数
  3367. this.qdSpreadSetting = {
  3368. cols: [
  3369. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  3370. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  3371. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3372. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3373. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  3374. ],
  3375. emptyRows: this.billsCount,
  3376. headRows: 1,
  3377. headRowHeight: [32],
  3378. headerFont: '12px 微软雅黑',
  3379. font: '12px 微软雅黑',
  3380. };
  3381. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  3382. // 初始化 部位数量复核表 参数
  3383. this.posSpreadSetting = {
  3384. cols: [
  3385. {title: '计量单元', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  3386. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  3387. ],
  3388. emptyRows: this.posCount,
  3389. headRows: 1,
  3390. headRowHeight: [32],
  3391. headerFont: '12px 微软雅黑',
  3392. font: '12px 微软雅黑',
  3393. };
  3394. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  3395. this.posSpreadSetting.cols.push(
  3396. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  3397. )
  3398. }
  3399. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  3400. // 初始化 签约清单 参数
  3401. this.dealSpreadSetting = {
  3402. cols: [
  3403. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  3404. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  3405. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  3406. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  3407. ],
  3408. emptyRows: 0,
  3409. headRows: 1,
  3410. headRowHeight: [32],
  3411. headerFont: '12px 微软雅黑',
  3412. font: '12px 微软雅黑',
  3413. };
  3414. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  3415. this.dealSheet = this.dealSpread.getActiveSheet();
  3416. // 初始化 清单编号、部位数量复核表 表格
  3417. this.initView();
  3418. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  3419. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  3420. $.contextMenu({
  3421. selector: '.batch-l-t',
  3422. build: function ($trigger, e) {
  3423. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  3424. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3425. },
  3426. items: {
  3427. 'create': {
  3428. name: '新增行',
  3429. icon: 'fa-sign-in',
  3430. callback: function (key, opt) {
  3431. const qdSheet = self.qdSpread.getActiveSheet();
  3432. const posSheet = self.posSpread.getActiveSheet();
  3433. qdSheet.addRows(qdSheet.getRowCount(), 1);
  3434. const index = qdSheet.getRowCount();
  3435. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  3436. posSheet.addColumns(posSheet.getColumnCount(), 1);
  3437. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  3438. },
  3439. },
  3440. 'delete': {
  3441. name: '删除行',
  3442. icon: 'fa-remove',
  3443. callback: function (key, opt) {
  3444. const qdSheet = self.qdSpread.getActiveSheet();
  3445. const posSheet = self.posSpread.getActiveSheet();
  3446. const sel = qdSheet.getSelections()[0];
  3447. qdSheet.deleteRows(sel.row, sel.rowCount);
  3448. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  3449. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  3450. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  3451. }
  3452. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  3453. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  3454. }
  3455. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  3456. },
  3457. }
  3458. }
  3459. });
  3460. // 拉取签约清单数据
  3461. if (dealBills) {
  3462. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  3463. } else {
  3464. postData('/tender/' + getTenderId() + '/deal/get-data', {}, function (data) {
  3465. SpreadJsObj.loadSheetData(self.dealSpread.getActiveSheet(), 'data', data);
  3466. });
  3467. }
  3468. // 双击签约清单,自动添加到清单编号窗口
  3469. this.dealSpread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3470. const deal = info.sheet.zh_data[info.row];
  3471. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  3472. const sel = qdSheet.getSelections()[0];
  3473. qdSheet.getCell(sel.row, 0).value(deal.code);
  3474. qdSheet.getCell(sel.row, 1).value(deal.name);
  3475. qdSheet.getCell(sel.row, 2).value(deal.unit);
  3476. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  3477. if (sel.row + 1 === qdSheet.getRowCount()) {
  3478. const count = sel.row + 2;
  3479. qdSheet.setRowCount(count);
  3480. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  3481. const colCount = posSheet.getColumnCount() + 1
  3482. posSheet.setColumnCount(colCount);
  3483. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  3484. }
  3485. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  3486. });
  3487. this.qdSpread.bind(spreadNS.Events.ClipboardPasting, function (e, info) {
  3488. info.cancel = true;
  3489. const transpose = $('[name=batch-transpose]')[0].checked;
  3490. const pasteData = SpreadJsObj.analysisPasteText(info.pasteData.text, transpose);
  3491. const billsSheet = info.sheet, posSheet = self.posSpread.getActiveSheet();
  3492. const billsCount = info.sheet.getRowCount(), finalCount = info.cellRange.row + pasteData.length + 1;
  3493. SpreadJsObj.beginMassOperation(billsSheet);
  3494. if (finalCount > billsCount) {
  3495. billsSheet.setRowCount(finalCount);
  3496. posSheet.setColumnCount(finalCount + 2);
  3497. for (let i = billsCount - 1; i <= finalCount; i++) {
  3498. billsSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3499. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3500. }
  3501. }
  3502. for (let iRow = 0; iRow < pasteData.length; iRow++) {
  3503. const curRow = iRow + info.cellRange.row;
  3504. pasteData[iRow].forEach((value, iCol) => {
  3505. billsSheet.getCell(curRow, iCol + info.cellRange.col).value(value);
  3506. });
  3507. if ([0, 1].indexOf(info.cellRange.col) >= 0) {
  3508. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3509. const bills = _.find(dealBills, {code: billsSheet.getText(curRow, 0)});
  3510. if (bills) {
  3511. billsSheet.getCell(curRow, 1).value(bills.name);
  3512. billsSheet.getCell(curRow, 2).value(bills.unit);
  3513. billsSheet.getCell(curRow, 3).value(bills.unit_price);
  3514. }
  3515. }
  3516. }
  3517. SpreadJsObj.endMassOperation(billsSheet);
  3518. });
  3519. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3520. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  3521. const count = qdSheet.getRowCount();
  3522. if (billsCount > count) {
  3523. qdSheet.setRowCount(billsCount);
  3524. for (let i = count + 1; i <= billsCount; i++) {
  3525. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3526. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3527. }
  3528. }
  3529. });
  3530. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  3531. if (info.col === 0) {
  3532. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3533. if (dealBills && dealBills.length > 0) {
  3534. const bills = _.find(dealBills, {code: info.editingText});
  3535. if (bills) {
  3536. info.sheet.getCell(info.row, 1).value(bills.name);
  3537. info.sheet.getCell(info.row, 2).value(bills.unit);
  3538. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  3539. }
  3540. }
  3541. }
  3542. });
  3543. this.obj.bind('shown.bs.modal', function () {
  3544. self.qdSpread.refresh();
  3545. self.posSpread.refresh();
  3546. self.dealSpread.refresh();
  3547. });
  3548. $('#batch-ok').click(function () {
  3549. const sheet = ledgerSpread.getActiveSheet();
  3550. const sel = sheet.getSelections()[0];
  3551. const row = sel.row;
  3552. const select = ledgerTree.nodes[row];
  3553. if (select) {
  3554. const insertData = {};
  3555. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  3556. insertData.id = ledgerTree.getNodeKey(select);
  3557. insertData.batchData = self.getBatchData();
  3558. if (insertData.batchData.length > 0) {
  3559. postData(window.location.pathname + '/update', {postType: 'batch-insert', postData: insertData}, function (data) {
  3560. pos.updateDatas(data.pos);
  3561. const result = ledgerTree.loadPostData(data.ledger);
  3562. treeOperationObj.refreshTree(sheet, result);
  3563. sheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  3564. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, result.create[0].index]);
  3565. treeOperationObj.refreshOperationValid(sheet);
  3566. posOperationObj.loadCurPosData();
  3567. ancGclObj.loadCurAncillaryGcl();
  3568. self.obj.modal('hide');
  3569. }, null, true);
  3570. } else {
  3571. self.obj.modal('hide');
  3572. }
  3573. }
  3574. });
  3575. $('input[name=batch-filter]').change(function () {
  3576. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  3577. });
  3578. this.initDealBillsSearch();
  3579. }
  3580. search(keyword) {
  3581. this.searchResult = [];
  3582. this.searchCur = 0;
  3583. if (keyword) {
  3584. for (const [i, d] of this.dealSheet.zh_data.entries()) {
  3585. if (d.code.indexOf(keyword) >= 0 || d.name.indexOf(keyword) >= 0) this.searchResult.push(d);
  3586. }
  3587. }
  3588. $('#batch-dbs-count').html(`结果:${this.searchResult.length}`);
  3589. if (this.searchResult.length > 0) SpreadJsObj.locateData(this.dealSheet, this.searchResult[0]);
  3590. }
  3591. searchPre() {
  3592. this.searchCur = this.searchCur - 1;
  3593. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  3594. SpreadJsObj.locateData(this.dealSheet, this.searchResult[this.searchCur]);
  3595. }
  3596. searchNext() {
  3597. this.searchCur = this.searchCur + 1;
  3598. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  3599. SpreadJsObj.locateData(this.dealSheet, this.searchResult[this.searchCur]);
  3600. }
  3601. initDealBillsSearch() {
  3602. const self = this;
  3603. $('#batch-dbs-keyword').change(function () { self.search(this.value); });
  3604. $('#batch-dbs-pre').click(function (e) {
  3605. self.searchPre();
  3606. e.stopPropagation();
  3607. });
  3608. $('#batch-dbs-next').click(function (e) {
  3609. self.searchNext();
  3610. e.stopPropagation();
  3611. });
  3612. }
  3613. // 初始化左侧表格
  3614. initView () {
  3615. // 初始化 清单编号
  3616. const qdSheet = this.qdSpread.getActiveSheet();
  3617. qdSheet.setColumnWidth(0, 45, spreadNS.SheetArea.rowHeader);
  3618. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  3619. SpreadJsObj.refreshColumnAlign(qdSheet);
  3620. // 清理原有数据
  3621. SpreadJsObj.beginMassOperation(qdSheet);
  3622. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3623. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  3624. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  3625. }
  3626. qdSheet.setSelection(0, 0, 1 ,1);
  3627. SpreadJsObj.endMassOperation(qdSheet);
  3628. // 初始化 部位数量复核表
  3629. const posSheet = this.posSpread.getActiveSheet();
  3630. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  3631. SpreadJsObj.refreshColumnAlign(posSheet);
  3632. // 清理原有数据
  3633. SpreadJsObj.beginMassOperation(posSheet);
  3634. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  3635. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3636. posSheet.setSelection(0, 0, 1 ,1);
  3637. SpreadJsObj.endMassOperation(posSheet);
  3638. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  3639. }
  3640. // 获取界面数据
  3641. getBatchData () {
  3642. const result = [];
  3643. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  3644. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  3645. if (qdSheet.getText(iRow, 0) === '') { continue; }
  3646. const qd = {
  3647. b_code: qdSheet.getText(iRow, 0),
  3648. name: qdSheet.getText(iRow, 1),
  3649. unit: qdSheet.getText(iRow, 2),
  3650. price: _.toNumber(qdSheet.getText(iRow, 3)),
  3651. pos: [],
  3652. };
  3653. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  3654. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  3655. if (value !== 0 && !isNaN(value)) {
  3656. qd.pos.push({
  3657. name: posSheet.getText(iPosRow, 0),
  3658. drawing_code: posSheet.getText(iPosRow, 1),
  3659. quantity: value, porder: qd.pos.length + 1,
  3660. });
  3661. }
  3662. }
  3663. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  3664. }
  3665. return result;
  3666. }
  3667. }
  3668. class ContractExpr {
  3669. constructor(setting) {
  3670. const self = this;
  3671. this.obj = $('#contract_expr');
  3672. this.exprObj = $('#ce-expr');
  3673. this.exprSpread = SpreadJsObj.createNewSpread($('#expr_spread')[0]);
  3674. this.exprSheet = this.exprSpread.getActiveSheet();
  3675. const exprSpreadSetting = {
  3676. cols: [
  3677. { title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 180, formatter: '@', cellType: 'tree' },
  3678. { title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 100, formatter: '@' },
  3679. { title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 230, formatter: '@' },
  3680. { title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit' },
  3681. ],
  3682. emptyRows: 0,
  3683. headRows: 2,
  3684. headRowHeight: [25, 25],
  3685. defaultRowHeight: 21,
  3686. headerFont: '12px 微软雅黑',
  3687. font: '12px 微软雅黑',
  3688. readOnly: true,
  3689. getColor: function (sheet, data, row, col, defaultColor) {
  3690. if (self.targetNode && data && data.id === self.targetNode.id) {
  3691. return spreadColor.pay.expr_err;
  3692. } if (self.invalidRows && self.invalidRows.indexOf(row + 1) >= 0) {
  3693. return spreadColor.pay.yf_without;
  3694. } else {
  3695. return defaultColor;
  3696. }
  3697. }
  3698. };
  3699. sjsSettingObj.setFxTreeStyle(exprSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  3700. SpreadJsObj.initSheet(this.exprSheet, exprSpreadSetting);
  3701. this.exprTree = createNewPathTree('ledger', {
  3702. id: 'ledger_id',
  3703. pid: 'ledger_pid',
  3704. order: 'order',
  3705. level: 'level',
  3706. rootId: -1,
  3707. keys: ['id', 'tender_id', 'ledger_id'],
  3708. });
  3709. this.exprTree.loadDatas(setting.sourceTree.datas);
  3710. SpreadJsObj.loadSheetData(this.exprSheet, SpreadJsObj.DataType.Tree, this.exprTree);
  3711. // this.exprSpread.bind(spreadNS.Events.SelectionChanged, function(e, info) {
  3712. // const select = SpreadJsObj.getSelectObject(info.sheet);
  3713. // if (select && self.targetNode && select.id === self.targetNode.id) {
  3714. // $('#select-row').html('');
  3715. // } else {
  3716. // $('#select-row').html(`(${select.code || ''}${select.b_code || ''})`);
  3717. // }
  3718. // });
  3719. this.obj.bind('shown.bs.modal', function () {
  3720. self.exprSpread.refresh();
  3721. });
  3722. $('td[exprValue]').dblclick(function() {
  3723. const name = this.getAttribute('name');
  3724. let row;
  3725. if (name === 'tr') {
  3726. row = self.targetRow;
  3727. } else {
  3728. const node = SpreadJsObj.getSelectObject(self.exprSheet);
  3729. if (node.id === self.targetNode.id) return;
  3730. row = self.exprTree.nodes.indexOf(node) + 1;
  3731. }
  3732. if (self.invalidRows.indexOf(row) >= 0) return;
  3733. self.exprObj.val(self.exprObj.val() + `<<f${row}$${this.getAttribute('exprValue')}>>`);
  3734. });
  3735. $('#contract-expr-ok').click(function() {
  3736. const exprStr = $('#ce-expr').val().toLowerCase();
  3737. if ((!exprStr && !self.orgExpr) || (exprStr === self.orgExpr)) {
  3738. self.obj.modal('hide');
  3739. return;
  3740. }
  3741. const [valid, msg] = TreeExprCalc.checkExprValid(exprStr, self.invalidRows);
  3742. if (!valid) {
  3743. toastr.error(msg);
  3744. return;
  3745. }
  3746. const expr = TreeExprCalc.exprStr2Expr(exprStr);
  3747. if (expr.length > 500) {
  3748. toastr.error('输入表达式过长');
  3749. return;
  3750. }
  3751. // $('#ce-expr-org').val(expr + ' ' + TreeExprCalc.expr2ExprStr(expr));
  3752. postData('expr/save', { calc_module: 'stage', calc_tag: 'contract', calc_id: self.targetNode.id, expr }, function() {
  3753. self.targetNode.contract_expr = expr;
  3754. self.obj.modal('hide');
  3755. });
  3756. });
  3757. this.initLedgerSearch();
  3758. this.initShowLevel();
  3759. TreeExprCalc.init({ tree: this.exprTree });
  3760. }
  3761. search(keyword) {
  3762. this.searchResult = [];
  3763. this.searchCur = 0;
  3764. if (keyword) {
  3765. for (const [i, d] of this.exprSheet.zh_tree.nodes.entries()) {
  3766. if (d.code && d.code.indexOf(keyword) >= 0) {
  3767. this.searchResult.push(d);
  3768. continue;
  3769. }
  3770. if (d.b_code && d.b_code.indexOf(keyword) >= 0) {
  3771. this.searchResult.push(d);
  3772. continue;
  3773. }
  3774. if (d.name && d.name.indexOf(keyword) >= 0) {
  3775. this.searchResult.push(d);
  3776. continue;
  3777. }
  3778. }
  3779. }
  3780. $('#expr_search_count').html(`结果:${this.searchResult.length}`);
  3781. if (this.searchResult.length > 0) SpreadJsObj.locateTreeNode(this.exprSheet, this.searchResult[0].ledger_id);
  3782. }
  3783. searchPre() {
  3784. this.searchCur = this.searchCur - 1;
  3785. if (this.searchCur < 0) this.searchCur = this.searchResult.length - 1;
  3786. SpreadJsObj.locateTreeNode(this.exprSheet, this.searchResult[this.searchCur].ledger_id);
  3787. }
  3788. searchNext() {
  3789. this.searchCur = this.searchCur + 1;
  3790. if (this.searchCur >= this.searchResult.length) this.searchCur = 0;
  3791. SpreadJsObj.locateTreeNode(this.exprSheet, this.searchResult[this.searchCur].ledger_id);
  3792. }
  3793. initLedgerSearch() {
  3794. const self = this;
  3795. this.searchResult = [];
  3796. this.searchCur = 0;
  3797. $('#expr_search_count').html(`结果:${this.searchResult.length}`);
  3798. $('#expr_search_keyword').change(function () { self.search(this.value); });
  3799. $('#expr_search_pre').click(function (e) {
  3800. self.searchPre();
  3801. e.stopPropagation();
  3802. });
  3803. $('#expr_search_next').click(function (e) {
  3804. self.searchNext();
  3805. e.stopPropagation();
  3806. });
  3807. }
  3808. initShowLevel(){
  3809. // 显示层次
  3810. (function (select, sheet) {
  3811. $(select).click(function () {
  3812. const tag = $(this).attr('tag');
  3813. const tree = sheet.zh_tree;
  3814. if (!tree) return;
  3815. setTimeout(() => {
  3816. showWaitingView();
  3817. switch (tag) {
  3818. case "1":
  3819. case "2":
  3820. case "3":
  3821. case "4":
  3822. case "5":
  3823. tree.expandByLevel(parseInt(tag));
  3824. SpreadJsObj.refreshTreeRowVisible(sheet);
  3825. break;
  3826. case "last":
  3827. tree.expandByCustom(() => { return true; });
  3828. SpreadJsObj.refreshTreeRowVisible(sheet);
  3829. break;
  3830. case "leafXmj":
  3831. tree.expandToLeafXmj();
  3832. SpreadJsObj.refreshTreeRowVisible(sheet);
  3833. break;
  3834. }
  3835. closeWaitingView();
  3836. }, 100);
  3837. });
  3838. })('a[name=ce-showLevel]', this.exprSheet);
  3839. }
  3840. async setTargetNode(node) {
  3841. const self = this;
  3842. this.targetNode = node;
  3843. const relaNode = this.exprTree.getItems(node.ledger_id);
  3844. this.invalidNode = this.exprTree.getAllParents(relaNode);
  3845. this.invalidRows = this.invalidNode.map(x => {
  3846. return self.exprTree.nodes.indexOf(x) + 1;
  3847. });
  3848. this.targetRow = this.exprTree.nodes.indexOf(relaNode) + 1;
  3849. if (node.contract_expr === undefined) {
  3850. node.contract_expr = await postDataAsync('expr/load', {calc_module: 'stage', calc_tag: 'contract', calc_id: node.id});
  3851. }
  3852. this.orgExpr = node.contract_expr;
  3853. $('#ce-expr').val(TreeExprCalc.expr2ExprStr(this.orgExpr));
  3854. }
  3855. initView(node) {
  3856. this.orgExpr = '';
  3857. this.setTargetNode(node);
  3858. $('#expr-hint').html(`${node.code || ''}${node.b_code || ''} ${node.name || ''}`);
  3859. $('#target-row').html(`(${node.code || ''}${node.b_code || ''})`);
  3860. SpreadJsObj.locateTreeNode(this.exprSheet, node.ledger_id);
  3861. SpreadJsObj.reloadRowBackColor(this.exprSheet, 0, this.exprSheet.getRowCount());
  3862. this.exprSpread.refresh();
  3863. }
  3864. }
  3865. $('a', '#anc-gcl-nav').bind('click', function(e) {
  3866. e.preventDefault();
  3867. const tab = $(this);
  3868. const showSideTab = function (show) {
  3869. const left = $('#pos-spread'), right = $('#pos-right'), parent = left.parent();
  3870. if (show) {
  3871. right.show();
  3872. autoFlashHeight();
  3873. /**
  3874. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  3875. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  3876. * 故需要通过最终的parent.width再计算一次left.width
  3877. *
  3878. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  3879. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  3880. *
  3881. */
  3882. const percent = 100 - right.outerWidth() /parent.width() * 100;
  3883. left.css('width', percent + '%');
  3884. } else {
  3885. left.width(parent.width());
  3886. right.hide();
  3887. }
  3888. };
  3889. if (!tab.hasClass('active')) {
  3890. tab.addClass('active');
  3891. showSideTab(tab.hasClass('active'));
  3892. } else {
  3893. tab.removeClass('active');
  3894. showSideTab(tab.hasClass('active'));
  3895. }
  3896. if (posSpread) posSpread.refresh();
  3897. if (ancGclSpread) ancGclSpread.refresh();
  3898. });
  3899. $.divResizer({
  3900. select: '#pos-right-spr',
  3901. callback: function () {
  3902. if (posSpread) posSpread.refresh();
  3903. if (ancGclSpread) ancGclSpread.refresh();
  3904. }
  3905. });
  3906. // $('#searchAccount').click(() => {
  3907. // const data = {
  3908. // keyword: $('#searchName').val(),
  3909. // };
  3910. // postData('/search/user', data, (data) => {
  3911. // const resultDiv = $('#searchResult');
  3912. // if (data) {
  3913. // $('h5>span', resultDiv).text(data.name);
  3914. // $('#addAuditor').attr('auditorId', data.id);
  3915. // $('h6', resultDiv).text(data.role);
  3916. // $('p', resultDiv).text(data.company);
  3917. // resultDiv.show();
  3918. // } else {
  3919. // toastr.info('未查询到该审核人');
  3920. // resultDiv.hide();
  3921. // }
  3922. // }, () => {
  3923. // $('#searchResult').hide();
  3924. // });
  3925. // });
  3926. // // 审批人分组选择
  3927. // $('#account_group').change(function () {
  3928. // let account_html = '<option value="0">选择审批人</option>';
  3929. // for (const account of accountList) {
  3930. // if (parseInt($(this).val()) === 0 || parseInt($(this).val()) === account.account_group) {
  3931. // const role = account.role !== '' ? '(' + account.role + ')' : '';
  3932. // const company = account.company !== '' ? ' -' + account.company : '';
  3933. // account_html += '<option value="' + account.id + '">' + account.name + role + company + '</option>';
  3934. // }
  3935. // }
  3936. // $('#account_list').html(account_html);
  3937. // });
  3938. let timer = null;
  3939. let oldSearchVal = null;
  3940. $('#gr-search').bind('input propertychange', function(e) {
  3941. oldSearchVal = e.target.value
  3942. timer && clearTimeout(timer)
  3943. timer = setTimeout(() => {
  3944. const newVal = $('#gr-search').val()
  3945. let html = ''
  3946. if (newVal && newVal === oldSearchVal) {
  3947. accountList.filter(item => item && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  3948. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  3949. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  3950. class="ml-auto">${item.mobile || ''}</span></p>
  3951. <span class="text-muted">${item.role || ''}</span>
  3952. </dd>`
  3953. })
  3954. $('.book-list').empty()
  3955. $('.book-list').append(html)
  3956. } else {
  3957. if (!$('.acc-btn').length) {
  3958. accountGroup.forEach((group, idx) => {
  3959. if (!group) return
  3960. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  3961. </a> ${group.groupName}</dt>
  3962. <div class="dd-content" data-toggleid="${idx}">`
  3963. group.groupList.forEach(item => {
  3964. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  3965. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  3966. class="ml-auto">${item.mobile || ''}</span></p>
  3967. <span class="text-muted">${item.role || ''}</span>
  3968. </dd>`
  3969. });
  3970. html += '</div>'
  3971. })
  3972. $('.book-list').empty()
  3973. $('.book-list').append(html)
  3974. }
  3975. }
  3976. }, 400);
  3977. });
  3978. // 添加审批流程按钮逻辑
  3979. $('.book-list').on('click', 'dt', function () {
  3980. const idx = $(this).find('.acc-btn').attr('data-groupid')
  3981. const type = $(this).find('.acc-btn').attr('data-type')
  3982. if (type === 'hide') {
  3983. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  3984. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o')
  3985. $(this).find('.acc-btn').attr('data-type', 'show')
  3986. })
  3987. } else {
  3988. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  3989. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square')
  3990. $(this).find('.acc-btn').attr('data-type', 'hide')
  3991. })
  3992. }
  3993. return false
  3994. });
  3995. // 添加到审批流程中
  3996. $('dl').on('click', 'dd', function () {
  3997. const auditorId = parseInt($(this).data('id'))
  3998. if (auditorId) {
  3999. postData('/tender/' + getTenderId() + '/ledger/audit/add', { auditorId }, (datas) => {
  4000. const html = [];
  4001. // 如果是重新上报,添加到重新上报列表中
  4002. const auditorshtml = [];
  4003. for (const [index,data] of datas.entries()) {
  4004. if (index !== 0) {
  4005. html.push('<li class="list-group-item" auditorId="' + data.audit_id + '">');
  4006. if (shenpi_status === shenpiConst.sp_status.sqspr || (shenpi_status === shenpiConst.sp_status.gdzs && index+1 !== datas.length)) {
  4007. html.push('<a href="javascript: void(0)" class="text-danger pull-right">移除</a>');
  4008. }
  4009. html.push('<span>');
  4010. html.push(data.audit_order + ' ');
  4011. html.push(data.name + ' ');
  4012. html.push('</span>');
  4013. html.push('<small class="text-muted">');
  4014. html.push(data.role);
  4015. html.push('</small></li>');
  4016. }
  4017. auditorshtml.push('<li class="list-group-item" ' + (index !== 0 ? 'data-auditorid="' + data.audit_id + '"' : '') + '>');
  4018. auditorshtml.push('<i class="fa ' + (index+1 === datas.length ? 'fa-stop-circle' : 'fa-chevron-circle-down') + '"></i> ');
  4019. auditorshtml.push(data.name + ' <small class="text-muted">' + data.role + '</small>');
  4020. if (index === 0) {
  4021. auditorshtml.push('<span class="pull-right">原报</span>');
  4022. } else if (index+1 === datas.length) {
  4023. auditorshtml.push('<span class="pull-right">终审</span>');
  4024. } else {
  4025. auditorshtml.push('<span class="pull-right">'+ transFormToChinese(index) +'审</span>');
  4026. }
  4027. auditorshtml.push('</li>');
  4028. }
  4029. $('#auditors').html(html.join(''));
  4030. $('#auditors-list').html(auditorshtml.join(''));
  4031. });
  4032. }
  4033. });
  4034. $('body').on('click', '#auditors li>a', function () {
  4035. const li = $(this).parent();
  4036. const data = {
  4037. auditorId: parseInt(li.attr('auditorId')),
  4038. };
  4039. postData('/tender/' + getTenderId() + '/ledger/audit/delete', data, (data2) => {
  4040. li.remove();
  4041. for (const a of data2) {
  4042. const aLi = $('li[auditorId=' + a.audit_id + ']');
  4043. $('span', aLi).text(a.audit_order + ' ' + a.name + ' ');
  4044. }
  4045. // 如果是重新上报
  4046. // 令最后一个图标转换
  4047. $('#auditors-list li[data-auditorid="' + data.auditorId + '"]').remove();
  4048. if ($('#auditors-list li').length !== 0 && !$('#auditors-list li i').hasClass('fa-stop-circle')) {
  4049. $('#auditors-list li').eq($('#auditors-list li').length-1).children('i')
  4050. .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  4051. }
  4052. // $('#auditors-list2 li[data-auditid="' + data.auditorId + '"]').remove();
  4053. // if ($('#auditors-list2 li').length !== 0 && !$('#auditors-list2 li i').hasClass('fa-stop-circle')) {
  4054. // $('#auditors-list2 li').eq($('#auditors-list2 li').length-1).children('i')
  4055. // .removeClass('fa-chevron-circle-down').addClass('fa-stop-circle');
  4056. // }
  4057. for (let i = 0; i < $('#auditors-list li').length; i++) {
  4058. $('#auditors-list li').eq(i).find('.pull-right').text(i === 0 ? '原报' : (i+1 === $('#auditors-list li').length ? '终' : transFormToChinese(i)) + '审')
  4059. // $('#auditors-list2 li').eq(i).find('.pull-right').text((i+1 === $('#auditors-list2 li').length ? '终' : transFormToChinese(i+1)) + '审')
  4060. }
  4061. });
  4062. });
  4063. $('#hideSp').click(function () {
  4064. $('#sp-list').modal('hide');
  4065. });
  4066. // 多层modal关闭后的滚动bug修复
  4067. $('#sp-list').on('hidden.bs.modal', function (e) {
  4068. $(document.body).addClass('modal-open');
  4069. });
  4070. // 显示层次
  4071. (function (select, sheet) {
  4072. $(select).click(function () {
  4073. const tag = $(this).attr('tag');
  4074. const tree = sheet.zh_tree;
  4075. if (!tree) return;
  4076. setTimeout(() => {
  4077. showWaitingView();
  4078. switch (tag) {
  4079. case "1":
  4080. case "2":
  4081. case "3":
  4082. case "4":
  4083. case "5":
  4084. tree.expandByLevel(parseInt(tag));
  4085. SpreadJsObj.refreshTreeRowVisible(sheet);
  4086. break;
  4087. case "last":
  4088. tree.expandByCustom(() => { return true; });
  4089. SpreadJsObj.refreshTreeRowVisible(sheet);
  4090. break;
  4091. case "leafXmj":
  4092. tree.expandToLeafXmj();
  4093. SpreadJsObj.refreshTreeRowVisible(sheet);
  4094. break;
  4095. }
  4096. closeWaitingView();
  4097. }, 100);
  4098. });
  4099. })('a[name=showLevel]', ledgerSpread.getActiveSheet());
  4100. // $('#exportLedger').click(function () {
  4101. // const data = [];
  4102. // const setting = {
  4103. // header: ['项目节编号', '清单子目号', '部位明细', '名称', '单位', '清单数量', '设计数量1', '设计数量2', '单价', '合价', '图号', '备注'],
  4104. // width: [100, 70, 70, 300, 60, 80, 80, 80, 80, 80, 100, 100],
  4105. // hAlign: ['left', 'left', 'left', 'left','center', 'right', 'right', 'right', 'right', 'right', 'left', 'left'],
  4106. // };
  4107. // for (const node of ledgerTree.nodes) {
  4108. // data.push([node.code, node.b_code, '', node.name, node.unit,
  4109. // node.quantity, node.dgn_qty1, node.dgn_qty2, node.unit_price, node.total_price,
  4110. // node.drawing_code, node.memo
  4111. // ]);
  4112. // const posRange = pos.getLedgerPos(node.id);
  4113. // if (posRange && posRange.length > 0) {
  4114. // for (const [i, p] of posRange.entries()) {
  4115. // data.push(['', '', (i + 1) + '', p.name, '',
  4116. // p.quantity, '', '', '', '',
  4117. // p.drawing_code, p.memo
  4118. // ]);
  4119. // }
  4120. // }
  4121. // }
  4122. //
  4123. // XLSXObj.exportXlsxSheet(setting, data, "台账分解.xlsx");
  4124. // });
  4125. $('#exportLedger').click(function () {
  4126. const data = [];
  4127. const setting = {
  4128. cols: [
  4129. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 100, formatter: '@'},
  4130. {title: '清单子目号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  4131. {title: '计量单元', colSpan: '1', rowSpan: '1', field: 'pos_code', hAlign: 1, width: 70, formatter: '@'},
  4132. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 300, formatter: '@'},
  4133. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@'},
  4134. {title: '签约数量', colSpan: '1', rowSpan: '1', field: 'deal_qty', hAlign: 2, width: 80, type: 'Number'},
  4135. {title: '签约金额', colSpan: '1', rowSpan: '1', field: 'deal_tp', hAlign: 2, width: 80, type: 'Number'},
  4136. {title: '清单数量', colSpan: '1', rowSpan: '1', field: 'quantity', hAlign: 2, width: 80, type: 'Number'},
  4137. {title: '设计数量1', colSpan: '1', rowSpan: '1', field: 'dgn_qty1', hAlign: 2, width: 80, type: 'Number'},
  4138. {title: '设计数量2', colSpan: '1', rowSpan: '1', field: 'dgn_qty2', hAlign: 2, width: 80, type: 'Number'},
  4139. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 80, type: 'Number'},
  4140. {title: '合价', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  4141. {title: '图号', colSpan: '1', rowSpan: '1', field: 'drawing_code', hAlign: 0, width: 100, formatter: '@'},
  4142. {title: '备注', colSpan: '1', rowSpan: '1', field: 'memo', hAlign: 0, width: 100, formatter: '@'},
  4143. ],
  4144. headRows: 1,
  4145. headRowHeight: [32],
  4146. defaultRowHeight: 21,
  4147. headerFont: 'bold 10px 微软雅黑',
  4148. font: '10px 微软雅黑'
  4149. };
  4150. const hasCl = ledgerSpreadSetting.cols.find(x => { return x.field === 'sjcl_qty'});
  4151. const qtyF = hasCl ? 'quantity' : 'sgfh_qty';
  4152. const tpF = hasCl ? 'total_price' : 'sgfh_tp';
  4153. for (const node of ledgerTree.nodes) {
  4154. data.push({
  4155. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  4156. unit_price: node.unit_price, quantity: node[qtyF], total_price: node[tpF],
  4157. deal_qty: node.deal_qty, deal_tp: node.deal_tp,
  4158. dgn_qty1: node.dgn_qty1, dgn_qty2: node.dgn_qty2,
  4159. drawing_code: node.drawing_code, memo: node.memo
  4160. });
  4161. const posRange = pos.getLedgerPos(node.id);
  4162. if (posRange && posRange.length > 0) {
  4163. for (const [i, p] of posRange.entries()) {
  4164. data.push({
  4165. pos_code: (i + 1) + '', name: p.name,
  4166. quantity: p[qtyF], drawing_code: p.drawing_code, memo: p.memo
  4167. });
  4168. }
  4169. }
  4170. }
  4171. SpreadExcelObj.exportSimpleXlsxSheet(setting, data, "台账分解.xlsx");
  4172. });
  4173. $('#sync-ledger').click(function () {
  4174. postData(syncLedgerUrl, {}, function (result) {
  4175. ledgerTree.loadDatas(result.bills);
  4176. treeCalc.calculateAll(ledgerTree);
  4177. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), 'tree', ledgerTree);
  4178. pos.loadDatas(result.pos);
  4179. posOperationObj.loadCurPosData();
  4180. ancGclObj.loadCurAncillaryGcl();
  4181. checkShowLast(result.bills.length);
  4182. });
  4183. });
  4184. const dataChecker = DataChecker({
  4185. checkUrl: window.location.pathname + '/check',
  4186. completeData: function (data) {
  4187. pos.updateDatas({update: data.source.pos});
  4188. const loadResult = ledgerTree.loadPostData({update: data.source.bills});
  4189. treeOperationObj.refreshTree(ledgerSpread.getActiveSheet(), loadResult);
  4190. posOperationObj.loadCurPosData();
  4191. ancGclObj.loadCurAncillaryGcl();
  4192. for (const e of data.error) {
  4193. e.serialNo = ledgerTree.getNodeIndex(ledgerTree.getItems(e.ledger_id)) + 1;
  4194. }
  4195. },
  4196. errorList: errorList,
  4197. });
  4198. $('[name=audit-start]').submit(function (e) {
  4199. if (checkAuditorFrom()) {
  4200. $(this).parent().parent().parent().modal('hide');
  4201. dataChecker.checkAndPost(this.action, {});
  4202. $('#hide-all').hide();
  4203. }
  4204. return false;
  4205. });
  4206. $('#ledger-check2').click(() => {
  4207. ledgerCheck2({
  4208. ledgerTree: ledgerTree,
  4209. ledgerPos: pos,
  4210. checkList: checkList,
  4211. decimal: tenderInfo.decimal,
  4212. checkOption: checkOption,
  4213. }).then(result => {
  4214. check2Viewing({
  4215. extra: ZhCalc.div(ledgerTree.datas.length + pos.datas.length, 10000, 0),
  4216. randomWait: true,
  4217. prefix: 'check2-',
  4218. checks: result,
  4219. checkList: checkList,
  4220. });
  4221. });
  4222. });
  4223. // 切换附件里节点和所有附件
  4224. $('#fujian .nav-link').on('click', function () {
  4225. const tabPanel = $(this).attr('fujian-content');
  4226. if (tabPanel !== 'syfujian') {
  4227. $('#showPage').hide();
  4228. $('#bach-download').prop('type', 'curr');
  4229. } else {
  4230. $('#showPage').show();
  4231. $('#bach-download').prop('type', 'all');
  4232. }
  4233. $('#showAttachment').hide();
  4234. });
  4235. // 上传附件
  4236. $('#upload-file-btn').click(function () {
  4237. // if (curAuditor && curAuditor.aid !== cur_uid) {
  4238. // return toastr.error('当前操作没有权限!');
  4239. // }
  4240. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  4241. if (!node) return;
  4242. const files = $('#upload-file')[0].files;
  4243. const formData = new FormData();
  4244. formData.append('lid', node.id);
  4245. for (const file of files) {
  4246. if (file === undefined) {
  4247. toastr.error('未选择上传文件!');
  4248. return false;
  4249. }
  4250. const filesize = file.size;
  4251. if (filesize > 30 * 1024 * 1024) {
  4252. toastr.error('存在上传文件大小过大!');
  4253. return false;
  4254. }
  4255. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  4256. if (whiteList && !whiteList.includes(fileext)) {
  4257. toastr.error('只能上传指定格式的附件!');
  4258. return false;
  4259. }
  4260. formData.append('size', filesize);
  4261. formData.append('file[]', file);
  4262. }
  4263. postDataWithFile('/tender/' + tender.id + '/ledger/upload/file', formData, function (data) {
  4264. $('#upload').modal('hide');
  4265. // 插入到attData中
  4266. attData = data.concat(attData);
  4267. // 重新生成List
  4268. getAllList();
  4269. getNodeList(node.id);
  4270. }, function () {
  4271. toastr.error('附件上传失败');
  4272. });
  4273. $('#upload-file').val('');
  4274. });
  4275. // 获取附件信息
  4276. $('.list-table').on('click', '.att-file-name', function () {
  4277. const fid = $(this).attr('file-id');
  4278. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  4279. return;
  4280. }
  4281. const att = attData.find(function (item) {
  4282. return item.id === parseInt(fid);
  4283. });
  4284. $('#edit-att').hide();
  4285. $('#show-att').show();
  4286. if (att !== undefined) {
  4287. // 进来先把编辑功能隐藏
  4288. $('#btn-att a').eq(3).hide()
  4289. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  4290. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4291. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  4292. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  4293. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  4294. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  4295. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  4296. $('#show-att tr').eq(3).children('td').text(att.remark);
  4297. // 附件uid等于当前用户id, 附件上传本人
  4298. if (parseInt(cur_uid) === att.uid) {
  4299. $('#btn-att').show();
  4300. const showDel = tender.ledger_status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  4301. if (showDel) $('#btn-att a').eq(3).show();
  4302. // $('#btn-att a').eq(3).show();
  4303. $('#btn-att a').eq(2).hide();
  4304. $('#btn-att a').eq(4).hide();
  4305. $('#btn-att a').eq(5).hide();
  4306. } else {
  4307. $('#btn-att').hide();
  4308. $('#btn-att a').eq(3).hide();
  4309. $('#btn-att a').eq(2).hide();
  4310. $('#btn-att a').eq(4).hide();
  4311. $('#btn-att a').eq(5).hide();
  4312. }
  4313. $('#showAttachment').attr('file-id', fid);
  4314. $('#showAttachment').show();
  4315. } else {
  4316. $('#showAttachment').hide();
  4317. $('#showAttachment').attr('file-id', '');
  4318. toastr.error('附件信息获取失败');
  4319. }
  4320. });
  4321. // $('body').on('click', '.alllist-table a', handleFileList);
  4322. $('body').on('click', '#btn-att a', function () {
  4323. const content = $(this).attr('content');
  4324. const fid = $('#showAttachment').attr('file-id');
  4325. const node = SpreadJsObj.getSelectObject(ledgerSpread.getActiveSheet());
  4326. if (content === 'edit') {
  4327. $('#btn-att a').eq(3).hide();
  4328. $('#btn-att a').eq(2).show();
  4329. $('#btn-att a').eq(4).show();
  4330. $('#btn-att a').eq(5).show();
  4331. $('#show-att').hide();
  4332. $('#edit-att').show();
  4333. const att = attData.find(function (item) {
  4334. return item.id === parseInt(fid);
  4335. });
  4336. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  4337. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  4338. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4339. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  4340. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  4341. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  4342. } else if (content === 'cancel') {
  4343. $('#show-att').show();
  4344. $('#edit-att').hide();
  4345. $('#btn-att a').eq(3).show();
  4346. $('#btn-att a').eq(2).hide();
  4347. $('#btn-att a').eq(4).hide();
  4348. $('#btn-att a').eq(5).hide();
  4349. } else if (content === 'save') {
  4350. const formData = new FormData();
  4351. formData.append('id', fid);
  4352. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  4353. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  4354. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  4355. const file = $('#change-att-btn')[0];
  4356. if (file.files[0] !== undefined) {
  4357. const filesize = file.files[0].size;
  4358. formData.append('size', filesize);
  4359. formData.append('file', file.files[0]);
  4360. }
  4361. postDataWithFile('/tender/' + tender.id + '/ledger/save/file', formData, function (data) {
  4362. // 替换到attData中
  4363. const att_index = attData.findIndex(function (item) {
  4364. return item.id === parseInt(fid);
  4365. });
  4366. attData.splice(att_index, 1, data);
  4367. // 重新生成List
  4368. getAllList(parseInt($('#currentPage').text()));
  4369. getNodeList(node.id);
  4370. $('#show-att').show();
  4371. $('#edit-att').hide();
  4372. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  4373. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  4374. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  4375. $('#show-att tr').eq(2).children('td').eq(0).text(data.username);
  4376. $('#show-att tr').eq(2).children('td').eq(1).text(data.in_time);
  4377. $('#show-att tr').eq(3).children('td').text(data.remark);
  4378. $('#btn-att a').eq(3).show();
  4379. $('#btn-att a').eq(2).hide();
  4380. $('#btn-att a').eq(4).hide();
  4381. $('#btn-att a').eq(5).hide();
  4382. }, function () {
  4383. toastr.error('附件上传失败');
  4384. });
  4385. $('#change-att-btn').val('');
  4386. } else if (content === 'del') {
  4387. const data = {id: fid};
  4388. postData('/tender/' + tender.id + '/ledger/delete/file', data, function (result) {
  4389. // 删除到attData中
  4390. const att_index = attData.findIndex(function (item) {
  4391. return item.id === parseInt(fid);
  4392. });
  4393. attData.splice(att_index, 1);
  4394. // 重新生成List
  4395. if ($('#alllist-table tr').length === 1) {
  4396. getAllList(parseInt($('#currentPage').text()) - 1);
  4397. } else {
  4398. getAllList(parseInt($('#currentPage').text()));
  4399. }
  4400. getNodeList(node.id);
  4401. $('#showAttachment').hide();
  4402. $('#showAttachment').attr('file-id', '');
  4403. });
  4404. } else if (content === 'view') {
  4405. const data = {id: fid};
  4406. postData('/tender/' + tender.id + '/ledger/check/file', data, function (result) {
  4407. const { filepath } = result
  4408. $('#load-file').attr('href', filepath);
  4409. $('#load-file')[0].click();
  4410. });
  4411. } else if (content === 'location') {
  4412. const att = attData.find(item => item.id === parseInt(fid));
  4413. if (Object.keys(att).length) {
  4414. SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), att.ledger_id, true);
  4415. posOperationObj.loadCurPosData();
  4416. ancGclObj.loadCurAncillaryGcl();
  4417. }
  4418. }
  4419. });
  4420. // 替换附件
  4421. $('#change-att-btn').on('change', function () {
  4422. const file = $('#change-att-btn')[0].files[0];
  4423. const name = file.name;
  4424. const filename = name.substring(0, name.lastIndexOf("."));
  4425. const fileext = name.substr(name.indexOf("."));
  4426. const filesize = file.size;
  4427. if (filesize > 30 * 1024 * 1024) {
  4428. toastr.error('文件大小过大!');
  4429. $('#change-att-btn').val('');
  4430. return false;
  4431. }
  4432. if (whiteList && !whiteList.includes(fileext)) {
  4433. toastr.error('只能上传指定格式的附件!');
  4434. $('#change-att-btn').val('');
  4435. return false;
  4436. }
  4437. $('#edit-att .form-group').eq(0).find('input').val(filename);
  4438. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  4439. });
  4440. // 切换页数
  4441. $('.page-select').on('click', function () {
  4442. const totalPageNum = parseInt($('#totalPage').text());
  4443. const lastPageNum = parseInt($('#currentPage').text());
  4444. const status = $(this).attr('content');
  4445. if (status === 'pre' && lastPageNum > 1) {
  4446. getAllList(lastPageNum-1);
  4447. $('#showAttachment').hide();
  4448. $('#syfujian .check-all-file').prop('checked', false)
  4449. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4450. getAllList(lastPageNum+1);
  4451. $('#showAttachment').hide();
  4452. $('#syfujian .check-all-file').prop('checked', false)
  4453. }
  4454. });
  4455. // 批量下载
  4456. $('#bach-download').click(function() {
  4457. const fileIds = [];
  4458. const type = $(this).attr('type');
  4459. let node = ''
  4460. if (type === 'curr') {
  4461. node = '#nodelist-table .check-file:checked'
  4462. } else {
  4463. node = '#alllist-table .check-file:checked'
  4464. }
  4465. $(node).each(function() {
  4466. const fileId = $(this).attr('file-id');
  4467. fileId && fileIds.push(fileId);
  4468. });
  4469. if (fileIds.length) {
  4470. if (fileIds.length > 20) {
  4471. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  4472. }
  4473. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  4474. $(this).attr('disabled', "true")
  4475. const btn = $(this);
  4476. const fileArr = [];
  4477. for (const id of fileIds) {
  4478. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  4479. fileArr.push({
  4480. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  4481. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  4482. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  4483. });
  4484. }
  4485. const packageName = `${tender.name}-台账分解-附件.zip`;
  4486. try {
  4487. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  4488. } catch (e) {
  4489. btn.removeAttr('disabled');
  4490. toastr.clear();
  4491. toastr.error('批量下载失败');
  4492. }
  4493. // postCompressFile(`/tender/${tender.id}/ledger/compresse/file`, {fileIds}, function(result) {
  4494. // toastr.clear()
  4495. // toastr.success('压缩文件成功')
  4496. // btn.removeAttr('disabled')
  4497. // const href = window.URL.createObjectURL(result)
  4498. // $('#zipDown').attr('href', href);
  4499. // $('#zipDown').attr('download', `${tender.name}-台账分解-附件.zip`);
  4500. // $("#zipDown")[0].click();
  4501. // }, () => {
  4502. // btn.removeAttr('disabled')
  4503. // toastr.clear()
  4504. // toastr.error('批量下载失败')
  4505. // });
  4506. // const url = `/tender/${tender.id}/ledger/compresse/file?fileIds=${JSON.stringify(fileIds)}`;
  4507. }
  4508. });
  4509. // 监听附件check是否选中
  4510. $('.list-table').on('click', '.check-file', function() {
  4511. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  4512. const childs = $(this).parents('.list-table').children().length;
  4513. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  4514. if (checkedList.length === childs) {
  4515. checkBox.prop("checked", true);
  4516. } else {
  4517. checkBox.prop("checked", false);
  4518. }
  4519. });
  4520. $('.check-all-file').click(function() {
  4521. const isCheck = $(this).is(':checked');
  4522. $(this).parents('table').find('.list-table').each(function() {
  4523. $(this).find('input:checkbox').prop("checked", isCheck);
  4524. })
  4525. });
  4526. });
  4527. // 生成当前节点列表
  4528. function getNodeList(node) {
  4529. let html = '';
  4530. for(const att of attData) {
  4531. if (node === att.lid) {
  4532. // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  4533. html += `<tr>
  4534. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  4535. <td>
  4536. <div class="d-flex">
  4537. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  4538. <a href="/tender/${tender.id}/ledger/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  4539. </div>
  4540. </td><td>${att.username}</td></tr>`
  4541. }
  4542. }
  4543. $('#nodelist-table').html(html);
  4544. $('#nodelist-table').on('click', 'tr', function() {
  4545. $('#nodelist-table tr').removeClass('bg-light')
  4546. $(this).addClass('bg-light')
  4547. })
  4548. }
  4549. // 生成所有附件列表
  4550. function getAllList(currPageNum = 1) {
  4551. // 每页最多几个附件
  4552. const pageCount = 20;
  4553. // 附件总数
  4554. const total = attData.length;
  4555. // 总页数
  4556. const pageNum = Math.ceil(total/pageCount);
  4557. $('#totalPage').text(pageNum);
  4558. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  4559. // 当前页附件内容
  4560. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  4561. currPageFileData = currPageAttData;
  4562. let html = '';
  4563. for(const att of currPageAttData) {
  4564. html += `<tr>
  4565. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  4566. <td>
  4567. <div class="d-flex">
  4568. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  4569. <a href="/tender/${tender.id}/ledger/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  4570. </div>
  4571. </td><td>${att.username}</td></tr>`
  4572. }
  4573. $('#alllist-table').html(html);
  4574. $('#alllist-table').on('click', 'tr', function() {
  4575. $('#alllist-table tr').removeClass('bg-light')
  4576. $(this).addClass('bg-light')
  4577. })
  4578. }
  4579. // 检查上报情况
  4580. function checkAuditorFrom () {
  4581. if ($('#auditors li').length === 0) {
  4582. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  4583. toastr.error('请联系管理员添加审批人');
  4584. } else {
  4585. toastr.error('请先选择审批人,再上报数据');
  4586. }
  4587. return false;
  4588. } else {
  4589. $('#hide-all').show();
  4590. return true;
  4591. }
  4592. }
  4593. // texterea换行
  4594. function auditCheck(i) {
  4595. const opinion = $('textarea[name="opinion"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  4596. $('textarea[name="opinion"]').eq(i).val(opinion);
  4597. return true;
  4598. }