change_revise.js 311 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/revise-billsSelect';
  10. const invalidFields = {
  11. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price', 'ex_qty1', 'ex_tp1'],
  12. gcl: ['dgn_qty1', 'dgn_qty2'],
  13. posCode: ['b_code'],
  14. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'ex_qty1', 'ex_tp1'],
  15. posXmj: ['code'],
  16. };
  17. function getExprInfo (field, converse = false) {
  18. const exprField = [
  19. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  20. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  21. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  22. ];
  23. return converse ? _.find(exprField, {expr: field}) : _.find(exprField, {qty: field});
  24. }
  25. function transExpr(expr) {
  26. return $.trim(expr).replace('\t', '').replace('=', '').replace(new RegExp('%', 'gm'), '/100');
  27. }
  28. const copyBlockTag = 'zh.calc.copyBlock';
  29. const dskCompilation = 'zh.calc.dskCompilation';
  30. const checkOption = {
  31. sibling: { enable: 1 },
  32. empty_code: { enable: 1 },
  33. calc: {
  34. enable: 1,
  35. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  36. },
  37. zero: { enable: 1 },
  38. zeroPos: { enable: 1 },
  39. tp: {
  40. enable: 1,
  41. fields: [
  42. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  43. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  44. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  45. {qty: 'quantity', tp: 'total_price'},
  46. {qty: 'deal_qty', tp: 'deal_tp'},
  47. ],
  48. },
  49. same_code: { enable: 1 },
  50. same_bills: { enable: 1 },
  51. };
  52. $(document).ready(() => {
  53. let stdXmj, stdGcl, searchLedger;
  54. let changeGclData = false;
  55. autoFlashHeight();
  56. billsSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', });
  57. const billsIndex = _.findIndex(billsSpreadSetting.cols, { field: 'drawing_code' }) !== -1 ? _.findIndex(billsSpreadSetting.cols, { field: 'drawing_code' }) : (_.findIndex(billsSpreadSetting.cols, { field: 'ex_tp1' }) !== -1 ? _.findIndex(billsSpreadSetting.cols, { field: 'ex_tp1' }) + 1 : billsSpreadSetting.cols.length - 1);
  58. billsSpreadSetting.cols.splice(billsIndex, 0, { title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isValuation', getValue: 'getValue.isValuation' });
  59. billsSpreadSetting.cols.splice(billsIndex + 1, 0, {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, readOnly: 'readOnly.isSettle', getValue: 'getValue.camount'},);
  60. billsSpreadSetting.cols.splice(billsIndex + 2, 0, {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},);
  61. if (!billsSpreadSetting.readOnly) {
  62. for (const col of billsSpreadSetting.cols) {
  63. if (!col.readOnly || col.readOnly === false)
  64. col.readOnly = 'readOnly.isChangeAdd';
  65. }
  66. }
  67. posSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', getValue: 'getValue.isChange' });
  68. const posIndex = _.findIndex(posSpreadSetting.cols, { field: 'drawing_code' }) !== -1 ? _.findIndex(posSpreadSetting.cols, { field: 'drawing_code' }) : posSpreadSetting.cols.length;
  69. posSpreadSetting.cols.splice(posIndex, 0, { title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isValuation', getValue: 'getValue.isValuation' });
  70. posSpreadSetting.cols.splice(posIndex + 1, 0, {title: '申请变更增(+)减(-)|数量', colSpan: '1|1', rowSpan: '|1', field: 'camount', hAlign: 2, width: 120, readOnly: 'readOnly.isSettle', getValue: 'getValue.camount'},);
  71. if (!posSpreadSetting.readOnly) {
  72. for (const col of posSpreadSetting.cols) {
  73. if (!col.readOnly || col.readOnly === false)
  74. col.readOnly = 'readOnly.isChangeAdd';
  75. }
  76. }
  77. const billsCol = {
  78. getValue: {
  79. isChange: function (data) {
  80. if (!data) return 0;
  81. if (!data.name) return 0;
  82. const cInfo = _.find(changeList, { gcl_id: data.id, mx_id: '' });
  83. return cInfo ? 1 : 0;
  84. },
  85. isValuation: function (data) {
  86. if (!data) return 0;
  87. if (!data.name) return 0;
  88. const cList = _.filter(changeList, { gcl_id: data.id });
  89. if (cList.length === 0) return 0;
  90. return _.find(cList, { is_valuation: 0 }) ? 0 : 1;
  91. },
  92. camount: function (data) {
  93. const cInfo = _.find(changeList, {gcl_id: data.id, mx_id: ''});
  94. return cInfo ? ZhCalc.round(cInfo.camount, findDecimal(data.unit)) : ZhCalc.round(data.camount, findDecimal(data.unit));
  95. }
  96. },
  97. readOnly: {
  98. isChangeAdd: function (data) {
  99. return !readOnly && !data.formc;
  100. },
  101. isChangeList: function (data) {
  102. if (!data) return true;
  103. let edit = !readOnly && !(data.is_leaf && data.b_code);
  104. if (!edit && data.id) {
  105. const lPos = pos.getLedgerPos(data.id);
  106. if (lPos && lPos.length > 0) {
  107. edit = true;
  108. }
  109. }
  110. return edit;
  111. },
  112. isValuation: function (data) {
  113. if (!data) return true;
  114. return !readOnly && !(data && data.name && _.findIndex(changeList, { gcl_id: data.id, mx_id: '' }) !== -1);
  115. },
  116. isSettle: function (data) {
  117. if (!data) return true;
  118. return !readOnly && !(!billsCol.readOnly.isChangeList(data) && (!data.settle_status || (data.settle_status && data.settle_status !== settleStatus.finish)));
  119. }
  120. }
  121. };
  122. const posCol = {
  123. getValue: {
  124. isChange: function (data) {
  125. if (!data) return 0;
  126. if (!data.name) return 0;
  127. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  128. return cInfo ? 1 : 0;
  129. },
  130. isValuation: function (data) {
  131. if (!data) return 0;
  132. if (!data.name) return 0;
  133. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  134. return cInfo ? cInfo.is_valuation : 0;
  135. },
  136. camount: function (data) {
  137. if (!data) return '';
  138. if (!data.name) return '';
  139. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  140. return cInfo ? ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit)) : '';
  141. }
  142. },
  143. readOnly: {
  144. isChangeAdd: function (data) {
  145. return !readOnly && !data.formc && (!data.settle_status || (data.settle_status && data.settle_status === settleStatus.finish));
  146. },
  147. isChangeList: function (data) {
  148. if (!data) return true;
  149. // console.log(data.name);
  150. return !readOnly && !data.name;
  151. },
  152. isValuation: function (data) {
  153. if (!data) return true;
  154. return !readOnly && !posCol.getValue.isChange(data);
  155. },
  156. isSettle: function (data) {
  157. if (!data) return true;
  158. return !readOnly && !(!posCol.readOnly.isChangeList(data) && (!data.settle_status || (data.settle_status && data.settle_status !== settleStatus.finish)));
  159. }
  160. }
  161. };
  162. console.log(posSpreadSetting);
  163. // 判断是否是已结算清单
  164. function checkIsSettle(data) {
  165. const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
  166. if (info && info.settle_status && info.settle_status === settleStatus.finish) {
  167. return true;
  168. }
  169. return false;
  170. }
  171. // 初始化spread
  172. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  173. const billsSheet = billsSpread.getActiveSheet();
  174. billsSpreadSetting.rowHeader = [
  175. {
  176. rowHeaderType: 'circle',
  177. setting: {
  178. size: 5,
  179. indent: 16,
  180. getColor: function (index, data) {
  181. if (!data) return;
  182. if(!data.formc && !data.cid) return;
  183. return '#dc3545';
  184. }
  185. },
  186. },
  187. ];
  188. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  189. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  190. return spreadColor.stage.settle;
  191. }
  192. if (data && data.is_change) {
  193. return '#c3e6cb';
  194. }
  195. return defaultColor;
  196. };
  197. billsSpreadSetting.localCache = {
  198. key: 'changes-ledger-spread',
  199. colWidth: true,
  200. };
  201. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  202. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  203. sjsSettingObj.setNodeTypeCol(billsSpreadSetting.cols, [{field: 'node_type'}]);
  204. SpreadJsObj.initSpreadSettingEvents(billsSpreadSetting, billsCol);
  205. if (billsSpreadSetting.frozenColCount) billsSpreadSetting.frozenColCount = billsSpreadSetting.frozenColCount + 1;
  206. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  207. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  208. const posSheet = posSpread.getActiveSheet();
  209. posSpreadSetting.rowHeader = [
  210. {
  211. rowHeaderType: 'circle',
  212. setting: {
  213. size: 5,
  214. indent: 16,
  215. getColor: function (index, data) {
  216. if (!data) return;
  217. if(!data.formc) return;
  218. return '#dc3545';
  219. }
  220. },
  221. },
  222. ];
  223. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  224. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  225. return spreadColor.stage.settle;
  226. }
  227. return defaultColor;
  228. };
  229. posSpreadSetting.localCache = {
  230. key: 'changes-pos-spread',
  231. colWidth: true,
  232. };
  233. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  234. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  235. SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  236. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  237. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  238. const errorList = $.cs_errorList({
  239. tabSelector: '#error-list-tab',
  240. selector: '#error-list',
  241. relaSpread: billsSpread,
  242. storeKey: 'change-revise-error-' + window.location.pathname.split('/')[2],
  243. afterLocated: function () {
  244. posSpreadObj.loadCurPosData();
  245. },
  246. afterShow: function () {
  247. billsSpread.refresh();
  248. if (posSpread) posSpread.refresh();
  249. },
  250. });
  251. const checkList = $.ledger_checkList({
  252. id: 'check-list',
  253. tabSelector: '#check-list-tab',
  254. selector: '#check-list',
  255. relaSpread: billsSpread,
  256. storeKey: 'change-revise-check-' + window.location.pathname.split('/')[2],
  257. checkType: getCheckType(checkOption),
  258. afterLocated: function () {
  259. posSpreadObj.loadCurPosData();
  260. },
  261. afterShow: function () {
  262. billsSpread.refresh();
  263. if (posSpread) posSpread.refresh();
  264. },
  265. });
  266. const sumLoadMiss = $.sumLoadMiss({
  267. tabSelector: '#sum-load-miss-tab',
  268. selector: '#sum-load-miss',
  269. relaSpread: billsSpread,
  270. storeKey: 'change-revise-slm-' + window.location.pathname.split('/')[2],
  271. id: 'revise-slm',
  272. afterLocated: function () {
  273. posSpreadObj.loadCurPosData();
  274. },
  275. afterShow: function () {
  276. billsSpread.refresh();
  277. if (posSpread) posSpread.refresh();
  278. },
  279. });
  280. // 初始化 节点树结构
  281. const treeSetting = {
  282. id: 'ledger_id',
  283. pid: 'ledger_pid',
  284. order: 'order',
  285. level: 'level',
  286. rootId: -1,
  287. keys: ['id', 'tender_id', 'ledger_id'],
  288. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price', 'ca_tp', 'ex_tp1'],
  289. autoExpand: 3,
  290. markExpandKey: 'change-bills-expand',
  291. markExpandSubKey: window.location.pathname.split('/')[2],
  292. };
  293. if (!isTz) {
  294. treeSetting.calcFields.push('deal_tp');
  295. }
  296. treeSetting.calcFun = function (node) {
  297. if (node && node.b_code && node.is_leaf) {
  298. const posData = pos.getLedgerPos(node.id) || [];
  299. let camount = ZhCalc.round(node.camount, findDecimal(node.unit)) || 0;
  300. if (posData.length > 0) {
  301. let sgfh_qty = 0;
  302. let sjcl_qty = 0;
  303. let qtcl_qty = 0;
  304. let ex_qty1 = 0;
  305. camount = 0;
  306. for (const np of posData) {
  307. sgfh_qty = ZhCalc.add(sgfh_qty, np.sgfh_qty);
  308. sjcl_qty = ZhCalc.add(sjcl_qty, np.sjcl_qty);
  309. qtcl_qty = ZhCalc.add(qtcl_qty, np.qtcl_qty);
  310. ex_qty1 = ZhCalc.add(ex_qty1, np.ex_qty1);
  311. const cInfo = _.find(changeList, { gcl_id: np.lid, mx_id: np.id });
  312. camount = cInfo ? ZhCalc.add(camount, ZhCalc.round(cInfo.camount, findDecimal(node.unit))) : camount;
  313. }
  314. if (!_.isEqual(node.sgfh_qty, sgfh_qty) || !_.isEqual(node.sjcl_qty, sjcl_qty) || !_.isEqual(node.qtcl_qty, qtcl_qty)) {
  315. node.sgfh_qty = sgfh_qty;
  316. node.sjcl_qty = sjcl_qty;
  317. node.qtcl_qty = qtcl_qty;
  318. node.ex_qty1 = ex_qty1;
  319. node.quantity = ZhCalc.sum([node.sgfh_qty, node.sjcl_qty, node.qtcl_qty]);
  320. node.sgfh_tp = ZhCalc.mul(sgfh_qty, node.unit_price, decimal.tp) || 0;
  321. node.sjcl_tp = ZhCalc.mul(sjcl_qty, node.unit_price, decimal.tp) || 0;
  322. node.qtcl_tp = ZhCalc.mul(qtcl_qty, node.unit_price, decimal.tp) || 0;
  323. node.total_price = ZhCalc.mul(node.quantity, node.unit_price, decimal.tp) || 0;
  324. }
  325. if (!_.isEqual(node.ex_qty1, ex_qty1)) {
  326. node.ex_qty1 = ex_qty1;
  327. node.ex_tp1 = ZhCalc.mul(node.ex_qty1, node.unit_price, decimal.tp) || 0;
  328. }
  329. }
  330. node.camount = camount;
  331. node.ca_tp = ZhCalc.mul(camount, node.unit_price, decimal.tp) || 0;
  332. }
  333. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  334. };
  335. const billsTree = createNewPathTree('revise', treeSetting);
  336. console.log(billsTree, treeSetting);
  337. // 初始化 计量单元
  338. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  339. // 清单 相关方法&绑定spreadjs事件
  340. const billsTreeSpreadObj = {
  341. loadExprToInput(sheet) {
  342. const sel = sheet.getSelections()[0];
  343. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  344. if (col && col.field === 'camount') {
  345. const data = SpreadJsObj.getSelectObject(sheet);
  346. if (data) {
  347. const cInfo = _.find(changeList, { gcl_id: data.id, mx_id: '' });
  348. if (!cInfo) {
  349. if (billsCol.readOnly.isChangeList(data)) {
  350. $('#bills-expr').val('').attr('readOnly', true);
  351. $('#bills-expr').removeAttr('data-row');
  352. } else {
  353. $('#bills-expr').val('').attr('field', col.field).attr('org', '')
  354. .attr('readOnly', false).attr('data-row', sel.row);
  355. }
  356. } else {
  357. const value = cInfo.camount_expr ? cInfo.camount_expr : ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit));
  358. $('#bills-expr').val(value).attr('field', col.field).attr('org', ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit)))
  359. .attr('readOnly', billsCol.readOnly.isSettle(data)).attr('data-row', sel.row);
  360. }
  361. } else {
  362. $('#bills-expr').val('').attr('readOnly', true);
  363. $('#bills-expr').removeAttr('data-row');
  364. }
  365. } else if (col && col.type === 'Number') {
  366. const data = SpreadJsObj.getSelectObject(sheet);
  367. if (data) {
  368. const exprInfo = getExprInfo(col.field);
  369. if (exprInfo) {
  370. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  371. .attr('field', col.field).attr('org', data[col.field]);
  372. } else {
  373. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  374. }
  375. if (col.field.indexOf('dgn') >= 0) {
  376. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== '') || !data.formc);
  377. } else if (col.field === 'unit_price') {
  378. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true) || !data.formc);
  379. } else {
  380. const nodePos = pos.getLedgerPos(data.id);
  381. if (nodePos && nodePos.length > 0) {
  382. $('#bills-expr').val('').attr('readOnly', true);
  383. $('#bills-expr').removeAttr('data-row');
  384. } else {
  385. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || !data.formc);
  386. }
  387. }
  388. $('#bills-expr').attr('data-row', sel.row);
  389. } else {
  390. $('#bills-expr').val('').attr('readOnly', true);
  391. $('#bills-expr').removeAttr('data-row');
  392. }
  393. } else {
  394. $('#bills-expr').val('').attr('readOnly', true);
  395. $('#bills-expr').removeAttr('data-row');
  396. }
  397. },
  398. getDefaultSelectInfo: function (sheet) {
  399. const tree = sheet.zh_tree;
  400. if (!tree) return;
  401. const sel = sheet.getSelections()[0];
  402. const node = sheet.zh_tree.nodes[sel.row];
  403. if (!node) return;
  404. let count = 1;
  405. if (sel.rowCount > 1) {
  406. for (let r = 1; r < sel.rowCount; r++) {
  407. const rNode = sheet.zh_tree.nodes[sel.row + r];
  408. if (rNode.level > node.level) continue;
  409. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  410. toastr.warning('请选择同一节点下的节点,进行该操作');
  411. return;
  412. }
  413. count += 1;
  414. }
  415. }
  416. return [tree, node, count];
  417. },
  418. /**
  419. * 刷新顶部按钮是否可用
  420. * @param sheet
  421. * @param selections
  422. */
  423. refreshOperationValid: function (sheet, selection) {
  424. const setObjEnable = function (obj, enable) {
  425. if (enable) {
  426. obj.removeClass('disabled');
  427. } else {
  428. obj.addClass('disabled');
  429. }
  430. };
  431. const invalidAll = function () {
  432. setObjEnable($('a[name=base-opr][type=add]'), false);
  433. setObjEnable($('a[name=base-opr][type=delete]'), false);
  434. setObjEnable($('a[name=base-opr][type=up-move]'), false);
  435. setObjEnable($('a[name=base-opr][type=down-move]'), false);
  436. setObjEnable($('a[name=base-opr][type=up-level]'), false);
  437. setObjEnable($('a[name=base-opr][type=down-level]'), false);
  438. };
  439. const sel = selection ? selection[0] : sheet.getSelections()[0];
  440. const row = sel ? sel.row : -1;
  441. const tree = sheet.zh_tree;
  442. if (!tree) {
  443. invalidAll();
  444. return;
  445. }
  446. const first = sheet.zh_tree.nodes[row];
  447. if (!first) {
  448. invalidAll();
  449. return;
  450. }
  451. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  452. if (sel.rowCount > 1 && first) {
  453. for (let r = 1; r < sel.rowCount; r++) {
  454. const rNode = tree.nodes[sel.row + r];
  455. if (!rNode) {
  456. sameParent = false;
  457. break;
  458. }
  459. if (!rNode.formc) {
  460. sameParent = false;
  461. break;
  462. }
  463. nodeUsed = nodeUsed || rNode.used;
  464. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  465. if (rNode.level > first.level) continue;
  466. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  467. sameParent = false;
  468. break;
  469. }
  470. last = rNode;
  471. }
  472. }
  473. const preNode = tree.getPreSiblingNode(first);
  474. const siblings = tree.getChildren(tree.getParent(first));
  475. let upPower = true;
  476. for (let order = last.order; order < siblings.length - 1; order ++) {
  477. if (!siblings[order].formc) {
  478. upPower = false;
  479. break;
  480. }
  481. }
  482. const valid = !sheet.zh_setting.readOnly;
  483. setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  484. setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed && first.formc && !settleFinish);
  485. setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode && first.formc);
  486. setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last) && first.formc);
  487. const posRange = last ? pos.getLedgerPos(last.id) : [];
  488. setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  489. && first.level > 2 && ((!posRange || posRange.length === 0) || last.settle_status !== settleStatus.finish || tree.isLastSibling(last)) && upPower && first.formc);
  490. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  491. setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
  492. && first.level > 1 && preNode && (preNode.children.length > 0 || (preNode.children.length === 0 && preNode.formc && (!preNodePosRange || preNodePosRange.length === 0))) && !preNode.used && first.formc && preNode.settle_status !== settleStatus.finish);
  493. setObjEnable($('#cut'), valid);
  494. setObjEnable($('#paste'), valid);
  495. },
  496. /**
  497. *
  498. * @param sheet
  499. * @param data
  500. */
  501. refreshTree: function (sheet, data) {
  502. SpreadJsObj.massOperationSheet(sheet, function () {
  503. const tree = sheet.zh_tree;
  504. // 处理删除
  505. if (data.delete) {
  506. data.delete.sort(function (a, b) {
  507. return b.deleteIndex - a.deleteIndex;
  508. });
  509. for (const d of data.delete) {
  510. sheet.deleteRows(d.deleteIndex, 1);
  511. }
  512. }
  513. // 处理新增
  514. if (data.create) {
  515. const newNodes = data.create;
  516. if (newNodes) {
  517. newNodes.sort(function (a, b) {
  518. return a.index - b.index;
  519. });
  520. for (const node of newNodes) {
  521. sheet.addRows(node.index, 1);
  522. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  523. }
  524. }
  525. }
  526. // 处理更新
  527. if (data.update) {
  528. const rows = [];
  529. for (const u of data.update) {
  530. rows.push(tree.nodes.indexOf(u));
  531. }
  532. SpreadJsObj.reLoadRowsData(sheet, rows);
  533. }
  534. // 处理展开
  535. if (data.expand) {
  536. const expanded = [];
  537. for (const e of data.expand) {
  538. if (expanded.indexOf(e) === -1) {
  539. const posterity = tree.getPosterity(e);
  540. for (const p of posterity) {
  541. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  542. expanded.push(p);
  543. }
  544. }
  545. }
  546. }
  547. });
  548. },
  549. selectionChanged: function (e, info) {
  550. if (info.newSelections) {
  551. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  552. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  553. billsTreeSpreadObj.refreshPosData();
  554. }
  555. }
  556. billsTreeSpreadObj.loadExprToInput(info.sheet);
  557. },
  558. refreshPosData: function() {
  559. SpreadJsObj.resetTopAndSelect(posSheet);
  560. posSpreadObj.loadCurPosData();
  561. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  562. posSearch.search($('#pos-keyword').val());
  563. },
  564. /**
  565. * 新增节点
  566. * @param spread
  567. */
  568. baseOpr: function (sheet, type, addCount = 1) {
  569. const self = this;
  570. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  571. if (!tree || !node || !count) return;
  572. if (type === 'delete') {
  573. const parent = tree.getParent(node);
  574. const children = parent ? parent.children : tree.children;
  575. const index = children.indexOf(node);
  576. for (let i = 0; i < count; i++) {
  577. const child = children[i+index];
  578. if (tree.checkNodeUsed(child, pos)) {
  579. toastr.warning('选中的节点已计量,不可删除');
  580. return;
  581. }
  582. if (child.settle_status === settleStatus.finish) {
  583. toastr.warning('选中的节点已结算,不可删除');
  584. return;
  585. }
  586. }
  587. } else if (type === 'up-level') {
  588. const parent = tree.getParent(node);
  589. const children = parent ? parent.children : tree.children;
  590. const index = children.indexOf(node);
  591. const lastSelect = children[index + count - 1];
  592. if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) {
  593. toastr.warning('选中的节点已计量,不可升级');
  594. return;
  595. }
  596. if (lastSelect.settle_status === settleStatus.finish && (children.length > index + count)) {
  597. toastr.warning('选中的节点已结算,不可升级');
  598. return;
  599. }
  600. // for (let i = index; i < children.length; i++) {
  601. // const child = children[index];
  602. // if (tree.checkNodeUsed(child, pos)) {
  603. // if (i >= index + count) {
  604. // toastr.warning('其后节点已计量,选中的节点不可升级');
  605. // } else {
  606. // toastr.warning('选中的节点已计量,不可升级');
  607. // }
  608. // return;
  609. // }
  610. // }
  611. } else if (type === 'down-level') {
  612. const parent = tree.getParent(node);
  613. const children = parent ? parent.children : tree.children;
  614. const index = children.indexOf(node);
  615. if (index > 0 && children[index-1].used) {
  616. toastr.warning('其前节点已计量,选中的节点不可降级');
  617. return;
  618. }
  619. if (index > 0 && children[index-1].settle_status === settleStatus.finish) {
  620. toastr.warning('其前节点已结算,选中的节点不可降级');
  621. return;
  622. }
  623. for (let i = index; i < count; i++) {
  624. const child = children[i+index];
  625. if (tree.checkNodeUsed(child, pos)) {
  626. toastr.warning('选中的节点已计量,不可降级');
  627. return;
  628. }
  629. if (tree.settle_status === settleStatus.finish) {
  630. toastr.warning('选中的节点已结算,不可降级');
  631. return;
  632. }
  633. }
  634. } else if (type === 'add') {
  635. if (node.settle_status === settleStatus.finish) {
  636. toastr.warning('选中的节点已结算,不可新增子项');
  637. return;
  638. }
  639. }
  640. if (type === 'delete') {
  641. deleteAfterHint(function () {
  642. postData(window.location.pathname + '/update', {
  643. postType: type,
  644. postData: {
  645. id: node.ledger_id,
  646. count: type === 'add' ? addCount : count,
  647. }
  648. }, function (result) {
  649. changeList = result.changeList;
  650. const refreshData = tree.loadPostData(result);
  651. self.refreshTree(sheet, refreshData);
  652. const sel = sheet.getSelections()[0];
  653. if (sel) {
  654. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  655. billsTreeSpreadObj.refreshPosData();
  656. }
  657. self.refreshOperationValid(sheet);
  658. changeGclData = true;
  659. });
  660. });
  661. } else {
  662. postData(window.location.pathname + '/update', {
  663. postType: type,
  664. postData: {
  665. id: node.ledger_id,
  666. count: type === 'add' ? addCount : count,
  667. }
  668. }, function (result) {
  669. changeList = result.changeList;
  670. const refreshData = tree.loadPostData(result);
  671. self.refreshTree(sheet, refreshData);
  672. if (['up-move', 'down-move'].indexOf(type) > -1) {
  673. const sel = sheet.getSelections()[0];
  674. if (sel) {
  675. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  676. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  677. }
  678. } else if (type === 'add') {
  679. const sel = sheet.getSelections()[0];
  680. if (sel) {
  681. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  682. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
  683. billsTreeSpreadObj.refreshPosData();
  684. }
  685. }
  686. self.refreshOperationValid(sheet);
  687. changeGclData = true;
  688. });
  689. }
  690. },
  691. buttonClicked: function (e, info, v) {
  692. if (info.sheet.zh_setting) {
  693. const select = SpreadJsObj.getSelectObject(info.sheet);
  694. const col = info.sheet.zh_setting.cols[info.col];
  695. if (col.field === 'is_change') {
  696. if (billsCol.readOnly.isChangeList(select)) {
  697. return
  698. }
  699. if (info.sheet.isEditing()) {
  700. info.sheet.endEdit(true);
  701. }
  702. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  703. if (is_change) {
  704. makeGclGatherData();
  705. const gclInfo = _.find(gclGatherData, function (item) {
  706. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
  707. });
  708. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  709. return item.gcl_id === select.id;
  710. });
  711. const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
  712. const data = {
  713. lid: gclInfo.leafXmjs[0].gcl_id || select.id,
  714. code: gclInfo.b_code,
  715. name: gclInfo.name || '',
  716. unit: gclInfo.unit || '',
  717. unit_price: gclInfo.unit_price,
  718. oamount: xmjInfo.quantity,
  719. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  720. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  721. xmj_code: xmjInfo.code || '',
  722. xmj_jldy: xmjInfo.jldy || '',
  723. xmj_dwgc: xmjInfo.dwgc || '',
  724. xmj_fbgc: xmjInfo.fbgc || '',
  725. xmj_fxgc: xmjInfo.fxgc || '',
  726. gcl_id: select.id,
  727. mx_id: '',
  728. };
  729. if (oldCInfo) {
  730. data.detail = oldCInfo.detail;
  731. data.camount = oldCInfo.camount;
  732. data.camount_expr = oldCInfo.camount_expr;
  733. data.spamount = oldCInfo.spamount;
  734. data.is_valuation = oldCInfo.is_valuation;
  735. data.delimit = oldCInfo.delimit;
  736. }
  737. // 更新至服务器
  738. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  739. changeList = result.changeList;
  740. select.is_change = 1;
  741. select.is_valuation = data.is_valuation !== undefined ? data.is_valuation : 1;
  742. if (oldCInfo) {
  743. select.camount = data.camount;
  744. const refreshNode = billsTree.loadPostData({ update: [select] });
  745. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  746. }
  747. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  748. }, function () {
  749. info.sheet.setValue(info.row, info.col, 0);
  750. });
  751. } else {
  752. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.id }) !== -1) {
  753. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  754. info.sheet.setValue(info.row, info.col, 1);
  755. return
  756. }
  757. const cInfo = _.find(changeList, { gcl_id: select.id });
  758. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  759. toastr.warning('该清单计量单元已被使用,无法取消勾选');
  760. info.sheet.setValue(info.row, info.col, 1);
  761. return
  762. } else if (checkIsSettle(cInfo)) {
  763. toastr.warning('该清单计量单元已结算,无法取消勾选');
  764. info.sheet.setValue(info.row, info.col, 1);
  765. return
  766. } else {
  767. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  768. changeList = result.changeList;
  769. select.is_change = 0;
  770. select.is_valuation = 0;
  771. select.camount = null;
  772. const billsNode = select;
  773. billsTreeSpreadObj.reCalcCamount(billsNode);
  774. const loadResult = { update: [billsNode] };
  775. const refreshNode = billsTree.loadPostData(loadResult);
  776. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  777. // 重算申请数量金额
  778. // const refreshNode = billsTree.loadPostData(result);
  779. // billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  780. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  781. }, function () {
  782. info.sheet.setValue(info.row, info.col, 1);
  783. });
  784. }
  785. }
  786. } else if (col.field === 'is_valuation') {
  787. if (billsCol.readOnly.isChangeList(select)) {
  788. return;
  789. }
  790. if (!billsCol.getValue.isChange(select)) {
  791. toastr.warning('请先勾选变更清单才能勾选计价');
  792. info.sheet.setValue(info.row, info.col, 0);
  793. return;
  794. }
  795. if (info.sheet.isEditing()) {
  796. info.sheet.endEdit(true);
  797. }
  798. const cInfo = _.find(changeList, { gcl_id: select.id, mx_id: '' });
  799. if (_.findIndex(changeUsedData, { cbid: cInfo.id }) !== -1) {
  800. toastr.warning('该变更清单已被调用,无法更改计价');
  801. info.sheet.setValue(info.row, info.col, cInfo.is_valuation);
  802. return;
  803. }
  804. const is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  805. // select.is_valuation = is_valuation;
  806. cInfo.is_valuation = is_valuation;
  807. delete cInfo.waitingLoading;
  808. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  809. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  810. info.sheet.setValue(info.row, info.col, is_valuation);
  811. }, function () {
  812. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  813. cInfo.is_valuation = select.is_valuation;
  814. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  815. });
  816. }
  817. }
  818. },
  819. /**
  820. * 编辑单元格响应事件
  821. * @param {Object} e
  822. * @param {Object} info
  823. */
  824. editEnded: function (e, info) {
  825. if (info.sheet.zh_setting) {
  826. const col = info.sheet.zh_setting.cols[info.col];
  827. if (col.field === 'is_change' || col.field === 'is_valuation') {
  828. return;
  829. }
  830. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  831. const node = sortData[info.row];
  832. if (col.field === 'camount') {
  833. if (!node) {
  834. toastr.error('数据错误,请选择台账节点后再试');
  835. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  836. return;
  837. }
  838. let cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  839. if (!cInfo) {
  840. if (billsCol.readOnly.isSettle(node)) {
  841. toastr.error('清单数据未完善,无法编辑申请数量');
  842. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  843. return;
  844. }
  845. makeGclGatherData();
  846. const gclInfo = _.find(gclGatherData, function (item) {
  847. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: node.id });
  848. });
  849. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  850. return item.gcl_id === node.id;
  851. });
  852. const oldCInfo = _.find(oldChangeList, { gcl_id: node.id, mx_id: '' });
  853. const data = {
  854. lid: gclInfo.leafXmjs[0].gcl_id || node.id,
  855. code: gclInfo.b_code,
  856. name: gclInfo.name || '',
  857. unit: gclInfo.unit || '',
  858. unit_price: gclInfo.unit_price,
  859. oamount: xmjInfo.quantity,
  860. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  861. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  862. xmj_code: xmjInfo.code || '',
  863. xmj_jldy: xmjInfo.jldy || '',
  864. xmj_dwgc: xmjInfo.dwgc || '',
  865. xmj_fbgc: xmjInfo.fbgc || '',
  866. xmj_fxgc: xmjInfo.fxgc || '',
  867. gcl_id: node.id,
  868. mx_id: '',
  869. };
  870. if (oldCInfo) {
  871. data.detail = oldCInfo.detail;
  872. data.camount = oldCInfo.camount;
  873. data.camount_expr = oldCInfo.camount_expr;
  874. data.spamount = oldCInfo.spamount;
  875. data.is_valuation = oldCInfo.is_valuation;
  876. data.delimit = oldCInfo.delimit;
  877. }
  878. cInfo = data;
  879. // toastr.error('未勾选变更清单,无法编辑申请数量');
  880. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  881. // return;
  882. }
  883. let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
  884. const orgValue = validText && validText !== ''
  885. ? (_.toNumber(validText) ? cInfo.camount : cInfo.camount_expr)
  886. : (cInfo.camount_expr && cInfo.camount_expr !== '' ? cInfo.camount_expr : cInfo.camount);
  887. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  888. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  889. return;
  890. }
  891. const exprQuantity = {
  892. expr: '',
  893. quantity: 0,
  894. };
  895. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  896. if (!valid) {
  897. toastr.error(msg);
  898. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  899. return;
  900. }
  901. if (isNaN(exprQuantity.quantity)) {
  902. toastr.error('不能输入其它非数字类型字符');
  903. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  904. return;
  905. }
  906. validText = parseFloat(exprQuantity.quantity);
  907. if (cInfo.id) {
  908. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  909. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  910. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  911. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  912. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  913. return;
  914. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  915. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  916. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  917. return;
  918. }
  919. }
  920. cInfo[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  921. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  922. cInfo.camount_expr = exprQuantity.expr;
  923. node[col.field] = cInfo[col.field];
  924. delete cInfo.waitingLoading;
  925. if (cInfo.id) {
  926. if (cInfo.camount === 0 && cInfo.camount_expr === '') {
  927. if (changeOrder && _.findIndex(oldChangeList, {id: cInfo.id}) !== -1) {
  928. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  929. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  930. return
  931. }
  932. if (_.find(changeUsedData, {cbid: cInfo.id})) {
  933. toastr.warning('清单计量单元已被使用,无法取消勾选');
  934. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  935. return
  936. } else if (checkIsSettle(cInfo)) {
  937. toastr.warning('清单计量单元已结算,无法取消勾选');
  938. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  939. return
  940. }
  941. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  942. changeList = result.changeList;
  943. node.is_change = 0;
  944. node.is_valuation = 0;
  945. node.camount = null;
  946. const billsNode = node;
  947. billsTreeSpreadObj.reCalcCamount(billsNode);
  948. const loadResult = { update: [billsNode] };
  949. const refreshNode = billsTree.loadPostData(loadResult);
  950. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  951. billsTreeSpreadObj.loadExprToInput(billsSheet);
  952. });
  953. } else {
  954. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  955. type: 'update',
  956. updateData: cInfo
  957. }, function (result) {
  958. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  959. const billsNode = node;
  960. billsTreeSpreadObj.reCalcCamount(billsNode);
  961. const loadResult = {update: [billsNode]};
  962. const refreshNode = billsTree.loadPostData(loadResult);
  963. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  964. }, function () {
  965. cInfo[col.field] = orgValue;
  966. cInfo.spamount = orgValue;
  967. node[col.field] = orgValue;
  968. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  969. });
  970. }
  971. } else {
  972. // 更新至服务器
  973. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  974. changeList = result.changeList;
  975. node.is_change = 1;
  976. node.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  977. node.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  978. billsTreeSpreadObj.reCalcCamount(node);
  979. const refreshNode = billsTree.loadPostData({ update: [node] });
  980. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  981. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  982. }, function () {
  983. cInfo[col.field] = orgValue;
  984. cInfo.spamount = orgValue;
  985. node[col.field] = orgValue;
  986. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  987. });
  988. }
  989. return;
  990. }
  991. const data = {
  992. id: node.id,
  993. tender_id: node.tender_id,
  994. ledger_id: node.ledger_id
  995. };
  996. // 未改变值则不提交
  997. const orgValue = node[col.field];
  998. const newValue = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
  999. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  1000. return;
  1001. }
  1002. // 台账模式,检查计量单元相关
  1003. if (isTz) {
  1004. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  1005. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  1006. col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
  1007. col.field === 'ex_qty1' || col.field === 'ex_tp1') {
  1008. if (!node.children || node.children.length ===0) {
  1009. const lPos = pos.getLedgerPos(node.id);
  1010. if (lPos && lPos.length > 0) {
  1011. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  1012. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1013. return;
  1014. }
  1015. }
  1016. }
  1017. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  1018. const lPos = pos.getLedgerPos(node.id);
  1019. if (lPos && lPos.length > 0) {
  1020. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  1021. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1022. return;
  1023. }
  1024. }
  1025. }
  1026. // 获取更新数据
  1027. const exprInfo = getExprInfo(col.field);
  1028. if (info.editingText) {
  1029. const text = newValue;
  1030. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  1031. toastr.error('节点已计量,请勿删除编号');
  1032. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1033. return;
  1034. }
  1035. if (col.type === 'Number') {
  1036. const num = _.toNumber(text);
  1037. if (_.isFinite(num)) {
  1038. data[col.field] = num;
  1039. if (exprInfo) {
  1040. data[exprInfo.expr] = '';
  1041. }
  1042. } else {
  1043. try {
  1044. data[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
  1045. if (exprInfo) {
  1046. data[exprInfo.expr] = newValue;
  1047. }
  1048. } catch(err) {
  1049. toastr.error('输入的表达式非法');
  1050. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1051. return;
  1052. }
  1053. }
  1054. } else {
  1055. data[col.field] = text;
  1056. }
  1057. } else {
  1058. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  1059. toastr.error('节点已计量,请勿删除编号');
  1060. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1061. return;
  1062. }
  1063. data[col.field] = null;
  1064. if (exprInfo) {
  1065. data[exprInfo.expr] = '';
  1066. }
  1067. }
  1068. if (col.field === 'b_code' && newValue) {
  1069. const ledgerData = _.filter(billsTree.nodes, function (item) {
  1070. return item.b_code !== null && item.b_code !== '' && !item.formc;
  1071. });
  1072. const ledgerOneData = _.find(ledgerData, { b_code: newValue });
  1073. if (ledgerOneData) {
  1074. data.name = ledgerOneData.name;
  1075. data.unit = ledgerOneData.unit;
  1076. data.unit_price = ledgerOneData.unit_price;
  1077. }
  1078. }
  1079. // 更新至服务器
  1080. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1081. changeList = result.changeList;
  1082. const refreshNode = billsTree.loadPostData(result);
  1083. for (const u of refreshNode.update) {
  1084. billsTreeSpreadObj.reCalcCamount(u);
  1085. }
  1086. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1087. billsTreeSpreadObj.refreshPosData();
  1088. changeGclData = true;
  1089. });
  1090. }
  1091. },
  1092. clipboardPasting: function (e, info) {
  1093. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  1094. info.cancel = true;
  1095. if (!setting || !tree) return;
  1096. // const range = info.cellRange;
  1097. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  1098. // const node = tree.nodes[iRow];
  1099. // if (tree.checkNodeUsed(node, pos)) {
  1100. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  1101. // return;
  1102. // }
  1103. // }
  1104. const pasteData = info.pasteData.html
  1105. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  1106. : (info.pasteData.text === ''
  1107. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  1108. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  1109. const hint = {
  1110. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  1111. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  1112. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  1113. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  1114. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  1115. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  1116. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  1117. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  1118. // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  1119. settle: {type: 'warning', msg: '已结算节点,不可修改数量、单价、金额'},
  1120. };
  1121. const datas = [], filterNodes = [], camountData = [], insertCamountData = [];
  1122. let pid, level, filterRow = 0;
  1123. makeGclGatherData();
  1124. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  1125. const curRow = info.cellRange.row + iRow;
  1126. const node = tree.nodes[curRow];
  1127. if (!node) continue;
  1128. if (!pid) pid = node.ledger_pid;
  1129. if (!level) level = node.level;
  1130. // if (node.ledger_pid !== pid) {
  1131. // toastMessageUniq(hint.sameParent);
  1132. // filterRow+=1;
  1133. // continue;
  1134. // }
  1135. if (node.level < level) break;
  1136. let bPaste = false;
  1137. const data = info.sheet.zh_tree.getNodeKeyData(node);
  1138. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1139. const curCol = info.cellRange.col + iCol;
  1140. const colSetting = info.sheet.zh_setting.cols[curCol];
  1141. const value = colSetting.wordWrap ? pasteData[iRow-filterRow][iCol] : trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  1142. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  1143. toastMessageUniq(hint.parent);
  1144. continue;
  1145. }
  1146. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  1147. toastMessageUniq(hint.gcl);
  1148. continue;
  1149. }
  1150. const lPos = pos.getLedgerPos(node.id);
  1151. if (lPos && lPos.length > 0) {
  1152. if (value === '' && colSetting.field === 'b_code') {
  1153. toastMessageUniq(hint.posCode);
  1154. continue;
  1155. }
  1156. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  1157. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  1158. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp' ||
  1159. colSetting.field === 'camount' || colSetting.field === 'ca_tp' ||
  1160. colSetting.field === 'ex_qty1' || colSetting.field === 'ex_tp1') {
  1161. if (isTz) {
  1162. toastMessageUniq(hint.posQty);
  1163. continue;
  1164. }
  1165. }
  1166. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  1167. toastMessageUniq(hint.posXmj);
  1168. continue;
  1169. }
  1170. }
  1171. if (tree.checkNodeUsed(node, pos) && colSetting.field === 'unit_price') {
  1172. toastMessageUniq (hint.usedUp);
  1173. continue;
  1174. }
  1175. if (colSetting.type === 'Number' && node.settle_status === settleStatus.finish) {
  1176. toastMessageUniq(hint.settle);
  1177. continue;
  1178. }
  1179. if (colSetting.field === 'camount') {
  1180. bPaste = true;
  1181. let validText = value;
  1182. let cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1183. if (!cInfo) {
  1184. const gclInfo = _.find(gclGatherData, function (item) {
  1185. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: node.id });
  1186. });
  1187. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  1188. return item.gcl_id === node.id;
  1189. });
  1190. const oldCInfo = _.find(oldChangeList, { gcl_id: node.id, mx_id: '' });
  1191. const data = {
  1192. lid: gclInfo.leafXmjs[0].gcl_id || node.id,
  1193. code: gclInfo.b_code,
  1194. name: gclInfo.name || '',
  1195. unit: gclInfo.unit || '',
  1196. unit_price: gclInfo.unit_price,
  1197. oamount: xmjInfo.quantity,
  1198. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  1199. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  1200. xmj_code: xmjInfo.code || '',
  1201. xmj_jldy: xmjInfo.jldy || '',
  1202. xmj_dwgc: xmjInfo.dwgc || '',
  1203. xmj_fbgc: xmjInfo.fbgc || '',
  1204. xmj_fxgc: xmjInfo.fxgc || '',
  1205. gcl_id: node.id,
  1206. mx_id: '',
  1207. };
  1208. if (oldCInfo) {
  1209. data.detail = oldCInfo.detail;
  1210. data.camount = oldCInfo.camount;
  1211. data.camount_expr = oldCInfo.camount_expr;
  1212. data.spamount = oldCInfo.spamount;
  1213. data.is_valuation = oldCInfo.is_valuation;
  1214. data.delimit = oldCInfo.delimit;
  1215. }
  1216. cInfo = data;
  1217. // bPaste = false;
  1218. // continue;
  1219. }
  1220. const exprQuantity = {
  1221. expr: '',
  1222. quantity: 0,
  1223. };
  1224. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  1225. if (!valid) {
  1226. toastMessageUniq(hint.invalidExpr);
  1227. bPaste = false;
  1228. continue;
  1229. }
  1230. if (isNaN(exprQuantity.quantity)) {
  1231. toastMessageUniq(hint.invalidExpr);
  1232. bPaste = false;
  1233. continue;
  1234. }
  1235. validText = parseFloat(exprQuantity.quantity);
  1236. if (cInfo.id) {
  1237. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1238. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  1239. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1240. toastr.error(curRow ? '台账第' + (curRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1241. bPaste = false;
  1242. continue;
  1243. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1244. toastr.error(curRow ? '台账第' + (curRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1245. bPaste = false;
  1246. continue;
  1247. }
  1248. }
  1249. if (bPaste) {
  1250. node.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  1251. filterNodes.push(node);
  1252. if (cInfo.id) {
  1253. camountData.push({id: cInfo.id, camount: node.camount, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
  1254. } else {
  1255. cInfo.camount = node.camount;
  1256. cInfo.camount_expr = exprQuantity.expr;
  1257. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  1258. insertCamountData.push(cInfo);
  1259. }
  1260. } else {
  1261. filterNodes.push(node);
  1262. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1263. }
  1264. continue;
  1265. }
  1266. if (colSetting.type === 'Number') {
  1267. const num = _.toNumber(value);
  1268. if (num) {
  1269. data[colSetting.field] = num;
  1270. } else {
  1271. try {
  1272. data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
  1273. const exprInfo = getExprInfo(colSetting.field);
  1274. if (exprInfo) {
  1275. data[exprInfo.expr] = value;
  1276. }
  1277. bPaste = true;
  1278. } catch (err) {
  1279. toastMessageUniq(hint.invalidExpr);
  1280. continue;
  1281. }
  1282. }
  1283. } else {
  1284. if (node.used && (colSetting.field === 'code' || colSetting.field ==='b_code')
  1285. && data[colSetting.field] !== '' && value === '') {
  1286. toastMessageUniq(hint.usedCode);
  1287. continue;
  1288. }
  1289. data[colSetting.field] = value;
  1290. }
  1291. if (colSetting.field === 'b_code' && value) {
  1292. const ledgerData = _.filter(billsTree.nodes, function (item) {
  1293. return item.b_code !== null && item.b_code !== '' && !item.formc;
  1294. });
  1295. const ledgerOneData = _.find(ledgerData, { b_code: value });
  1296. if (ledgerOneData) {
  1297. data.name = ledgerOneData.name;
  1298. data.unit = ledgerOneData.unit;
  1299. data.unit_price = ledgerOneData.unit_price;
  1300. }
  1301. }
  1302. bPaste = true;
  1303. }
  1304. if (bPaste) {
  1305. datas.push(data);
  1306. } else {
  1307. filterNodes.push(node);
  1308. }
  1309. }
  1310. if (camountData.length > 0 || insertCamountData.length > 0) {
  1311. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', insertData: insertCamountData, updateData: camountData }, function (result) {
  1312. changeList = result;
  1313. // 给所有filterNodes 加上is_change=1
  1314. filterNodes.forEach(function (item) {
  1315. item.is_change = 1;
  1316. });
  1317. const loadResult = { update: filterNodes };
  1318. const refreshNode = billsTree.loadPostData(loadResult);
  1319. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1320. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1321. }, function () {
  1322. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1323. return;
  1324. });
  1325. return;
  1326. }
  1327. if (datas.length > 0) {
  1328. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1329. changeList = result.changeList;
  1330. const refreshNode = tree.loadPostData(result);
  1331. if (refreshNode.update) {
  1332. refreshNode.update = refreshNode.update.concat(filterNodes);
  1333. }
  1334. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1335. changeGclData = true;
  1336. }, function () {
  1337. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1338. });
  1339. } else {
  1340. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1341. }
  1342. },
  1343. clipboardPasted: function (e, info) {
  1344. const hint = {
  1345. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  1346. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  1347. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  1348. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  1349. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  1350. };
  1351. const tree = info.sheet.zh_tree;
  1352. if (!tree) { return; }
  1353. const sortData = info.sheet.zh_tree.nodes;
  1354. const datas = [], filterNodes = [], camountData = [];
  1355. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  1356. let bPaste = false;
  1357. const curRow = info.cellRange.row + iRow;
  1358. const node = sortData[curRow];
  1359. if (node) {
  1360. const data = info.sheet.zh_tree.getNodeKeyData(node);
  1361. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1362. const curCol = info.cellRange.col + iCol;
  1363. const colSetting = info.sheet.zh_setting.cols[curCol];
  1364. const value = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  1365. const lPos = pos.getLedgerPos(node.id);
  1366. if (lPos && lPos.length > 0) {
  1367. if (value === '' && colSetting.field === 'b_code') {
  1368. toastMessageUniq(hint.posCode);
  1369. continue;
  1370. }
  1371. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  1372. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  1373. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp' ||
  1374. colSetting.field === 'camount' || colSetting.field === 'ca_tp' ||
  1375. colSetting.field === 'ex_qty1' || colSetting.field === 'ex_tp1') {
  1376. toastMessageUniq(hint.posQty);
  1377. continue;
  1378. }
  1379. }
  1380. if (node.used && colSetting.field === 'unit_price') {
  1381. toastMessageUniq (hint.usedUp);
  1382. continue;
  1383. }
  1384. if (colSetting.field === 'camount') {
  1385. bPaste = true;
  1386. let validText = value;
  1387. const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1388. if (!cInfo) {
  1389. bPaste = false;
  1390. continue;
  1391. }
  1392. const exprQuantity = {
  1393. expr: '',
  1394. quantity: 0,
  1395. };
  1396. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  1397. if (!valid) {
  1398. toastMessageUniq(hint.invalidExpr);
  1399. bPaste = false;
  1400. continue;
  1401. }
  1402. if (isNaN(exprQuantity.quantity)) {
  1403. toastMessageUniq(hint.invalidExpr);
  1404. bPaste = false;
  1405. continue;
  1406. }
  1407. validText = parseFloat(exprQuantity.quantity);
  1408. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1409. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  1410. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1411. toastr.error(curRow ? '台账第' + (curRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1412. bPaste = false;
  1413. continue;
  1414. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1415. toastr.error(curRow ? '台账第' + (curRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1416. bPaste = false;
  1417. continue;
  1418. }
  1419. if (bPaste) {
  1420. node.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  1421. filterNodes.push(node);
  1422. camountData.push({id: cInfo.id, camount: node.camount, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
  1423. } else {
  1424. filterNodes.push(node);
  1425. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1426. }
  1427. continue;
  1428. }
  1429. if (colSetting.type === 'Number') {
  1430. const num = _.toNumber(value);
  1431. if (num) {
  1432. data[colSetting.field] = num;
  1433. } else {
  1434. try {
  1435. data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
  1436. } catch (err) {
  1437. toastMessageUniq(hint.invalidExpr);
  1438. continue;
  1439. }
  1440. }
  1441. } else {
  1442. if (node.used && (colSetting.field === 'code' || colSetting.field === 'b_code')
  1443. && data[colSetting.field] !== '' && value === '') {
  1444. toastMessageUniq(hint.usedCode);
  1445. continue;
  1446. }
  1447. data[colSetting.field] = value;
  1448. }
  1449. if (colSetting.field === 'b_code' && value) {
  1450. const ledgerData = _.filter(billsTree.nodes, function (item) {
  1451. return item.b_code !== null && item.b_code !== '' && !item.formc;
  1452. });
  1453. const ledgerOneData = _.find(ledgerData, { b_code: value });
  1454. if (ledgerOneData) {
  1455. data.name = ledgerOneData.name;
  1456. data.unit = ledgerOneData.unit;
  1457. data.unit_price = ledgerOneData.unit_price;
  1458. }
  1459. }
  1460. bPaste = true;
  1461. }
  1462. if (bPaste) {
  1463. datas.push(data);
  1464. } else {
  1465. filterNodes.push(node);
  1466. }
  1467. }
  1468. }
  1469. if (camountData.length > 0) {
  1470. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountData }, function (result) {
  1471. changeList = result;
  1472. const loadResult = { update: filterNodes };
  1473. const refreshNode = billsTree.loadPostData(loadResult);
  1474. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1475. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1476. }, function () {
  1477. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1478. return;
  1479. });
  1480. return;
  1481. }
  1482. if (datas.length > 0) {
  1483. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1484. changeList = result.changeList;
  1485. const refreshNode = tree.loadPostData(result);
  1486. if (refreshNode.update) {
  1487. refreshNode.update = refreshNode.update.concat(filterNodes);
  1488. }
  1489. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1490. changeGclData = true;
  1491. }, function () {
  1492. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1493. });
  1494. } else {
  1495. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1496. }
  1497. },
  1498. deletePress: function (sheet) {
  1499. if (!sheet.zh_setting) return;
  1500. const sel = sheet.getSelections()[0], datas = [], camountDatas = [];
  1501. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1502. let bDel = false;
  1503. const node = sheet.zh_tree.nodes[iRow];
  1504. const data = sheet.zh_tree.getNodeKeyData(node);
  1505. const cData = {};
  1506. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1507. const col = sheet.zh_setting.cols[iCol];
  1508. const style = sheet.getStyle(iRow, iCol);
  1509. if (style.locked || (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) >= 0 && node.b_code)) continue;
  1510. if (col.type === 'Number' && node.settle_status === settleStatus.finish) continue;
  1511. if (['dgn_qty1', 'dgn_qty2', 'camount'].indexOf(col.field) < 0 && sheet.zh_tree.checkNodeUsed(node, pos)) {
  1512. toastr.warning('"' + (node.code || '') + (node.b_code || '') + ' ' + node.name +'"已计量,请勿修改');
  1513. return;
  1514. }
  1515. if (col.field === 'camount') {
  1516. const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1517. if (!cInfo) continue;
  1518. cData.id = cInfo.id;
  1519. cData.camount = null;
  1520. cData.camount_expr = '';
  1521. cData.spamount = null;
  1522. data.camount = null;
  1523. } else {
  1524. data[col.field] = null;
  1525. const exprInfo = getExprInfo(col.field);
  1526. if (exprInfo) {
  1527. data[exprInfo.expr] = '';
  1528. }
  1529. }
  1530. bDel = true;
  1531. }
  1532. if (bDel) {
  1533. datas.push(data);
  1534. if (cData.id) camountDatas.push(cData);
  1535. }
  1536. }
  1537. if (camountDatas.length > 0) {
  1538. for (const cInfo of camountDatas) {
  1539. if (changeOrder && _.findIndex(oldChangeList, {id: cInfo.id}) !== -1) {
  1540. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  1541. return
  1542. }
  1543. if (_.find(changeUsedData, {cbid: cInfo.id})) {
  1544. toastr.warning('清单计量单元已被使用,无法取消勾选');
  1545. return
  1546. } else if (checkIsSettle(cInfo)) {
  1547. toastr.warning('清单计量单元已结算,无法取消勾选');
  1548. return
  1549. }
  1550. }
  1551. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: _.map(camountDatas, 'id') }, function (result) {
  1552. changeList = result.changeList;
  1553. for (const d of datas) {
  1554. d.is_change = 0;
  1555. billsTreeSpreadObj.reCalcCamount(d);
  1556. }
  1557. const loadResult = { update: datas };
  1558. const refreshNode = billsTree.loadPostData(loadResult);
  1559. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1560. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1561. });
  1562. // postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountDatas }, function (result) {
  1563. // changeList = result;
  1564. // for (const d of datas) {
  1565. // billsTreeSpreadObj.reCalcCamount(d);
  1566. // }
  1567. // const loadResult = { update: datas };
  1568. // const refreshNode = billsTree.loadPostData(loadResult);
  1569. // billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1570. // billsTreeSpreadObj.loadExprToInput(billsSheet);
  1571. // });
  1572. return;
  1573. }
  1574. if (datas.length > 0) {
  1575. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1576. changeList = result.changeList;
  1577. const refreshNode = sheet.zh_tree.loadPostData(result);
  1578. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1579. billsTreeSpreadObj.loadExprToInput(sheet);
  1580. changeGclData = true;
  1581. });
  1582. }
  1583. },
  1584. pasteBlock: function (spread, copyInfo) {
  1585. const self = this;
  1586. const sheet = spread.getActiveSheet();
  1587. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  1588. if (node.settle_status === settleStatus.finish) {
  1589. toastr.warning('选中的节点已结算,不可粘贴整块');
  1590. return;
  1591. }
  1592. postData(window.location.pathname + '/update', {
  1593. postType: 'paste-block',
  1594. postData: {
  1595. id: tree.getNodeKey(node),
  1596. tid: copyInfo.tid,
  1597. block: copyInfo.block,
  1598. }
  1599. }, function (data) {
  1600. changeList = data.changeList;
  1601. pos.updateDatas(data.pos);
  1602. const result = tree.loadPostData(data.ledger);
  1603. self.refreshTree(sheet, result);
  1604. const sel = sheet.getSelections()[0];
  1605. if (sel) {
  1606. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  1607. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  1608. }
  1609. self.refreshOperationValid(sheet);
  1610. removeLocalCache(copyBlockTag);
  1611. changeGclData = true;
  1612. }, null, true);
  1613. },
  1614. topRowChanged: function (e, info) {
  1615. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1616. },
  1617. editStarting(e, info) {
  1618. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1619. const col = info.sheet.zh_setting.cols[info.col];
  1620. const node = info.sheet.zh_tree.nodes[info.row];
  1621. if (!node) {
  1622. info.cancel = true;
  1623. return;
  1624. }
  1625. if (col.field === 'camount') {
  1626. const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1627. if (!cInfo) {
  1628. if (billsCol.readOnly.isSettle(node)) {
  1629. toastr.error('清单数据未完善,无法编辑申请数量');
  1630. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1631. return
  1632. }
  1633. return;
  1634. }
  1635. if (cInfo.camount_expr && cInfo.camount_expr !== '') {
  1636. info.sheet.getCell(info.row, info.col).text(cInfo.camount_expr);
  1637. }
  1638. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  1639. info.cancel = true;
  1640. }
  1641. } else {
  1642. const exprInfo = getExprInfo(col.field);
  1643. if (exprInfo) {
  1644. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1645. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1646. }
  1647. }
  1648. switch (col.field) {
  1649. case 'code':
  1650. const posRange = pos.getLedgerPos(node.id);
  1651. info.cancel = posRange && posRange.length > 0;
  1652. break;
  1653. case 'unit_price':
  1654. info.cancel = (node.children && node.children.length > 0) || node.used || node.settle_status === settleStatus.finish;
  1655. break;
  1656. case 'sgfh_qty':
  1657. case 'sgfh_tp':
  1658. case 'sjcl_qty':
  1659. case 'sjcl_tp':
  1660. case 'qtcl_qty':
  1661. case 'qtcl_tp':
  1662. case 'deal_qty':
  1663. case 'deal_tp':
  1664. case 'ex_qty1':
  1665. case 'ex_tp1':
  1666. info.cancel = (node.children && node.children.length > 0) || node.settle_status === settleStatus.finish;
  1667. break;
  1668. case 'dgn_qty1':
  1669. case 'dgn_qty2':
  1670. info.cancel = !_.isEmpty(node.b_code || node.settle_status === settleStatus.finish);
  1671. break;
  1672. }
  1673. }
  1674. },
  1675. cut: function (sheet, sel, callback) {
  1676. if (!sheet || !sel) return;
  1677. if (sel.colCount >= sheet.zh_setting.cols.length) {
  1678. toastr.warning('请勿选中整行剪切');
  1679. return;
  1680. }
  1681. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  1682. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1683. const node = sortData[iRow];
  1684. if (node) {
  1685. const data = sheet.zh_tree.getNodeKeyData(node);
  1686. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1687. const col = sheet.zh_setting.cols[iCol];
  1688. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  1689. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  1690. col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
  1691. col.field === 'ex_qty1' || col.field === 'ex_tp1') {
  1692. const lPos = pos.getLedgerPos(node.id);
  1693. if (lPos && lPos.length > 0) {
  1694. toastr.error('不可剪切');
  1695. return;
  1696. }
  1697. }
  1698. const style = sheet.getStyle(iRow, iCol);
  1699. if (style.locked) {
  1700. toastr.error('不可剪切');
  1701. return;
  1702. }
  1703. const colSetting = sheet.zh_setting.cols[iCol];
  1704. data[colSetting.field] = null;
  1705. const exprInfo = getExprInfo(colSetting.field);
  1706. if (exprInfo) {
  1707. data[exprInfo.expr] = '';
  1708. }
  1709. }
  1710. datas.push(data);
  1711. }
  1712. }
  1713. if (datas.length > 0) {
  1714. callback();
  1715. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1716. changeList = result.changeList;
  1717. const refreshNode = sheet.zh_tree.loadPostData(result);
  1718. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1719. changeGclData = true;
  1720. });
  1721. }
  1722. },
  1723. sortCode: function (sheet) {
  1724. const tree = sheet.zh_tree;
  1725. if (!tree) return;
  1726. const select = SpreadJsObj.getSelectObject(sheet);
  1727. if (!select || !select.code || select.code === '') return;
  1728. const recursiveSortCode = function (data, parentCode, children) {
  1729. if (!children || children.length === 0) return;
  1730. for (const [i, child] of children.entries()) {
  1731. if (!child.b_code || child.b_code === '') {
  1732. const code = parentCode + '-' + (i + 1);
  1733. const cData = tree.getNodeKeyData(child);
  1734. cData.code = code;
  1735. data.push(cData);
  1736. if (!tree.isLeafXmj(child)) {
  1737. recursiveSortCode(data, code, child.children);
  1738. }
  1739. }
  1740. }
  1741. };
  1742. const data = [];
  1743. recursiveSortCode(data, select.code, select.children);
  1744. if (data.length > 0) {
  1745. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1746. changeList = result.changeList;
  1747. const refreshNode = tree.loadPostData(result);
  1748. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1749. changeGclData = true;
  1750. })
  1751. }
  1752. },
  1753. reCalcCamount: function (node) {
  1754. if (node && node.b_code) {
  1755. const posData = pos.getLedgerPos(node.id) || [];
  1756. let camount = node.camount || 0;
  1757. let is_valuation = node.is_valuation || 0;
  1758. if (posData.length > 0) {
  1759. camount = 0;
  1760. for (const np of posData) {
  1761. const cInfo = _.find(changeList, { gcl_id: np.lid, mx_id: np.id });
  1762. camount = cInfo ? ZhCalc.add(camount, ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit))) : camount;
  1763. if (cInfo && cInfo.is_valuation) {
  1764. is_valuation = 1;
  1765. }
  1766. }
  1767. }
  1768. node.camount = camount;
  1769. node.ca_tp = ZhCalc.mul(camount, node.unit_price, decimal.tp) || 0;
  1770. node.is_valuation = is_valuation;
  1771. }
  1772. },
  1773. _checkExprValid(expr) {
  1774. if (!expr) return [true, null];
  1775. const param = [];
  1776. let num = '', base = '';
  1777. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1778. if (/^[\d\.%]+/.test(expr[i])) {
  1779. if (base !== '') {
  1780. param.push({type: 'base', value: base});
  1781. base = '';
  1782. }
  1783. num = num + expr[i];
  1784. } else if (expr[i] === '(') {
  1785. if (num !== '') {
  1786. param.push({type: 'num', value: num});
  1787. num = '';
  1788. }
  1789. if (base !== '') {
  1790. param.push({type: 'base', value: base});
  1791. base = '';
  1792. }
  1793. param.push({type: 'left', value: '('});
  1794. } else if (expr[i] === ')') {
  1795. if (num !== '') {
  1796. param.push({type: 'num', value: num});
  1797. num = '';
  1798. }
  1799. if (base !== '') {
  1800. param.push({type: 'base', value: base});
  1801. base = '';
  1802. }
  1803. param.push({type: 'right', value: ')'});
  1804. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1805. if (num !== '') {
  1806. param.push({type: 'num', value: num});
  1807. num = '';
  1808. }
  1809. if (base !== '') {
  1810. param.push({type: 'base', value: base});
  1811. base = '';
  1812. }
  1813. param.push({type: 'calc', value: expr[i]});
  1814. } else {
  1815. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1816. }
  1817. }
  1818. if (num !== '') {
  1819. param.push({type: 'num', value: num});
  1820. num = '';
  1821. }
  1822. if (base !== '') {
  1823. param.push({type: 'base', value: base});
  1824. base = '';
  1825. }
  1826. if (param.length === 0) return true;
  1827. if (param.length > 1) {
  1828. if (param[0].value === '-' && param[1].type === 'num') {
  1829. param[1].value = '-' + param[1].value;
  1830. param.shift();
  1831. }
  1832. }
  1833. const iLen = param.length;
  1834. let iLeftCount = 0, iRightCount = 0;
  1835. for (const [i, p] of param.entries()) {
  1836. if (p.type === 'calc') {
  1837. if (i === 0 || i === iLen - 1)
  1838. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  1839. }
  1840. if (p.type === 'num') {
  1841. num = p.value.replace('%', '');
  1842. if (p.value.length - num.length > 1)
  1843. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1844. num = _.toNumber(num);
  1845. if (num === undefined || num === null || _.isNaN(num))
  1846. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1847. if (i > 0) {
  1848. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1849. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1850. } else if (param[i - 1].value === '/' && num === 0) {
  1851. return [false, '输入的表达式非法:请勿除0'];
  1852. }
  1853. }
  1854. }
  1855. if (p.type === 'base') {
  1856. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1857. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1858. }
  1859. if (p.type === 'left') {
  1860. iLeftCount += 1;
  1861. if (i !== 0 && param[i-1].type !== 'calc')
  1862. return [false, '输入的表达式非法:(前应有运算符'];
  1863. }
  1864. if (p.type === 'right') {
  1865. iRightCount += 1;
  1866. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1867. return [false, '输入的表达式非法:)后应有运算符'];
  1868. if (iRightCount > iLeftCount)
  1869. return [false, '输入的表达式非法:")"前无对应的"("'];
  1870. }
  1871. }
  1872. if (iLeftCount > iRightCount)
  1873. return [false, '输入的表达式非法:"("后无对应的")"'];
  1874. return [true, ''];
  1875. },
  1876. _checkExpr: function (text, data) {
  1877. if (text) {
  1878. const num = _.toNumber(text);
  1879. if (num) {
  1880. data.quantity = num;
  1881. data.expr = '';
  1882. } else {
  1883. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  1884. const [valid, msg] = this._checkExprValid(expr);
  1885. if (!valid) return [valid, msg];
  1886. data.expr = expr;
  1887. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr.replace(new RegExp('%', 'gm'), '/100'));
  1888. // const ce = new CalcEvalMin();
  1889. // data.quantity = ce.eval(expr);
  1890. // console.log(data.quantity);
  1891. }
  1892. } else {
  1893. data.quantity = 0;
  1894. data.expr = '';
  1895. }
  1896. return [true, ''];
  1897. },
  1898. };
  1899. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1900. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1901. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  1902. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  1903. if (!readOnly) {
  1904. // 增删上下移升降级
  1905. $('a[name="base-opr"]').click(function () {
  1906. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  1907. });
  1908. $('a[name=cpc]').click(function () {
  1909. billsSpread.commandManager().execute({
  1910. cmd: this.getAttribute('type'),
  1911. sheetName: billsSheet.name()
  1912. });
  1913. });
  1914. $('#bills-expr').bind('change onblur', function () {
  1915. if (this.readOnly) return;
  1916. const expr = $(this);
  1917. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1918. const select = billsTree.getItemsByIndex(row);
  1919. if (!select) return;
  1920. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1921. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1922. if (field === 'camount') {
  1923. let cInfo = _.find(changeList, { gcl_id: select.id, mx_id: '' });
  1924. if (!cInfo) {
  1925. if (billsCol.readOnly.isChangeList(select)) {
  1926. toastr.error('清单数据未完善,无法编辑申请数量');
  1927. SpreadJsObj.reLoadRowData(billsSheet, row);
  1928. return;
  1929. }
  1930. makeGclGatherData();
  1931. const gclInfo = _.find(gclGatherData, function (item) {
  1932. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
  1933. });
  1934. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  1935. return item.gcl_id === select.id;
  1936. });
  1937. const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
  1938. const data = {
  1939. lid: gclInfo.leafXmjs[0].gcl_id || select.id,
  1940. code: gclInfo.b_code,
  1941. name: gclInfo.name || '',
  1942. unit: gclInfo.unit || '',
  1943. unit_price: gclInfo.unit_price,
  1944. oamount: xmjInfo.quantity,
  1945. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  1946. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  1947. xmj_code: xmjInfo.code || '',
  1948. xmj_jldy: xmjInfo.jldy || '',
  1949. xmj_dwgc: xmjInfo.dwgc || '',
  1950. xmj_fbgc: xmjInfo.fbgc || '',
  1951. xmj_fxgc: xmjInfo.fxgc || '',
  1952. gcl_id: select.id,
  1953. mx_id: '',
  1954. };
  1955. if (oldCInfo) {
  1956. data.detail = oldCInfo.detail;
  1957. data.camount = oldCInfo.camount;
  1958. data.camount_expr = oldCInfo.camount_expr;
  1959. data.spamount = oldCInfo.spamount;
  1960. data.is_valuation = oldCInfo.is_valuation;
  1961. data.delimit = oldCInfo.delimit;
  1962. }
  1963. cInfo = data;
  1964. // toastr.error('未勾选变更清单,无法编辑申请数量');
  1965. // return;
  1966. }
  1967. const exprQuantity = {
  1968. expr: '',
  1969. quantity: 0,
  1970. };
  1971. const [valid, msg] = billsTreeSpreadObj._checkExpr(newValue, exprQuantity);
  1972. if (!valid) {
  1973. toastr.error(msg);
  1974. return;
  1975. }
  1976. if (isNaN(exprQuantity.quantity)) {
  1977. toastr.error('不能输入其它非数字类型字符');
  1978. return;
  1979. }
  1980. const camount = parseFloat(exprQuantity.quantity);
  1981. if (cInfo.id) {
  1982. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1983. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  1984. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1985. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1986. return;
  1987. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1988. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1989. return;
  1990. }
  1991. }
  1992. cInfo.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1993. select.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1994. cInfo.spamount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1995. cInfo.camount_expr = exprQuantity.expr;
  1996. delete cInfo.waitingLoading;
  1997. if (cInfo.id) {
  1998. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  1999. SpreadJsObj.reLoadRowData(billsSheet, row);
  2000. billsTreeSpreadObj.reCalcCamount(select);
  2001. const loadResult = { update: [select] };
  2002. const refreshNode = billsTree.loadPostData(loadResult);
  2003. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2004. billsTreeSpreadObj.loadExprToInput(billsSheet);
  2005. }, function () {
  2006. cInfo.camount = orgValue;
  2007. cInfo.spamount = orgValue;
  2008. select.camount = orgValue;
  2009. SpreadJsObj.reLoadRowData(billsSheet, row);
  2010. });
  2011. } else {
  2012. // 更新至服务器
  2013. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  2014. changeList = result.changeList;
  2015. select.is_change = 1;
  2016. select.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  2017. select.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  2018. billsTreeSpreadObj.reCalcCamount(select);
  2019. const refreshNode = billsTree.loadPostData({ update: [select] });
  2020. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2021. SpreadJsObj.reLoadRowData(billsSheet, row);
  2022. }, function () {
  2023. cInfo[col.field] = orgValue;
  2024. cInfo.spamount = orgValue;
  2025. node[col.field] = orgValue;
  2026. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2027. });
  2028. }
  2029. return;
  2030. }
  2031. const data = {
  2032. id: select.id,
  2033. tender_id: select.tender_id,
  2034. ledger_id: select.ledger_id
  2035. };
  2036. const exprInfo = getExprInfo(field);
  2037. if (newValue !== '') {
  2038. const num = _.toNumber(newValue);
  2039. if (num) {
  2040. data[field] = num;
  2041. if (exprInfo) {
  2042. data[exprInfo.expr] = '';
  2043. }
  2044. } else {
  2045. try {
  2046. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2047. if (exprInfo) {
  2048. data[exprInfo.expr] = newValue;
  2049. }
  2050. } catch (err) {
  2051. toastr.error('输入的表达式非法');
  2052. return;
  2053. }
  2054. }
  2055. } else {
  2056. data[field] = null;
  2057. if (exprInfo) {
  2058. data[exprInfo.expr] = '';
  2059. }
  2060. }
  2061. // 更新至服务器
  2062. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  2063. changeList = result.changeList;
  2064. const refreshNode = billsTree.loadPostData(result);
  2065. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2066. changeGclData = true;
  2067. });
  2068. });
  2069. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  2070. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  2071. billsSpread.bind(spreadNS.Events.ButtonClicked, billsTreeSpreadObj.buttonClicked);
  2072. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  2073. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  2074. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  2075. SpreadJsObj.Clipboard.setCopyData(copyText);
  2076. });
  2077. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  2078. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  2079. }
  2080. // 右键菜单
  2081. let batchInsertObj;
  2082. $.contextMenu.types.batchInsert = function (item, opt, root) {
  2083. const self = this;
  2084. if ($.isFunction(item.icon)) {
  2085. item._icon = item.icon.call(this, this, $t, key, item);
  2086. } else {
  2087. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  2088. // to enable font awesome
  2089. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  2090. } else {
  2091. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  2092. }
  2093. }
  2094. this.addClass(item._icon);
  2095. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="20" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  2096. .appendTo(this);
  2097. const $input = $obj.find('input');
  2098. const event = () => {
  2099. if (self.hasClass('context-menu-disabled')) return;
  2100. item.batchInsert($input[0], root);
  2101. };
  2102. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  2103. $input.click((e) => {e.stopPropagation();})
  2104. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  2105. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  2106. };
  2107. const billsContextMenuOptions = {
  2108. selector: '#bills-spread',
  2109. build: function ($trigger, e) {
  2110. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  2111. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2112. },
  2113. items: {}
  2114. };
  2115. if (!readOnly) {
  2116. billsContextMenuOptions.items.create = {
  2117. name: '新增',
  2118. icon: 'fa-sign-in',
  2119. callback: function (key, opt) {
  2120. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  2121. },
  2122. disabled: function (key, opt) {
  2123. const sheet = billsSheet;
  2124. const selection = sheet.getSelections();
  2125. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2126. const row = sel ? sel.row : -1;
  2127. const tree = sheet.zh_tree;
  2128. if (!tree) return true;
  2129. const first = sheet.zh_tree.nodes[row];
  2130. const valid = !sheet.zh_setting.readOnly;
  2131. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  2132. }
  2133. };
  2134. billsContextMenuOptions.items.delete = {
  2135. name: '删除',
  2136. icon: 'fa-remove',
  2137. callback: function (key, opt) {
  2138. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  2139. },
  2140. disabled: function (key, opt) {
  2141. const sheet = billsSheet;
  2142. const selection = sheet.getSelections();
  2143. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2144. const row = sel ? sel.row : -1;
  2145. const tree = sheet.zh_tree;
  2146. if (!tree) return true;
  2147. const first = sheet.zh_tree.nodes[row];
  2148. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  2149. if (sel.rowCount > 1 && first) {
  2150. for (let r = 1; r < sel.rowCount; r++) {
  2151. const rNode = tree.nodes[sel.row + r];
  2152. if (!rNode) {
  2153. sameParent = false;
  2154. break;
  2155. }
  2156. if (!rNode.formc) {
  2157. return true;
  2158. }
  2159. nodeUsed = nodeUsed || rNode.used;
  2160. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  2161. if (rNode.level > first.level) continue;
  2162. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  2163. sameParent = false;
  2164. break;
  2165. }
  2166. last = rNode;
  2167. }
  2168. }
  2169. const valid = !sheet.zh_setting.readOnly;
  2170. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed && first.formc && !settleFinish);
  2171. }
  2172. };
  2173. billsContextMenuOptions.items.sprBase = '----';
  2174. }
  2175. billsContextMenuOptions.items.copyBlock = {
  2176. name: '复制整块',
  2177. icon: 'fa-files-o',
  2178. callback: function (key, opt) {
  2179. const copyBlockList = [];
  2180. const sheet = billsSheet;
  2181. const sel = sheet.getSelections()[0];
  2182. let iRow = sel.row;
  2183. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  2184. while (iRow < sel.row + sel.rowCount) {
  2185. const node = sheet.zh_tree.nodes[iRow];
  2186. if (node.ledger_pid !== pid) {
  2187. toastr.error('仅可同时选中同层节点');
  2188. return;
  2189. }
  2190. const posterity = sheet.zh_tree.getPosterity(node);
  2191. iRow += posterity.length + 1;
  2192. posterity.unshift(node);
  2193. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  2194. }
  2195. for (const cbl of copyBlockList) {
  2196. for (const b of cbl) {
  2197. const posRange = pos.getLedgerPos(b.id);
  2198. if (posRange && posRange.length > 0) b.pos = posRange;
  2199. }
  2200. }
  2201. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  2202. },
  2203. visible: function (key, opt) {
  2204. const sheet = billsSheet;
  2205. const selection = sheet.getSelections();
  2206. const row = selection[0].row;
  2207. const select = billsTree.nodes[row];
  2208. return select;
  2209. },
  2210. disabled: function (key, opt) {
  2211. const sheet = billsSheet;
  2212. const selection = sheet.getSelections();
  2213. const row = selection[0].row;
  2214. const select = billsTree.nodes[row];
  2215. return select && select.level <= 1;
  2216. }
  2217. };
  2218. billsContextMenuOptions.items.copyBlockXmj = {
  2219. name: '复制整块(只复制项目节)',
  2220. icon: 'fa-files-o',
  2221. callback: function (key, opt) {
  2222. const copyBlockList = [];
  2223. const sheet = billsSheet;
  2224. const sel = sheet.getSelections()[0];
  2225. let iRow = sel.row;
  2226. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  2227. while (iRow < sel.row + sel.rowCount) {
  2228. const node = sheet.zh_tree.nodes[iRow];
  2229. if (node.ledger_pid !== pid) {
  2230. toastr.error('仅可同时选中同层节点');
  2231. return;
  2232. }
  2233. const posterity = sheet.zh_tree.getPosterity(node);
  2234. iRow += posterity.length + 1;
  2235. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  2236. copyPosterity.unshift(node);
  2237. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  2238. for (const p of copyData) {
  2239. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  2240. p.is_leaf = children.length === 0;
  2241. }
  2242. copyBlockList.push(copyData);
  2243. }
  2244. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  2245. },
  2246. visible: function (key, opt) {
  2247. const sheet = billsSheet;
  2248. const selection = sheet.getSelections();
  2249. const row = selection[0].row;
  2250. const select = billsTree.nodes[row];
  2251. return select;
  2252. },
  2253. disabled: function (key, opt) {
  2254. const sheet = billsSheet;
  2255. const selection = sheet.getSelections();
  2256. const row = selection[0].row;
  2257. const select = billsTree.nodes[row];
  2258. return select && select.level <= 1;
  2259. }
  2260. };
  2261. if (!readOnly) {
  2262. billsContextMenuOptions.items.pasteBlock = {
  2263. name: '粘贴整块',
  2264. icon: 'fa-clipboard',
  2265. disabled: function (key, opt) {
  2266. //const block = treeOperationObj.block || [];
  2267. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  2268. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  2269. },
  2270. callback: function (key, opt) {
  2271. //const block = treeOperationObj.block || [];
  2272. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  2273. if (copyInfo.block.length > 0) {
  2274. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  2275. } else {
  2276. document.execCommand('paste');
  2277. }
  2278. },
  2279. visible: function (key, opt) {
  2280. return !readOnly;
  2281. }
  2282. };
  2283. billsContextMenuOptions.items.sprBlock = '----';
  2284. }
  2285. if (!readOnly) {
  2286. billsContextMenuOptions.items.batchInsert = {
  2287. name: '批量插入',
  2288. type: 'batchInsert',
  2289. value: '2',
  2290. icon: 'fa-sign-in',
  2291. batchInsert: function (obj, root) {
  2292. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  2293. obj.value = obj.max;
  2294. toastr.warning('批量插入不可多于' + obj.max);
  2295. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  2296. obj.value = obj.min;
  2297. toastr.warning('批量插入不可少于' + obj.min);
  2298. } else {
  2299. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  2300. root.$menu.trigger('contextmenu:hide');
  2301. }
  2302. },
  2303. disabled: function (key, opt) {
  2304. const sheet = billsSheet;
  2305. const selection = sheet.getSelections();
  2306. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2307. const row = sel ? sel.row : -1;
  2308. const tree = sheet.zh_tree;
  2309. if (!tree) return true;
  2310. const first = sheet.zh_tree.nodes[row];
  2311. const valid = !sheet.zh_setting.readOnly;
  2312. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  2313. }
  2314. };
  2315. billsContextMenuOptions.items.batchInsertBillsPos = {
  2316. name: '批量插入清单-计量单元',
  2317. icon: 'fa-sign-in',
  2318. visible: function (key, opt) {
  2319. return false;
  2320. },
  2321. disabled: function (key, opt) {
  2322. if (!isTz) return true;
  2323. const select = SpreadJsObj.getSelectObject(billsSheet);
  2324. if (select) {
  2325. if (select.code && select.code !== '') {
  2326. return !billsTree.isLeafXmj(select) || select.settle_status === settleStatus.finish;
  2327. } else {
  2328. const parent = billsTree.getParent(select);
  2329. return !(parent && billsTree.isLeafXmj(parent)) || !(parent && parent.settle_status === settleStatus.finish);
  2330. }
  2331. } else {
  2332. return false;
  2333. }
  2334. },
  2335. callback: function (key, opt) {
  2336. if (!batchInsertObj) {
  2337. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  2338. } else {
  2339. batchInsertObj.initView();
  2340. }
  2341. $('#batch').modal('show');
  2342. }
  2343. };
  2344. }
  2345. billsContextMenuOptions.items.sprTag = '----';
  2346. billsContextMenuOptions.items.showLast = {
  2347. name: '显示至最底层',
  2348. callback: function (key, opt, menu, e) {
  2349. const node = SpreadJsObj.getSelectObject(billsSheet);
  2350. setTimeout(() => {
  2351. showWaitingView();
  2352. billsTree.expandByCustom(x => {
  2353. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  2354. });
  2355. SpreadJsObj.refreshTreeRowVisible(billsSheet);
  2356. closeWaitingView();
  2357. }, 100);
  2358. },
  2359. };
  2360. $.contextMenu(billsContextMenuOptions);
  2361. // 计量单元 相关方法&绑定spreadjs事件
  2362. const posSpreadObj = {
  2363. refreshOperationValid: function (sheet, selection) {
  2364. const setObjEnable = function (obj, enable) {
  2365. if (enable) {
  2366. obj.removeClass('disabled');
  2367. } else {
  2368. obj.addClass('disabled');
  2369. }
  2370. };
  2371. const invalidAll = function () {
  2372. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  2373. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  2374. };
  2375. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2376. const row = sel ? sel.row : -1;
  2377. const first = sheet.zh_data[row];
  2378. if (!first) {
  2379. invalidAll();
  2380. return;
  2381. }
  2382. let last = first;
  2383. if (sel.rowCount > 1 && first) {
  2384. for (let r = 1; r < sel.rowCount; r++) {
  2385. const rNode = sheet.zh_data[sel.row + r];
  2386. if (!rNode) break;
  2387. last = rNode;
  2388. }
  2389. }
  2390. const preNode = sheet.zh_data[row - 1];
  2391. const valid = !sheet.zh_setting.readOnly;
  2392. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode && first.formc);
  2393. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1) && first.formc);
  2394. },
  2395. loadExprToInput: function () {
  2396. const sel = posSheet.getSelections()[0];
  2397. if (!sel) return;
  2398. const col = posSheet.zh_setting.cols[sel.col];
  2399. const cell = posSheet.getCell(sel.col, sel.col);
  2400. if (col && col.field === 'camount') {
  2401. const data = SpreadJsObj.getSelectObject(posSheet);
  2402. if (data) {
  2403. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  2404. if (!cInfo) {
  2405. if (posCol.readOnly.isChangeList(data)) {
  2406. $('#pos-expr').val('').attr('readOnly', true);
  2407. $('#pos-expr').removeAttr('data-row');
  2408. } else {
  2409. $('#pos-expr').val('').attr('field', col.field).attr('org', '')
  2410. .attr('readOnly', false).attr('data-row', sel.row);
  2411. }
  2412. } else {
  2413. const value = cInfo.camount_expr ? cInfo.camount_expr : cInfo.camount;
  2414. $('#pos-expr').val(value).attr('field', col.field).attr('org', cInfo.camount)
  2415. .attr('readOnly', posCol.readOnly.isSettle(data)).attr('data-row', sel.row);
  2416. }
  2417. } else {
  2418. $('#pos-expr').val('').attr('readOnly', true);
  2419. $('#pos-expr').removeAttr('data-row');
  2420. }
  2421. } else if (col && col.type === 'Number') {
  2422. const data = SpreadJsObj.getSelectObject(posSheet);
  2423. if (data) {
  2424. const exprInfo = getExprInfo(col.field);
  2425. const value = exprInfo
  2426. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  2427. : data[col.field];
  2428. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  2429. .attr('readOnly', readOnly || !data.formc || data.settle_status === settleStatus.finish).attr('data-row', sel.row);
  2430. } else {
  2431. $('#pos-expr').val('').attr('readOnly', true);
  2432. $('#pos-expr').removeAttr('data-row');
  2433. }
  2434. } else {
  2435. $('#pos-expr').val('').attr('readOnly', true);
  2436. $('#pos-expr').removeAttr('data-row');
  2437. }
  2438. },
  2439. /**
  2440. * 加载计量单元 根据当前台账选择节点
  2441. */
  2442. loadCurPosData: function () {
  2443. const node = SpreadJsObj.getSelectObject(billsSheet);
  2444. // SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  2445. // SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  2446. if (node) {
  2447. const posData = pos.getLedgerPos(node.id) || [];
  2448. console.log(posData);
  2449. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  2450. posSheet.zh_setting.readOnly = readOnly || (node.used && posData.length === 0) || (node.settle_status && node.settle_status === settleStatus.finish);
  2451. } else {
  2452. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  2453. posSheet.zh_setting.readOnly = true;
  2454. }
  2455. SpreadJsObj.massOperationSheet(posSheet, function () {
  2456. if (posSheet.zh_setting) {
  2457. posSheet.zh_setting.cols.forEach(function (col, i) {
  2458. for (let iRow = 0; iRow < posSheet.getRowCount(); iRow++) {
  2459. if (i !== 0 && col.field !== 'camount' && col.field !== 'is_valuation') {
  2460. posSheet.getCell(iRow, i).locked((posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].formc) || posSheet.zh_setting.readOnly || false);
  2461. } else {
  2462. let lock = false;
  2463. if (!posSheet.zh_data[iRow]) {
  2464. lock = true;
  2465. }
  2466. if (col.field === 'camount' && posCol.readOnly.isSettle(posSheet.zh_data[iRow])) {
  2467. lock = true;
  2468. }
  2469. posSheet.getCell(iRow, i).locked(lock || (posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].name) || posSheet.zh_setting.readOnly || false);
  2470. }
  2471. }
  2472. });
  2473. }
  2474. });
  2475. // SpreadJsObj.refreshSheetReadOnly(posSheet);
  2476. posSpreadObj.loadExprToInput();
  2477. posSpreadObj.refreshOperationValid(posSheet);
  2478. },
  2479. baseOpr: function (sheet, type) {
  2480. const data = {
  2481. postType: 'pos',
  2482. posPostType: type === 'delete' ? type : 'update',
  2483. postData: [],
  2484. };
  2485. const selection = sheet.getSelections();
  2486. const row = selection[0].row, count = selection[0].rowCount;
  2487. const first = sheet.zh_data[row];
  2488. if (type === 'delete') {
  2489. for (let iRow = 0; iRow < count; iRow++) {
  2490. const posData = sheet.zh_data[iRow + row];
  2491. if (posData) {
  2492. if (posData.used) {
  2493. toastr.error('"' + posData.name + '"已计量,请勿删除');
  2494. return;
  2495. }
  2496. if (posData.settle_status) {
  2497. toastr.error('"' + posData.name + '"已结算,请勿删除');
  2498. return;
  2499. }
  2500. data.postData.push(sheet.zh_data[iRow + row].id);
  2501. }
  2502. }
  2503. } else if (type === 'up-move') {
  2504. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  2505. for (let iRow = 0; iRow < count; iRow++) {
  2506. const posData = sheet.zh_data[iRow + row];
  2507. if (posData) {
  2508. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  2509. preUpdate.porder = posData.porder;
  2510. }
  2511. }
  2512. data.postData.push(preUpdate);
  2513. } else if (type === 'down-move') {
  2514. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  2515. for (let iRow = count - 1; iRow >= 0; iRow--) {
  2516. const posData = sheet.zh_data[iRow + row];
  2517. if (posData) {
  2518. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  2519. nextUpdate.porder = posData.porder;
  2520. }
  2521. }
  2522. data.postData.push(nextUpdate);
  2523. } else if (type === 'add') {
  2524. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2525. if (billsNode.settle_status === settleStatus.finish) {
  2526. toastr.warning('清单已结算,不可新增计量单元');
  2527. return;
  2528. }
  2529. }
  2530. if (data.postData.length > 0) {
  2531. postData(window.location.pathname + '/update', data, function (result) {
  2532. changeList = result.changeList;
  2533. if (type === 'delete') {
  2534. pos.removeDatas(result.pos);
  2535. sheet.deleteRows(row, count);
  2536. const loadResult = billsTree.loadPostData(result.ledger);
  2537. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2538. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2539. posSpreadObj.refreshOperationValid(posSheet);
  2540. } else {
  2541. pos.updateDatas(result.pos);
  2542. const sel = selection[0];
  2543. if (sel) {
  2544. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  2545. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  2546. }
  2547. posSpreadObj.loadCurPosData();
  2548. }
  2549. changeGclData = true;
  2550. });
  2551. }
  2552. },
  2553. editStarting: function (e, info) {
  2554. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2555. const sel = info.sheet.getSelections();
  2556. if (!sel || !sel[0]) return;
  2557. const col = info.sheet.zh_setting.cols[sel[0].col];
  2558. const node = SpreadJsObj.getSelectObject(info.sheet);
  2559. const exprInfo = getExprInfo(col.field);
  2560. if (col.field === 'camount') {
  2561. const cInfo = _.find(changeList, { gcl_id: node.lid, mx_id: node.id });
  2562. if (!cInfo) {
  2563. if (posCol.readOnly.isSettle(node)) {
  2564. toastr.error('清单数据未完善,无法编辑申请数量');
  2565. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2566. return
  2567. }
  2568. return
  2569. }
  2570. if (cInfo.camount_expr && cInfo.camount_expr !== '') {
  2571. info.sheet.getCell(info.row, info.col).text(cInfo.camount_expr);
  2572. }
  2573. } else if (node && exprInfo) {
  2574. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  2575. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  2576. }
  2577. }
  2578. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  2579. info.cancel = true;
  2580. }
  2581. },
  2582. buttonClicked: function (e, info) {
  2583. if (info.sheet.zh_setting) {
  2584. const select = SpreadJsObj.getSelectObject(info.sheet);
  2585. const col = info.sheet.zh_setting.cols[info.col];
  2586. if (col.field === 'is_change') {
  2587. if (posCol.readOnly.isChangeList(select)) {
  2588. info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
  2589. return
  2590. }
  2591. if (info.sheet.isEditing()) {
  2592. info.sheet.endEdit(true);
  2593. }
  2594. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2595. // const valutaionCol = _.findIndex(info.sheet.zh_setting.cols, { field: 'is_valuation' });
  2596. if (is_change) {
  2597. makeGclGatherData();
  2598. const gclInfo = _.find(gclGatherData, function (item) {
  2599. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
  2600. });
  2601. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
  2602. const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
  2603. const data = {
  2604. lid: select.lid,
  2605. code: gclInfo.b_code,
  2606. name: gclInfo.name || '',
  2607. unit: gclInfo.unit || '',
  2608. unit_price: gclInfo.unit_price,
  2609. oamount: xmjInfo.quantity,
  2610. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  2611. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  2612. xmj_code: xmjInfo.code || '',
  2613. xmj_jldy: xmjInfo.jldy || '',
  2614. xmj_dwgc: xmjInfo.dwgc || '',
  2615. xmj_fbgc: xmjInfo.fbgc || '',
  2616. xmj_fxgc: xmjInfo.fxgc || '',
  2617. gcl_id: select.lid,
  2618. mx_id: select.id,
  2619. }
  2620. if (oldCInfo) {
  2621. data.detail = oldCInfo.detail;
  2622. data.camount = oldCInfo.camount;
  2623. data.camount_expr = oldCInfo.camount_expr;
  2624. data.spamount = oldCInfo.spamount;
  2625. data.is_valuation = oldCInfo.is_valuation;
  2626. data.delimit = oldCInfo.delimit;
  2627. }
  2628. // 更新至服务器
  2629. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  2630. changeList = result.changeList;
  2631. select.is_change = 1;
  2632. select.is_valuation = data.is_valuation !== undefined ? data.is_valuation : 1;
  2633. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2634. // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
  2635. if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
  2636. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2637. billsNode.is_change = 1;
  2638. billsTreeSpreadObj.reCalcCamount(billsNode);
  2639. const loadResult = { update: [billsNode] };
  2640. const refreshNode = billsTree.loadPostData(loadResult);
  2641. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2642. }
  2643. }, function () {
  2644. info.sheet.setValue(info.row, info.col, 0);
  2645. });
  2646. } else {
  2647. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.lid, mx_id: select.id }) !== -1) {
  2648. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  2649. info.sheet.setValue(info.row, info.col, 1);
  2650. return
  2651. }
  2652. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  2653. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  2654. toastr.warning('该计量单元已被使用,无法取消变更');
  2655. info.sheet.setValue(info.row, info.col, 1);
  2656. return
  2657. } else if (checkIsSettle(cInfo)) {
  2658. toastr.warning('该计量单元已结算,无法取消变更');
  2659. info.sheet.setValue(info.row, info.col, 1);
  2660. return
  2661. } else {
  2662. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  2663. changeList = result.changeList;
  2664. select.is_change = 0;
  2665. select.is_valuation = 0;
  2666. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2667. // info.sheet.setValue(info.row, valutaionCol, 0);
  2668. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2669. billsTreeSpreadObj.reCalcCamount(billsNode);
  2670. // 判断是否只剩一个,并同步去勾
  2671. if (_.findIndex(changeList, { gcl_id: select.lid }) === -1) {
  2672. billsNode.is_change = 0;
  2673. }
  2674. const loadResult = { update: [billsNode] };
  2675. const refreshNode = billsTree.loadPostData(loadResult);
  2676. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2677. }, function () {
  2678. info.sheet.setValue(info.row, info.col, 1);
  2679. });
  2680. }
  2681. }
  2682. } else if (col.field === 'is_valuation') {
  2683. if (!posCol.getValue.isChange(select)) {
  2684. toastr.warning('请先勾选变更清单才能勾选计价');
  2685. info.sheet.setValue(info.row, info.col, !select || !select.is_valuation ? 0 : 1);
  2686. return;
  2687. }
  2688. if (info.sheet.isEditing()) {
  2689. info.sheet.endEdit(true);
  2690. }
  2691. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  2692. if (_.findIndex(changeUsedData, { cbid: cInfo.id }) !== -1) {
  2693. toastr.warning('该变更清单已被调用,无法更改计价');
  2694. info.sheet.setValue(info.row, info.col, cInfo.is_valuation);
  2695. return;
  2696. }
  2697. const is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2698. // select.is_valuation = is_valuation;
  2699. cInfo.is_valuation = is_valuation;
  2700. delete cInfo.waitingLoading;
  2701. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  2702. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2703. info.sheet.setValue(info.row, info.col, is_valuation);
  2704. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2705. SpreadJsObj.reLoadRowData(billsSheet, billsTree.getNodeIndex(billsNode));
  2706. }, function () {
  2707. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2708. cInfo.is_valuation = select.is_valuation;
  2709. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2710. });
  2711. }
  2712. }
  2713. },
  2714. /**
  2715. * 编辑单元格响应事件
  2716. * @param {Object} e
  2717. * @param {Object} info
  2718. */
  2719. editEnded: function (e, info) {
  2720. if (!info.sheet.zh_setting) {
  2721. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2722. return;
  2723. }
  2724. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  2725. const node = posSpreadObj.billsNode;
  2726. const col = info.sheet.zh_setting.cols[info.col];
  2727. if (col.field === 'is_change' || col.field === 'is_valuation') {
  2728. return;
  2729. }
  2730. if (col.field === 'camount') {
  2731. if (!node) {
  2732. toastr.error('数据错误,请选择台账节点后再试');
  2733. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2734. return;
  2735. }
  2736. let cInfo = _.find(changeList, { gcl_id: posData.lid, mx_id: posData.id });
  2737. if (!cInfo) {
  2738. if (posCol.readOnly.isSettle(posData)) {
  2739. toastr.error('清单数据未完善,无法编辑申请数量');
  2740. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2741. return
  2742. }
  2743. makeGclGatherData();
  2744. const gclInfo = _.find(gclGatherData, function (item) {
  2745. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: posData.lid, mx_id: posData.id });
  2746. });
  2747. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: posData.id });
  2748. const oldCInfo = _.find(oldChangeList, { gcl_id: posData.lid, mx_id: posData.id });
  2749. const data = {
  2750. lid: posData.lid,
  2751. code: gclInfo.b_code,
  2752. name: gclInfo.name || '',
  2753. unit: gclInfo.unit || '',
  2754. unit_price: gclInfo.unit_price,
  2755. oamount: xmjInfo.quantity,
  2756. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  2757. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  2758. xmj_code: xmjInfo.code || '',
  2759. xmj_jldy: xmjInfo.jldy || '',
  2760. xmj_dwgc: xmjInfo.dwgc || '',
  2761. xmj_fbgc: xmjInfo.fbgc || '',
  2762. xmj_fxgc: xmjInfo.fxgc || '',
  2763. gcl_id: posData.lid,
  2764. mx_id: posData.id,
  2765. }
  2766. if (oldCInfo) {
  2767. data.detail = oldCInfo.detail;
  2768. data.camount = oldCInfo.camount;
  2769. data.camount_expr = oldCInfo.camount_expr;
  2770. data.spamount = oldCInfo.spamount;
  2771. data.is_valuation = oldCInfo.is_valuation;
  2772. data.delimit = oldCInfo.delimit;
  2773. }
  2774. cInfo = data;
  2775. // toastr.error('未勾选变更清单,无法编辑申请数量');
  2776. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2777. // return;
  2778. }
  2779. let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
  2780. const orgValue = validText && validText !== ''
  2781. ? (_.toNumber(validText) ? cInfo.camount : cInfo.camount_expr)
  2782. : (cInfo.camount_expr && cInfo.camount_expr !== '' ? cInfo.camount_expr : cInfo.camount);
  2783. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  2784. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2785. return;
  2786. }
  2787. const exprQuantity = {
  2788. expr: '',
  2789. quantity: 0,
  2790. };
  2791. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  2792. if (!valid) {
  2793. toastr.error(msg);
  2794. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2795. return;
  2796. }
  2797. if (isNaN(exprQuantity.quantity)) {
  2798. toastr.error('不能输入其它非数字类型字符');
  2799. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2800. return;
  2801. }
  2802. validText = parseFloat(exprQuantity.quantity);
  2803. if (cInfo.id) {
  2804. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  2805. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  2806. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  2807. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  2808. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2809. return;
  2810. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  2811. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  2812. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2813. return;
  2814. }
  2815. }
  2816. cInfo[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  2817. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  2818. cInfo.camount_expr = exprQuantity.expr;
  2819. delete cInfo.waitingLoading;
  2820. if (cInfo.id) {
  2821. if (cInfo.camount === 0 && cInfo.camount_expr === '') {
  2822. if (changeOrder && _.findIndex(oldChangeList, {id: cInfo.id}) !== -1) {
  2823. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  2824. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2825. return
  2826. }
  2827. if (_.find(changeUsedData, {cbid: cInfo.id})) {
  2828. toastr.warning('清单计量单元已被使用,无法取消勾选');
  2829. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2830. return
  2831. } else if (checkIsSettle(cInfo)) {
  2832. toastr.warning('清单计量单元已结算,无法取消勾选');
  2833. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2834. return
  2835. }
  2836. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  2837. changeList = result.changeList;
  2838. node.is_change = 0;
  2839. node.is_valuation = 0;
  2840. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2841. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2842. billsTreeSpreadObj.reCalcCamount(billsNode);
  2843. // 判断是否只剩一个,并同步去勾
  2844. if (_.findIndex(changeList, { gcl_id: node.lid }) === -1) {
  2845. billsNode.is_change = 0;
  2846. }
  2847. const loadResult = { update: [billsNode] };
  2848. const refreshNode = billsTree.loadPostData(loadResult);
  2849. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2850. });
  2851. } else {
  2852. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type: 'update', updateData: cInfo }, function (result) {
  2853. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2854. const billsNode = node;
  2855. billsTreeSpreadObj.reCalcCamount(billsNode);
  2856. const loadResult = {update: [billsNode]};
  2857. const refreshNode = billsTree.loadPostData(loadResult);
  2858. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2859. }, function () {
  2860. cInfo[col.field] = orgValue;
  2861. cInfo.spamount = orgValue;
  2862. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2863. });
  2864. }
  2865. } else {
  2866. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  2867. changeList = result.changeList;
  2868. posData.is_change = 1;
  2869. posData.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  2870. posData.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  2871. posData.ca_tp = cInfo.camount !== undefined ? ZhCalc.mul(cInfo.camount, cInfo.unit_price, decimal.tp) : null;
  2872. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2873. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2874. // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
  2875. if (_.findIndex(changeList, { gcl_id: posData.lid }) !== -1) {
  2876. billsNode.is_change = 1;
  2877. }
  2878. billsTreeSpreadObj.reCalcCamount(billsNode);
  2879. const loadResult = { update: [billsNode] };
  2880. const refreshNode = billsTree.loadPostData(loadResult);
  2881. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2882. }, function () {
  2883. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2884. });
  2885. }
  2886. return;
  2887. }
  2888. const orgText = posData ? posData[col.field] : null;
  2889. const newText = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
  2890. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  2891. if (!node) {
  2892. toastr.error('数据错误,请选择台账节点后再试');
  2893. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2894. return;
  2895. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  2896. toastr.error('父节点不可插入计量单元');
  2897. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2898. return;
  2899. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  2900. toastr.error('项目节不可插入计量单元');
  2901. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2902. return;
  2903. }
  2904. const data = {postType: 'pos'};
  2905. if (col.field === 'name') {
  2906. if (newText === '' && posData) {
  2907. toastr.error('部位名称不可为空', 'error');
  2908. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2909. return;
  2910. } else if (!posData) {
  2911. if (newText && newText !== '') {
  2912. data.posPostType = 'add';
  2913. const sortData = info.sheet.zh_data;
  2914. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  2915. data.postData = { name: newText, lid: node.id, porder: order};
  2916. if (node.settle_status === settleStatus.finish) {
  2917. toastr.error('已结算清单不可插入计量单元');
  2918. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2919. return;
  2920. }
  2921. } else {
  2922. return;
  2923. }
  2924. } else {
  2925. data.posPostType = 'update';
  2926. data.postData = {id: posData.id, name: newText};
  2927. if (col.type === 'Number' && posData.settle_status === settleStatus.finish) {
  2928. toastr.error('计量单元已结算,不可修改');
  2929. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2930. return;
  2931. }
  2932. }
  2933. } else if (!posData) {
  2934. toastr.warning('新增计量单元请先输入名称');
  2935. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2936. return;
  2937. } else {
  2938. data.posPostType = 'update';
  2939. data.postData = {id: posData.id};
  2940. if (col.type === 'Number') {
  2941. const exprInfo = getExprInfo(col.field);
  2942. const num = _.toNumber(newText);
  2943. if (_.isFinite(num)) {
  2944. data.postData[col.field] = num;
  2945. if (exprInfo) {
  2946. data.postData[exprInfo.expr] = '';
  2947. }
  2948. } else {
  2949. try {
  2950. data.postData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
  2951. if (exprInfo) {
  2952. data.postData[exprInfo.expr] = newText;
  2953. }
  2954. } catch(err) {
  2955. toastr.error('输入的表达式非法');
  2956. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2957. return;
  2958. }
  2959. }
  2960. } else if (col.field.indexOf('_expr') > 0) {
  2961. const exprInfo = getExprInfo(col.field, true);
  2962. if (!exprInfo) return;
  2963. if (newText) {
  2964. try {
  2965. data.postData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
  2966. data.postData[exprInfo.expr] = newText;
  2967. } catch(err) {
  2968. toastr.error('输入的表达式非法');
  2969. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2970. return;
  2971. }
  2972. } else {
  2973. data.postData[exprInfo.qty] = 0;
  2974. data.postData[exprInfo.expr] = '';
  2975. }
  2976. } else {
  2977. data.postData[col.field] = newText;
  2978. }
  2979. }
  2980. postData(window.location.pathname + '/update', data, function (result) {
  2981. changeList = result.changeList;
  2982. const updateRst = pos.updateDatas(result.pos);
  2983. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  2984. if (updateRst.create.length > 0) {
  2985. posSpreadObj.loadCurPosData();
  2986. } else {
  2987. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2988. }
  2989. const loadResult = billsTree.loadPostData(result.ledger);
  2990. // 判断是否只剩一个,并同步去勾
  2991. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2992. // billsNode.is_change = ? 1 : 0;
  2993. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  2994. billsNode.is_change = 1;
  2995. } else {
  2996. billsNode.is_change = 0;
  2997. billsNode.is_valuation = 0;
  2998. billsNode.camount = null;
  2999. billsNode.ca_tp = null;
  3000. }
  3001. if (loadResult.update) {
  3002. const r = _.find(loadResult.update, { id: billsNode.id });
  3003. r.is_change = billsNode.is_change;
  3004. } else {
  3005. loadResult.update = [billsNode];
  3006. }
  3007. const refreshNode = billsTree.loadPostData(loadResult);
  3008. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3009. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3010. changeGclData = true;
  3011. }, function () {
  3012. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3013. });
  3014. },
  3015. /**
  3016. * 删除按钮响应事件
  3017. * @param sheet
  3018. */
  3019. deletePress: function (sheet) {
  3020. if (!sheet.zh_setting) return;
  3021. const sortData = sheet.zh_data;
  3022. const datas = [], posSelects = [], camountDatas = [];
  3023. const sel = sheet.getSelections()[0];
  3024. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  3025. let bDel = false;
  3026. const node = sortData[iRow];
  3027. if (node) {
  3028. const data = {id: node.id};
  3029. const cData = {};
  3030. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  3031. const colSetting = sheet.zh_setting.cols[iCol];
  3032. if (colSetting.field === 'name') {
  3033. toastr.error('部位名称不能为空');
  3034. return;
  3035. }
  3036. const style = sheet.getStyle(iRow, iCol);
  3037. if (!style.locked) {
  3038. const colSetting = sheet.zh_setting.cols[iCol];
  3039. if (colSetting.field === 'camount') {
  3040. const cInfo = _.find(changeList, { gcl_id: node.lid, mx_id: node.id });
  3041. if (!cInfo) continue;
  3042. cData.id = cInfo.id;
  3043. cData.camount = null;
  3044. cData.camount_expr = '';
  3045. cData.spamount = null;
  3046. } else if (colSetting.field.indexOf('_expr') > 0) {
  3047. const exprInfo = getExprInfo(colSetting.field, true);
  3048. if (!exprInfo) continue;
  3049. data[exprInfo.expr] = '';
  3050. data[exprInfo.qty] = 0;
  3051. } else {
  3052. data[colSetting.field] = null;
  3053. const exprInfo = getExprInfo(colSetting.field);
  3054. if (exprInfo) data[exprInfo.expr] = '';
  3055. }
  3056. bDel = true;
  3057. }
  3058. }
  3059. if (bDel) {
  3060. datas.push(data);
  3061. if (cData.id) camountDatas.push(cData);
  3062. posSelects.push(node);
  3063. }
  3064. }
  3065. }
  3066. if (camountDatas.length > 0) {
  3067. for (const cInfo of camountDatas) {
  3068. if (changeOrder && _.findIndex(oldChangeList, {id: cInfo.id}) !== -1) {
  3069. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  3070. posSpreadObj.loadCurPosData();
  3071. return
  3072. }
  3073. if (_.find(changeUsedData, {cbid: cInfo.id})) {
  3074. toastr.warning('该计量单元已被使用,无法取消变更');
  3075. posSpreadObj.loadCurPosData();
  3076. return
  3077. } else if (checkIsSettle(cInfo)) {
  3078. toastr.warning('该计量单元已结算,无法取消变更');
  3079. posSpreadObj.loadCurPosData();
  3080. return
  3081. }
  3082. }
  3083. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: _.map(camountDatas, 'id') }, function (result) {
  3084. changeList = result.changeList;
  3085. for (const d of datas) {
  3086. d.is_change = 0;
  3087. d.is_valuation = 0;
  3088. }
  3089. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3090. billsTreeSpreadObj.reCalcCamount(billsNode);
  3091. // 判断是否只剩一个,并同步去勾
  3092. if (_.findIndex(changeList, { gcl_id: posSelects[0].lid }) === -1) {
  3093. billsNode.is_change = 0;
  3094. }
  3095. const loadResult = { update: [billsNode] };
  3096. const refreshNode = billsTree.loadPostData(loadResult);
  3097. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3098. posSpreadObj.loadCurPosData();
  3099. }, function () {
  3100. posSpreadObj.loadCurPosData();
  3101. });
  3102. // postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountDatas }, function (result) {
  3103. // changeList = result;
  3104. // const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3105. // billsTreeSpreadObj.reCalcCamount(billsNode);
  3106. // const loadResult = { update: [billsNode] };
  3107. // const refreshNode = billsTree.loadPostData(loadResult);
  3108. // billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3109. // posSpreadObj.loadCurPosData();
  3110. // }, function () {
  3111. // posSpreadObj.loadCurPosData();
  3112. // });
  3113. return;
  3114. }
  3115. if (datas.length > 0) {
  3116. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  3117. changeList = result.changeList;
  3118. pos.updateDatas(result.pos);
  3119. posSpreadObj.loadCurPosData();
  3120. const loadResult = billsTree.loadPostData(result.ledger);
  3121. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3122. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3123. changeGclData = true;
  3124. }, function () {
  3125. posSpreadObj.loadCurPosData();
  3126. });
  3127. }
  3128. },
  3129. /**
  3130. * 删除 计量单元
  3131. * @param sheet
  3132. */
  3133. deletePos: function (sheet) {
  3134. const selection = sheet.getSelections();
  3135. const data = {
  3136. postType: 'pos',
  3137. posPostType: 'delete',
  3138. postData: [],
  3139. };
  3140. const row = selection[0].row, count = selection[0].rowCount;
  3141. const sortData = sheet.zh_data;
  3142. for (let iRow = 0; iRow < count; iRow++) {
  3143. const posData = sortData[iRow + row];
  3144. if (posData) {
  3145. if (posData.used) {
  3146. toastr.error('"' + posData.name + '"已计量,请勿删除');
  3147. return;
  3148. }
  3149. if (posData.settle_status === settleStatus.finish) {
  3150. toastr.error(`"${posData.name}"已计量,请勿删除`);
  3151. return;
  3152. }
  3153. data.postData.push(sortData[iRow + row].id);
  3154. }
  3155. }
  3156. if (data.postData.length > 0) {
  3157. postData(window.location.pathname + '/update', data, function (result) {
  3158. changeList = result.changeList;
  3159. pos.removeDatas(result.pos);
  3160. sheet.deleteRows(row, count);
  3161. const loadResult = billsTree.loadPostData(result.ledger);
  3162. // 判断是否只剩一个,并同步去勾
  3163. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3164. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  3165. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  3166. billsNode.is_change = 1;
  3167. } else {
  3168. billsNode.is_change = 0;
  3169. billsNode.is_valuation = 0;
  3170. billsNode.camount = null;
  3171. billsNode.ca_tp = null;
  3172. }
  3173. if (loadResult.update) {
  3174. const r = _.find(loadResult.update, { id: billsNode.id });
  3175. r.is_change = billsNode.is_change;
  3176. } else {
  3177. loadResult.update = [billsNode];
  3178. }
  3179. billsTreeSpreadObj.reCalcCamount(billsNode);
  3180. const refreshNode = billsTree.loadPostData(loadResult);
  3181. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3182. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3183. changeGclData = true;
  3184. });
  3185. }
  3186. },
  3187. /**
  3188. * 粘贴单元格响应事件
  3189. * @param e
  3190. * @param info
  3191. */
  3192. clipboardPasted: function (e, info) {
  3193. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  3194. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  3195. }
  3196. const node = SpreadJsObj.getSelectObject(billsSheet);
  3197. if (node.code && (node.code !== '')) {
  3198. toastr.error('项目节不可含有节点明细');
  3199. posSpreadObj.loadCurPosData();
  3200. return;
  3201. }
  3202. if (node.children && (node.children.length > 0)) {
  3203. toastr.error('仅节点子项可以含有计量单元');
  3204. posSpreadObj.loadCurPosData();
  3205. return;
  3206. }
  3207. if (node.settle_status === settleStatus.finish) {
  3208. toastr.error('清单已结算,请勿修改计量单元数据');
  3209. posSpread.loadCurPosData();
  3210. return;
  3211. }
  3212. if (!info.sheet.zh_setting) {
  3213. posSpreadObj.loadCurPosData();
  3214. return;
  3215. }
  3216. const data = [];
  3217. const camountData = [], insertCamountData = [];
  3218. const sortData = info.sheet.zh_data || [];
  3219. const hint = {
  3220. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  3221. settle: {type: 'warning', msg: '计量单元已结算,不可修改台账数据,已过滤'},
  3222. };
  3223. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  3224. const nameCol = info.sheet.zh_setting.cols.findIndex(x => { return x.field === 'name'; });
  3225. if (info.cellRange.col > nameCol || info.cellRange.col + info.cellRange.colCount < nameCol) {
  3226. toastr.warning('新增计量单元请先输入名称');
  3227. posSpreadObj.loadCurPosData();
  3228. return;
  3229. }
  3230. }
  3231. let bHint = false;
  3232. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  3233. makeGclGatherData();
  3234. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3235. let bPaste = true;
  3236. const curRow = info.cellRange.row + iRow;
  3237. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  3238. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  3239. const curCol = info.cellRange.col + iCol;
  3240. const colSetting = info.sheet.zh_setting.cols[curCol];
  3241. if (!colSetting) continue;
  3242. posData[colSetting.field] = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  3243. if (posData.id && colSetting.type === 'Number' && sortData[curRow].settle_status === settleStatus.finish) {
  3244. bPaste = false;
  3245. toastMessageUniq(hint.settle);
  3246. continue;
  3247. }
  3248. if (colSetting.field === 'camount') {
  3249. bPaste = true;
  3250. let validText = posData[colSetting.field];
  3251. let cInfo = _.find(changeList, { gcl_id: posData.lid, mx_id: posData.id });
  3252. if (!cInfo) {
  3253. const gclInfo = _.find(gclGatherData, function (item) {
  3254. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: posData.lid, mx_id: posData.id });
  3255. });
  3256. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: posData.id });
  3257. const oldCInfo = _.find(oldChangeList, { gcl_id: posData.lid, mx_id: posData.id });
  3258. const data = {
  3259. lid: posData.lid,
  3260. code: gclInfo.b_code,
  3261. name: gclInfo.name || '',
  3262. unit: gclInfo.unit || '',
  3263. unit_price: gclInfo.unit_price,
  3264. oamount: xmjInfo.quantity,
  3265. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  3266. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  3267. xmj_code: xmjInfo.code || '',
  3268. xmj_jldy: xmjInfo.jldy || '',
  3269. xmj_dwgc: xmjInfo.dwgc || '',
  3270. xmj_fbgc: xmjInfo.fbgc || '',
  3271. xmj_fxgc: xmjInfo.fxgc || '',
  3272. gcl_id: posData.lid,
  3273. mx_id: posData.id,
  3274. }
  3275. if (oldCInfo) {
  3276. data.detail = oldCInfo.detail;
  3277. data.camount = oldCInfo.camount;
  3278. data.camount_expr = oldCInfo.camount_expr;
  3279. data.spamount = oldCInfo.spamount;
  3280. data.is_valuation = oldCInfo.is_valuation;
  3281. data.delimit = oldCInfo.delimit;
  3282. }
  3283. cInfo = data;
  3284. // bPaste = false;
  3285. // continue;
  3286. }
  3287. const exprQuantity = {
  3288. expr: '',
  3289. quantity: 0,
  3290. };
  3291. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  3292. if (!valid) {
  3293. toastMessageUniq(hint.expr);
  3294. bPaste = false;
  3295. continue;
  3296. }
  3297. if (isNaN(exprQuantity.quantity)) {
  3298. toastMessageUniq(hint.expr);
  3299. bPaste = false;
  3300. continue;
  3301. }
  3302. validText = parseFloat(exprQuantity.quantity);
  3303. if (cInfo.id) {
  3304. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3305. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  3306. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3307. toastr.error(curRow ? '计量单元第' + (curRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3308. bPaste = false;
  3309. continue;
  3310. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3311. toastr.error(curRow ? '计量单元第' + (curRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3312. bPaste = false;
  3313. continue;
  3314. }
  3315. }
  3316. if (bPaste) {
  3317. if (cInfo.id) {
  3318. camountData.push({id: cInfo.id, camount: ZhCalc.round(validText, findDecimal(node.unit)) || 0, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
  3319. } else {
  3320. cInfo.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  3321. cInfo.camount_expr = exprQuantity.expr;
  3322. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  3323. insertCamountData.push(cInfo);
  3324. }
  3325. } else {
  3326. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  3327. }
  3328. continue;
  3329. }
  3330. if (colSetting.type === 'Number') {
  3331. const num = _.toNumber(posData[colSetting.field]);
  3332. if (num) {
  3333. posData[colSetting.field] = num;
  3334. } else {
  3335. try {
  3336. posData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(posData[colSetting.field]));
  3337. const exprInfo = getExprInfo(colSetting.field);
  3338. if (exprInfo) {
  3339. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  3340. }
  3341. } catch (err) {
  3342. if (!bHint) {
  3343. toastr.warning('粘贴了非法表达式,已过滤');
  3344. bHint = true;
  3345. }
  3346. bPaste = false;
  3347. }
  3348. }
  3349. } else if (colSetting.field.indexOf('_expr') > 0) {
  3350. try {
  3351. const exprInfo = getExprInfo(colSetting.field, true);
  3352. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  3353. if (posData[exprInfo.expr] || !posData[exprInfo.qty]) {
  3354. posData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(posData[exprInfo.expr]));
  3355. }
  3356. bPaste = true;
  3357. } catch (err) {
  3358. toastMessageUniq(hint.expr);
  3359. }
  3360. } else {
  3361. bPaste = true;
  3362. }
  3363. }
  3364. if (bPaste) {
  3365. data.push(posData);
  3366. }
  3367. }
  3368. if (camountData.length > 0 || insertCamountData.length > 0) {
  3369. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', insertData: insertCamountData, updateData: camountData }, function (result) {
  3370. changeList = result;
  3371. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3372. billsTreeSpreadObj.reCalcCamount(billsNode);
  3373. const loadResult = { update: [billsNode] };
  3374. const refreshNode = billsTree.loadPostData(loadResult);
  3375. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3376. posSpreadObj.loadCurPosData();
  3377. }, function () {
  3378. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3379. return;
  3380. });
  3381. return;
  3382. }
  3383. if (data.length === 0) {
  3384. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3385. return;
  3386. }
  3387. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  3388. changeList = result.changeList;
  3389. pos.updateDatas(result.pos);
  3390. posSpreadObj.loadCurPosData();
  3391. const loadResult = result.ledger;
  3392. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3393. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  3394. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  3395. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  3396. billsNode.is_change = 1;
  3397. } else {
  3398. billsNode.is_change = 0;
  3399. billsNode.is_valuation = 0;
  3400. billsNode.camount = null;
  3401. billsNode.ca_tp = null;
  3402. }
  3403. if (loadResult.update && loadResult.update.length > 0) {
  3404. const r = _.find(loadResult.update, { id: billsNode.id });
  3405. console.log(r, billsNode, loadResult.update);
  3406. r.is_change = billsNode.is_change;
  3407. } else {
  3408. loadResult.update = [billsNode];
  3409. }
  3410. billsTreeSpreadObj.reCalcCamount(billsNode);
  3411. const refreshNode = billsTree.loadPostData(loadResult);
  3412. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3413. posSpreadObj.loadCurPosData();
  3414. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3415. changeGclData = true;
  3416. }, function () {
  3417. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3418. });
  3419. },
  3420. selectionChanged: function (e, info) {
  3421. posSpreadObj.loadExprToInput();
  3422. posSpreadObj.refreshOperationValid(posSheet);
  3423. },
  3424. addPegs: function (pegs) {
  3425. if (!pegs || pegs.length <= 0) return;
  3426. const node = SpreadJsObj.getSelectObject(billsSheet);
  3427. if (!node) return;
  3428. const sheet = posSpread.getActiveSheet();
  3429. const sortData = sheet.zh_data || [];
  3430. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  3431. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  3432. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  3433. changeList = result.changeList;
  3434. pos.updateDatas(result.pos);
  3435. posSpreadObj.loadCurPosData();
  3436. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3437. changeGclData = true;
  3438. });
  3439. }
  3440. };
  3441. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  3442. if (!readOnly) {
  3443. $('a[name="pos-opr"]').click(function () {
  3444. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  3445. });
  3446. $('#pos-expr').bind('change onblur', function () {
  3447. if (this.readOnly) return;
  3448. const expr = $(this);
  3449. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  3450. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  3451. if (!select) return;
  3452. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3453. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  3454. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  3455. if (field === 'camount') {
  3456. let cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  3457. if (!cInfo) {
  3458. if (posCol.readOnly.isSettle(select)) {
  3459. toastr.error('清单数据未完善,无法编辑申请数量');
  3460. SpreadJsObj.reLoadRowData(posSheet, row);
  3461. return
  3462. }
  3463. makeGclGatherData();
  3464. const gclInfo = _.find(gclGatherData, function (item) {
  3465. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
  3466. });
  3467. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
  3468. const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
  3469. const data = {
  3470. lid: select.lid,
  3471. code: gclInfo.b_code,
  3472. name: gclInfo.name || '',
  3473. unit: gclInfo.unit || '',
  3474. unit_price: gclInfo.unit_price,
  3475. oamount: xmjInfo.quantity,
  3476. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  3477. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  3478. xmj_code: xmjInfo.code || '',
  3479. xmj_jldy: xmjInfo.jldy || '',
  3480. xmj_dwgc: xmjInfo.dwgc || '',
  3481. xmj_fbgc: xmjInfo.fbgc || '',
  3482. xmj_fxgc: xmjInfo.fxgc || '',
  3483. gcl_id: select.lid,
  3484. mx_id: select.id,
  3485. }
  3486. if (oldCInfo) {
  3487. data.detail = oldCInfo.detail;
  3488. data.camount = oldCInfo.camount;
  3489. data.camount_expr = oldCInfo.camount_expr;
  3490. data.spamount = oldCInfo.spamount;
  3491. data.is_valuation = oldCInfo.is_valuation;
  3492. data.delimit = oldCInfo.delimit;
  3493. }
  3494. cInfo = data;
  3495. // toastr.error('未勾选变更清单,无法编辑申请数量');
  3496. // return;
  3497. }
  3498. const exprQuantity = {
  3499. expr: '',
  3500. quantity: 0,
  3501. };
  3502. const [valid, msg] = billsTreeSpreadObj._checkExpr(newValue, exprQuantity);
  3503. if (!valid) {
  3504. toastr.error(msg);
  3505. return;
  3506. }
  3507. if (isNaN(exprQuantity.quantity)) {
  3508. toastr.error('不能输入其它非数字类型字符');
  3509. return;
  3510. }
  3511. const camount = parseFloat(exprQuantity.quantity);
  3512. if (cInfo.id) {
  3513. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3514. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  3515. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3516. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3517. return;
  3518. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3519. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3520. return;
  3521. }
  3522. }
  3523. cInfo.camount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
  3524. cInfo.spamount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
  3525. cInfo.camount_expr = exprQuantity.expr;
  3526. delete cInfo.waitingLoading;
  3527. if (cInfo.id) {
  3528. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  3529. SpreadJsObj.reLoadRowData(posSheet, row);
  3530. billsTreeSpreadObj.reCalcCamount(billsNode);
  3531. const loadResult = { update: [billsNode] };
  3532. const refreshNode = billsTree.loadPostData(loadResult);
  3533. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3534. posSpreadObj.loadExprToInput(posSheet);
  3535. }, function () {
  3536. cInfo.camount = orgValue;
  3537. cInfo.spamount = orgValue;
  3538. SpreadJsObj.reLoadRowData(posSheet, row);
  3539. });
  3540. } else {
  3541. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  3542. changeList = result.changeList;
  3543. select.is_change = 1;
  3544. select.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  3545. select.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  3546. select.ca_tp = cInfo.camount !== undefined ? ZhCalc.mul(cInfo.camount, cInfo.unit_price, decimal.tp) : null;
  3547. SpreadJsObj.reLoadRowData(posSheet, row);
  3548. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3549. // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
  3550. if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
  3551. billsNode.is_change = 1;
  3552. }
  3553. billsTreeSpreadObj.reCalcCamount(billsNode);
  3554. const loadResult = { update: [billsNode] };
  3555. const refreshNode = billsTree.loadPostData(loadResult);
  3556. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3557. }, function () {
  3558. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3559. });
  3560. }
  3561. return;
  3562. }
  3563. const data = {id: select.id};
  3564. const exprInfo = getExprInfo(field);
  3565. if (newValue !== '') {
  3566. const num = _.toNumber(newValue);
  3567. if (num) {
  3568. data[field] = num;
  3569. if (exprInfo) data[exprInfo.expr] = '';
  3570. } else {
  3571. try {
  3572. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  3573. if (exprInfo) data[exprInfo.expr] = newValue;
  3574. } catch (err) {
  3575. toastr.error('输入的表达式非法');
  3576. return;
  3577. }
  3578. }
  3579. } else {
  3580. data[field] = null;
  3581. if (exprInfo) data[exprInfo.expr] = '';
  3582. }
  3583. // 更新至服务器
  3584. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  3585. changeList = result.changeList;
  3586. const updateRst = pos.updateDatas(result.pos);
  3587. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  3588. SpreadJsObj.reLoadRowData(posSheet, row);
  3589. const loadResult = billsTree.loadPostData(result.ledger);
  3590. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3591. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3592. changeGclData = true;
  3593. });
  3594. });
  3595. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  3596. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  3597. posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
  3598. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  3599. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  3600. $.contextMenu({
  3601. selector: '#pos-spread',
  3602. build: function ($trigger, e) {
  3603. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  3604. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3605. },
  3606. items: {
  3607. 'delete': {
  3608. name: '删除',
  3609. icon: 'fa-remove',
  3610. disabled: function (key, opt) {
  3611. if (posSheet.zh_data) {
  3612. const selection = posSheet.getSelections();
  3613. const sel = selection ? selection[0] : sheet.getSelections()[0];
  3614. const row = sel ? sel.row : -1;
  3615. const rowCount = sel.rowCount;
  3616. let settleFinish = false;
  3617. for (let i = row; i < row + rowCount; i++) {
  3618. if (!posSheet.zh_data[i]) continue;
  3619. settleFinish = settleFinish || posSheet.zh_data[i].settle_status === settleStatus.finish;
  3620. }
  3621. return (posSheet.zh_data.length < selection[0].row + selection[0].rowCount) || (posSheet.zh_data[selection[0].row] && !posSheet.zh_data[selection[0].row].formc) || settleFinish;
  3622. } else {
  3623. return true;
  3624. }
  3625. },
  3626. callback: function (key, opt) {
  3627. posSpreadObj.deletePos(posSheet);
  3628. }
  3629. },
  3630. }
  3631. });
  3632. }
  3633. // 加载清单&计量单元数据
  3634. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  3635. let gclGatherData;
  3636. postData(preUrl + '/defaultBills', { from: 'revise' }, function (result) {
  3637. for (const b of result.bills) {
  3638. if (!(b.is_leaf && b.b_code)) {
  3639. b.is_change = 0;
  3640. b.is_valutaion = 0;
  3641. } else {
  3642. const cInfo = _.find(changeList, { gcl_id: b.id });
  3643. b.is_change = cInfo ? 1 : 0;
  3644. b.is_valuation = cInfo ? cInfo.is_valuation : 0;
  3645. b.camount = cInfo ? cInfo.camount : 0;
  3646. }
  3647. }
  3648. billsTree.loadDatas(result.bills);
  3649. pos.loadDatas(result.pos);
  3650. treeCalc.calculateAll(billsTree);
  3651. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  3652. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  3653. checkShowLast(result.bills.length);
  3654. posSpreadObj.loadCurPosData();
  3655. SpreadJsObj.resetTopAndSelect(posSheet);
  3656. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3657. billsTreeSpreadObj.loadExprToInput(billsSheet);
  3658. checkList.loadHisCheckData();
  3659. makeGclGatherData();
  3660. console.log(billsTree);
  3661. }, null);
  3662. $.divResizer({
  3663. select: '#revise-resize',
  3664. callback: function () {
  3665. billsSpread.refresh();
  3666. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  3667. $(".sp-wrap").height(bcontent-30);
  3668. posSpread.refresh();
  3669. }
  3670. });
  3671. function makeGclGatherData() {
  3672. if (changeGclData || !gclGatherData) {
  3673. gclGatherModel.loadLedgerData(billsTree.datas);
  3674. gclGatherModel.loadPosData(pos.datas);
  3675. gclGatherData = gclGatherModel.gatherGclData();
  3676. gclGatherData = _.filter(gclGatherData, function (item) {
  3677. return item.leafXmjs && item.leafXmjs.length !== 0;
  3678. });
  3679. gclGatherData = gclGatherData.sort(sortByCode);
  3680. changeGclData = false;
  3681. }
  3682. }
  3683. class DealBills {
  3684. constructor (selector, spreadSetting) {
  3685. const self = this;
  3686. this.loaded = false;
  3687. this.obj = $(selector)[0];
  3688. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  3689. this.spreadSetting = spreadSetting;
  3690. this.spread = SpreadJsObj.createNewSpread(this.obj);
  3691. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  3692. if (!readOnly) {
  3693. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3694. const dealSheet = info.sheet;
  3695. const mainSheet = billsSheet;
  3696. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  3697. if (!dealBills) { return; }
  3698. const mainTree = mainSheet.zh_tree;
  3699. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  3700. if (!mainNode || !mainTree) { return; }
  3701. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3702. toastr.warning('非最底层项目下,不应添加节点');
  3703. return;
  3704. }
  3705. if (mainNode.settle_status === settleStatus.finish) {
  3706. toastr.warning('已结算节点下,不应添加签约清单');
  3707. return;
  3708. }
  3709. postData(window.location.pathname + '/update', {
  3710. postType: 'add-deal',
  3711. postData: {
  3712. id: mainNode.ledger_id,
  3713. type: mainNode.code ? 'child' : 'next',
  3714. dealBills: {
  3715. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  3716. unit_price: dealBills.unit_price,
  3717. }
  3718. },
  3719. }, function (result) {
  3720. changeList = result.changeList;
  3721. const refreshData = mainTree.loadPostData(result);
  3722. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  3723. const sel = mainSheet.getSelections()[0];
  3724. if (sel && refreshData.create[0]) {
  3725. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  3726. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  3727. }
  3728. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3729. billsSpread.focus();
  3730. posSpreadObj.loadCurPosData();
  3731. changeGclData = true;
  3732. });
  3733. });
  3734. }
  3735. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  3736. }
  3737. loadData (callback) {
  3738. if (this.loaded) {
  3739. if (callback) callback();
  3740. return;
  3741. }
  3742. const self = this;
  3743. postData(this.url+'/get-data', {}, function (data) {
  3744. self.data = data;
  3745. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  3746. self.loaded = true;
  3747. if (callback) callback();
  3748. });
  3749. }
  3750. calculateData () {
  3751. if (this.data) {
  3752. for (const d of this.data) {
  3753. d.total_price = _.multiply(d.quantity, d.unit_price);
  3754. }
  3755. }
  3756. }
  3757. }
  3758. class BatchInsertBillsPosObj {
  3759. constructor (obj) {
  3760. const self = this;
  3761. this.obj = obj;
  3762. this.billsCount = 6;
  3763. this.posCount = 1000;
  3764. this.filter = getLocalCache('zh-calc-batch-filter');
  3765. if (!this.filter) {
  3766. this.filter = '1';
  3767. }
  3768. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  3769. // 初始化 清单编号窗口 参数
  3770. this.qdSpreadSetting = {
  3771. cols: [
  3772. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  3773. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  3774. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3775. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3776. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  3777. ],
  3778. emptyRows: this.billsCount,
  3779. headRows: 1,
  3780. headRowHeight: [32],
  3781. headerFont: '12px 微软雅黑',
  3782. font: '12px 微软雅黑',
  3783. };
  3784. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  3785. // 初始化 部位数量复核表 参数
  3786. this.posSpreadSetting = {
  3787. cols: [
  3788. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  3789. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  3790. ],
  3791. emptyRows: this.posCount,
  3792. headRows: 1,
  3793. headRowHeight: [32],
  3794. headerFont: '12px 微软雅黑',
  3795. font: '12px 微软雅黑',
  3796. };
  3797. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  3798. this.posSpreadSetting.cols.push(
  3799. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  3800. )
  3801. }
  3802. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  3803. // 初始化 签约节点 参数
  3804. this.dealSpreadSetting = {
  3805. cols: [
  3806. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  3807. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  3808. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  3809. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  3810. ],
  3811. emptyRows: 0,
  3812. headRows: 1,
  3813. headRowHeight: [32],
  3814. headerFont: '12px 微软雅黑',
  3815. font: '12px 微软雅黑',
  3816. };
  3817. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  3818. // 初始化 清单编号、部位数量复核表 表格
  3819. this.initView();
  3820. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  3821. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  3822. // 拉取签约节点数据
  3823. dealBills.loadData(() => {
  3824. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  3825. });
  3826. // 双击签约节点,自动添加到清单编号窗口
  3827. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  3828. const deal = info.sheet.zh_data[info.row];
  3829. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  3830. const sel = qdSheet.getSelections()[0];
  3831. qdSheet.getCell(sel.row, 0).value(deal.code);
  3832. qdSheet.getCell(sel.row, 1).value(deal.name);
  3833. qdSheet.getCell(sel.row, 2).value(deal.unit);
  3834. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  3835. if (sel.row + 1 === qdSheet.getRowCount()) {
  3836. const count = sel.row + 2;
  3837. qdSheet.setRowCount(count);
  3838. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  3839. const colCount = posSheet.getColumnCount() + 1;
  3840. posSheet.setColumnCount(colCount);
  3841. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  3842. }
  3843. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  3844. qdSheet.getParent().focus();
  3845. });
  3846. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3847. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  3848. const count = posSheet.getColumnCount() - 2;
  3849. if (billsCount > count) {
  3850. posSheet.setColumnCount(billsCount + 2);
  3851. for (let i = count + 1; i <= billsCount; i++) {
  3852. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3853. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3854. }
  3855. }
  3856. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  3857. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3858. if (dealBills && dealBills.length > 0) {
  3859. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3860. const curRow = iRow + info.cellRange.row;
  3861. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  3862. if (bills) {
  3863. info.sheet.getCell(curRow, 1).value(bills.name);
  3864. info.sheet.getCell(curRow, 2).value(bills.unit);
  3865. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  3866. }
  3867. }
  3868. }
  3869. }
  3870. });
  3871. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3872. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  3873. const count = qdSheet.getRowCount();
  3874. if (billsCount > count) {
  3875. qdSheet.setRowCount(billsCount);
  3876. for (let i = count + 1; i <= billsCount; i++) {
  3877. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3878. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3879. }
  3880. }
  3881. });
  3882. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  3883. if (info.col === 0) {
  3884. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3885. if (dealBills && dealBills.length > 0) {
  3886. const bills = _.find(dealBills, {code: info.editingText});
  3887. if (bills) {
  3888. info.sheet.getCell(info.row, 1).value(bills.name);
  3889. info.sheet.getCell(info.row, 2).value(bills.unit);
  3890. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  3891. }
  3892. }
  3893. }
  3894. });
  3895. this.obj.bind('shown.bs.modal', function () {
  3896. self.qdSpread.refresh();
  3897. self.posSpread.refresh();
  3898. self.dealSpread.refresh();
  3899. });
  3900. $('#batch-ok').click(function () {
  3901. const selection = billsSheet.getSelections();
  3902. const sel = selection[0];
  3903. const row = selection[0].row;
  3904. const select = billsTree.nodes[row];
  3905. if (select) {
  3906. const insertData = {};
  3907. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  3908. insertData.id = select[billsTree.setting.id];
  3909. insertData.batchData = self.getBatchData();
  3910. if (insertData.batchData.length > 0) {
  3911. postData(window.location.pathname + '/update', {
  3912. postType: 'batch-insert',
  3913. postData: insertData
  3914. }, function (data) {
  3915. changeList = result.changeList;
  3916. pos.updateDatas(data.pos);
  3917. const result = billsTree.loadPostData(data.ledger);
  3918. billsTreeSpreadObj.refreshTree(billsSheet, result);
  3919. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  3920. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  3921. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  3922. posSpreadObj.loadCurPosData();
  3923. changeGclData = true;
  3924. self.obj.modal('hide');
  3925. }, null, true);
  3926. } else {
  3927. self.obj.modal('hide');
  3928. }
  3929. }
  3930. });
  3931. $('input[name=batch-filter]').change(function () {
  3932. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  3933. });
  3934. $.contextMenu({
  3935. selector: '.batch-l-t',
  3936. build: function ($trigger, e) {
  3937. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  3938. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3939. },
  3940. items: {
  3941. 'create': {
  3942. name: '新增行',
  3943. icon: 'fa-sign-in',
  3944. callback: function (key, opt) {
  3945. const qdSheet = self.qdSpread.getActiveSheet();
  3946. const posSheet = self.posSpread.getActiveSheet();
  3947. qdSheet.addRows(qdSheet.getRowCount(), 1);
  3948. const index = qdSheet.getRowCount();
  3949. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  3950. posSheet.addColumns(posSheet.getColumnCount(), 1);
  3951. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  3952. },
  3953. },
  3954. 'delete': {
  3955. name: '删除行',
  3956. icon: 'fa-remove',
  3957. callback: function (key, opt) {
  3958. const qdSheet = self.qdSpread.getActiveSheet();
  3959. const posSheet = self.posSpread.getActiveSheet();
  3960. const sel = qdSheet.getSelections()[0];
  3961. qdSheet.deleteRows(sel.row, sel.rowCount);
  3962. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  3963. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  3964. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  3965. }
  3966. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  3967. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  3968. }
  3969. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  3970. },
  3971. },
  3972. }
  3973. });
  3974. }
  3975. // 初始化左侧表格
  3976. initView () {
  3977. // 初始化 清单编号
  3978. const qdSheet = this.qdSpread.getActiveSheet();
  3979. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  3980. SpreadJsObj.refreshColumnAlign(qdSheet);
  3981. // 清理原有数据
  3982. SpreadJsObj.beginMassOperation(qdSheet);
  3983. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3984. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  3985. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  3986. }
  3987. qdSheet.setSelection(0, 0, 1 ,1);
  3988. SpreadJsObj.endMassOperation(qdSheet);
  3989. // 初始化 部位数量复核表
  3990. const posSheet = this.posSpread.getActiveSheet();
  3991. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  3992. SpreadJsObj.refreshColumnAlign(posSheet);
  3993. // 清理原有数据
  3994. SpreadJsObj.beginMassOperation(posSheet);
  3995. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  3996. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3997. posSheet.setSelection(0, 0, 1 ,1);
  3998. SpreadJsObj.endMassOperation(posSheet);
  3999. // 检查签约节点数据,以工具栏数据为准
  4000. if (dealBills) {
  4001. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  4002. }
  4003. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  4004. }
  4005. // 获取界面数据
  4006. getBatchData () {
  4007. const result = [];
  4008. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  4009. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  4010. if (qdSheet.getText(iRow, 0) === '') { continue; }
  4011. const qd = {
  4012. b_code: qdSheet.getText(iRow, 0),
  4013. name: qdSheet.getText(iRow, 1),
  4014. unit: qdSheet.getText(iRow, 2),
  4015. price: _.toNumber(qdSheet.getText(iRow, 3)),
  4016. pos: [],
  4017. };
  4018. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  4019. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  4020. if (value !== 0 && !isNaN(value)) {
  4021. qd.pos.push({
  4022. name: posSheet.getText(iPosRow, 0),
  4023. drawing_code: posSheet.getText(iPosRow, 1),
  4024. quantity: value, porder: qd.pos.length + 1,
  4025. });
  4026. }
  4027. }
  4028. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  4029. }
  4030. return result;
  4031. }
  4032. }
  4033. const dealBills = new DealBills('#deal-bills-spread', {
  4034. cols: [
  4035. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  4036. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  4037. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  4038. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  4039. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  4040. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  4041. ],
  4042. emptyRows: 0,
  4043. headRows: 1,
  4044. headRowHeight: [32],
  4045. headColWidth: [30],
  4046. defaultRowHeight: 21,
  4047. headerFont: '12px 微软雅黑',
  4048. font: '12px 微软雅黑',
  4049. selectedBackColor: '#fffacd',
  4050. });
  4051. class Jlzf {
  4052. constructor (selector, spreadSetting) {
  4053. const self = this;
  4054. this.loaded = false;
  4055. this.obj = $(selector);
  4056. const relaSelect = {
  4057. showLevel: `cb-${spreadSetting.stdType}-sl`,
  4058. searchText: `cb-${spreadSetting.stdType}-st`,
  4059. searchResult: `cb-${spreadSetting.stdType}-sr`,
  4060. searchPre: `cb-${spreadSetting.stdType}-sp`,
  4061. searchNext: `cb-${spreadSetting.stdType}-sn`,
  4062. searchClose: `cb-${spreadSetting.stdType}-sc`,
  4063. };
  4064. this.obj.html(
  4065. '<div class="sjs-bar d-flex">\n' +
  4066. ' <div class="ml-1">\n' +
  4067. ' <div class="px-2 border-primary border-1 d-flex">\n' +
  4068. ' <div class="d-inline-block">\n' +
  4069. ' <div class="input-group input-group-sm mr-1">' +
  4070. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  4071. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  4072. ' <div class="input-group-append" >\n' +
  4073. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  4074. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  4075. ' </div>\n' +
  4076. ' </div>\n' +
  4077. ' </div>\n' +
  4078. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  4079. ' </div>\n' +
  4080. ' </div>' +
  4081. '</div>\n' +
  4082. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  4083. );
  4084. autoFlashHeight();
  4085. const sh = `.cb-${spreadSetting.stdType}-sh`;
  4086. function getObjHeight(select) {
  4087. return select.length > 0 ? select.height() : 0;
  4088. }
  4089. const cHeader = getObjHeight($(".c-header"));
  4090. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  4091. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  4092. this.spreadSetting = spreadSetting;
  4093. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  4094. const searchSheet = this.spread.getActiveSheet();
  4095. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  4096. if (!readOnly) {
  4097. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  4098. const dealSheet = info.sheet;
  4099. const mainSheet = billsSheet;
  4100. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  4101. if (!dealBills) { return; }
  4102. const mainTree = mainSheet.zh_tree;
  4103. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  4104. if (!mainNode || !mainTree) { return; }
  4105. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  4106. toastr.warning('非最底层项目下,不应添加节点');
  4107. return;
  4108. }
  4109. if (mainNode.settle_status === settleStatus.finish) {
  4110. toastr.warning('已结算节点下,不应添加签约清单');
  4111. return;
  4112. }
  4113. postData(window.location.pathname + '/update', {
  4114. postType: 'add-deal',
  4115. postData: {
  4116. id: mainNode.ledger_id,
  4117. type: mainNode.code ? 'child' : 'next',
  4118. dealBills: {
  4119. b_code: dealBills.b_code, code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  4120. unit_price: dealBills.unit_price,
  4121. }
  4122. },
  4123. }, function (result) {
  4124. changeList = result.changeList;
  4125. const refreshData = mainTree.loadPostData(result);
  4126. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  4127. const sel = mainSheet.getSelections()[0];
  4128. if (sel && refreshData.create[0]) {
  4129. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  4130. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  4131. }
  4132. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  4133. billsSpread.focus();
  4134. posSpreadObj.loadCurPosData();
  4135. changeGclData = true;
  4136. });
  4137. });
  4138. }
  4139. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  4140. const searchObj = {
  4141. result: [],
  4142. cur: 0,
  4143. searchStdNode: function() {
  4144. const keyword = $(`#${relaSelect.searchText}`).val();
  4145. const sortData = SpreadJsObj.getSortData(searchSheet);
  4146. searchObj.result = keyword ? sortData.filter(x => {
  4147. return (x.code && x.code.indexOf(keyword) >= 0) || (x.b_code && x.b_code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  4148. }) : [];
  4149. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  4150. searchObj.cur = 0;
  4151. if (searchObj.result.length > 0) {
  4152. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  4153. }
  4154. },
  4155. searchPre: function () {
  4156. if (searchObj.result.length === 0) return;
  4157. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  4158. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  4159. },
  4160. searchNext: function () {
  4161. if (searchObj.result.length === 0) return;
  4162. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  4163. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  4164. },
  4165. clear: function () {
  4166. $(`#${relaSelect.searchText}`).val('');
  4167. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  4168. searchObj.result = [];
  4169. searchObj.cur = 0;
  4170. }
  4171. };
  4172. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  4173. $(`#${relaSelect.searchPre}`).click(function (e) {
  4174. searchObj.searchPre();
  4175. e.stopPropagation();
  4176. });
  4177. $(`#${relaSelect.searchNext}`).click(function (e) {
  4178. searchObj.searchNext();
  4179. e.stopPropagation();
  4180. });
  4181. $(`#${relaSelect.searchClose}`).click(function (e) {
  4182. searchObj.clear();
  4183. e.stopPropagation();
  4184. });
  4185. };
  4186. loadData (callback) {
  4187. // if (this.loaded) {
  4188. // if (callback) callback();
  4189. // return;
  4190. // }
  4191. const self = this;
  4192. const datas = billsTree.nodes.filter(node => node.is_leaf === 1 && !node.code && node.ccid !== undefined && node.ccid !== '');
  4193. const showDatas = [];
  4194. for (const d of datas) {
  4195. if (_.findIndex(showDatas, { b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price }) === -1) {
  4196. showDatas.push({ code: d.code, b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price });
  4197. }
  4198. }
  4199. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', _.uniqWith(showDatas, _.isEqual).sort(sortByCode));
  4200. // self.loaded = true;
  4201. if (callback) callback();
  4202. }
  4203. }
  4204. const jlzfBills = new Jlzf('#jlzf-spread', {
  4205. cols: [
  4206. // {title: '项目节编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  4207. {title: '清单编号', field: 'b_code', hAlign: 0, width: 100, formatter: '@'},
  4208. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  4209. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  4210. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4211. ],
  4212. emptyRows: 0,
  4213. headRows: 1,
  4214. headRowHeight: [32],
  4215. headColWidth: [30],
  4216. defaultRowHeight: 21,
  4217. headerFont: '12px 微软雅黑',
  4218. font: '12px 微软雅黑',
  4219. selectedBackColor: '#fffacd',
  4220. readOnly: true,
  4221. stdType: 'jlzf',
  4222. });
  4223. class Dsk {
  4224. constructor (selector, spreadSetting) {
  4225. const self = this;
  4226. this.loaded = false;
  4227. this.obj = $(selector);
  4228. const dskProjectHtml = spreadSetting.libs.map(l => {
  4229. return `<option value="${l.pid}" ${spreadSetting.select_lib === l.pid ? 'selected' : ''}>${l.name}</option>`;
  4230. });
  4231. const relaSelect = {
  4232. showLevel: `cb-${spreadSetting.stdType}-sl`,
  4233. searchText: `cb-${spreadSetting.stdType}-st`,
  4234. searchResult: `cb-${spreadSetting.stdType}-sr`,
  4235. searchPre: `cb-${spreadSetting.stdType}-sp`,
  4236. searchNext: `cb-${spreadSetting.stdType}-sn`,
  4237. searchClose: `cb-${spreadSetting.stdType}-sc`,
  4238. };
  4239. this.obj.html(
  4240. '<div class="sjs-bar d-flex">\n' +
  4241. ' <div class="dropdown mr-1">\n' +
  4242. ' <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  4243. ' <i class="fa fa-list-ol"></i> 显示层级\n' +
  4244. ' </button>\n' +
  4245. ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
  4246. ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
  4247. ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
  4248. ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
  4249. ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
  4250. ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
  4251. ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
  4252. ' </div>\n' +
  4253. ' </div>' +
  4254. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project">${dskProjectHtml.join('')}</select></div>\n` +
  4255. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project-tree"></select></div>\n` +
  4256. ' <div class="ml-1">\n' +
  4257. ' <div class="dropdown">\n' +
  4258. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  4259. ' <i class="fa fa-search"></i>\n' +
  4260. ' </button>\n' +
  4261. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  4262. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  4263. ' <div class="d-inline-block">\n' +
  4264. ' <div class="input-group input-group-sm mr-1">' +
  4265. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  4266. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  4267. ' <div class="input-group-append" >\n' +
  4268. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  4269. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  4270. ' </div>\n' +
  4271. ' </div>\n' +
  4272. ' </div>\n' +
  4273. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  4274. ' </div>\n' +
  4275. ' </div>\n' +
  4276. ' </div>\n' +
  4277. ' </div>' +
  4278. '</div>\n' +
  4279. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  4280. );
  4281. autoFlashHeight();
  4282. const sh = `.cb-${spreadSetting.stdType}-sh`;
  4283. function getObjHeight(select) {
  4284. return select.length > 0 ? select.height() : 0;
  4285. }
  4286. const cHeader = getObjHeight($(".c-header"));
  4287. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  4288. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  4289. this.spreadSetting = spreadSetting;
  4290. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  4291. const searchSheet = this.spread.getActiveSheet();
  4292. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  4293. (function (select, sheet) {
  4294. $(select).click(function () {
  4295. if (!sheet.zh_tree) return;
  4296. const tag = $(this).attr('tag');
  4297. const tree = sheet.zh_tree;
  4298. setTimeout(() => {
  4299. switch (tag) {
  4300. case "1":
  4301. case "2":
  4302. case "3":
  4303. case "4":
  4304. case "5":
  4305. tree.expandByLevel(parseInt(tag));
  4306. SpreadJsObj.refreshTreeRowVisible(sheet);
  4307. break;
  4308. case "last":
  4309. tree.expandByCustom(() => { return true; });
  4310. SpreadJsObj.refreshTreeRowVisible(sheet);
  4311. break;
  4312. }
  4313. }, 100);
  4314. });
  4315. })(`a[name=${relaSelect.showLevel}]`, searchSheet);
  4316. if (!readOnly) {
  4317. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  4318. const dealSheet = info.sheet;
  4319. const mainSheet = billsSheet;
  4320. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  4321. if (!dealBills) { return; }
  4322. const mainTree = mainSheet.zh_tree;
  4323. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  4324. if (!mainNode || !mainTree) { return; }
  4325. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  4326. toastr.warning('非最底层项目下,不应添加节点');
  4327. return;
  4328. }
  4329. if (mainNode.settle_status === settleStatus.finish) {
  4330. toastr.warning('已结算节点下,不应添加签约清单');
  4331. return;
  4332. }
  4333. const is_bill = dealBills.kind === 4;
  4334. // 判断dealBills.code以-开头,是则向上判断是否需要拼接code名称
  4335. function makeCode(dealBills) {
  4336. const originalCode = dealBills.code;
  4337. if (!originalCode || originalCode.charAt(0) !== '-') {
  4338. return originalCode;
  4339. }
  4340. const parents = dealSheet.zh_tree.getAllParents(dealBills);
  4341. if (!parents || parents.length === 0) {
  4342. return originalCode;
  4343. }
  4344. const kind4Parents = _.filter(parents, { kind: 4 });
  4345. if (!kind4Parents || kind4Parents.length === 0) {
  4346. return originalCode;
  4347. }
  4348. const firstParentCode = kind4Parents[0].code;
  4349. if (firstParentCode.charAt(0) === '-') {
  4350. return originalCode;
  4351. }
  4352. const codeParts = [];
  4353. for (const parent of kind4Parents.reverse()) {
  4354. codeParts.push(parent.code);
  4355. if (parent.code.charAt(0) !== '-') {
  4356. break;
  4357. }
  4358. }
  4359. if (codeParts.length > 0) {
  4360. return codeParts.reverse().join('') + originalCode;
  4361. }
  4362. return originalCode;
  4363. }
  4364. const oneBills = {
  4365. b_code: is_bill ? makeCode(dealBills) : null, code: !is_bill ? dealBills.code : null, name: dealBills.name, unit: dealBills.unit,
  4366. unit_price: is_bill ? dealBills.unitPrice : null, quantity: null, total_price: null,
  4367. sgfh_qty: null, sgfh_tp: null,
  4368. };
  4369. postData(window.location.pathname + '/update', {
  4370. postType: 'add-deal',
  4371. postData: {
  4372. id: mainNode.ledger_id,
  4373. type: mainNode.code ? 'child' : 'next',
  4374. dealBills: oneBills,
  4375. },
  4376. }, function (result) {
  4377. changeList = result.changeList;
  4378. const refreshData = mainTree.loadPostData(result);
  4379. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  4380. const sel = mainSheet.getSelections()[0];
  4381. if (sel && refreshData.create[0]) {
  4382. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  4383. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  4384. }
  4385. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  4386. billsSpread.focus();
  4387. posSpreadObj.loadCurPosData();
  4388. changeGclData = true;
  4389. });
  4390. });
  4391. }
  4392. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  4393. const searchObj = {
  4394. result: [],
  4395. cur: 0,
  4396. searchStdNode: function() {
  4397. const keyword = $(`#${relaSelect.searchText}`).val();
  4398. searchObj.result = keyword ? dskProjectBills2Tree.tenderTree.nodes.filter(x => {
  4399. return (x.code && x.code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  4400. }) : [];
  4401. // searchObj.result = [];
  4402. // for (const x of pathTree.nodes) {
  4403. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  4404. // searchObj.result.push(x);
  4405. // }
  4406. // }
  4407. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  4408. searchObj.cur = 0;
  4409. if (searchObj.result.length > 0) {
  4410. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]));
  4411. }
  4412. },
  4413. searchPre: function () {
  4414. if (searchObj.result.length === 0) return;
  4415. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  4416. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  4417. },
  4418. searchNext: function () {
  4419. if (searchObj.result.length === 0) return;
  4420. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  4421. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  4422. },
  4423. clear: function () {
  4424. $(`#${relaSelect.searchText}`).val('');
  4425. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  4426. searchObj.result = [];
  4427. searchObj.cur = 0;
  4428. }
  4429. };
  4430. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  4431. $(`#${relaSelect.searchPre}`).click(function (e) {
  4432. searchObj.searchPre();
  4433. e.stopPropagation();
  4434. });
  4435. $(`#${relaSelect.searchNext}`).click(function (e) {
  4436. searchObj.searchNext();
  4437. e.stopPropagation();
  4438. });
  4439. $(`#${relaSelect.searchClose}`).click(function (e) {
  4440. searchObj.clear();
  4441. e.stopPropagation();
  4442. });
  4443. };
  4444. loadData (callback) {
  4445. if (this.loaded) {
  4446. if (callback) callback();
  4447. return;
  4448. }
  4449. const self = this;
  4450. if (dskAccountData && dskAccountData.select_project) {
  4451. self.loaded = true;
  4452. changeDskProject(dskAccountData.select_project);
  4453. } else {
  4454. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', []);
  4455. self.loaded = true;
  4456. }
  4457. if (callback) callback();
  4458. }
  4459. }
  4460. $('body').on('change', '#change-dsk-project', function () {
  4461. const pid = $(this).val();
  4462. changeDskProject(pid);
  4463. });
  4464. $('body').on('change', '#change-dsk-project-tree', function () {
  4465. const treeId = $(this).val();
  4466. const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project });
  4467. changeDskProjectTree(projectInfo, treeId);
  4468. });
  4469. function setDskProjectTreeSelect(trees) {
  4470. let html = '';
  4471. for (const tree of trees) {
  4472. html += `<option value="${tree.ID}" ${tree.ID === dskAccountData.select_tree ? 'selected' : ''}>${tree.name}</option>`;
  4473. }
  4474. $('#change-dsk-project-tree').html(html);
  4475. }
  4476. function changeDskProject(pid) {
  4477. const projectInfo = _.find(dskProjects, { pid });
  4478. if (!projectInfo) {
  4479. dskAccountData.select_project = null;
  4480. dskAccountData.select_tree = null;
  4481. const tree = dskProjectBills2Tree.convert([]);
  4482. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  4483. return;
  4484. }
  4485. postData('/profile/dsk/api', { type: 'project_tree', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, projectId: projectInfo.pid }, function (datas) {
  4486. const trees = _.filter(datas, x => x.type === 4);
  4487. dskAccountData.select_project = projectInfo.pid;
  4488. setDskProjectTreeSelect(trees);
  4489. changeDskProjectTree(projectInfo, trees.length > 0 ? trees[0].ID : null);
  4490. });
  4491. }
  4492. function changeDskProjectTree(projectInfo, treeId) {
  4493. dskAccountData.select_tree = treeId;
  4494. if (!treeId) {
  4495. const tree = dskProjectBills2Tree.convert([]);
  4496. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  4497. return;
  4498. }
  4499. postData('/profile/dsk/api', { type: 'project_bills', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, treeId }, function (result) {
  4500. const tree = dskProjectBills2Tree.convert(result);
  4501. console.log(tree);
  4502. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  4503. });
  4504. }
  4505. const dskBills = new Dsk('#dsk-spread', {
  4506. cols: [
  4507. {title: '编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  4508. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  4509. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  4510. {title: '单价', field: 'unitPrice', hAlign: 2, width: 80, formatter: '@'},
  4511. {title: '数量', field: 'quantity', hAlign: 2, width: 80, formatter: '@'},
  4512. ],
  4513. emptyRows: 0,
  4514. headRows: 1,
  4515. headRowHeight: [32],
  4516. headColWidth: [30],
  4517. defaultRowHeight: 21,
  4518. headerFont: '12px 微软雅黑',
  4519. font: '12px 微软雅黑',
  4520. selectedBackColor: '#fffacd',
  4521. readOnly: true,
  4522. stdType: 'dsk',
  4523. libs: dskProjects,
  4524. select_lib: dskAccountData.select_project ? dskAccountData.select_project : null,
  4525. });
  4526. const dskProjectBills2Tree = (function () {
  4527. const treeSetting = {
  4528. id: 'dpb_id',
  4529. pid: 'dpb_pid',
  4530. order: 'seq',
  4531. level: 'level',
  4532. rootId: '-1',
  4533. fullPath: 'full_path',
  4534. };
  4535. const tenderTree = createNewPathTree('gather', treeSetting);
  4536. function setChildrenNode(node, dxs, files, tenders) {
  4537. const dxchildren = _.filter(dxs, { parentID: node.bid });
  4538. const children = _.filter(files, { parentID: node.bid });
  4539. const tenderChildren = _.filter(tenders, { parentID: node.bid });
  4540. const checkChildren = _.orderBy([...dxchildren, ...children, ...tenderChildren], ['seq', 'asc']);
  4541. for (const t of checkChildren) {
  4542. const child = {
  4543. bid: t.ID,
  4544. parentID: t.parentID,
  4545. name: t.name,
  4546. kind: t.kind,
  4547. code: t.code,
  4548. quantity: t.quantity,
  4549. quantity2: t.quantity2,
  4550. unit: t.unit,
  4551. unitPrice: t.unitPrice,
  4552. totalPrice: t.totalPrice,
  4553. formulaCode: t.formulaCode,
  4554. flag: t.flag,
  4555. remark: t.remark,
  4556. };
  4557. tenderTree.addNode(child, node);
  4558. setChildrenNode(child, dxs, files, tenders);
  4559. }
  4560. }
  4561. function convert (projects) {
  4562. tenderTree.clearDatas();
  4563. // 区分文件夹及项目
  4564. const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
  4565. const dxs = _.filter(projects, { kind: 1 });
  4566. const files = _.filter(projects, { kind: 4 });
  4567. const tenders = _.filter(projects, { kind: 8 });
  4568. for (const t of topLevel) {
  4569. const node = {
  4570. bid: t.ID,
  4571. parentID: t.parentID,
  4572. name: t.name,
  4573. kind: t.kind,
  4574. code: t.code,
  4575. quantity: t.quantity,
  4576. quantity2: t.quantity2,
  4577. unit: t.unit,
  4578. unitPrice: t.unitPrice,
  4579. totalPrice: t.totalPrice,
  4580. formulaCode: t.formulaCode,
  4581. flag: t.flag,
  4582. remark: t.remark,
  4583. };
  4584. tenderTree.addNode(node, null);
  4585. setChildrenNode(node, dxs, files, tenders);
  4586. }
  4587. tenderTree.sortTreeNode(true);
  4588. return tenderTree;
  4589. }
  4590. return { tenderTree, convert }
  4591. })();
  4592. $.divResizer({
  4593. select: '#revise-right-spr',
  4594. callback: function () {
  4595. billsSpread.refresh();
  4596. if (posSpread) posSpread.refresh();
  4597. if (stdXmj) stdXmj.spread.refresh();
  4598. if (stdGcl) stdGcl.spread.refresh();
  4599. if (dealBills) dealBills.spread.refresh();
  4600. if (searchLedger) searchLedger.spread.refresh();
  4601. if (errorList) errorList.spread.refresh();
  4602. if (checkList) checkList.spread.refresh();
  4603. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  4604. if (jlzfBills) jlzfBills.spread.refresh();
  4605. if (dskBills) dskBills.spread.refresh();
  4606. }
  4607. });
  4608. $.subMenu({
  4609. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  4610. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  4611. key: 'menu.1.0.0',
  4612. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  4613. callback: function (info) {
  4614. if (info.mini) {
  4615. $('.panel-title').addClass('fluid');
  4616. $('#sub-menu').removeClass('panel-sidebar');
  4617. } else {
  4618. $('.panel-title').removeClass('fluid');
  4619. $('#sub-menu').addClass('panel-sidebar');
  4620. }
  4621. autoFlashHeight();
  4622. billsSpread.refresh();
  4623. if (posSpread) posSpread.refresh();
  4624. if (stdXmj) stdXmj.spread.refresh();
  4625. if (stdGcl) stdGcl.spread.refresh();
  4626. if (dealBills) dealBills.spread.refresh();
  4627. if (searchLedger) searchLedger.spread.refresh();
  4628. if (errorList) errorList.spread.refresh();
  4629. if (checkList) checkList.spread.refresh();
  4630. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  4631. if (jlzfBills) jlzfBills.spread.refresh();
  4632. if (dskBills) dskBills.spread.refresh();
  4633. }
  4634. });
  4635. // showSideTools(true);
  4636. billsSpread.refresh();
  4637. if (posSpread) posSpread.refresh();
  4638. const stdLibCellDoubleClick = function (updateData, stdNode, stdTree) {
  4639. const mainSheet = billsSheet;
  4640. if (!stdTree || !mainSheet.zh_tree) { return; }
  4641. const mainTree = mainSheet.zh_tree;
  4642. const sel = mainSheet.getSelections()[0];
  4643. const mainNode = mainTree.nodes[sel.row];
  4644. if (!stdNode) return;
  4645. if (updateData.postData.stdType === 'gcl') {
  4646. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  4647. toastr.warning('非最底层项目下,不应添加节点');
  4648. return;
  4649. }
  4650. if (mainNode.settle_status === settleStatus.finish) {
  4651. toastr.warning('已结算节点下,不可添加工程量清单');
  4652. return;
  4653. }
  4654. } else {
  4655. const stdNodes = stdTree.getAllParents(stdNode);
  4656. for (const node of stdNodes) {
  4657. const parent = mainTree.datas.find(x => { return x.code === node.code && x.name === node.name; });
  4658. if (parent && parent.settle_status === settleStatus.finish) {
  4659. toastr.warning('项目节父项已结算,不可添加节点');
  4660. return;
  4661. }
  4662. }
  4663. }
  4664. postData(window.location.pathname + '/update', {
  4665. postType: 'add-std',
  4666. postData: {
  4667. id: mainTree.getNodeKey(mainNode),
  4668. tender_id: mainNode.tender_id,
  4669. stdType: updateData.postData.stdType,
  4670. stdLibId: stdNode.list_id,
  4671. stdNode: stdTree.getNodeKey(stdNode)
  4672. }
  4673. }, function (result) {
  4674. changeList = result.changeList;
  4675. const refreshNode = mainTree.loadPostData(result);
  4676. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  4677. if (sel) {
  4678. if (refreshNode.create && refreshNode.create.length > 0) {
  4679. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  4680. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  4681. } else {
  4682. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  4683. if (node) {
  4684. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  4685. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  4686. }
  4687. }
  4688. }
  4689. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  4690. billsSpread.focus();
  4691. posSpreadObj.loadCurPosData();
  4692. changeGclData = true;
  4693. });
  4694. };
  4695. const stdXmjSetting = {
  4696. selector: '#std-xmj',
  4697. stdType: 'xmj',
  4698. libs: stdChapters,
  4699. treeSetting: {
  4700. id: 'chapter_id',
  4701. pid: 'pid',
  4702. order: 'order',
  4703. level: 'level',
  4704. rootId: -1,
  4705. keys: ['id', 'list_id', 'chapter_id'],
  4706. },
  4707. spreadSetting: {
  4708. cols: [
  4709. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  4710. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  4711. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  4712. ],
  4713. treeCol: 0,
  4714. emptyRows: 0,
  4715. headRows: 1,
  4716. headRowHeight: [32],
  4717. defaultRowHeight: 21,
  4718. headerFont: '12px 微软雅黑',
  4719. font: '12px 微软雅黑',
  4720. headColWidth: [30],
  4721. selectedBackColor: '#fffacd',
  4722. },
  4723. cellDoubleClick: stdLibCellDoubleClick,
  4724. page: 'revise',
  4725. tid: window.location.pathname.split('/')[2],
  4726. };
  4727. const stdGclSetting = {
  4728. selector: '#std-gcl',
  4729. stdType: 'gcl',
  4730. libs: stdBills,
  4731. treeSetting: {
  4732. id: 'bill_id',
  4733. pid: 'pid',
  4734. order: 'order',
  4735. level: 'level',
  4736. rootId: -1,
  4737. keys: ['id', 'list_id', 'bill_id']
  4738. },
  4739. spreadSetting: {
  4740. cols: [
  4741. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  4742. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  4743. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  4744. ],
  4745. treeCol: 0,
  4746. emptyRows: 0,
  4747. headRows: 1,
  4748. headRowHeight: [32],
  4749. defaultRowHeight: 21,
  4750. headerFont: '12px 微软雅黑',
  4751. font: '12px 微软雅黑',
  4752. headColWidth: [30],
  4753. selectedBackColor: '#fffacd',
  4754. },
  4755. cellDoubleClick: stdLibCellDoubleClick,
  4756. page: 'revise',
  4757. tid: window.location.pathname.split('/')[2],
  4758. };
  4759. // 展开收起标准节点
  4760. $('a', '#side-menu').bind('click', function (e) {
  4761. e.preventDefault();
  4762. const tab = $(this), tabPanel = $(tab.attr('content'));
  4763. // 展开工具栏、切换标签
  4764. if (!tab.hasClass('active')) {
  4765. const close = $('.active', '#side-menu').length === 0;
  4766. $('a', '#side-menu').removeClass('active');
  4767. tab.addClass('active');
  4768. $('.tab-content .tab-pane').removeClass('active');
  4769. tabPanel.addClass('active');
  4770. showSideTools(tab.hasClass('active'));
  4771. if (tab.attr('content') === '#std-xmj') {
  4772. if (!stdXmj) {
  4773. stdXmj = $.stdLib(stdXmjSetting);
  4774. }
  4775. stdXmj.spread.refresh();
  4776. } else if (tab.attr('content') === '#std-gcl') {
  4777. if (!stdGcl) {
  4778. stdGcl = $.stdLib(stdGclSetting);
  4779. }
  4780. stdGcl.spread.refresh();
  4781. } else if (tab.attr('content') === '#deal-bills') {
  4782. dealBills.loadData();
  4783. dealBills.spread.refresh();
  4784. } else if (tab.attr('content') === '#search') {
  4785. if (!searchLedger) {
  4786. searchLedger = $.ledgerSearch({
  4787. selector: '#search',
  4788. ledger: { billsTree: billsTree, pos: pos },
  4789. searchOver: true,
  4790. searchEmpty: true,
  4791. resultSpreadSetting: {
  4792. cols: [
  4793. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  4794. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  4795. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  4796. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  4797. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4798. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  4799. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  4800. ],
  4801. emptyRows: 0,
  4802. headRows: 1,
  4803. headRowHeight: [32],
  4804. headColWidth: [30],
  4805. defaultRowHeight: 21,
  4806. headerFont: '12px 微软雅黑',
  4807. font: '12px 微软雅黑',
  4808. selectedBackColor: '#fffacd',
  4809. readOnly: true,
  4810. },
  4811. locate: function(cur) {
  4812. if (!cur.lid) return;
  4813. SpreadJsObj.locateTreeNode(billsSheet, cur.lid, true);
  4814. posSpreadObj.loadCurPosData();
  4815. if (cur.pid && cur.pid !== -1) {
  4816. const pIndex = posSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
  4817. SpreadJsObj.locateRow(posSheet, pIndex);
  4818. }
  4819. },
  4820. customSearch: [
  4821. {
  4822. key: 'revise', title: '新增部位', valid: true, parent: true,
  4823. check: function (node) {
  4824. if (node.formc || node.cid) {
  4825. return true;
  4826. } else {
  4827. return false;
  4828. }
  4829. }
  4830. }
  4831. ],
  4832. });
  4833. }
  4834. searchLedger.spread.refresh();
  4835. } else if (tab.attr('content') === '#error-list') {
  4836. errorList.spread.refresh();
  4837. } else if (tab.attr('content') === '#check-list') {
  4838. checkList.spread.refresh();
  4839. } else if (tab.attr('content') === '#sum-load-miss') {
  4840. sumLoadMiss.spread.refresh();
  4841. } else if (tab.attr('content') === '#dsk-list') {
  4842. const dskActiveTab = $('#dsk-tab a[class*="active"]').attr('href');
  4843. $(dskActiveTab).addClass('active');
  4844. if (dskActiveTab === '#jlzf-spread') {
  4845. $('#get-dsk-btn').hide();
  4846. $('#get-dsk-bills-btn').hide();
  4847. jlzfBills.loadData();
  4848. jlzfBills.spread.refresh();
  4849. } else if (dskActiveTab === '#dsk-spread') {
  4850. $('#get-dsk-btn').show();
  4851. $('#get-dsk-bills-btn').show();
  4852. dskBills.loadData();
  4853. dskBills.spread.refresh();
  4854. }
  4855. }
  4856. }
  4857. else {// 收起工具栏
  4858. tab.removeClass('active');
  4859. tabPanel.removeClass('active');
  4860. showSideTools(tab.hasClass('active'));
  4861. }
  4862. billsSpread.refresh();
  4863. if (posSpread) posSpread.refresh();
  4864. });
  4865. // 新增清单切换tab
  4866. $('#dsk-tab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  4867. e.preventDefault();
  4868. const dskActiveTab = $(this).attr('href');
  4869. if (dskActiveTab === '#jlzf-spread') {
  4870. $('#get-dsk-btn').hide();
  4871. $('#get-dsk-bills-btn').hide();
  4872. jlzfBills.loadData();
  4873. jlzfBills.spread.refresh();
  4874. } else if (dskActiveTab === '#dsk-spread') {
  4875. $('#get-dsk-btn').show();
  4876. $('#get-dsk-bills-btn').show();
  4877. dskBills.loadData();
  4878. dskBills.spread.refresh();
  4879. }
  4880. });
  4881. // 显示层次
  4882. (function (select, sheet) {
  4883. $(select).click(function () {
  4884. if (!sheet.zh_tree) return;
  4885. const tag = $(this).attr('tag');
  4886. const tree = sheet.zh_tree;
  4887. setTimeout(() => {
  4888. showWaitingView();
  4889. switch (tag) {
  4890. case "1":
  4891. case "2":
  4892. case "3":
  4893. case "4":
  4894. case "5":
  4895. tree.expandByLevel(parseInt(tag));
  4896. SpreadJsObj.refreshTreeRowVisible(sheet);
  4897. break;
  4898. case "last":
  4899. tree.expandByCustom(() => { return true; });
  4900. SpreadJsObj.refreshTreeRowVisible(sheet);
  4901. break;
  4902. case "leafXmj":
  4903. tree.expandToLeafXmj();
  4904. SpreadJsObj.refreshTreeRowVisible(sheet);
  4905. break;
  4906. }
  4907. closeWaitingView();
  4908. }, 100);
  4909. });
  4910. })('a[name=showLevel]', billsSheet);
  4911. const dataChecker = DataChecker({
  4912. checkUrl: window.location.pathname + '/check',
  4913. completeData: function (data) {
  4914. pos.updateDatas({update: data.source.pos});
  4915. const loadResult = billsTree.loadPostData({update: data.source.bills});
  4916. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  4917. posSpreadObj.loadCurPosData();
  4918. for (const e of data.error) {
  4919. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  4920. }
  4921. },
  4922. errorList: errorList,
  4923. });
  4924. $('#ledger-check2').click(() => {
  4925. ledgerCheck2({
  4926. ledgerTree: billsTree,
  4927. ledgerPos: pos,
  4928. checkList: checkList,
  4929. decimal: decimal,
  4930. checkOption: checkOption,
  4931. }).then(result => {
  4932. check2Viewing({
  4933. extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
  4934. randomWait: true,
  4935. prefix: 'check2-',
  4936. checks: result,
  4937. checkList: checkList,
  4938. });
  4939. });
  4940. });
  4941. if (isYb) {
  4942. let compilationList = [];
  4943. $('#get-dsk-btn').click(function () {
  4944. // 判断是否已绑定dsk用户
  4945. postData('/profile/dsk/api', {type: 'hadbind'}, function (result) {
  4946. if (result === 1) {
  4947. $('#error-dsk .modal-body').find('h5').eq(0).show();
  4948. $('#error-dsk .modal-body').find('h5').eq(1).hide();
  4949. $('#error-dsk').modal('show');
  4950. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定手机');
  4951. } else if (result === 2) {
  4952. $('#error-dsk .modal-body').find('h5').eq(1).show();
  4953. $('#error-dsk .modal-body').find('h5').eq(0).hide();
  4954. $('#error-dsk').modal('show');
  4955. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定账号');
  4956. } else {
  4957. postData('/profile/dsk/api', {
  4958. type: 'compilation',
  4959. getProject: 1,
  4960. compilationId: getLocalCache(dskCompilation)
  4961. }, function (result) {
  4962. let html = '';
  4963. for (const data of result.compilation) {
  4964. if (data.ID !== '5c66649650da2d000d8d37ba' && data.ID !== '5b52b027fd3bb0000b257cf8') {
  4965. html += `<option value="${data.ID}" ${result.select_compilation === data.ID ? 'selected' : ''}>${data.name}</option>`;
  4966. }
  4967. }
  4968. dskAccountData = result.dskAccountData;
  4969. compilationList = result.compilation;
  4970. console.log(compilationList);
  4971. $('#dsk-compilation-list').html(html);
  4972. $('#add-dsk').modal('show');
  4973. setLocalCache(dskCompilation, result.select_compilation);
  4974. makeDskProjectSjsHtml(result.project);
  4975. });
  4976. }
  4977. })
  4978. });
  4979. $('#get-dsk-bills-btn').click(function () {
  4980. const projectInfo = _.find(dskProjects, {pid: dskAccountData.select_project ? dskAccountData.select_project : null});
  4981. changeDskProjectTree(projectInfo, dskAccountData.select_tree ? dskAccountData.select_tree : null);
  4982. });
  4983. $('body').on('change', '#dsk-compilation-list', function () {
  4984. const compilationId = $(this).val();
  4985. setLocalCache(dskCompilation, compilationId);
  4986. dskProjectSpreadObj.refreshSourceTree();
  4987. });
  4988. $('.hide-dsk-modal').click(function () {
  4989. $('#error-dsk').modal('hide');
  4990. });
  4991. let dp = false;
  4992. let gsObj = {
  4993. setting: null,
  4994. gsSheet: null,
  4995. grSheet: null,
  4996. tenderSourceTree: null,
  4997. grArray: dskProjects ? dskProjects : [],
  4998. orgSelect: null,
  4999. };
  5000. function makeDskProjectSjsHtml(datas) {
  5001. if (!dp) {
  5002. initDskProjectTree();
  5003. dp = true;
  5004. }
  5005. gsObj.tenderSourceTree = dskProject2Tree.convert(datas);
  5006. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  5007. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  5008. if (datas.length === 0) {
  5009. $('#show-project-0').show();
  5010. } else {
  5011. $('#show-project-0').hide();
  5012. }
  5013. }
  5014. const dskProjectSpreadObj = {
  5015. _addTender: function (tender) {
  5016. const gr = gsObj.grArray.find(function (x) {
  5017. return x.pid === tender.pid;
  5018. });
  5019. const c_id = getLocalCache(dskCompilation);
  5020. const t = {
  5021. pid: tender.pid,
  5022. name: tender.name,
  5023. compilationId: c_id,
  5024. compilationName: _.find(compilationList, {ID: c_id}).name
  5025. };
  5026. if (!gr) gsObj.grArray.push(t);
  5027. return t;
  5028. },
  5029. _removeTender: function (tender) {
  5030. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  5031. return x.pid === tender.pid;
  5032. });
  5033. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  5034. },
  5035. reloadResultData: function () {
  5036. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  5037. },
  5038. refreshSourceTree: function () {
  5039. const c_id = getLocalCache(dskCompilation);
  5040. if (c_id) {
  5041. postData('/profile/dsk/api', {type: 'project', compilationId: c_id}, function (result) {
  5042. makeDskProjectSjsHtml(result);
  5043. });
  5044. }
  5045. },
  5046. gsButtonClicked: function (e, info) {
  5047. if (!info.sheet.zh_setting) return;
  5048. const col = info.sheet.zh_setting.cols[info.col];
  5049. if (col.field !== 'selected') return;
  5050. const node = SpreadJsObj.getSelectObject(info.sheet);
  5051. node.selected = !node.selected;
  5052. if (node.children && node.children.length > 0) {
  5053. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  5054. for (const p of posterity) {
  5055. p.selected = node.selected;
  5056. if ((!p.children || p.children.length === 0) && p.type === 2) {
  5057. if (p.selected) {
  5058. dskProjectSpreadObj._addTender(p);
  5059. } else {
  5060. dskProjectSpreadObj._removeTender(p);
  5061. }
  5062. }
  5063. }
  5064. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  5065. } else if (node.type === 2) {
  5066. if (node.selected) {
  5067. dskProjectSpreadObj._addTender(node);
  5068. } else {
  5069. dskProjectSpreadObj._removeTender(node);
  5070. }
  5071. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  5072. }
  5073. dskProjectSpreadObj.reloadResultData();
  5074. },
  5075. deleteGr: function () {
  5076. if (gsObj.grArray.length === 0) return;
  5077. if (gsObj.grSheet.getSelections().length === 0) return;
  5078. const selections = gsObj.grSheet.getSelections();
  5079. const sel = selections ? selections[0] : gsObj.grSheet.getSelections()[0];
  5080. const row = sel && sel.row !== undefined ? sel.row : -1;
  5081. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  5082. return false;
  5083. }
  5084. const delList = [];
  5085. for (let r = 0; r < sel.rowCount; r++) {
  5086. const select = gsObj.grArray[row + r];
  5087. delList.push(select);
  5088. }
  5089. _.pullAll(gsObj.grArray, delList);
  5090. dskProjectSpreadObj.reloadResultData();
  5091. dskProjectSpreadObj.refreshSourceTree();
  5092. },
  5093. };
  5094. const initDskProjectTree = function () {
  5095. const gsSpread = SpreadJsObj.createNewSpread($('#dsk-project-source-spread')[0]);
  5096. gsObj.gsSheet = gsSpread.getActiveSheet();
  5097. const gsSpreadSetting = {
  5098. cols: [
  5099. {
  5100. title: '选择',
  5101. field: 'selected',
  5102. hAlign: 1,
  5103. width: 40,
  5104. formatter: '@',
  5105. cellType: 'checkbox',
  5106. readOnly: true,
  5107. },
  5108. {
  5109. title: '名称',
  5110. field: 'name',
  5111. hAlign: 0,
  5112. width: 400,
  5113. formatter: '@',
  5114. readOnly: true,
  5115. folderCell: true,
  5116. cellType: 'tree'
  5117. },
  5118. ],
  5119. emptyRows: 0,
  5120. headRows: 1,
  5121. headRowHeight: [32],
  5122. defaultRowHeight: 21,
  5123. headerFont: '12px 微软雅黑',
  5124. font: '12px 微软雅黑',
  5125. headColWidth: [0],
  5126. selectedBackColor: '#fffacd',
  5127. };
  5128. SpreadJsObj.initSheet(gsObj.gsSheet, gsSpreadSetting);
  5129. gsSpread.bind(spreadNS.Events.ButtonClicked, dskProjectSpreadObj.gsButtonClicked);
  5130. const grSpread = SpreadJsObj.createNewSpread($('#dsk-project-result-spread')[0]);
  5131. gsObj.grSheet = grSpread.getActiveSheet();
  5132. const grSpreadSetting = {
  5133. cols: [
  5134. {
  5135. title: '名称',
  5136. colSpan: '1',
  5137. rowSpan: '1',
  5138. field: 'name',
  5139. hAlign: 0,
  5140. width: 250,
  5141. formatter: '@',
  5142. readOnly: true,
  5143. cellType: 'ellipsisAutoTip',
  5144. scrollHeightClass: '.modal-height-500'
  5145. },
  5146. {
  5147. title: '所属编办',
  5148. colSpan: '1',
  5149. rowSpan: '1',
  5150. field: 'compilationName',
  5151. hAlign: 0,
  5152. width: 150,
  5153. formatter: '@',
  5154. readOnly: true
  5155. },
  5156. ],
  5157. emptyRows: 0,
  5158. headRows: 1,
  5159. headRowHeight: [32],
  5160. defaultRowHeight: 21,
  5161. headerFont: '12px 微软雅黑',
  5162. font: '12px 微软雅黑',
  5163. headColWidth: []
  5164. };
  5165. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  5166. // 右键删除已选项目
  5167. const gsContextMenuOptions = {
  5168. selector: '#dsk-project-result-spread',
  5169. build: function ($trigger, e) {
  5170. const target = SpreadJsObj.safeRightClickSelection($trigger, e, grSpread);
  5171. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  5172. },
  5173. items: {
  5174. delete: {
  5175. name: '删除',
  5176. icon: 'fa-remove',
  5177. callback: function (key, opt) {
  5178. dskProjectSpreadObj.deleteGr();
  5179. },
  5180. disabled: function (key, opt) {
  5181. const selection = gsObj.grSheet.getSelections();
  5182. const sel = selection ? selection[0] : gsObj.grSheet.getSelections()[0];
  5183. const row = sel && sel.row !== undefined ? sel.row : -1;
  5184. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  5185. return true;
  5186. }
  5187. return false;
  5188. }
  5189. },
  5190. }
  5191. };
  5192. $.contextMenu(gsContextMenuOptions);
  5193. $('#add-dsk').bind('shown.bs.modal', function () {
  5194. if (gsSpread) gsSpread.refresh();
  5195. if (grSpread) grSpread.refresh();
  5196. });
  5197. };
  5198. const dskProject2Tree = (function () {
  5199. const treeSetting = {
  5200. id: 'tmt_id',
  5201. pid: 'tmt_pid',
  5202. order: 'seq',
  5203. level: 'level',
  5204. rootId: '-1',
  5205. fullPath: 'full_path',
  5206. };
  5207. const tenderTree = createNewPathTree('gather', treeSetting);
  5208. function setChildrenNode(node, files, tenders) {
  5209. const children = _.filter(files, {parentID: node.pid});
  5210. const tenderChildren = _.filter(tenders, {parentID: node.pid});
  5211. const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
  5212. for (const c of checkChildren) {
  5213. // if (c.type === 1 && _.filter(files, { parentID: c.ID }).length === 0 && _.filter(tenders, { parentID: c.ID }).length === 0) {
  5214. // // 判断文件夹下有无东西,没有就不插入
  5215. // continue;
  5216. // }
  5217. const child = {
  5218. pid: c.ID,
  5219. parentID: c.parentID,
  5220. name: c.name,
  5221. type: c.type,
  5222. selected: _.findIndex(gsObj.grArray, {pid: c.ID}) >= 0
  5223. };
  5224. tenderTree.addNode(child, node);
  5225. if (c.type === 1) setChildrenNode(child, files, tenders);
  5226. }
  5227. }
  5228. function convert(projects) {
  5229. tenderTree.clearDatas();
  5230. const result = filterFolders(projects);
  5231. const topLevel = _.orderBy(_.filter(result, {parentID: '-1'}), ['seq', 'asc']);
  5232. const files = _.filter(result, {type: 1});
  5233. const tenders = _.filter(result, {type: 2});
  5234. for (const t of topLevel) {
  5235. const node = {
  5236. pid: t.ID,
  5237. parentID: t.parentID,
  5238. name: t.name,
  5239. type: t.type,
  5240. selected: t.type === 2 ? _.findIndex(gsObj.grArray, {pid: t.ID}) >= 0 : false,
  5241. };
  5242. tenderTree.addNode(node, null);
  5243. if (t.type === 1) setChildrenNode(node, files, tenders);
  5244. }
  5245. tenderTree.sortTreeNode(true);
  5246. return tenderTree;
  5247. }
  5248. return {tenderTree, convert}
  5249. })();
  5250. function filterFolders(data) {
  5251. // 构建ID到节点的映射
  5252. const idMap = data.reduce((map, node) => {
  5253. map[node.ID] = node;
  5254. return map;
  5255. }, {});
  5256. // 建立父子关系映射
  5257. const parentMap = data.reduce((map, node) => {
  5258. if (node.parentID !== '-1') {
  5259. if (!map[node.parentID]) {
  5260. map[node.parentID] = [];
  5261. }
  5262. map[node.parentID].push(node.ID);
  5263. }
  5264. return map;
  5265. }, {});
  5266. // 检查节点及其子节点是否包含清单(type=1)
  5267. const hasChecklist = (id) => {
  5268. const node = idMap[id];
  5269. if (node.type === 2) {
  5270. return true;
  5271. }
  5272. if (!parentMap[id]) {
  5273. return false;
  5274. }
  5275. return parentMap[id].some(childID => hasChecklist(childID));
  5276. };
  5277. // 过滤节点
  5278. const filteredIDs = new Set();
  5279. data.forEach(node => {
  5280. if (node.type === 2 || hasChecklist(node.ID)) {
  5281. let currentID = node.ID;
  5282. while (currentID !== '-1') {
  5283. filteredIDs.add(currentID);
  5284. currentID = idMap[currentID].parentID;
  5285. }
  5286. }
  5287. });
  5288. // 返回过滤后的数据
  5289. return data.filter(node => filteredIDs.has(node.ID));
  5290. }
  5291. $('#set-dsk-project').click(function () {
  5292. postData('/profile/dsk/api', {
  5293. type: 'save_projects',
  5294. tid: window.location.pathname.split('/')[2],
  5295. project_list: gsObj.grArray
  5296. }, function (result) {
  5297. // dskAccountData.select_project = result;
  5298. dskProjects = gsObj.grArray;
  5299. if (!dskAccountData.select_project || dskAccountData.select_project !== result) {
  5300. dskAccountData.select_project = result;
  5301. changeDskProject(result);
  5302. dskBills.spread.refresh();
  5303. }
  5304. setDskProjectSelect(gsObj.grArray);
  5305. $('#add-dsk').modal('hide');
  5306. });
  5307. });
  5308. $('#add-dsk').on('hide.bs.modal', function () {
  5309. $('#autoTip').hide();
  5310. });
  5311. function setDskProjectSelect(projects) {
  5312. let html = '';
  5313. for (const project of projects) {
  5314. html += `<option value="${project.pid}" ${project.pid === dskAccountData.select_project ? 'selected' : ''}>${project.name}</option>`;
  5315. }
  5316. $('#change-dsk-project').html(html);
  5317. }
  5318. // 选中所有新增部位/清单
  5319. $('#add-all-revise').click(function() {
  5320. const this_cid = window.location.pathname.split('/')[4];
  5321. makeGclGatherData();
  5322. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  5323. type: 'get-revise-list',
  5324. }, function (result) {
  5325. const addDatas = [];
  5326. for (const ggd in gclGatherData) {
  5327. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  5328. let hadcid = 0;
  5329. for (const xmj of gclGatherData[ggd].leafXmjs) {
  5330. const changeLedger = _.find(result.changeLedgerList, {id: xmj.gcl_id});
  5331. const changePos = _.find(result.changePosList, {id: xmj.mx_id, lid: xmj.gcl_id});
  5332. if (changeLedger || changePos) {
  5333. xmj.cid = 1;
  5334. xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
  5335. hadcid = 1;
  5336. }
  5337. }
  5338. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  5339. }
  5340. for (const gclInfo of _.filter(gclGatherData, {cid: 1})) {
  5341. const leafXmjs = _.filter(gclInfo.leafXmjs, {ccid: this_cid});
  5342. if (leafXmjs.length > 0) {
  5343. gclInfo.is_change = 1;
  5344. for (const xmj of leafXmjs) {
  5345. if (_.findIndex(changeList, function (item) {
  5346. return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
  5347. }) === -1) {
  5348. addDatas.push({
  5349. lid: xmj.gcl_id,
  5350. code: gclInfo.code,
  5351. name: gclInfo.name || '',
  5352. unit: gclInfo.unit || '',
  5353. unit_price: gclInfo.unit_price,
  5354. oamount: xmj.quantity,
  5355. oamount2: xmj.quantity,
  5356. bwmx: xmj.bwmx || xmj.jldy || '',
  5357. xmj_code: xmj.code || '',
  5358. xmj_jldy: xmj.jldy || '',
  5359. xmj_dwgc: xmj.dwgc || '',
  5360. xmj_fbgc: xmj.fbgc || '',
  5361. xmj_fxgc: xmj.fxgc || '',
  5362. gcl_id: xmj.gcl_id,
  5363. mx_id: xmj.mx_id || '',
  5364. });
  5365. }
  5366. }
  5367. }
  5368. }
  5369. console.log(addDatas);
  5370. if (addDatas.length > 0) {
  5371. // 更新至服务器
  5372. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  5373. type: 'add-change-list',
  5374. postData: addDatas,
  5375. }, function (result) {
  5376. toastr.success('已新增当前变更令新增的所有部位/清单');
  5377. changeList = result.changeList;
  5378. const sortData = SpreadJsObj.getSortData(billsSheet);
  5379. const billsNodes = _.filter(sortData, function (item) {
  5380. return _.findIndex(addDatas, {gcl_id: item.id}) !== -1;
  5381. });
  5382. for (const billsNode of billsNodes) {
  5383. billsNode.is_change = 1;
  5384. }
  5385. const loadResult = { update: billsNodes };
  5386. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  5387. posSpreadObj.loadCurPosData();
  5388. });
  5389. } else {
  5390. toastr.warning('未存在当前变更令新增的部位/清单');
  5391. }
  5392. });
  5393. });
  5394. const batchPosSpreadObj = {
  5395. clearBpSheet: function (sheet) {
  5396. sheet.zh_data = [];
  5397. sheet.deleteRows(0, sheet.getRowCount() - 3);
  5398. SpreadJsObj.resetTopAndSelect(sheet);
  5399. },
  5400. clearSpSheet: function (sheet) {
  5401. sheet.zh_data = [];
  5402. sheet.deleteRows(0, sheet.getRowCount());
  5403. SpreadJsObj.resetTopAndSelect(sheet);
  5404. for (const bp of bpObj.bpData) {
  5405. bp.add = false;
  5406. bpObj.bpSheet.zh_data[bpObj.bpData.indexOf(bp)].add = false;
  5407. }
  5408. SpreadJsObj.reLoadSheetData(bpObj.bpSheet);
  5409. },
  5410. genId: function (prefix) {
  5411. const id = prefix + '-' + Date.now().toString(36) + '-' + Math.floor(Math.random() * 0x100000).toString(36);
  5412. // 若要绝对确保在 DOM 中唯一,可检查并重试:
  5413. return id;
  5414. },
  5415. bpClipboardPasted: function (e, info) {
  5416. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  5417. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  5418. }
  5419. const node = SpreadJsObj.getSelectObject(billsSheet);
  5420. const updateDatas = [];
  5421. const insertDatas = [];
  5422. const sortData = info.sheet.zh_data || [];
  5423. const hint = {
  5424. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  5425. };
  5426. let bHint = false;
  5427. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  5428. let bPaste = true;
  5429. const curRow = info.cellRange.row + iRow;
  5430. const posData = curRow >= sortData.length ? {} : sortData[curRow];
  5431. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  5432. const curCol = info.cellRange.col + iCol;
  5433. const colSetting = info.sheet.zh_setting.cols[curCol];
  5434. if (!colSetting) continue;
  5435. let validText = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  5436. if (colSetting.field === 'camount') {
  5437. bPaste = true;
  5438. const exprQuantity = {
  5439. expr: '',
  5440. quantity: 0,
  5441. };
  5442. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  5443. if (!valid) {
  5444. toastMessageUniq(hint.expr);
  5445. bPaste = false;
  5446. continue;
  5447. }
  5448. if (isNaN(exprQuantity.quantity)) {
  5449. toastMessageUniq(hint.expr);
  5450. bPaste = false;
  5451. continue;
  5452. }
  5453. validText = parseFloat(exprQuantity.quantity);
  5454. posData.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  5455. posData.camount_expr = exprQuantity.expr;
  5456. continue;
  5457. }
  5458. posData[colSetting.field] = validText;
  5459. }
  5460. if (bPaste && posData.name) {
  5461. delete posData.waitingLoading;
  5462. if (curRow >= sortData.length) {
  5463. posData.id = batchPosSpreadObj.genId(curRow);
  5464. bpObj.bpData.push(posData);
  5465. insertDatas.push(posData);
  5466. } else {
  5467. // 更改bpObj.bpData同行数据用posData替换
  5468. bpObj.bpData[curRow] = posData;
  5469. updateDatas.push(posData);
  5470. }
  5471. }
  5472. }
  5473. if (insertDatas.length > 0) {
  5474. for (const d of insertDatas) {
  5475. const pos = _.find(bpObj.posData, { name: d.name });
  5476. const bpPoss = _.filter(bpObj.bpData, { name: d.name });
  5477. const spPos = _.find(bpObj.spData, { name: d.name });
  5478. if (pos && bpPoss.length > 0) {
  5479. const cInfo = _.find(changeList, { gcl_id: pos.lid, mx_id: pos.id });
  5480. if (cInfo) {
  5481. continue;
  5482. }
  5483. // 其它bpPoss add为false
  5484. for (const b of bpPoss) {
  5485. b.add = false;
  5486. }
  5487. const bp = _.find(bpObj.bpData, { id: d.id });
  5488. bp.add = true;
  5489. if (spPos) {
  5490. spPos.id = d.id;
  5491. spPos.camount = d.camount;
  5492. spPos.camount_expr = d.camount_expr;
  5493. } else {
  5494. bpObj.spData.push({
  5495. id: d.id,
  5496. gcl_id: pos.lid,
  5497. mx_id: pos.id,
  5498. name: d.name,
  5499. camount: d.camount || 0,
  5500. camount_expr: d.camount_expr || '',
  5501. is_valuation: 1,
  5502. });
  5503. }
  5504. }
  5505. }
  5506. }
  5507. if (updateDatas.length > 0) {
  5508. for (const d of updateDatas) {
  5509. const pos = _.find(bpObj.posData, { name: d.name });
  5510. const spPos = _.find(bpObj.spData, { id: d.id });
  5511. if (pos && spPos) {
  5512. const cInfo = _.find(changeList, { gcl_id: pos.lid, mx_id: pos.id });
  5513. if (cInfo) {
  5514. continue;
  5515. }
  5516. spPos.camount = d.camount || 0;
  5517. spPos.camount_expr = d.camount_expr || '';
  5518. }
  5519. }
  5520. }
  5521. SpreadJsObj.loadSheetData(bpObj.bpSheet, SpreadJsObj.DataType.Data, bpObj.bpData);
  5522. SpreadJsObj.loadSheetData(bpObj.spSheet, SpreadJsObj.DataType.Data, bpObj.spData);
  5523. },
  5524. bpEditStarting: function (e, info) {
  5525. const sel = info.sheet.getSelections();
  5526. if (!sel || !sel[0]) return;
  5527. const col = info.sheet.zh_setting.cols[sel[0].col];
  5528. const node = SpreadJsObj.getSelectObject(info.sheet);
  5529. if (!node || !node.id) return;
  5530. if (col.field === 'camount') {
  5531. if (node.camount_expr && node.camount_expr !== '') {
  5532. info.sheet.getCell(info.row, info.col).text(node.camount_expr);
  5533. }
  5534. }
  5535. },
  5536. bpEditEnded: function (e, info) {
  5537. if (!info.sheet.zh_setting) {
  5538. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5539. return;
  5540. }
  5541. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  5542. const node = SpreadJsObj.getSelectObject(billsSheet);
  5543. const col = info.sheet.zh_setting.cols[info.col];
  5544. if (!posData || !posData.id || !col) {
  5545. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5546. return;
  5547. }
  5548. if (col.field === 'camount') {
  5549. let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
  5550. const orgValue = validText && validText !== ''
  5551. ? (_.toNumber(validText) ? posData.camount : posData.camount_expr)
  5552. : (posData.camount_expr && posData.camount_expr !== '' ? posData.camount_expr : posData.camount);
  5553. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  5554. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5555. return;
  5556. }
  5557. const exprQuantity = {
  5558. expr: '',
  5559. quantity: 0,
  5560. };
  5561. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  5562. if (!valid) {
  5563. toastr.error(msg);
  5564. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5565. return;
  5566. }
  5567. if (isNaN(exprQuantity.quantity)) {
  5568. toastr.error('不能输入其它非数字类型字符');
  5569. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5570. return;
  5571. }
  5572. validText = parseFloat(exprQuantity.quantity);
  5573. posData[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  5574. posData.camount_expr = exprQuantity.expr;
  5575. const spPos = _.find(bpObj.spData, { id: posData.id });
  5576. if (spPos) {
  5577. spPos.camount = posData.camount;
  5578. spPos.camount_expr = posData.camount_expr;
  5579. const spRow = _.findIndex(bpObj.spSheet.zh_data, { id: posData.id });
  5580. if (spRow >= 0) {
  5581. bpObj.spSheet.zh_data[spRow].camount = posData.camount;
  5582. bpObj.spSheet.zh_data[spRow].camount_expr = posData.camount_expr;
  5583. SpreadJsObj.reLoadRowData(bpObj.spSheet, spRow);
  5584. }
  5585. }
  5586. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5587. }
  5588. },
  5589. spClipboardPasted: function (e, info) {
  5590. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  5591. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  5592. }
  5593. const node = SpreadJsObj.getSelectObject(billsSheet);
  5594. const data = [];
  5595. const rows = [];
  5596. const sortData = info.sheet.zh_data || [];
  5597. const hint = {
  5598. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  5599. };
  5600. let bHint = false;
  5601. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  5602. let bPaste = true;
  5603. const curRow = info.cellRange.row + iRow;
  5604. const posData = sortData[curRow];
  5605. if (!posData || !posData.id) continue;
  5606. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  5607. const curCol = info.cellRange.col + iCol;
  5608. const colSetting = info.sheet.zh_setting.cols[curCol];
  5609. if (!colSetting) continue;
  5610. let validText = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  5611. if (colSetting.field === 'camount') {
  5612. bPaste = true;
  5613. const exprQuantity = {
  5614. expr: '',
  5615. quantity: 0,
  5616. };
  5617. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  5618. if (!valid) {
  5619. toastMessageUniq(hint.expr);
  5620. bPaste = false;
  5621. continue;
  5622. }
  5623. if (isNaN(exprQuantity.quantity)) {
  5624. toastMessageUniq(hint.expr);
  5625. bPaste = false;
  5626. continue;
  5627. }
  5628. validText = parseFloat(exprQuantity.quantity);
  5629. posData.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  5630. posData.camount_expr = exprQuantity.expr;
  5631. continue;
  5632. }
  5633. }
  5634. if (bPaste) {
  5635. delete posData.waitingLoading;
  5636. bpObj.spData[curRow] = posData;
  5637. data.push(posData);
  5638. }
  5639. }
  5640. if (data.length > 0) {
  5641. for (const [i,d] of data.entries()) {
  5642. const bpPos = _.find(bpObj.bpData, { id: d.id });
  5643. if (bpPos) {
  5644. bpPos.camount = d.camount;
  5645. bpPos.camount_expr = d.camount_expr;
  5646. const bpRow = _.findIndex(bpObj.bpSheet.zh_data, { id: d.id });
  5647. if (bpRow >= 0) {
  5648. bpObj.bpSheet.zh_data[bpRow].camount = d.camount;
  5649. bpObj.bpSheet.zh_data[bpRow].camount_expr = d.camount_expr;
  5650. SpreadJsObj.reLoadRowData(bpObj.bpSheet, bpRow);
  5651. }
  5652. }
  5653. }
  5654. }
  5655. SpreadJsObj.loadSheetData(bpObj.spSheet, SpreadJsObj.DataType.Data, bpObj.spData);
  5656. },
  5657. spEditStarting: function (e, info) {
  5658. const sel = info.sheet.getSelections();
  5659. if (!sel || !sel[0]) return;
  5660. const col = info.sheet.zh_setting.cols[sel[0].col];
  5661. const node = SpreadJsObj.getSelectObject(info.sheet);
  5662. if (!node || !node.id) return;
  5663. if (col.field === 'camount') {
  5664. if (node.camount_expr && node.camount_expr !== '') {
  5665. info.sheet.getCell(info.row, info.col).text(node.camount_expr);
  5666. }
  5667. }
  5668. },
  5669. spEditEnded: function (e, info) {
  5670. if (!info.sheet.zh_setting) {
  5671. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5672. return;
  5673. }
  5674. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  5675. const node = SpreadJsObj.getSelectObject(billsSheet);
  5676. const col = info.sheet.zh_setting.cols[info.col];
  5677. if (!posData || !posData.id || !col) {
  5678. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5679. return;
  5680. }
  5681. if (col.field === 'camount') {
  5682. let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
  5683. const orgValue = validText && validText !== ''
  5684. ? (_.toNumber(validText) ? posData.camount : posData.camount_expr)
  5685. : (posData.camount_expr && posData.camount_expr !== '' ? posData.camount_expr : posData.camount);
  5686. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  5687. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5688. return;
  5689. }
  5690. const exprQuantity = {
  5691. expr: '',
  5692. quantity: 0,
  5693. };
  5694. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  5695. if (!valid) {
  5696. toastr.error(msg);
  5697. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5698. return;
  5699. }
  5700. if (isNaN(exprQuantity.quantity)) {
  5701. toastr.error('不能输入其它非数字类型字符');
  5702. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5703. return;
  5704. }
  5705. validText = parseFloat(exprQuantity.quantity);
  5706. posData[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  5707. posData.camount_expr = exprQuantity.expr;
  5708. const bpPos = _.find(bpObj.bpData, { id: posData.id });
  5709. if (bpPos) {
  5710. bpPos.camount = posData.camount;
  5711. bpPos.camount_expr = posData.camount_expr;
  5712. const bpRow = _.findIndex(bpObj.bpSheet.zh_data, { id: posData.id });
  5713. if (bpRow >= 0) {
  5714. bpObj.bpSheet.zh_data[bpRow].camount = posData.camount;
  5715. bpObj.bpSheet.zh_data[bpRow].camount_expr = posData.camount_expr;
  5716. SpreadJsObj.reLoadRowData(bpObj.bpSheet, bpRow);
  5717. }
  5718. }
  5719. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5720. }
  5721. },
  5722. spButtonClicked: function (e, info) {
  5723. if (!info.sheet.zh_setting) return;
  5724. const col = info.sheet.zh_setting.cols[info.col];
  5725. if (col.field !== 'is_valuation') return;
  5726. const node = SpreadJsObj.getSelectObject(info.sheet);
  5727. node.is_valuation = !node.is_valuation ? 1 : 0;
  5728. SpreadJsObj.reLoadSheetData(bpObj.spSheet);
  5729. },
  5730. deleteBp: function () {
  5731. if (bpObj.bpData.length === 0) return;
  5732. if (bpObj.bpSheet.getSelections().length === 0) return;
  5733. const selections = bpObj.bpSheet.getSelections();
  5734. const sel = selections ? selections[0] : bpObj.bpSheet.getSelections()[0];
  5735. const row = sel && sel.row !== undefined ? sel.row : -1;
  5736. if (row === -1 || sel.row + sel.rowCount > bpObj.bpData.length) {
  5737. return false;
  5738. }
  5739. const delList = [];
  5740. for (let r = 0; r < sel.rowCount; r++) {
  5741. const select = bpObj.bpData[row + r];
  5742. delList.push(select);
  5743. const spRow = _.findIndex(bpObj.spData, { id: select.id });
  5744. bpObj.spData.splice(spRow, 1);
  5745. bpObj.spSheet.deleteRows(spRow, 1);
  5746. }
  5747. _.pullAll(bpObj.bpData, delList);
  5748. bpObj.bpSheet.deleteRows(row, sel.rowCount);
  5749. // SpreadJsObj.loadSheetData(bpObj.bpSheet, SpreadJsObj.DataType.Data, bpObj.bpData);
  5750. SpreadJsObj.resetTopAndSelect(bpObj.bpSheet);
  5751. },
  5752. deleteSp: function () {
  5753. if (bpObj.spData.length === 0) return;
  5754. if (bpObj.spSheet.getSelections().length === 0) return;
  5755. const selections = bpObj.spSheet.getSelections();
  5756. const sel = selections ? selections[0] : bpObj.spSheet.getSelections()[0];
  5757. const row = sel && sel.row !== undefined ? sel.row : -1;
  5758. if (row === -1 || sel.row + sel.rowCount > bpObj.spData.length) {
  5759. return false;
  5760. }
  5761. const delList = [];
  5762. for (let r = 0; r < sel.rowCount; r++) {
  5763. const select = bpObj.spData[row + r];
  5764. const bpSelect = _.filter(bpObj.bpData, { name: select.name });
  5765. for (const b of bpSelect) {
  5766. b.add = false;
  5767. }
  5768. delList.push(select);
  5769. }
  5770. _.pullAll(bpObj.spData, delList);
  5771. bpObj.spSheet.deleteRows(row, sel.rowCount);
  5772. SpreadJsObj.resetTopAndSelect(bpObj.spSheet);
  5773. SpreadJsObj.reLoadSheetData(bpObj.bpSheet);
  5774. },
  5775. };
  5776. $('#batch-pos').on('show.bs.modal', function (e) {
  5777. makeBatchPosSjsHtml();
  5778. });
  5779. let bp = false;
  5780. let bpObj = {
  5781. setting: null,
  5782. opSheet: null,
  5783. bpSheet: null,
  5784. spSheet: null,
  5785. posData: [],
  5786. spData: [],
  5787. bpData: [],
  5788. };
  5789. function makeBatchPosSjsHtml() {
  5790. if (!bp) {
  5791. initBatchPos();
  5792. bp = true;
  5793. }
  5794. const node = SpreadJsObj.getSelectObject(billsSheet);
  5795. if (node) {
  5796. const posData = pos.getLedgerPos(node.id) || [];
  5797. bpObj.posData = posData;
  5798. $('#batch-ledger-name').text(node.b_code);
  5799. SpreadJsObj.loadSheetData(bpObj.opSheet, SpreadJsObj.DataType.Data, posData);
  5800. } else {
  5801. bpObj.posData = [];
  5802. $('#batch-ledger-name').text('');
  5803. SpreadJsObj.loadSheetData(bpObj.opSheet, SpreadJsObj.DataType.Data, []);
  5804. }
  5805. $('#clear-bp-btn').click();
  5806. }
  5807. const initBatchPos = function () {
  5808. const opSpread = SpreadJsObj.createNewSpread($('#origin-pos-spread')[0]);
  5809. bpObj.opSheet = opSpread.getActiveSheet();
  5810. const opSpreadSetting = {
  5811. emptyRows: 0,
  5812. headRows: 2,
  5813. headRowHeight: [25, 25],
  5814. defaultRowHeight: 21,
  5815. headerFont: '12px 微软雅黑',
  5816. font: '12px 微软雅黑',
  5817. headColWidth: [],
  5818. readOnly: true,
  5819. // selectedBackColor: '#fffacd',
  5820. };
  5821. opSpreadSetting.cols = posSpreadSetting.cols;
  5822. SpreadJsObj.initSheet(bpObj.opSheet, opSpreadSetting);
  5823. const bpSpread = SpreadJsObj.createNewSpread($('#batch-pos-spread')[0]);
  5824. bpObj.bpSheet = bpSpread.getActiveSheet();
  5825. const bpSpreadSetting = {
  5826. cols: [
  5827. {
  5828. title: '计量单元',
  5829. field: 'name',
  5830. hAlign: 0,
  5831. width: 200,
  5832. formatter: '@',
  5833. readOnly: true,
  5834. },
  5835. {
  5836. title: '申请变更数量',
  5837. field: 'camount',
  5838. hAlign: 2,
  5839. width: 120,
  5840. // readOnly: true,
  5841. },
  5842. ],
  5843. emptyRows: 3,
  5844. headRows: 1,
  5845. headRowHeight: [32],
  5846. defaultRowHeight: 21,
  5847. headerFont: '12px 微软雅黑',
  5848. font: '12px 微软雅黑',
  5849. headColWidth: []
  5850. // selectedBackColor: '#fffacd',
  5851. };
  5852. bpSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  5853. if (data && data.add) {
  5854. return '#c3e6cb';
  5855. }
  5856. return defaultColor;
  5857. };
  5858. SpreadJsObj.initSheet(bpObj.bpSheet, bpSpreadSetting);
  5859. bpSpread.bind(spreadNS.Events.EditStarting, batchPosSpreadObj.bpEditStarting);
  5860. bpSpread.bind(spreadNS.Events.EditEnded, batchPosSpreadObj.bpEditEnded);
  5861. bpSpread.bind(spreadNS.Events.ClipboardPasted, batchPosSpreadObj.bpClipboardPasted);
  5862. const spSpread = SpreadJsObj.createNewSpread($('#save-pos-spread')[0]);
  5863. bpObj.spSheet = spSpread.getActiveSheet();
  5864. const spSpreadSetting = {
  5865. cols: [
  5866. {
  5867. title: '计量单元',
  5868. field: 'name',
  5869. hAlign: 0,
  5870. width: 200,
  5871. formatter: '@',
  5872. readOnly: true,
  5873. },
  5874. {
  5875. title: '申请变更数量',
  5876. field: 'camount',
  5877. hAlign: 2,
  5878. width: 120,
  5879. // readOnly: true,
  5880. },
  5881. {
  5882. title: '计价',
  5883. field: 'is_valuation',
  5884. hAlign: 1,
  5885. width: 40,
  5886. formatter: '@',
  5887. cellType: 'checkbox',
  5888. readOnly: true,
  5889. },
  5890. ],
  5891. emptyRows: 0,
  5892. headRows: 1,
  5893. headRowHeight: [32],
  5894. defaultRowHeight: 21,
  5895. headerFont: '12px 微软雅黑',
  5896. font: '12px 微软雅黑',
  5897. headColWidth: []
  5898. };
  5899. SpreadJsObj.initSheet(bpObj.spSheet, spSpreadSetting);
  5900. spSpread.bind(spreadNS.Events.ButtonClicked, batchPosSpreadObj.spButtonClicked);
  5901. spSpread.bind(spreadNS.Events.EditStarting, batchPosSpreadObj.spEditStarting);
  5902. spSpread.bind(spreadNS.Events.EditEnded, batchPosSpreadObj.spEditEnded);
  5903. spSpread.bind(spreadNS.Events.ClipboardPasted, batchPosSpreadObj.spClipboardPasted);
  5904. // 右键删除已选粘贴
  5905. const bpContextMenuOptions = {
  5906. selector: '#batch-pos-spread',
  5907. build: function ($trigger, e) {
  5908. const target = SpreadJsObj.safeRightClickSelection($trigger, e, bpSpread);
  5909. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  5910. },
  5911. items: {
  5912. delete: {
  5913. name: '删除',
  5914. icon: 'fa-remove',
  5915. callback: function (key, opt) {
  5916. batchPosSpreadObj.deleteBp();
  5917. },
  5918. disabled: function (key, opt) {
  5919. const selection = bpObj.bpSheet.getSelections();
  5920. const sel = selection ? selection[0] : bpObj.bpSheet.getSelections()[0];
  5921. const row = sel && sel.row !== undefined ? sel.row : -1;
  5922. if (row === -1 || sel.row + sel.rowCount > bpObj.bpData.length) {
  5923. return true;
  5924. }
  5925. return false;
  5926. }
  5927. },
  5928. }
  5929. };
  5930. $.contextMenu(bpContextMenuOptions);
  5931. // 右键删除已选录入
  5932. const spContextMenuOptions = {
  5933. selector: '#save-pos-spread',
  5934. build: function ($trigger, e) {
  5935. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  5936. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  5937. },
  5938. items: {
  5939. delete: {
  5940. name: '删除',
  5941. icon: 'fa-remove',
  5942. callback: function (key, opt) {
  5943. batchPosSpreadObj.deleteSp();
  5944. },
  5945. disabled: function (key, opt) {
  5946. const selection = bpObj.spSheet.getSelections();
  5947. const sel = selection ? selection[0] : bpObj.spSheet.getSelections()[0];
  5948. const row = sel && sel.row !== undefined ? sel.row : -1;
  5949. if (row === -1 || sel.row + sel.rowCount > bpObj.spData.length) {
  5950. return true;
  5951. }
  5952. return false;
  5953. }
  5954. },
  5955. }
  5956. };
  5957. // $.contextMenu(spContextMenuOptions);
  5958. $('#batch-pos').bind('shown.bs.modal', function () {
  5959. if (opSpread) opSpread.refresh();
  5960. if (bpSpread) bpSpread.refresh();
  5961. if (spSpread) spSpread.refresh();
  5962. });
  5963. $('#clear-bp-btn').click(function () {
  5964. bpObj.bpData = [];
  5965. batchPosSpreadObj.clearBpSheet(bpObj.bpSheet);
  5966. bpObj.spData = [];
  5967. batchPosSpreadObj.clearSpSheet(bpObj.spSheet);
  5968. });
  5969. // $('#clear-op-btn').click(function () {
  5970. // bpObj.spData = [];
  5971. // batchPosSpreadObj.clearSpSheet(bpObj.spSheet);
  5972. // });
  5973. $('#add-changelist-btn').click(function () {
  5974. if (bpObj.spData.length === 0) {
  5975. toastr.warning('录入区计量单元为空');
  5976. return;
  5977. }
  5978. const datas = [];
  5979. makeGclGatherData();
  5980. for (const posData of bpObj.spData) {
  5981. const gclInfo = _.find(gclGatherData, function (item) {
  5982. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: posData.gcl_id, mx_id: posData.mx_id });
  5983. });
  5984. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: posData.mx_id });
  5985. const oldCInfo = _.find(oldChangeList, { gcl_id: posData.gcl_id, mx_id: posData.mx_id });
  5986. if (gclInfo && xmjInfo) {
  5987. const data = {
  5988. lid: xmjInfo.gcl_id,
  5989. code: gclInfo.b_code,
  5990. name: gclInfo.name || '',
  5991. unit: gclInfo.unit || '',
  5992. unit_price: gclInfo.unit_price,
  5993. oamount: xmjInfo.quantity,
  5994. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  5995. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  5996. xmj_code: xmjInfo.code || '',
  5997. xmj_jldy: xmjInfo.jldy || '',
  5998. xmj_dwgc: xmjInfo.dwgc || '',
  5999. xmj_fbgc: xmjInfo.fbgc || '',
  6000. xmj_fxgc: xmjInfo.fxgc || '',
  6001. gcl_id: xmjInfo.gcl_id,
  6002. mx_id: xmjInfo.mx_id || '',
  6003. is_valuation: posData.is_valuation,
  6004. camount: posData.camount,
  6005. camount_expr: posData.camount_expr,
  6006. spamount: posData.camount,
  6007. }
  6008. if (oldCInfo) {
  6009. data.detail = oldCInfo.detail;
  6010. data.delimit = oldCInfo.delimit;
  6011. }
  6012. datas.push(data);
  6013. }
  6014. }
  6015. if (datas.length > 0) {
  6016. console.log(datas);
  6017. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', insertData: datas, updateData: [] }, function (result) {
  6018. changeList = result;
  6019. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  6020. billsTreeSpreadObj.reCalcCamount(billsNode);
  6021. const loadResult = { update: [billsNode] };
  6022. const refreshNode = billsTree.loadPostData(loadResult);
  6023. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  6024. posSpreadObj.loadCurPosData();
  6025. $('#batch-pos').modal('hide');
  6026. });
  6027. }
  6028. return;
  6029. });
  6030. };
  6031. }
  6032. });
  6033. function findDecimal(unit) {
  6034. let value = precision.other.value;
  6035. const changeUnits = precision;
  6036. for (const d in changeUnits) {
  6037. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  6038. value = changeUnits[d].value;
  6039. break;
  6040. }
  6041. }
  6042. return value;
  6043. }
  6044. // 编号排序,多重判断
  6045. function sortByCode(a, b, code = 'b_code') {
  6046. let code1 = a[code].split('-');
  6047. let code2 = b[code].split('-');
  6048. let code1length = code1.length;
  6049. let code2length = code2.length;
  6050. for (let i = 0; i < code1length; i ++) {
  6051. if (i+1 <= code2length) {
  6052. if (code1[i] != code2[i]) {
  6053. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  6054. return parseInt(code1[i]) - parseInt(code2[i]);
  6055. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  6056. return 1;
  6057. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  6058. return -1;
  6059. } else {
  6060. const str1length = code1[i].length;
  6061. const str2length = code2[i].length;
  6062. for (let j = 0; j < str1length; j++) {
  6063. if (j+1 <= str2length) {
  6064. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  6065. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  6066. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  6067. if (str1length == str2length) {
  6068. return 0;
  6069. } else {
  6070. return str1length - str2length;
  6071. }
  6072. }
  6073. } else {
  6074. if (j+1 >= str1length) {
  6075. return 1;
  6076. } else {
  6077. return -1;
  6078. }
  6079. }
  6080. }
  6081. }
  6082. } else if (i+1 == code1length && code1[i] == code2[i]) {
  6083. if (code1length == code2length) {
  6084. return 0;
  6085. } else {
  6086. return code1length - code2length;
  6087. }
  6088. }
  6089. } else {
  6090. if (i+1 >= code1length) {
  6091. return 1;
  6092. } else {
  6093. return -1;
  6094. }
  6095. }
  6096. }
  6097. }