change_revise.js 310 KB

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