change_information.js 318 KB

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