change_information.js 322 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517
  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(changeSpreadSheet.zh_data);
  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 count4Amount = cl.audit_amount ? cl.audit_amount.split(',').length : 0;
  514. cl.spa_tp = ZhCalc.round(ZhCalc.mul(ZhCalc.round(cl.unit_price, unitPriceUnit), ZhCalc.round(cl.spamount, findDecimal(cl.unit))), totalPriceUnit);
  515. // 根据count4Amoun得出audit_amount_X值
  516. cl.amount = count4Amount ? cl['audit_amount_' + count4Amount + ''] : 0;
  517. cl.a_tp = ZhCalc.round(ZhCalc.mul(ZhCalc.round(cl.unit_price, unitPriceUnit), ZhCalc.round(cl.amount, findDecimal(cl.unit))), totalPriceUnit);
  518. if (hzIndex !== -1) {
  519. hzList[hzIndex].camount = ZhCalc.add(hzList[hzIndex].camount, cl.camount);
  520. hzList[hzIndex].ca_tp = ZhCalc.add(hzList[hzIndex].ca_tp, cl.ca_tp);
  521. hzList[hzIndex].spamount = ZhCalc.add(hzList[hzIndex].spamount, cl.spamount);
  522. hzList[hzIndex].spa_tp = ZhCalc.add(hzList[hzIndex].spa_tp, cl.spa_tp);
  523. hzList[hzIndex].amount = ZhCalc.add(hzList[hzIndex].amount, cl.amount);
  524. hzList[hzIndex].a_tp = ZhCalc.add(hzList[hzIndex].a_tp, cl.a_tp);
  525. } else {
  526. hzList.push(cl);
  527. }
  528. }
  529. if (hzList.length > 0) {
  530. // 按清单编号排序
  531. hzList.sort(sortByCode);
  532. }
  533. console.log(hzList);
  534. // // sjs设置
  535. SpreadJsObj.loadSheetData(hzSpread.getActiveSheet(), SpreadJsObj.DataType.Data, hzList);
  536. hzSpreadObj.makeBackColor();
  537. hzSpreadObj.makeSjsFooter();
  538. });
  539. // 切换页数
  540. $('.page-select').on('click', function () {
  541. const totalPageNum = parseInt($('#totalPage').text());
  542. const lastPageNum = parseInt($('#currentPage').text());
  543. const status = $(this).attr('content');
  544. if (status === 'pre' && lastPageNum > 1) {
  545. getAllList(lastPageNum-1);
  546. $('#showAttachment').hide();
  547. $('#syfujian .check-all-file').prop('checked', false)
  548. } else if (status === 'next' && lastPageNum < totalPageNum) {
  549. getAllList(lastPageNum+1);
  550. $('#showAttachment').hide();
  551. $('#syfujian .check-all-file').prop('checked', false)
  552. }
  553. });
  554. // 数字只判断几个值(unit_price, oamount)
  555. const numField = ['unit_price', 'oamount2'];
  556. const changeSpreadSetting = {
  557. cols: [
  558. {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: 'readOnly.isValuation'},
  559. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit'},
  560. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  561. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
  562. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
  563. {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  564. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isSettle2'},
  565. {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', visible: openChangeState},
  566. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount2', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
  567. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  568. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
  569. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  570. // {title: '变更后|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'},
  571. // {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.changed_tp'},
  572. // {title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'},
  573. ],
  574. emptyRows: 0,
  575. headRows: 2,
  576. headRowHeight: [25, 25],
  577. defaultRowHeight: 21,
  578. headerFont: '12px 微软雅黑',
  579. font: '12px 微软雅黑',
  580. rowHeader:[
  581. {
  582. rowHeaderType: 'circle',
  583. setting: {
  584. size: 5,
  585. indent: 16,
  586. getColor: function (index, data) {
  587. if (!data) return;
  588. if (data.ccid && data.ccid === 1) {
  589. return '#dc3545';
  590. }
  591. if (data.id && data.lid != 0 && !data.children) {
  592. return '#ffc107';
  593. }
  594. if(data.lid != 0) return;
  595. return '#007bff';
  596. }
  597. },
  598. },
  599. ],
  600. localCache: {
  601. key: 'changes-spread',
  602. colWidth: true,
  603. }
  604. };
  605. if (readOnly) {
  606. changeSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
  607. changeSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.sa_tp'});
  608. for (const aid of aidList) {
  609. // const userinfo = _.find(auditList2, { 'uid': aid });
  610. const audit = _.find(auditors2, function(item){
  611. return _.findIndex(item, { audit_order: aid }) !== -1;
  612. });
  613. const newColcount = {
  614. title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
  615. colSpan: '2|1', rowSpan: '1|1',
  616. field: 'audit_amount_' + aid,
  617. hAlign: 2, width: 60, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle',
  618. };
  619. const newColTp = {
  620. title: '|金额',
  621. colSpan: '|1', rowSpan: '|1',
  622. field: 'sa_tp_' + aid,
  623. hAlign: 2, width: 80, type: 'Number',
  624. };
  625. changeSpreadSetting.cols.push(newColcount);
  626. changeSpreadSetting.cols.push(newColTp);
  627. }
  628. }
  629. 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'});
  630. changeSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'changed_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.changed_tp'});
  631. // if (!readOnly) {
  632. // changeSpreadSetting.cols.push({title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'});
  633. // }
  634. changeSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  635. return checkIsSettle(data) ? spreadColor.stage.settle : defaultColor;
  636. }
  637. const changeCol = {
  638. getValue: {
  639. unit_price: function(data) {
  640. return ZhCalc.round(data.unit_price, unitPriceUnit);
  641. },
  642. oa_tp: function (data) {
  643. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit);
  644. },
  645. ca_tp: function (data) {
  646. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
  647. },
  648. oamount2: function (data) {
  649. return ZhCalc.round(data.oamount2, findDecimal(data.unit));
  650. },
  651. camount: function (data) {
  652. return ZhCalc.round(data.camount, findDecimal(data.unit));
  653. },
  654. changed_amount: function (data) {
  655. return ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
  656. },
  657. changed_tp: function (data) {
  658. return ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit),
  659. ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit));
  660. },
  661. // del_list: function (data) {
  662. // return !_.find(changeUsedData, { cbid: data.id }) && !checkIsSettle(data) ? '移除' : '';
  663. // }
  664. },
  665. readOnly: {
  666. isValuation: function (data) {
  667. return !(!readOnly && ((data.id && _.findIndex(changeUsedData, { cbid: data.id }) !== -1) || (data.children && data.children.length === 1 && _.findIndex(changeUsedData, { cbid: data.children[0].id }) !== -1)));
  668. },
  669. isEdit: function (data) {
  670. return !(!readOnly && data.lid == 0 && data.id && !checkIsSettle(data));
  671. },
  672. isSettle: function (data) {
  673. return !((!readOnly || shenpiPower) && ((data.id && !checkIsSettle(data)) || (data.children && data.children.length === 1 && !checkIsSettle(data.children[0]))));
  674. },
  675. isSettle2: function (data) {
  676. return !(!readOnly && ((data.id && !checkIsSettle(data)) || (data.children && data.children.length === 1 && !checkIsSettle(data.children[0]))));
  677. }
  678. },
  679. };
  680. const changeSpreadObj = {
  681. makeSjsFooter: function () {
  682. // 增加汇总行并设为锁定禁止编辑状态
  683. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  684. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  685. const cellType1 = new GC.Spread.Sheets.CellTypes.Text();
  686. changeSpreadSheet.getCell(changeSpreadSheet.getRowCount() - 1, 0).cellType(cellType1);
  687. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  688. changeSpreadObj.countSum();
  689. },
  690. setAuditValue: function () {
  691. if (readOnly) {
  692. for (const c of changeList) {
  693. for (const j of aidList) {
  694. c['audit_amount_' + j] = ZhCalc.round(c['audit_amount_' + j], findDecimal(c.unit));
  695. c['sa_tp_' + j] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + j], ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit);
  696. }
  697. }
  698. }
  699. },
  700. loadExprToInput: function () {
  701. const sel = changeSpreadSheet.getSelections()[0];
  702. if (!sel) return;
  703. const col = changeSpreadSheet.zh_setting.cols[sel.col];
  704. const data = SpreadJsObj.getSelectObject(changeSpreadSheet);
  705. if (col && col.field === 'camount' && data && (!data.gcl_id || (data.children && data.children.length === 1))) {
  706. if (readOnly) {
  707. $('#camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
  708. } else {
  709. $('#camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
  710. }
  711. } else {
  712. $('#camount-expr').attr('readonly', true).val('');
  713. }
  714. },
  715. topRowChanged: function (e, info) {
  716. SpreadJsObj.saveTopAndSelect(info.sheet, ckChangeSpread);
  717. },
  718. selectionChanged: function (e, info) {
  719. if (info.newSelections) {
  720. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  721. const data = SpreadJsObj.getSelectObject(changeSpreadSheet);
  722. if (info.oldSelections && info.oldSelections[0].row !== changeSpreadSheet.getRowCount() - 1) {
  723. info.sheet.getRange(info.oldSelections[0].row, -1, 1, -1).backColor('#fff');
  724. }
  725. if (!data) {
  726. SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Data, []);
  727. return;
  728. }
  729. console.log(info);
  730. changeSpreadObj.refreshXmjData();
  731. if (!readOnly) changeSpreadObj.refreshActn();
  732. }
  733. }
  734. changeSpreadObj.loadExprToInput();
  735. },
  736. showHideAudit: function (show = false) {
  737. if (shenpiPower) {
  738. show = true;
  739. }
  740. if (readOnly) {
  741. const count = changeSpreadSetting.cols.length;
  742. for (let i = startLimit + 5; i < count - 2; i++) {
  743. changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
  744. }
  745. changeSpreadSheet.setColumnVisible(startLimit + 3, !show, GC.Spread.Sheets.SheetArea.viewport);
  746. changeSpreadSheet.setColumnVisible(startLimit + 4, !show, GC.Spread.Sheets.SheetArea.viewport);
  747. }
  748. },
  749. calcOneSum: function (node) {
  750. if (node.children && node.children.length > 0) {
  751. if (readOnly) {
  752. for (const aid of aidList) {
  753. let audit_amount = 0;
  754. for (const c of node.children) {
  755. audit_amount = ZhCalc.add(audit_amount, ZhCalc.round(c['audit_amount_' + aid], findDecimal(node.unit)));
  756. }
  757. if (!_.isEqual(node['audit_amount_' + aid], audit_amount)) {
  758. node['audit_amount_' + aid] = audit_amount;
  759. }
  760. node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(audit_amount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit);
  761. }
  762. }
  763. let is_valuation = 1;
  764. let ccid = 0;
  765. let oamount2 = 0;
  766. let camount = 0;
  767. let samount = 0;
  768. let spamount = 0;
  769. for (const c of node.children) {
  770. oamount2 = ZhCalc.add(oamount2, ZhCalc.round(c.oamount2, findDecimal(node.unit)));
  771. camount = ZhCalc.add(camount, ZhCalc.round(c.camount, findDecimal(node.unit)));
  772. samount = ZhCalc.add(samount, ZhCalc.round(c.samount, findDecimal(node.unit)));
  773. spamount = ZhCalc.add(spamount, ZhCalc.round(c.spamount, findDecimal(node.unit)));
  774. if (c.is_valuation === 0) is_valuation = 0;
  775. if (_.findIndex(changeLedgerList, { id: c.gcl_id }) !== -1 || _.findIndex(changePosList, { id: c.mx_id }) !== -1) {
  776. ccid = 1;
  777. }
  778. c.order = node.order;
  779. }
  780. if (!_.isEqual(node.oamount2, oamount2) || !_.isEqual(node.camount, camount) || !_.isEqual(node.samount, samount)) {
  781. node.oamount2 = oamount2;
  782. node.camount = camount;
  783. node.samount = samount;
  784. node.spamount = spamount;
  785. node.change_amount = ZhCalc.add(oamount2, camount);
  786. }
  787. node.is_valuation = is_valuation;
  788. node.ccid = ccid;
  789. this.calcNodeTp(node);
  790. } else {
  791. if (readOnly) {
  792. for (const aid of aidList) {
  793. node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit);
  794. }
  795. }
  796. this.calcNodeTp(node);
  797. }
  798. return node;
  799. },
  800. calcNodeTp: function (node) {
  801. node.change_amount = ZhCalc.add(node.oamount2, node.camount);
  802. node.oa_tp = ZhCalc.round(ZhCalc.mul(node.oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  803. node.ca_tp = ZhCalc.round(ZhCalc.mul(node.camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  804. node.sa_tp = ZhCalc.round(ZhCalc.mul(node.samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  805. const spa_tp = ZhCalc.round(ZhCalc.mul(node.spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  806. node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null : ZhCalc.add(node.oa_tp, node.ca_tp) || null;
  807. },
  808. refreshXmjData: function() {
  809. SpreadJsObj.resetTopAndSelect(xmjSheet);
  810. xmjSpreadObj.loadCurXmjData();
  811. SpreadJsObj.saveTopAndSelect(changeSpreadSheet, ckChangeSpread);
  812. // posSearch.search($('#pos-keyword').val());
  813. },
  814. makeNewChangeList: function(newOrder = changeOrder) {
  815. // 先加载台账数据
  816. if (!newOrder) {
  817. const newChangeList2 = [];
  818. for (const gcl of changeListData) {
  819. if (!newOrder) {
  820. if (gcl.leafXmjs !== undefined && gcl.leafXmjs !== null) {
  821. const cl = _.filter(changeList, function (item) {
  822. return _.findIndex(gcl.leafXmjs, { gcl_id: item.gcl_id }) !== -1;
  823. });
  824. if (cl.length > 0) {
  825. for (const l of gcl.leafXmjs) {
  826. const c = _.find(cl, { gcl_id: l.gcl_id, mx_id: l.mx_id || '' });
  827. if (c) newChangeList2.push(c);
  828. }
  829. }
  830. } else {
  831. // 签约清单
  832. const c = _.find(changeList, { lid: gcl.id });
  833. if (c) newChangeList2.push(c);
  834. }
  835. }
  836. }
  837. // 按台账去重新排序changeList,空白清单居后
  838. const sycList = _.difference(changeList, newChangeList2);
  839. changeList = newChangeList2.concat(sycList);
  840. }
  841. const newChangeList = [];
  842. for (const cl of changeList) {
  843. const newCl = _.cloneDeep(cl);
  844. if (cl.gcl_id && _.findIndex(newChangeList, { gcl_id: cl.gcl_id }) === -1) {
  845. // delete newCl.id;
  846. // newCl.bwmx = '';
  847. // newCl.detail = '';
  848. // newCl.delimit = null;
  849. newCl.children = [];
  850. newCl.children.push(cl);
  851. if (_.findIndex(changeLedgerList, { id: newCl.gcl_id }) !== -1 || _.findIndex(changePosList, { id: newCl.mx_id }) !== -1) {
  852. newCl.ccid = 1;
  853. }
  854. newChangeList.push(newCl);
  855. } else if (!cl.gcl_id) {
  856. newChangeList.push(newCl);
  857. } else {
  858. const newCl2 = _.find(newChangeList, { gcl_id: cl.gcl_id });
  859. if (newCl2) {
  860. if (_.findIndex(changeLedgerList, { id: newCl.gcl_id }) !== -1 || _.findIndex(changePosList, { id: newCl.mx_id }) !== -1) {
  861. newCl2.ccid = 1;
  862. }
  863. delete newCl2.id;
  864. newCl2.bwmx = '';
  865. newCl2.detail = '';
  866. newCl2.delimit = null;
  867. newCl2.children.push(newCl);
  868. }
  869. }
  870. }
  871. const updateOrderList = [];
  872. // order如果不同,则修改并提交
  873. let i = 0;
  874. // 重算金额和数量汇总
  875. for (const node of newChangeList) {
  876. if (node.children && node.children.length > 0) {
  877. changeSpreadObj.calcOneSum(node);
  878. node.order = i + 1;
  879. const cls = node.gcl_id ? _.filter(changeList, { gcl_id: node.gcl_id }) : [];
  880. for (const c of cls) {
  881. if (node.order !== c.order) {
  882. c.order = node.order;
  883. updateOrderList.push({ id: c.id, order: node.order });
  884. }
  885. }
  886. } else {
  887. if (node.order !== i + 1) {
  888. node.order = i + 1;
  889. updateOrderList.push({ id: node.id, order: node.order });
  890. }
  891. changeSpreadObj.calcOneSum(node);
  892. if (readOnly) {
  893. for (const aid of aidList) {
  894. node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  895. }
  896. }
  897. }
  898. i++;
  899. }
  900. return [newChangeList, updateOrderList];
  901. },
  902. countSum: function () {
  903. const rowCount = changeSpreadSheet.getRowCount();
  904. let oa_tp = 0,
  905. ca_tp = 0,
  906. sa_tp = 0,
  907. changed_tp = 0;
  908. const aidLength = readOnly ? aidList.length : 0;
  909. for (const data of changeSpreadSheet.zh_data) {
  910. oa_tp = ZhCalc.add(oa_tp, data.oa_tp);
  911. ca_tp = ZhCalc.add(ca_tp, data.ca_tp);
  912. sa_tp = ZhCalc.add(sa_tp, data.sa_tp);
  913. changed_tp = ZhCalc.add(changed_tp, data.changed_tp);
  914. }
  915. changeSpreadSheet.setValue(rowCount - 1, startLimit, oa_tp !== 0 ? oa_tp : null);
  916. changeSpreadSheet.setValue(rowCount - 1, startLimit + 2, ca_tp !== 0 ? ca_tp : null);
  917. if (readOnly) {
  918. changeSpreadSheet.setValue(rowCount - 1, (startLimit + 4), sa_tp !== 0 ? sa_tp : null);
  919. changeSpreadSheet.setValue(rowCount - 1, (startLimit + 4 + aidLength * 2 + 2), changed_tp !== 0 ? changed_tp : null);
  920. } else {
  921. changeSpreadSheet.setValue(rowCount - 1, (startLimit + 4), changed_tp !== 0 ? changed_tp : null);
  922. }
  923. if (readOnly) {
  924. // 用户的数据合计
  925. for (const j in aidList) {
  926. let audit_sum = 0;
  927. for (const data of changeSpreadSheet.zh_data) {
  928. audit_sum = ZhCalc.add(audit_sum, data['sa_tp_' + aidList[j]]);
  929. }
  930. changeSpreadSheet.setValue(rowCount - 1, startLimit + 6 + j * 2, audit_sum !== 0 ? audit_sum : null);
  931. }
  932. }
  933. },
  934. reloadRow: function (sheet, row, rowCount = 0, clearAll = false) {
  935. if (rowCount) {
  936. SpreadJsObj.reLoadRowData(sheet, row, rowCount);
  937. } else {
  938. SpreadJsObj.reLoadRowData(sheet, row);
  939. }
  940. if (clearAll) {
  941. for (const i in sheet.zh_data) {
  942. const data = sheet.zh_data[i];
  943. if (data) {
  944. sheet.getRange(i, -1, 1, -1).backColor('#fff');
  945. }
  946. }
  947. }
  948. sheet.getRange(row, -1, 1, -1).backColor('#fffacd');
  949. },
  950. reloadSheet: function (newChangeList) {
  951. changeSpreadObj.setAuditValue();
  952. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, newChangeList);
  953. SpreadJsObj.loadTopAndSelect(changeSpreadSheet, ckChangeSpread);
  954. changeSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
  955. changeSpreadObj.makeSjsFooter();
  956. xmjSpreadObj.loadCurXmjData();
  957. changeSpreadObj.loadExprToInput();
  958. if (!readOnly) changeSpreadObj.refreshActn();
  959. }
  960. };
  961. // sjsSettingObj.setGridSelectStyle(changeSpreadSetting);
  962. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  963. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  964. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  965. let changeListData;
  966. let gclGatherData;
  967. postData(preUrl + '/defaultBills', {}, function (result) {
  968. ledgerList = result.bills;
  969. posList = result.pos;
  970. gclGatherModel.loadLedgerData(result.bills);
  971. gclGatherModel.loadPosData(result.pos);
  972. gclGatherData = gclGatherModel.gatherGclData();
  973. gclGatherData = _.filter(gclGatherData, function (item) {
  974. return item.leafXmjs && item.leafXmjs.length !== 0;
  975. });
  976. for (const ggd in gclGatherData) {
  977. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  978. gclGatherData.splice(ggd, 1);
  979. }
  980. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  981. let hadcid = 0;
  982. for (const xmj of gclGatherData[ggd].leafXmjs) {
  983. const changeLedger = _.find(changeLedgerList, { id: xmj.gcl_id });
  984. const changePos = _.find(changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
  985. if (changeLedger || changePos) {
  986. xmj.cid = 1;
  987. xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
  988. hadcid = 1;
  989. }
  990. }
  991. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  992. }
  993. console.log(gclGatherData);
  994. // 数组去重
  995. const dealBillList = result.dealBills;
  996. for (const db of gclGatherData) {
  997. const exist_index = dealBillList.findIndex(function (item) {
  998. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  999. });
  1000. if (exist_index !== -1) {
  1001. dealBillList.splice(exist_index, 1);
  1002. }
  1003. }
  1004. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  1005. if (!readOnly || shenpiPower) {
  1006. checkAndChange(changeListData);
  1007. }
  1008. showMode(changeMode);
  1009. });
  1010. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  1011. changeSpread.bind(spreadNS.Events.topRowChanged, changeSpreadObj.topRowChanged);
  1012. // 项目节信息获取
  1013. const xmjSpreadSetting = {
  1014. cols: [
  1015. {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: 'readOnly.isValuation'},
  1016. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'xmj_code', hAlign: 0, width: 80, readOnly: true},
  1017. // {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
  1018. {title: '细目', colSpan: '1', rowSpan: '2', field: 'xmj_jldy', hAlign: 0, width: 100, readOnly: true},
  1019. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'xmj_dwgc', hAlign: 0, width: 100, readOnly: true},
  1020. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'xmj_fbgc', hAlign: 0, width: 100, readOnly: true},
  1021. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'xmj_fxgc', hAlign: 0, width: 100, readOnly: true},
  1022. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 100, readOnly: true},
  1023. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  1024. {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', visible: openChangeState},
  1025. {title: '原设计|数量', colSpan: '1|1', rowSpan: '|1', field: 'oamount2', hAlign: 2, width: 120, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
  1026. {title: '申请变更增(+)减(-)|数量', colSpan: '1|1', rowSpan: '|1', field: 'camount', hAlign: 2, width: 120, readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
  1027. // {title: '数量', colSpan: '1', rowSpan: '2', field: 'oamount', hAlign: 2, width: 80},
  1028. ],
  1029. emptyRows: 0,
  1030. headRows: 2,
  1031. headRowHeight: [25, 25],
  1032. defaultRowHeight: 21,
  1033. headerFont: '12px 微软雅黑',
  1034. font: '12px 微软雅黑',
  1035. // readOnly: true,
  1036. rowHeader:[
  1037. {
  1038. rowHeaderType: 'circle',
  1039. setting: {
  1040. size: 5,
  1041. indent: 16,
  1042. getColor: function (index, data) {
  1043. if (!data) return;
  1044. if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
  1045. return '#dc3545';
  1046. }
  1047. }
  1048. },
  1049. },
  1050. ],
  1051. localCache: {
  1052. key: 'changes-xmj',
  1053. colWidth: true,
  1054. }
  1055. };
  1056. if (readOnly) {
  1057. xmjSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '1|1', rowSpan: '|1', field: 'samount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
  1058. for (const aid of aidList) {
  1059. const audit = _.find(auditors2, function(item){
  1060. return _.findIndex(item, { audit_order: aid }) !== -1;
  1061. });
  1062. const newColcount = {
  1063. title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
  1064. colSpan: '1|1', rowSpan: '|1',
  1065. field: 'audit_amount_' + aid,
  1066. hAlign: 2, width: 120, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle' ,
  1067. };
  1068. xmjSpreadSetting.cols.push(newColcount);
  1069. }
  1070. }
  1071. xmjSpreadSetting.cols.push({title: '变更后|数量', colSpan: '1|1', rowSpan: '|1', field: 'changed_amount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'},);
  1072. const xmjCol = {
  1073. getValue: {
  1074. oamount2: function (data) {
  1075. return ZhCalc.round(data.oamount2, findDecimal(data.unit));
  1076. },
  1077. camount: function (data) {
  1078. return ZhCalc.round(data.camount, findDecimal(data.unit));
  1079. },
  1080. samount: function (data) {
  1081. return ZhCalc.round(data.samount, findDecimal(data.unit));
  1082. },
  1083. changed_amount: function (data) {
  1084. return readOnly ? ZhCalc.round(ZhCalc.add(data.oamount2, data.spamount), findDecimal(data.unit)) : ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
  1085. },
  1086. },
  1087. readOnly: {
  1088. isEdit: function (data) {
  1089. return readOnly;
  1090. },
  1091. isValuation: function (data) {
  1092. return !(!readOnly && _.findIndex(changeUsedData, { cbid: data.clid }) !== -1);
  1093. },
  1094. isSettle: function (data) {
  1095. return !((!readOnly || shenpiPower) && !checkIsSettle(data));
  1096. },
  1097. isSettle2: function (data) {
  1098. return !(!readOnly && !checkIsSettle(data));
  1099. }
  1100. },
  1101. }
  1102. sjsSettingObj.setGridSelectStyle(xmjSpreadSetting);
  1103. SpreadJsObj.initSpreadSettingEvents(xmjSpreadSetting, xmjCol);
  1104. SpreadJsObj.initSheet(xmjSpread.getActiveSheet(), xmjSpreadSetting);
  1105. const xmjSheet = xmjSpread.getActiveSheet();
  1106. const xmjSpreadObj = {
  1107. loadExprToInput: function () {
  1108. const sel = xmjSheet.getSelections()[0];
  1109. if (!sel) return;
  1110. const col = xmjSheet.zh_setting.cols[sel.col];
  1111. const data = SpreadJsObj.getSelectObject(xmjSheet);
  1112. if (col && col.field === 'camount' && data) {
  1113. if (readOnly) {
  1114. $('#xmj-camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
  1115. } else {
  1116. $('#xmj-camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
  1117. }
  1118. } else {
  1119. $('#xmj-camount-expr').attr('readonly', true).val('');
  1120. }
  1121. },
  1122. /**
  1123. * 加载计量单元 根据当前台账选择节点
  1124. */
  1125. loadCurXmjData: function () {
  1126. const data = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1127. changeSpreadSheet.getRange(changeSpreadSheet.getSelections()[0].row, -1, 1, -1).backColor('#fffacd');
  1128. const xmj = [];
  1129. if (data && data.children && data.children.length > 0) {
  1130. for (const child of data.children) {
  1131. if (child.bwmx === child.xmj_jldy) {
  1132. child.bwmx = '';
  1133. }
  1134. xmj.push(child);
  1135. }
  1136. }
  1137. SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Data, xmj);
  1138. xmjSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
  1139. SpreadJsObj.resetTopAndSelect(xmjSheet);
  1140. xmjSpreadObj.loadExprToInput();
  1141. },
  1142. selectionChanged: function (e, info) {
  1143. xmjSpreadObj.loadExprToInput();
  1144. },
  1145. showHideAudit: function (show = false) {
  1146. if (shenpiPower) {
  1147. show = true;
  1148. }
  1149. if (readOnly) {
  1150. const xmjStartLimit = 9;
  1151. const count = xmjSpreadSetting.cols.length;
  1152. for (let i = xmjStartLimit + 2; i < count - 1; i++) {
  1153. xmjSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
  1154. }
  1155. xmjSheet.setColumnVisible(xmjStartLimit + 2, !show, GC.Spread.Sheets.SheetArea.viewport);
  1156. }
  1157. },
  1158. };
  1159. xmjSpread.bind(spreadNS.Events.SelectionChanged, xmjSpreadObj.selectionChanged);
  1160. if (!readOnly) {
  1161. $('.dropdown-menu input[name="paixu"]').on('click', function () {
  1162. const newChangeOrder = parseInt($(this).val());
  1163. if (newChangeOrder !== changeOrder) {
  1164. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList(newChangeOrder);
  1165. // 更新至服务器
  1166. postData(window.location.pathname + '/save', { type:'order_by', updateData: newChangeOrder, updateOrderList }, function (result) {
  1167. if (newChangeOrder === 0) {
  1168. $('#bpaixu').text('清单排序:清单编号');
  1169. $('#upAndMoveBtn').attr('style', 'display: none !important');
  1170. $('.order_text').text('添加');
  1171. changeOrder = newChangeOrder;
  1172. } else if (newChangeOrder === 1) {
  1173. $('#bpaixu').text('清单排序:添加顺序');
  1174. $('#upAndMoveBtn').show();
  1175. $('.order_text').text('插入');
  1176. changeOrder = newChangeOrder;
  1177. }
  1178. changeList = result.changeList;
  1179. changeUsedData = result.usedList;
  1180. const [newChangeList] = changeSpreadObj.makeNewChangeList();
  1181. changeSpreadObj.reloadSheet(newChangeList);
  1182. });
  1183. }
  1184. });
  1185. $('#set-site-btn').click(async function () {
  1186. if (changeOrder && !changeMode) {
  1187. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1188. if (!select && changeSpreadSheet.zh_data.length > 0) {
  1189. toastr.error('请选择清单再插入');
  1190. return;
  1191. }
  1192. 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) {
  1193. window.location.href = window.location.pathname + '/revise';
  1194. });
  1195. } else {
  1196. window.location.href = window.location.pathname + '/revise';
  1197. }
  1198. });
  1199. changeSpreadObj.refreshActn = function (rowCount = 1) {
  1200. const setObjEnable = function (obj, enable) {
  1201. if (enable) {
  1202. obj.removeClass('disabled');
  1203. } else {
  1204. obj.addClass('disabled');
  1205. }
  1206. };
  1207. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1208. // 还需判断是否已被调差清单调用
  1209. const selection = changeSpreadSheet.getSelections();
  1210. const sel = selection ? selection[0] : changeSpreadSheet.getSelections()[0];
  1211. const row = sel ? sel.row : -1;
  1212. const first = changeSpreadSheet.zh_data[row];
  1213. let last = first;
  1214. if (sel.rowCount > 1 && first) {
  1215. for (let r = 1; r < sel.rowCount; r++) {
  1216. const rNode = changeSpreadSheet.zh_data[sel.row + r];
  1217. if (!rNode) break;
  1218. last = rNode;
  1219. }
  1220. }
  1221. const preNode = changeSpreadSheet.zh_data[row - 1];
  1222. setObjEnable($('#up-move'), !readOnly && first && preNode && changeSpreadSheet.zh_data.indexOf(last) > 0 && sel.row + sel.rowCount <= changeSpreadSheet.zh_data.length);
  1223. setObjEnable($('#down-move'), !readOnly && first && changeSpreadSheet.zh_data.indexOf(last) < changeSpreadSheet.zh_data.length - 1 && sel.row + sel.rowCount <= changeSpreadSheet.zh_data.length);
  1224. // setObjEnable($('#open-list-modal'), !readOnly && select && changeList.indexOf(select) !== -1);
  1225. // setObjEnable($('#add-white-btn'), !readOnly && select && changeList.indexOf(select) !== -1);
  1226. };
  1227. changeSpreadObj.add = function () {
  1228. let select = null;
  1229. if (changeOrder) {
  1230. select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1231. }
  1232. postData(window.location.pathname + '/save', {type: 'add', postData: select ? select.order : null}, function (result) {
  1233. if (result) {
  1234. if (changeOrder === 1 && select) {
  1235. // 批量更新changeList的order值
  1236. _.forEach(changeList, function (item) {
  1237. item.order = item.order > select.order ? item.order + 1 : item.order;
  1238. });
  1239. _.forEach(changeSpreadSheet.zh_data, function (item) {
  1240. item.order = item.order > select.order ? item.order + 1 : item.order;
  1241. });
  1242. changeList.splice(select.order, 0, result);
  1243. changeSpreadSheet.addRows(select.order, 1);
  1244. changeSpreadSheet.zh_data.splice(select.order, 0, _.cloneDeep(result));
  1245. changeSpreadSheet.getRange(select.order - 1, -1, 1, -1).backColor('#fff');
  1246. changeSpreadSheet.setSelection(select.order, 1, 1, 1);
  1247. changeSpreadObj.reloadRow(changeSpreadSheet, select.order);
  1248. } else {
  1249. changeList.push(result);
  1250. changeSpreadSheet.zh_data.push(_.cloneDeep(result));
  1251. changeSpreadSheet.addRows(changeSpreadSheet.zh_data.length - 1, 1);
  1252. changeSpreadSheet.setSelection(changeSpreadSheet.zh_data.length - 1, 1, 1, 1);
  1253. changeSpreadObj.reloadRow(changeSpreadSheet, changeSpreadSheet.zh_data.length - 1, 0, true);
  1254. }
  1255. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  1256. changeSpreadObj.refreshXmjData();
  1257. changeSpreadObj.refreshActn();
  1258. }
  1259. });
  1260. };
  1261. changeSpreadObj.batchAdd = function(num) {
  1262. let select = null;
  1263. if (changeOrder) {
  1264. select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1265. }
  1266. postData(window.location.pathname + '/save', {type: 'batchadd', num, postData: select ? select.order : null}, function (result) {
  1267. if (result) {
  1268. changeList = result;
  1269. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  1270. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  1271. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1272. changeSpreadObj.reloadSheet(newChangeList);
  1273. }
  1274. });
  1275. };
  1276. // 计量单元修改
  1277. changeSpreadObj.del = function () {
  1278. const selection = changeSpreadSheet.getSelections();
  1279. const sel = selection ? selection[0] : xmjSheet.getSelections()[0];
  1280. const row = sel && sel.row !== undefined ? sel.row : -1;
  1281. const count = sel.rowCount;
  1282. if (readOnly || row === -1 || row + count > changeSpreadSheet.zh_data.length) {
  1283. return false;
  1284. }
  1285. const delList = [];
  1286. let lastSelect = null;
  1287. for (let r = 0; r < count; r++) {
  1288. const select = changeSpreadSheet.zh_data[row + r];
  1289. if (!select || !select.id) {
  1290. toastr.error('变更清单不存在或者该清单存在项目节');
  1291. return;
  1292. }
  1293. if(!select || _.find(changeUsedData, { cbid: select.id })) {
  1294. toastr.error('已调用的变更清单不能删除');
  1295. return false;
  1296. }
  1297. if (checkIsSettle(select)) {
  1298. toastr.error('已结算的变更清单不能删除');
  1299. return false;
  1300. }
  1301. if (r === count - 1 && changeOrder) {
  1302. lastSelect = select;
  1303. }
  1304. delList.push(select.id);
  1305. }
  1306. if (delList.length) {
  1307. postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null}, function (result) {
  1308. changeSpreadSheet.deleteRows(row, count);
  1309. changeSpreadSheet.zh_data.splice(row, count);
  1310. changeSpreadObj.countSum();
  1311. changeSpreadSheet.setSelection(0, 0, 1, 1);
  1312. changeSpreadObj.refreshXmjData();
  1313. changeSpreadObj.refreshActn();
  1314. });
  1315. }
  1316. };
  1317. changeSpreadObj.editStarting = function (e, info) {
  1318. const select = SpreadJsObj.getSelectObject(info.sheet);
  1319. if (select && select.id) {
  1320. const col = info.sheet.zh_setting.cols[info.col];
  1321. if (col.field === 'camount') {
  1322. if (select.camount_expr && select.camount_expr !== '') {
  1323. info.sheet.getCell(info.row, info.col).text(select.camount_expr);
  1324. }
  1325. }
  1326. }
  1327. };
  1328. changeSpreadObj.editEnded = function (e, info) {
  1329. if (!info.sheet.zh_setting) {
  1330. changeSpreadObj.reloadRow(info.sheet, info.row);
  1331. return;
  1332. }
  1333. const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1334. if (!select || !select.id) {
  1335. toastr.error('该变更清单无法编辑');
  1336. changeSpreadObj.reloadRow(info.sheet, info.row);
  1337. return;
  1338. }
  1339. const cInfo = _.find(changeList, { id: select.id });
  1340. if (!cInfo) {
  1341. toastr.error('数据错误,请刷新页面重试');
  1342. changeSpreadObj.reloadRow(info.sheet, info.row);
  1343. return;
  1344. }
  1345. const col = info.sheet.zh_setting.cols[info.col];
  1346. if (col.field === 'is_valuation') {
  1347. return;
  1348. }
  1349. let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  1350. let orgValue;
  1351. if (col.field === 'camount') {
  1352. orgValue = validText && validText !== ''
  1353. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  1354. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  1355. } else {
  1356. orgValue = select[col.field];
  1357. }
  1358. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1359. changeSpreadObj.reloadRow(info.sheet, info.row);
  1360. return;
  1361. }
  1362. if(col.field === 'camount') {
  1363. const exprQuantity = {
  1364. expr: '',
  1365. quantity: 0,
  1366. };
  1367. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  1368. if (!valid) {
  1369. toastr.error(msg);
  1370. changeSpreadObj.reloadRow(info.sheet, info.row);
  1371. return;
  1372. }
  1373. if (isNaN(exprQuantity.quantity)) {
  1374. toastr.error('不能输入其它非数字类型字符');
  1375. changeSpreadObj.reloadRow(info.sheet, info.row);
  1376. return;
  1377. }
  1378. validText = parseFloat(exprQuantity.quantity);
  1379. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1380. const usedInfo = _.find(changeUsedData, { cbid: select.id });
  1381. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1382. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1383. changeSpreadObj.reloadRow(info.sheet, info.row);
  1384. return;
  1385. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1386. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1387. changeSpreadObj.reloadRow(info.sheet, info.row);
  1388. return;
  1389. }
  1390. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  1391. select.camount_expr = exprQuantity.expr;
  1392. cInfo.spamount = select.spamount;
  1393. cInfo.camount_expr = exprQuantity.expr;
  1394. }
  1395. if (col.type === 'Number') {
  1396. if (isNaN(validText)) {
  1397. toastr.error('不能输入其它非数字类型字符');
  1398. changeSpreadObj.reloadRow(info.sheet, info.row);
  1399. return;
  1400. }
  1401. if (col.field === 'unit_price') {
  1402. validText = ZhCalc.round(validText, unitPriceUnit);
  1403. } else {
  1404. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  1405. }
  1406. if (col.field === 'delimit') {
  1407. const reg = /^(\d{1,2}|100)$/;
  1408. if (!(_.isNumber(validText) && reg.test(validText))) {
  1409. toastr.error('计量上限默认值只能输入0-100之间的整数');
  1410. changeSpreadObj.reloadRow(info.sheet, info.row);
  1411. return;
  1412. }
  1413. // 需要判断是否已调用,已调用的则不能低于原有值大小
  1414. const usedInfo = _.find(changeUsedData, { cbid: select.id });
  1415. if (usedInfo && usedInfo.qty) {
  1416. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
  1417. if (validText < minLimit) {
  1418. toastr.error('计量上限值至少大于等于 ' + minLimit);
  1419. changeSpreadObj.reloadRow(info.sheet, info.row);
  1420. return;
  1421. }
  1422. }
  1423. }
  1424. }
  1425. cInfo[col.field] = validText;
  1426. select[col.field] = validText;
  1427. console.log(cInfo);
  1428. delete cInfo.waitingLoading;
  1429. // 更新至服务器
  1430. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  1431. if (select.children && select.children.length === 1) {
  1432. const child = select.children[0];
  1433. child[col.field] = validText;
  1434. }
  1435. changeSpreadObj.calcOneSum(select);
  1436. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1437. changeSpreadObj.refreshXmjData();
  1438. changeSpreadObj.countSum();
  1439. changeSpreadObj.refreshActn();
  1440. if (info.row === info.sheet.zh_data.length - 1) {
  1441. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1442. changeSpreadObj.reloadSheet(newChangeList);
  1443. }
  1444. }, function () {
  1445. select[col.field] = orgValue;
  1446. cInfo[col.field] = orgValue;
  1447. if(col.field === 'camount') {
  1448. select.spamount = orgValue;
  1449. cInfo.spamount = orgValue;
  1450. }
  1451. changeSpreadObj.reloadRow(info.sheet, info.row);
  1452. });
  1453. };
  1454. changeSpreadObj.clipboardPasted = function (e, info) {
  1455. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1456. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1457. }
  1458. const hint = {
  1459. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1460. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1461. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  1462. };
  1463. const range = info.cellRange;
  1464. const sortData = info.sheet.zh_data || [];
  1465. const data = [];
  1466. // const rowData = [];
  1467. let needCopyIgnore = !$('#customCheck1').is(':checked');
  1468. let needColAdd = false;
  1469. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1470. let bPaste = true;
  1471. const curRow = range.row + iRow;
  1472. if (!sortData[curRow].id) {
  1473. bPaste = false;
  1474. continue;
  1475. }
  1476. const cLData = { id: sortData[curRow].id };
  1477. const hintRow = range.rowCount >= 1 ? curRow : '';
  1478. let sameCol = 0;
  1479. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1480. const curCol = range.col + iCol;
  1481. let colSetting = info.sheet.zh_setting.cols[curCol];
  1482. if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
  1483. const newCurCol = curCol + 1;
  1484. needColAdd = true;
  1485. colSetting = info.sheet.zh_setting.cols[newCurCol];
  1486. }
  1487. if (!colSetting) continue;
  1488. let validText = info.sheet.getText(curRow, curCol);
  1489. validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  1490. let orgValue;
  1491. if (colSetting.field === 'camount') {
  1492. orgValue = validText && validText !== ''
  1493. ? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
  1494. : (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
  1495. } else {
  1496. orgValue = sortData[curRow][colSetting.field];
  1497. }
  1498. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1499. sameCol++;
  1500. if (range.colCount === sameCol) {
  1501. bPaste = false;
  1502. }
  1503. continue;
  1504. }
  1505. if(colSetting.field === 'camount') {
  1506. const exprQuantity = {
  1507. expr: '',
  1508. quantity: 0,
  1509. };
  1510. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  1511. if (!valid) {
  1512. toastMessageUniq(getPasteHint(msg, hintRow));
  1513. bPaste = false;
  1514. continue;
  1515. }
  1516. if (isNaN(exprQuantity.quantity)) {
  1517. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1518. bPaste = false;
  1519. continue;
  1520. }
  1521. validText = parseFloat(exprQuantity.quantity);
  1522. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1523. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
  1524. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1525. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1526. bPaste = false;
  1527. continue;
  1528. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1529. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1530. bPaste = false;
  1531. continue;
  1532. }
  1533. cLData.camount_expr = exprQuantity.expr;
  1534. sortData[curRow].camount_expr = exprQuantity.expr;
  1535. }
  1536. if (colSetting.type === 'Number') {
  1537. if (isNaN(validText)) {
  1538. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1539. bPaste = false;
  1540. continue;
  1541. }
  1542. if (colSetting.field === 'unit_price') {
  1543. validText = ZhCalc.round(validText, unitPriceUnit);
  1544. } else {
  1545. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  1546. }
  1547. if (colSetting.field === 'delimit') {
  1548. const reg = /^(\d{1,2}|100)$/;
  1549. if (!(_.isNumber(validText) && reg.test(validText))) {
  1550. toastr.error('清单第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
  1551. bPaste = false;
  1552. continue;
  1553. }
  1554. // 需要判断是否已调用,已调用的则不能低于原有值大小
  1555. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
  1556. if (usedInfo && usedInfo.qty) {
  1557. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
  1558. if (validText < minLimit) {
  1559. toastr.error('清单第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
  1560. bPaste = false;
  1561. continue;
  1562. }
  1563. }
  1564. }
  1565. }
  1566. let unitdecimal = validText;
  1567. cLData[colSetting.field] = validText;
  1568. sortData[curRow][colSetting.field] = validText;
  1569. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  1570. }
  1571. if (bPaste) {
  1572. data.push(cLData);
  1573. // rowData.push(curRow);
  1574. } else {
  1575. changeSpreadObj.reloadRow(info.sheet, curRow);
  1576. }
  1577. }
  1578. if (data.length === 0) {
  1579. changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1580. return;
  1581. }
  1582. console.log(data);
  1583. // 更新至服务器
  1584. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  1585. changeList = result;
  1586. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1587. changeSpreadObj.reloadSheet(newChangeList);
  1588. }, function () {
  1589. changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1590. return;
  1591. });
  1592. };
  1593. changeSpreadObj.buttonClicked = function(e, info) {
  1594. if (info.sheet.zh_setting) {
  1595. const select = SpreadJsObj.getSelectObject(info.sheet);
  1596. if (!select || !select.id) {
  1597. changeSpreadObj.reloadRow(info.sheet, info.row);
  1598. return;
  1599. }
  1600. const cInfo = _.find(changeList, { id: select.id });
  1601. if (!cInfo) {
  1602. toastr.error('数据错误,请刷新页面重试');
  1603. changeSpreadObj.reloadRow(info.sheet, info.row);
  1604. return;
  1605. }
  1606. const col = info.sheet.zh_setting.cols[info.col];
  1607. if (col.field === 'is_valuation') {
  1608. if (info.sheet.isEditing()) {
  1609. info.sheet.endEdit(true);
  1610. }
  1611. if (_.findIndex(changeUsedData, { cbid: select.id }) !== -1) {
  1612. return;
  1613. }
  1614. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  1615. cInfo.is_valuation = select.is_valuation;
  1616. delete cInfo.waitingLoading;
  1617. // 更新至服务器
  1618. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  1619. changeSpreadObj.reloadRow(info.sheet, info.row);
  1620. if (select.children && select.children.length === 1) {
  1621. const child = select.children[0];
  1622. child[col.field] = select.is_valuation;
  1623. changeSpreadObj.refreshXmjData();
  1624. }
  1625. }, function () {
  1626. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  1627. cInfo.is_valuation = select.is_valuation;
  1628. changeSpreadObj.reloadRow(info.sheet, info.row);
  1629. });
  1630. }
  1631. }
  1632. };
  1633. changeSpreadObj.valueChanged = function(e, info) {
  1634. // 防止ctrl+z撤销数据
  1635. changeSpreadObj.reloadRow(info.sheet, info.row);
  1636. };
  1637. changeSpreadObj.setAllValuation = function (is_valuation) {
  1638. if (changeList.length === 0) {
  1639. toastr.warning('暂无清单无法设置清单计价');
  1640. return;
  1641. }
  1642. const needChangeList = _.filter(changeList, { is_valuation: is_valuation ? 0 : 1 });
  1643. if (needChangeList.length === 0) {
  1644. toastr.warning('全部清单已设置清单'+ (is_valuation ? '' : '不') +'计价');
  1645. return;
  1646. }
  1647. const realNeedChangeList = [];
  1648. for (const nc of needChangeList) {
  1649. if (_.findIndex(changeUsedData, { cbid: nc.id }) === -1) {
  1650. realNeedChangeList.push(nc.id);
  1651. }
  1652. }
  1653. if (realNeedChangeList.length === 0) {
  1654. toastr.warning('全部清单已设置清单'+ (is_valuation ? '' : '不') +'计价');
  1655. return;
  1656. }
  1657. postData(window.location.pathname + '/save', { type:'set_all_valuation', ids: realNeedChangeList, is_valuation }, function (result) {
  1658. changeList = result;
  1659. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1660. changeSpreadObj.reloadSheet(newChangeList);
  1661. });
  1662. };
  1663. changeSpreadObj.deletePress = function (sheet) {
  1664. if (!sheet.zh_setting) return;
  1665. // 暂时仅支持移除数量
  1666. const sel = sheet.getSelections()[0], datas = [];
  1667. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1668. let bDel = false;
  1669. const node = sheet.zh_data[iRow];
  1670. if (!node || !node.id) continue;
  1671. const cInfo = _.find(changeList, { id: node.id });
  1672. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1673. const col = sheet.zh_setting.cols[iCol];
  1674. if (col.field === 'camount' || col.field === 'oamount2') {
  1675. node[col.field] = null;
  1676. cInfo[col.field] = null;
  1677. if (col.field === 'camount') {
  1678. node.camount_expr = '';
  1679. node.spamount = null;
  1680. cInfo.camount_expr = '';
  1681. cInfo.spamount = null;
  1682. }
  1683. delete cInfo.waitingLoading;
  1684. bDel = true;
  1685. }
  1686. }
  1687. if (bDel) datas.push(cInfo);
  1688. }
  1689. if (datas.length > 0) {
  1690. postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
  1691. changeList = result;
  1692. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1693. changeSpreadObj.reloadSheet(newChangeList);
  1694. }, function () {
  1695. changeSpreadObj.reloadRow(sheet, sel.row, sel.rowCount);
  1696. return;
  1697. });
  1698. }
  1699. return;
  1700. };
  1701. changeSpreadObj.upMove = function () {
  1702. const data = {
  1703. type: 'changeOrder',
  1704. postData: [],
  1705. };
  1706. const selection = changeSpreadSheet.getSelections();
  1707. const row = selection[0].row, count = selection[0].rowCount;
  1708. const first = changeSpreadSheet.zh_data[row];
  1709. const firstRow = row;
  1710. if (!first) {
  1711. changeSpreadObj.refreshActn();
  1712. return false;
  1713. }
  1714. const pre = changeSpreadSheet.zh_data[row - 1];
  1715. const preUpdates = [];
  1716. if (pre && pre.id) {
  1717. preUpdates.push({ id: pre.id });
  1718. } else if (pre && pre.children && pre.children.length > 0) {
  1719. for (const item of pre.children) {
  1720. preUpdates.push({ id: item.id });
  1721. }
  1722. }
  1723. for (let iRow = 0; iRow < count; iRow++) {
  1724. const posData = changeSpreadSheet.zh_data[iRow + row];
  1725. if (posData) {
  1726. for (const item of preUpdates) {
  1727. item.order = posData.order;
  1728. }
  1729. if (posData.id) {
  1730. data.postData.push({id: posData.id, order: changeSpreadSheet.zh_data[iRow + row - 1].order});
  1731. } else if (posData && posData.children && posData.children.length > 0) {
  1732. for (const item of posData.children) {
  1733. data.postData.push({id: item.id, order: changeSpreadSheet.zh_data[iRow + row - 1].order});
  1734. }
  1735. }
  1736. }
  1737. }
  1738. data.postData.push(...preUpdates);
  1739. console.log(data);
  1740. if (data.postData.length > 0) {
  1741. postData(window.location.pathname + '/save', data, function () {
  1742. _.forEach(data.postData, function (item) {
  1743. const cl = _.find(changeList, { id: item.id });
  1744. cl.order = item.order;
  1745. });
  1746. changeList.sort(function (a, b) {
  1747. return a.order - b.order
  1748. });
  1749. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1750. const sel = selection[0];
  1751. if (sel) {
  1752. changeSpreadSheet.setSelection(row - 1, sel.col, sel.rowCount, sel.colCount);
  1753. changeSpreadSheet.getRange(row, -1, 1, -1).backColor('#fff');
  1754. SpreadJsObj.saveTopAndSelect(changeSpreadSheet, ckChangeSpread);
  1755. }
  1756. changeSpreadObj.reloadSheet(newChangeList);
  1757. });
  1758. }
  1759. };
  1760. changeSpreadObj.downMove = function () {
  1761. const data = {
  1762. type: 'changeOrder',
  1763. postData: [],
  1764. };
  1765. const selection = changeSpreadSheet.getSelections();
  1766. const row = selection[0].row, count = selection[0].rowCount;
  1767. const first = changeSpreadSheet.zh_data[row];
  1768. if (!first) {
  1769. changeSpreadObj.refreshActn();
  1770. return false;
  1771. }
  1772. const next = changeSpreadSheet.zh_data[row + count];
  1773. const nextUpdates = [];
  1774. if (next && next.id) {
  1775. nextUpdates.push({ id: next.id });
  1776. } else if (next && next.children && next.children.length > 0) {
  1777. for (const item of next.children) {
  1778. nextUpdates.push({ id: item.id });
  1779. }
  1780. }
  1781. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1782. const posData = changeSpreadSheet.zh_data[iRow + row];
  1783. if (posData) {
  1784. for (const item of nextUpdates) {
  1785. item.order = posData.order;
  1786. }
  1787. if (posData.id) {
  1788. data.postData.push({id: posData.id, order: changeSpreadSheet.zh_data[iRow + row + 1].order});
  1789. } else if (posData && posData.children && posData.children.length > 0) {
  1790. for (const item of posData.children) {
  1791. data.postData.push({id: item.id, order: changeSpreadSheet.zh_data[iRow + row + 1].order});
  1792. }
  1793. }
  1794. }
  1795. }
  1796. data.postData.push(...nextUpdates);
  1797. console.log(data);
  1798. if (data.postData.length > 0) {
  1799. postData(window.location.pathname + '/save', data, function () {
  1800. _.forEach(data.postData, function (item) {
  1801. const cl = _.find(changeList, { id: item.id });
  1802. cl.order = item.order;
  1803. });
  1804. changeList.sort(function (a, b) {
  1805. return a.order - b.order
  1806. });
  1807. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1808. const sel = selection[0];
  1809. if (sel) {
  1810. changeSpreadSheet.setSelection(row + 1, sel.col, sel.rowCount, sel.colCount);
  1811. changeSpreadSheet.getRange(row, -1, 1, -1).backColor('#fff');
  1812. SpreadJsObj.saveTopAndSelect(changeSpreadSheet, ckChangeSpread);
  1813. }
  1814. changeSpreadObj.reloadSheet(newChangeList);
  1815. });
  1816. }
  1817. };
  1818. // 表达式判断
  1819. $('#camount-expr').change(function () {
  1820. if (this.readOnly) return;
  1821. let validText = $(this).val();
  1822. const sel = changeSpreadSheet.getSelections()[0];
  1823. const row = sel ? sel.row : -1;
  1824. const col = changeSpreadSheet.zh_setting.cols[sel.col];
  1825. if (row === -1 || !(col && col.field === 'camount')) return;
  1826. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1827. if (!select || !select.id) return;
  1828. const cInfo = _.find(changeList, { id: select.id });
  1829. if (!cInfo) return;
  1830. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  1831. let orgValue = validText && validText !== ''
  1832. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  1833. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  1834. const orgExprValue = _.clone(select.camount_expr);
  1835. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1836. return;
  1837. }
  1838. const exprQuantity = {
  1839. expr: '',
  1840. quantity: 0,
  1841. };
  1842. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  1843. if (!valid) {
  1844. toastr.error(msg);
  1845. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  1846. return;
  1847. }
  1848. if (isNaN(exprQuantity.quantity)) {
  1849. toastr.error('不能输入其它非数字类型字符');
  1850. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  1851. return;
  1852. }
  1853. validText = parseFloat(exprQuantity.quantity);
  1854. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1855. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  1856. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1857. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1858. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  1859. return;
  1860. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1861. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1862. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  1863. return;
  1864. }
  1865. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  1866. select.camount_expr = exprQuantity.expr;
  1867. select.camount = validText;
  1868. cInfo.spamount = select.spamount;
  1869. cInfo.camount_expr = select.camount_expr;
  1870. cInfo.camount = validText;
  1871. // console.log(select);
  1872. delete cInfo.waitingLoading;
  1873. // 更新至服务器
  1874. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  1875. changeSpreadObj.reloadRow(changeSpreadSheet, row);
  1876. changeSpreadObj.calcOneSum(select);
  1877. changeSpreadObj.countSum();
  1878. changeSpreadObj.refreshActn();
  1879. if (SpreadJsObj.getSelectObject(changeSpreadSheet) === select) {
  1880. if (select.children && select.children.length === 1) {
  1881. changeSpreadObj.refreshXmjData();
  1882. }
  1883. }
  1884. }, function () {
  1885. select.camount = orgValue;
  1886. select.camount_expr = orgExprValue;
  1887. select.spamount = orgValue;
  1888. cInfo.camount = orgValue;
  1889. cInfo.camount_expr = orgExprValue;
  1890. cInfo.spamount = orgValue;
  1891. changeSpreadObj.reloadRow(changeSpreadSheet, row);
  1892. });
  1893. });
  1894. $('#add-white-btn').click(changeSpreadObj.add);
  1895. $('#up-move').click(changeSpreadObj.upMove);
  1896. $('#down-move').click(changeSpreadObj.downMove);
  1897. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  1898. changeSpread.bind(spreadNS.Events.EditStarting, changeSpreadObj.editStarting);
  1899. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  1900. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  1901. changeSpread.bind(spreadNS.Events.ButtonClicked, changeSpreadObj.buttonClicked);
  1902. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  1903. // 计量单元修改
  1904. xmjSpreadObj.del = function () {
  1905. const selection = xmjSheet.getSelections();
  1906. const sel = selection ? selection[0] : xmjSheet.getSelections()[0];
  1907. const row = sel && sel.row !== undefined ? sel.row : -1;
  1908. const count = sel.rowCount;
  1909. if (readOnly || row === -1 || row + count > xmjSheet.zh_data.length) {
  1910. return false;
  1911. }
  1912. const delList = [];
  1913. let lastSelect = null;
  1914. for (let r = 0; r < count; r++) {
  1915. const select = xmjSheet.zh_data[row + r];
  1916. if(!select || _.find(changeUsedData, { cbid: select.id })) {
  1917. toastr.error('已调用的变更清单不能删除');
  1918. return false;
  1919. }
  1920. if (checkIsSettle(select)) {
  1921. toastr.error('已结算的变更清单不能删除');
  1922. return false;
  1923. }
  1924. if (r === count - 1 && xmjSheet.zh_data.length === count && changeOrder) {
  1925. lastSelect = select;
  1926. }
  1927. delList.push(select.id);
  1928. }
  1929. if (delList.length) {
  1930. postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null, delLength: 1}, function (result) {
  1931. xmjSheet.deleteRows(row, count);
  1932. xmjSheet.zh_data.splice(row, count);
  1933. // 同步删除changeList值
  1934. _.forEach(delList, function (id) {
  1935. _.remove(changeList, { id: id });
  1936. });
  1937. const billsNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1938. const billIndex = _.indexOf(changeSpreadSheet.zh_data, billsNode);
  1939. let allDel = false;
  1940. // 判断是移除还是更新数量和金额
  1941. if (xmjSheet.zh_data.length === 0) {
  1942. changeSpreadSheet.deleteRows(billIndex, 1);
  1943. changeSpreadSheet.zh_data.splice(billIndex, 1);
  1944. allDel = true;
  1945. } else {
  1946. billsNode.children = xmjSheet.zh_data;
  1947. if (billsNode.children.length === 1) {
  1948. billsNode.id = billsNode.children[0].id;
  1949. billsNode.bwmx = billsNode.children[0].bwmx || billsNode.children[0].xmj_jldy;
  1950. billsNode.detail = billsNode.children[0].detail;
  1951. billsNode.delimit = billsNode.children[0].delimit;
  1952. }
  1953. changeSpreadObj.calcOneSum(billsNode);
  1954. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  1955. }
  1956. changeSpreadObj.countSum();
  1957. if (allDel) {
  1958. changeSpreadSheet.setSelection(0, 0, 1, 1);
  1959. changeSpreadObj.refreshXmjData();
  1960. changeSpreadObj.refreshActn();
  1961. }
  1962. });
  1963. }
  1964. };
  1965. xmjSpreadObj.editStarting = function (e, info) {
  1966. xmjSpreadObj.billsNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1967. const col = info.sheet.zh_setting.cols[info.col];
  1968. const select = SpreadJsObj.getSelectObject(info.sheet);
  1969. if (col.field === 'camount') {
  1970. if (select.camount_expr && select.camount_expr !== '') {
  1971. info.sheet.getCell(info.row, info.col).text(select.camount_expr);
  1972. }
  1973. }
  1974. };
  1975. xmjSpreadObj.editEnded = function (e, info) {
  1976. if (!info.sheet.zh_setting) {
  1977. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1978. return;
  1979. }
  1980. const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1981. console.log(info.sheet.zh_data);
  1982. const cInfo = _.find(changeList, { id: select.id });
  1983. if (!cInfo) {
  1984. toastr.error('数据错误,请刷新页面重试');
  1985. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1986. return;
  1987. }
  1988. const col = info.sheet.zh_setting.cols[info.col];
  1989. if (col.field === 'is_valuation') {
  1990. return;
  1991. }
  1992. let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  1993. let orgValue;
  1994. if (col.field === 'camount') {
  1995. orgValue = validText && validText !== ''
  1996. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  1997. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  1998. } else {
  1999. orgValue = select[col.field];
  2000. }
  2001. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  2002. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2003. return;
  2004. }
  2005. const node = xmjSpreadObj.billsNode;
  2006. if (!node) {
  2007. toastr.error('数据错误,请选择清单节点后再试');
  2008. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2009. return;
  2010. }
  2011. if(col.field === 'camount') {
  2012. const exprQuantity = {
  2013. expr: '',
  2014. quantity: 0,
  2015. };
  2016. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  2017. if (!valid) {
  2018. toastr.error(msg);
  2019. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2020. return;
  2021. }
  2022. if (isNaN(exprQuantity.quantity)) {
  2023. toastr.error('不能输入其它非数字类型字符');
  2024. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2025. return;
  2026. }
  2027. validText = parseFloat(exprQuantity.quantity);
  2028. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  2029. const usedInfo = _.find(changeUsedData, { cbid: select.id });
  2030. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  2031. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  2032. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2033. return;
  2034. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  2035. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  2036. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2037. return;
  2038. }
  2039. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  2040. select.camount_expr = exprQuantity.expr;
  2041. cInfo.spamount = select.spamount;
  2042. cInfo.camount_expr = exprQuantity.expr;
  2043. }
  2044. if (col.type === 'Number') {
  2045. if (isNaN(validText)) {
  2046. toastr.error('不能输入其它非数字类型字符');
  2047. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2048. return;
  2049. }
  2050. if (col.field === 'unit_price') {
  2051. validText = ZhCalc.round(validText, unitPriceUnit);
  2052. } else {
  2053. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  2054. }
  2055. if (col.field === 'delimit') {
  2056. const reg = /^(\d{1,2}|100)$/;
  2057. if (!(_.isNumber(validText) && reg.test(validText))) {
  2058. toastr.error('计量上限默认值只能输入0-100之间的整数');
  2059. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2060. return;
  2061. }
  2062. // 需要判断是否已调用,已调用的则不能低于原有值大小
  2063. const usedInfo = _.find(changeUsedData, { cbid: select.id });
  2064. if (usedInfo && usedInfo.qty) {
  2065. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
  2066. if (validText < minLimit) {
  2067. toastr.error('计量上限值至少大于等于 ' + minLimit);
  2068. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2069. return;
  2070. }
  2071. }
  2072. }
  2073. }
  2074. cInfo[col.field] = validText;
  2075. select[col.field] = validText;
  2076. console.log(cInfo);
  2077. delete cInfo.waitingLoading;
  2078. const children = info.sheet.zh_data;
  2079. // 更新至服务器
  2080. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  2081. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2082. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  2083. node.children = children;
  2084. if (node.children && node.children.length === 1) {
  2085. node[col.field] = validText;
  2086. if (col.field === 'camount') {
  2087. node.spamount = select.spamount;
  2088. node.camount_expr = select.camount_expr;
  2089. }
  2090. }
  2091. xmjSpreadObj.loadExprToInput();
  2092. changeSpreadObj.calcOneSum(node);
  2093. console.log(node);
  2094. if (SpreadJsObj.getSelectObject(changeSpreadSheet) !== node) {
  2095. SpreadJsObj.reLoadRowData(changeSpreadSheet, billIndex);
  2096. } else {
  2097. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  2098. }
  2099. changeSpreadObj.countSum();
  2100. }, function () {
  2101. select[col.field] = orgValue;
  2102. cInfo[col.field] = orgValue;
  2103. if(col.field === 'camount') {
  2104. select.spamount = orgValue;
  2105. cInfo.spamount = orgValue;
  2106. }
  2107. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2108. });
  2109. };
  2110. xmjSpreadObj.clipboardPasted = function (e, info) {
  2111. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2112. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2113. }
  2114. const hint = {
  2115. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  2116. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  2117. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2118. };
  2119. const range = info.cellRange;
  2120. const sortData = info.sheet.zh_data || [];
  2121. if (range.row + range.rowCount > sortData.length) {
  2122. toastMessageUniq(hint.cellError);
  2123. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  2124. xmjSpreadObj.loadCurXmjData();
  2125. return;
  2126. }
  2127. if (sortData.length > 0 && range.col + range.colCount > 12) {
  2128. toastMessageUniq(hint.cellError);
  2129. xmjSpreadObj.loadCurXmjData();
  2130. return;
  2131. }
  2132. if (!info.sheet.zh_setting) {
  2133. xmjSpreadObj.loadCurXmjData();
  2134. return;
  2135. }
  2136. const data = [];
  2137. // const rowData = [];
  2138. let needCopyIgnore = !$('#customCheck1').is(':checked');
  2139. let needColAdd = false;
  2140. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  2141. let bPaste = true;
  2142. const curRow = range.row + iRow;
  2143. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  2144. const cLData = { id: sortData[curRow].id };
  2145. const hintRow = range.rowCount >= 1 ? curRow : '';
  2146. let sameCol = 0;
  2147. for (let iCol = 0; iCol < range.colCount; iCol++) {
  2148. const curCol = range.col + iCol;
  2149. let colSetting = info.sheet.zh_setting.cols[curCol];
  2150. if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
  2151. const newCurCol = curCol + 1;
  2152. needColAdd = true;
  2153. colSetting = info.sheet.zh_setting.cols[newCurCol];
  2154. }
  2155. if (!colSetting) continue;
  2156. let validText = info.sheet.getText(curRow, curCol);
  2157. validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  2158. let orgValue;
  2159. if (colSetting.field === 'camount') {
  2160. orgValue = validText && validText !== ''
  2161. ? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
  2162. : (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
  2163. } else {
  2164. orgValue = sortData[curRow][colSetting.field];
  2165. }
  2166. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  2167. sameCol++;
  2168. if (range.colCount === sameCol) {
  2169. bPaste = false;
  2170. }
  2171. continue;
  2172. }
  2173. if(colSetting.field === 'camount') {
  2174. const exprQuantity = {
  2175. expr: '',
  2176. quantity: 0,
  2177. };
  2178. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  2179. if (!valid) {
  2180. toastMessageUniq(getPasteHint(msg, hintRow));
  2181. bPaste = false;
  2182. continue;
  2183. }
  2184. if (isNaN(exprQuantity.quantity)) {
  2185. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  2186. bPaste = false;
  2187. continue;
  2188. }
  2189. validText = parseFloat(exprQuantity.quantity);
  2190. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  2191. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
  2192. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  2193. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  2194. bPaste = false;
  2195. continue;
  2196. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  2197. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  2198. bPaste = false;
  2199. continue;
  2200. }
  2201. cLData.camount_expr = exprQuantity.expr;
  2202. sortData[curRow].camount_expr = exprQuantity.expr;
  2203. }
  2204. if (colSetting.type === 'Number') {
  2205. if (isNaN(validText)) {
  2206. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  2207. bPaste = false;
  2208. continue;
  2209. }
  2210. if (colSetting.field === 'unit_price') {
  2211. validText = ZhCalc.round(validText, unitPriceUnit);
  2212. } else {
  2213. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  2214. }
  2215. if (colSetting.field === 'delimit') {
  2216. const reg = /^(\d{1,2}|100)$/;
  2217. if (!(_.isNumber(validText) && reg.test(validText))) {
  2218. toastr.error('项目节第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
  2219. bPaste = false;
  2220. continue;
  2221. }
  2222. // 需要判断是否已调用,已调用的则不能低于原有值大小
  2223. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
  2224. if (usedInfo && usedInfo.qty) {
  2225. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
  2226. if (validText < minLimit) {
  2227. toastr.error('项目节第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
  2228. bPaste = false;
  2229. continue;
  2230. }
  2231. }
  2232. }
  2233. }
  2234. let unitdecimal = validText;
  2235. cLData[colSetting.field] = validText;
  2236. sortData[curRow][colSetting.field] = validText;
  2237. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  2238. }
  2239. if (bPaste) {
  2240. data.push(cLData);
  2241. // rowData.push(curRow);
  2242. } else {
  2243. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  2244. }
  2245. }
  2246. if (data.length === 0) {
  2247. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2248. return;
  2249. }
  2250. console.log(data);
  2251. // 更新至服务器
  2252. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  2253. changeList = result;
  2254. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2255. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  2256. node.children = info.sheet.zh_data;
  2257. if (node.children && node.children.length === 1) {
  2258. for (const col in data[0]) {
  2259. node[col] = data[0][col];
  2260. }
  2261. }
  2262. changeSpreadObj.calcOneSum(node);
  2263. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  2264. changeSpreadObj.countSum();
  2265. xmjSpreadObj.loadCurXmjData();
  2266. }, function () {
  2267. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2268. return;
  2269. });
  2270. };
  2271. xmjSpreadObj.buttonClicked = function(e, info) {
  2272. if (info.sheet.zh_setting) {
  2273. const select = SpreadJsObj.getSelectObject(info.sheet);
  2274. const cInfo = _.find(changeList, { id: select.id });
  2275. if (!cInfo) {
  2276. toastr.error('数据错误,请刷新页面重试');
  2277. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2278. return;
  2279. }
  2280. const col = info.sheet.zh_setting.cols[info.col];
  2281. if (col.field === 'is_valuation') {
  2282. if (info.sheet.isEditing()) {
  2283. info.sheet.endEdit(true);
  2284. }
  2285. if (_.findIndex(changeUsedData, { cbid: select.id }) !== -1) {
  2286. return;
  2287. }
  2288. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  2289. cInfo.is_valuation = select.is_valuation;
  2290. delete cInfo.waitingLoading;
  2291. // 更新至服务器
  2292. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  2293. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2294. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2295. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  2296. node.children = info.sheet.zh_data;
  2297. changeSpreadObj.calcOneSum(node);
  2298. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  2299. }, function () {
  2300. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2301. cInfo.is_valuation = select.is_valuation;
  2302. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2303. });
  2304. }
  2305. }
  2306. };
  2307. xmjSpreadObj.valueChanged = function(e, info) {
  2308. // 防止ctrl+z撤销数据
  2309. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2310. };
  2311. xmjSpreadObj.deletePress = function (sheet) {
  2312. if (!sheet.zh_setting) return;
  2313. // 暂时仅支持移除数量
  2314. const sel = sheet.getSelections()[0], datas = [];
  2315. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2316. let bDel = false;
  2317. const node = sheet.zh_data[iRow];
  2318. const cInfo = _.find(changeList, { id: node.id });
  2319. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2320. const col = sheet.zh_setting.cols[iCol];
  2321. if (col.field === 'camount' || col.field === 'oamount2') {
  2322. node[col.field] = null;
  2323. cInfo[col.field] = null;
  2324. if (col.field === 'camount') {
  2325. node.camount_expr = '';
  2326. node.spamount = null;
  2327. cInfo.camount_expr = '';
  2328. cInfo.spamount = null;
  2329. }
  2330. delete cInfo.waitingLoading;
  2331. bDel = true;
  2332. }
  2333. }
  2334. if (bDel) datas.push(cInfo);
  2335. }
  2336. if (datas.length > 0) {
  2337. postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
  2338. changeList = result;
  2339. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2340. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  2341. node.children = xmjSheet.zh_data;
  2342. changeSpreadObj.calcOneSum(node);
  2343. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  2344. changeSpreadObj.countSum();
  2345. xmjSpreadObj.loadCurXmjData();
  2346. }, function () {
  2347. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2348. return;
  2349. });
  2350. }
  2351. return;
  2352. };
  2353. xmjSpreadObj.setAllValuation = function (is_valuation) {
  2354. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2355. if (!select) {
  2356. toastr.error('未选中清单');
  2357. return;
  2358. }
  2359. if (!select.children || select.children.length === 0) {
  2360. toastr.warning('暂无清单无法设置清单计价');
  2361. return;
  2362. }
  2363. const needChangeList = _.filter(select.children, { is_valuation: is_valuation ? 0 : 1 });
  2364. if (needChangeList.length === 0) {
  2365. toastr.warning('全部已设置清单'+ (is_valuation ? '' : '不') +'计价');
  2366. return;
  2367. }
  2368. const realNeedChangeList = [];
  2369. for (const nc of needChangeList) {
  2370. if (_.findIndex(changeUsedData, { cbid: nc.id }) === -1) {
  2371. realNeedChangeList.push(nc.id);
  2372. }
  2373. }
  2374. if (realNeedChangeList.length === 0) {
  2375. toastr.warning('全部已设置清单'+ (is_valuation ? '' : '不') +'计价');
  2376. return;
  2377. }
  2378. postData(window.location.pathname + '/save', { type:'set_all_valuation', ids: realNeedChangeList, is_valuation }, function (result) {
  2379. changeList = result;
  2380. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  2381. changeSpreadObj.reloadSheet(newChangeList);
  2382. });
  2383. };
  2384. // 表达式判断
  2385. $('#xmj-camount-expr').change(function () {
  2386. if (this.readOnly) return;
  2387. let validText = $(this).val();
  2388. const sel = xmjSheet.getSelections()[0];
  2389. const row = sel ? sel.row : -1;
  2390. const col = xmjSheet.zh_setting.cols[sel.col];
  2391. if (row === -1 || !(col && col.field === 'camount')) return;
  2392. const select = SpreadJsObj.getSelectObject(xmjSheet);
  2393. if (!select) return;
  2394. const cInfo = _.find(changeList, { id: select.id });
  2395. if (!cInfo) return;
  2396. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  2397. let orgValue = validText && validText !== ''
  2398. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  2399. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  2400. const orgExprValue = _.clone(select.camount_expr);
  2401. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  2402. return;
  2403. }
  2404. const exprQuantity = {
  2405. expr: '',
  2406. quantity: 0,
  2407. };
  2408. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  2409. if (!valid) {
  2410. toastr.error(msg);
  2411. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  2412. return;
  2413. }
  2414. if (isNaN(exprQuantity.quantity)) {
  2415. toastr.error('不能输入其它非数字类型字符');
  2416. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  2417. return;
  2418. }
  2419. validText = parseFloat(exprQuantity.quantity);
  2420. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  2421. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  2422. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  2423. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  2424. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  2425. return;
  2426. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  2427. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  2428. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  2429. return;
  2430. }
  2431. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  2432. select.camount_expr = exprQuantity.expr;
  2433. select.camount = validText;
  2434. cInfo.spamount = select.spamount;
  2435. cInfo.camount_expr = select.camount_expr;
  2436. cInfo.camount = validText;
  2437. // console.log(select);
  2438. delete cInfo.waitingLoading;
  2439. // 更新至服务器
  2440. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  2441. SpreadJsObj.reLoadRowData(xmjSheet, row);
  2442. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2443. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  2444. node.children = xmjSheet.zh_data;
  2445. changeSpreadObj.calcOneSum(node);
  2446. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  2447. changeSpreadObj.countSum();
  2448. }, function () {
  2449. select.camount = orgValue;
  2450. select.camount_expr = orgExprValue;
  2451. select.spamount = orgValue;
  2452. cInfo.camount = orgValue;
  2453. cInfo.camount_expr = orgExprValue;
  2454. cInfo.spamount = orgValue;
  2455. SpreadJsObj.reLoadRowData(posSheet, row);
  2456. });
  2457. });
  2458. xmjSpread.bind(spreadNS.Events.EditEnded, xmjSpreadObj.editEnded);
  2459. xmjSpread.bind(spreadNS.Events.EditStarting, xmjSpreadObj.editStarting);
  2460. xmjSpread.bind(spreadNS.Events.ClipboardPasted, xmjSpreadObj.clipboardPasted);
  2461. xmjSpread.bind(spreadNS.Events.ValueChanged, xmjSpreadObj.valueChanged);
  2462. xmjSpread.bind(spreadNS.Events.ButtonClicked, xmjSpreadObj.buttonClicked);
  2463. SpreadJsObj.addDeleteBind(xmjSpread, xmjSpreadObj.deletePress);
  2464. let batchInsertObj;
  2465. $.contextMenu.types.batchInsert = function (item, opt, root) {
  2466. const self = this;
  2467. if ($.isFunction(item.icon)) {
  2468. item._icon = item.icon.call(this, this, $t, key, item);
  2469. } else {
  2470. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  2471. // to enable font awesome
  2472. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  2473. } else {
  2474. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  2475. }
  2476. }
  2477. this.addClass(item._icon);
  2478. 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>')
  2479. .appendTo(this);
  2480. const $input = $obj.find('input');
  2481. const event = () => {
  2482. if (self.hasClass('context-menu-disabled')) return;
  2483. item.batchInsert($input[0], root);
  2484. };
  2485. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  2486. $input.click((e) => {e.stopPropagation();})
  2487. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  2488. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  2489. };
  2490. // 右键菜单
  2491. $.contextMenu({
  2492. selector: '#change-spread',
  2493. build: function ($trigger, e) {
  2494. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  2495. // console.log(e, target);
  2496. // const range = SpreadJsObj.getTargetSelection(changeSpreadSheet, target);
  2497. // console.log(range);
  2498. let ts = getLocalCache(ckChangeSpread);
  2499. if (ts !== '') {
  2500. ts = JSON.parse(ts);
  2501. if (ts === undefined || ts === null) return;
  2502. if (ts.sel) {
  2503. changeSpreadSheet.getRange(ts.sel.row, -1, 1, -1).backColor('#fff');
  2504. }
  2505. }
  2506. changeSpreadObj.refreshXmjData();
  2507. changeSpreadObj.refreshActn();
  2508. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2509. },
  2510. items: {
  2511. 'createList': {
  2512. name: '添加台账清单',
  2513. icon: 'fa-sign-in',
  2514. visible: function () {
  2515. return changeOrder === 0;
  2516. },
  2517. callback: function (key, opt) {
  2518. // $('#addlist').modal('show');
  2519. $('#set-site-btn').click();
  2520. },
  2521. },
  2522. 'createAdd': {
  2523. name: '添加空白清单',
  2524. icon: 'fa-sign-in',
  2525. visible: function () {
  2526. return changeOrder === 0 && openChangeWhiteList;
  2527. },
  2528. callback: function (key, opt) {
  2529. changeSpreadObj.add();
  2530. },
  2531. },
  2532. 'batchInsert': {
  2533. name: '批量添加空白清单',
  2534. type: 'batchInsert',
  2535. value: '2',
  2536. icon: 'fa-sign-in',
  2537. visible: function () {
  2538. return changeOrder === 0 && openChangeWhiteList;
  2539. },
  2540. batchInsert: function (obj, root) {
  2541. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  2542. obj.value = obj.max;
  2543. toastr.warning('批量添加不可多于' + obj.max);
  2544. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  2545. obj.value = obj.min;
  2546. toastr.warning('批量添加不可少于' + obj.min);
  2547. } else {
  2548. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  2549. changeSpreadObj.batchAdd(obj.value);
  2550. root.$menu.trigger('contextmenu:hide');
  2551. }
  2552. },
  2553. },
  2554. 'createList1': {
  2555. name: '插入台账清单',
  2556. icon: 'fa-sign-in',
  2557. visible: function () {
  2558. return changeOrder === 1;
  2559. },
  2560. // disabled: function (key, opt) {
  2561. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2562. // const sel = changeSpreadSheet.getSelections()[0];
  2563. // changeSpreadObj.resetXmjSpread(select);
  2564. // // console.log(select, sel);
  2565. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  2566. // return false;
  2567. // } else {
  2568. // return true;
  2569. // }
  2570. // },
  2571. callback: function (key, opt) {
  2572. // $('#addlist').modal('show');
  2573. $('#set-site-btn').click();
  2574. },
  2575. },
  2576. 'createAdd1': {
  2577. name: '插入空白清单',
  2578. icon: 'fa-sign-in',
  2579. visible: function () {
  2580. return changeOrder === 1 && openChangeWhiteList;
  2581. },
  2582. // disabled: function (key, opt) {
  2583. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2584. // const sel = changeSpreadSheet.getSelections()[0];
  2585. // changeSpreadObj.resetXmjSpread(select);
  2586. // // console.log(select, sel);
  2587. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  2588. // return false;
  2589. // } else {
  2590. // return true;
  2591. // }
  2592. // },
  2593. callback: function (key, opt) {
  2594. changeSpreadObj.add();
  2595. },
  2596. },
  2597. 'batchInsert1': {
  2598. name: '批量插入空白清单',
  2599. type: 'batchInsert',
  2600. value: '2',
  2601. icon: 'fa-sign-in',
  2602. visible: function () {
  2603. return changeOrder === 1 && openChangeWhiteList;
  2604. },
  2605. // disabled: function (key, opt) {
  2606. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2607. // const sel = changeSpreadSheet.getSelections()[0];
  2608. // changeSpreadObj.resetXmjSpread(select);
  2609. // // console.log(select, sel);
  2610. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  2611. // return false;
  2612. // } else {
  2613. // return true;
  2614. // }
  2615. // },
  2616. batchInsert: function (obj, root) {
  2617. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  2618. obj.value = obj.max;
  2619. toastr.warning('批量插入不可多于' + obj.max);
  2620. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  2621. obj.value = obj.min;
  2622. toastr.warning('批量插入不可少于' + obj.min);
  2623. } else {
  2624. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  2625. changeSpreadObj.batchAdd(obj.value);
  2626. root.$menu.trigger('contextmenu:hide');
  2627. }
  2628. },
  2629. },
  2630. 'delete': {
  2631. name: '删除',
  2632. icon: 'fa-remove',
  2633. callback: function (key, opt) {
  2634. changeSpreadObj.del();
  2635. },
  2636. disabled: function (key, opt) {
  2637. const selection = changeSpreadSheet.getSelections();
  2638. const sel = selection ? selection[0] : changeSpreadSheet.getSelections()[0];
  2639. const row = sel ? sel.row : -1;
  2640. if (readOnly || row === -1 || sel.row + sel.rowCount > changeSpreadSheet.zh_data.length) {
  2641. return true;
  2642. }
  2643. const first = changeSpreadSheet.zh_data[row];
  2644. let valid = true;
  2645. if (sel.rowCount > 1 && first) {
  2646. for (let r = 1; r < sel.rowCount; r++) {
  2647. const rNode = changeSpreadSheet.zh_data[sel.row + r];
  2648. if (!rNode || !rNode.id) {
  2649. valid = false;
  2650. break;
  2651. }
  2652. if (_.find(changeUsedData, { cbid: rNode.id }) || checkIsSettle(rNode)) {
  2653. valid = false;
  2654. break;
  2655. }
  2656. }
  2657. }
  2658. return !(first && first.id && !_.find(changeUsedData, { cbid: first.id }) && !checkIsSettle(first) && valid);
  2659. }
  2660. },
  2661. sprEdit: '----',
  2662. 'allNotValuation': {
  2663. name: '设置全部清单不计价',
  2664. icon: 'fa-magic',
  2665. callback: function (key, opt) {
  2666. changeSpreadObj.setAllValuation(0);
  2667. },
  2668. },
  2669. 'allValuation': {
  2670. name: '设置全部清单计价',
  2671. icon: 'fa-magic',
  2672. callback: function (key, opt) {
  2673. changeSpreadObj.setAllValuation(1);
  2674. },
  2675. },
  2676. }
  2677. });
  2678. // 右键菜单
  2679. $.contextMenu({
  2680. selector: '#xmj-spread',
  2681. build: function ($trigger, e) {
  2682. const target = SpreadJsObj.safeRightClickSelection($trigger, e, xmjSpread);
  2683. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2684. },
  2685. items: {
  2686. 'delete': {
  2687. name: '删除',
  2688. icon: 'fa-remove',
  2689. callback: function (key, opt) {
  2690. xmjSpreadObj.del();
  2691. },
  2692. disabled: function (key, opt) {
  2693. const selection = xmjSheet.getSelections();
  2694. const sel = selection ? selection[0] : xmjSheet.getSelections()[0];
  2695. const row = sel && sel.row !== undefined ? sel.row : -1;
  2696. if (readOnly || row === -1 || sel.row + sel.rowCount > xmjSheet.zh_data.length) {
  2697. return true;
  2698. }
  2699. let isUsed = false;
  2700. for (let r = 0; r < sel.rowCount; r++) {
  2701. const select = xmjSheet.zh_data[row + r];
  2702. if(!select || _.find(changeUsedData, { cbid: select.id })) {
  2703. isUsed = true;
  2704. }
  2705. if (checkIsSettle(select)) {
  2706. isUsed = true;
  2707. }
  2708. }
  2709. return isUsed;
  2710. }
  2711. },
  2712. sprEdit: '----',
  2713. 'allNotValuation': {
  2714. name: '设置全部不计价',
  2715. icon: 'fa-magic',
  2716. callback: function (key, opt) {
  2717. xmjSpreadObj.setAllValuation(0);
  2718. },
  2719. disabled: function (key, opt) {
  2720. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2721. if (select.children && select.children.length > 0) {
  2722. return false;
  2723. } else {
  2724. return true;
  2725. }
  2726. }
  2727. },
  2728. 'allValuation': {
  2729. name: '设置全部计价',
  2730. icon: 'fa-magic',
  2731. callback: function (key, opt) {
  2732. xmjSpreadObj.setAllValuation(1);
  2733. },
  2734. disabled: function (key, opt) {
  2735. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2736. if (select.children && select.children.length > 0) {
  2737. return false;
  2738. } else {
  2739. return true;
  2740. }
  2741. }
  2742. },
  2743. }
  2744. });
  2745. }
  2746. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  2747. const ledgerSheet = ledgerSpread.getActiveSheet();
  2748. const ledgerSpreadSetting = {
  2749. cols: [
  2750. {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', getValue: 'getValue.is_valuation', readOnly: 'readOnly.isValuation'},
  2751. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree' },
  2752. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit2'},
  2753. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit2'},
  2754. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit2', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
  2755. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price', readOnly: 'readOnly.isEdit2'},
  2756. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  2757. {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', visible: openChangeState},
  2758. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount2', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
  2759. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  2760. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
  2761. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  2762. ],
  2763. emptyRows: 0,
  2764. headRows: 2,
  2765. headRowHeight: [25, 25],
  2766. defaultRowHeight: 21,
  2767. headerFont: '12px 微软雅黑',
  2768. font: '12px 微软雅黑',
  2769. // readOnly: true,
  2770. rowHeader:[
  2771. {
  2772. rowHeaderType: 'circle',
  2773. setting: {
  2774. size: 5,
  2775. indent: 16,
  2776. getColor: function (index, data) {
  2777. if (!data) return;
  2778. if ((!data.clid && data.id && (_.findIndex(changeLedgerList, { id: data.id }) !== -1 || _.findIndex(changePosList, { lid: data.id }) !== -1))
  2779. || (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. select[col.field] = validText;
  3521. console.log(cInfo);
  3522. delete cInfo.waitingLoading;
  3523. // 更新至服务器
  3524. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  3525. const loadResult = {
  3526. update: [select],
  3527. };
  3528. const refreshData = ledgerTree.loadPostData(loadResult);
  3529. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  3530. ledgerTreeSpreadObj.loadExprToInput();
  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. posSpreadObj.loadExprToInput();
  4055. }, function () {
  4056. select[col.field] = orgValue;
  4057. cInfo[col.field] = orgValue;
  4058. if(col.field === 'camount') {
  4059. select.spamount = orgValue;
  4060. cInfo.spamount = orgValue;
  4061. }
  4062. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4063. });
  4064. };
  4065. posSpreadObj.clipboardPasted = function (e, info) {
  4066. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  4067. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  4068. }
  4069. const hint = {
  4070. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  4071. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  4072. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  4073. };
  4074. const range = info.cellRange;
  4075. const sortData = info.sheet.zh_data || [];
  4076. if (range.row + range.rowCount > sortData.length) {
  4077. toastMessageUniq(hint.cellError);
  4078. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  4079. posSpreadObj.loadCurPosData();
  4080. return;
  4081. }
  4082. if (sortData.length > 0 && range.col + range.colCount > 6) {
  4083. toastMessageUniq(hint.cellError);
  4084. posSpreadObj.loadCurPosData();
  4085. return;
  4086. }
  4087. if (!info.sheet.zh_setting) {
  4088. posSpreadObj.loadCurPosData();
  4089. return;
  4090. }
  4091. const data = [];
  4092. // const rowData = [];
  4093. let needCopyIgnore = !$('#customCheck1').is(':checked');
  4094. let needColAdd = false;
  4095. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  4096. let bPaste = true;
  4097. const curRow = range.row + iRow;
  4098. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  4099. const cLData = { id: sortData[curRow].clid };
  4100. const hintRow = range.rowCount >= 1 ? curRow : '';
  4101. let sameCol = 0;
  4102. for (let iCol = 0; iCol < range.colCount; iCol++) {
  4103. const curCol = range.col + iCol;
  4104. let colSetting = info.sheet.zh_setting.cols[curCol];
  4105. if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
  4106. const newCurCol = curCol + 1;
  4107. needColAdd = true;
  4108. colSetting = info.sheet.zh_setting.cols[newCurCol];
  4109. }
  4110. if (!colSetting) continue;
  4111. let validText = info.sheet.getText(curRow, curCol);
  4112. validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  4113. let orgValue;
  4114. if (colSetting.field === 'camount') {
  4115. orgValue = validText && validText !== ''
  4116. ? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
  4117. : (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
  4118. } else {
  4119. orgValue = sortData[curRow][colSetting.field];
  4120. }
  4121. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  4122. sameCol++;
  4123. if (range.colCount === sameCol) {
  4124. bPaste = false;
  4125. }
  4126. continue;
  4127. }
  4128. if(colSetting.field === 'camount') {
  4129. const exprQuantity = {
  4130. expr: '',
  4131. quantity: 0,
  4132. };
  4133. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  4134. if (!valid) {
  4135. toastMessageUniq(getPasteHint(msg, hintRow));
  4136. bPaste = false;
  4137. continue;
  4138. }
  4139. if (isNaN(exprQuantity.quantity)) {
  4140. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  4141. bPaste = false;
  4142. continue;
  4143. }
  4144. validText = parseFloat(exprQuantity.quantity);
  4145. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4146. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
  4147. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  4148. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4149. bPaste = false;
  4150. continue;
  4151. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  4152. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4153. bPaste = false;
  4154. continue;
  4155. }
  4156. cLData.camount_expr = exprQuantity.expr;
  4157. sortData[curRow].camount_expr = exprQuantity.expr;
  4158. }
  4159. if (colSetting.type === 'Number') {
  4160. if (isNaN(validText)) {
  4161. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  4162. bPaste = false;
  4163. continue;
  4164. }
  4165. if (colSetting.field === 'unit_price') {
  4166. validText = ZhCalc.round(validText, unitPriceUnit);
  4167. } else {
  4168. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  4169. }
  4170. if (colSetting.field === 'delimit') {
  4171. const reg = /^(\d{1,2}|100)$/;
  4172. if (!(_.isNumber(validText) && reg.test(validText))) {
  4173. toastr.error('计量单元第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
  4174. bPaste = false;
  4175. continue;
  4176. }
  4177. // 需要判断是否已调用,已调用的则不能低于原有值大小
  4178. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
  4179. if (usedInfo && usedInfo.qty) {
  4180. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
  4181. if (validText < minLimit) {
  4182. toastr.error('计量单元第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
  4183. bPaste = false;
  4184. continue;
  4185. }
  4186. }
  4187. }
  4188. }
  4189. let unitdecimal = validText;
  4190. cLData[colSetting.field] = validText;
  4191. sortData[curRow][colSetting.field] = validText;
  4192. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  4193. }
  4194. if (bPaste) {
  4195. data.push(cLData);
  4196. // rowData.push(curRow);
  4197. } else {
  4198. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  4199. }
  4200. }
  4201. if (data.length === 0) {
  4202. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  4203. return;
  4204. }
  4205. console.log(data);
  4206. // 更新至服务器
  4207. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  4208. changeList = result;
  4209. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  4210. const loadResult = {
  4211. update: [node],
  4212. };
  4213. const refreshData = ledgerTree.loadPostData(loadResult);
  4214. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  4215. posSpreadObj.loadCurPosData();
  4216. }, function () {
  4217. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  4218. return;
  4219. });
  4220. };
  4221. posSpreadObj.buttonClicked = function(e, info) {
  4222. if (info.sheet.zh_setting) {
  4223. const select = SpreadJsObj.getSelectObject(info.sheet);
  4224. const cInfo = _.find(changeList, { id: select.clid });
  4225. if (!cInfo) {
  4226. toastr.error('数据错误,请刷新页面重试');
  4227. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4228. return;
  4229. }
  4230. const col = info.sheet.zh_setting.cols[info.col];
  4231. if (col.field === 'is_valuation') {
  4232. if (info.sheet.isEditing()) {
  4233. info.sheet.endEdit(true);
  4234. }
  4235. if (_.findIndex(changeUsedData, { cbid: select.clid }) !== -1) {
  4236. return;
  4237. }
  4238. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  4239. cInfo.is_valuation = select.is_valuation;
  4240. delete cInfo.waitingLoading;
  4241. // 更新至服务器
  4242. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  4243. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4244. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  4245. const loadResult = {
  4246. update: [node],
  4247. };
  4248. const refreshData = ledgerTree.loadPostData(loadResult);
  4249. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  4250. }, function () {
  4251. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  4252. cInfo.is_valuation = select.is_valuation;
  4253. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4254. });
  4255. }
  4256. }
  4257. };
  4258. posSpreadObj.valueChanged = function(e, info) {
  4259. // 防止ctrl+z撤销数据
  4260. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4261. };
  4262. posSpreadObj.deletePress = function (sheet) {
  4263. if (!sheet.zh_setting) return;
  4264. // 暂时仅支持移除数量
  4265. const sel = sheet.getSelections()[0], datas = [];
  4266. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  4267. let bDel = false;
  4268. const node = sheet.zh_data[iRow];
  4269. const cInfo = _.find(changeList, { id: node.clid });
  4270. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  4271. const col = sheet.zh_setting.cols[iCol];
  4272. if (col.field === 'camount' || col.field === 'oamount2') {
  4273. node[col.field] = null;
  4274. cInfo[col.field] = null;
  4275. if (col.field === 'camount') {
  4276. node.camount_expr = '';
  4277. node.spamount = null;
  4278. cInfo.camount_expr = '';
  4279. cInfo.spamount = null;
  4280. }
  4281. delete cInfo.waitingLoading;
  4282. bDel = true;
  4283. }
  4284. }
  4285. if (bDel) datas.push(cInfo);
  4286. }
  4287. if (datas.length > 0) {
  4288. postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
  4289. changeList = result;
  4290. const billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
  4291. const loadResult = {
  4292. update: [billsNode],
  4293. };
  4294. const refreshData = ledgerTree.loadPostData(loadResult);
  4295. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  4296. posSpreadObj.loadCurPosData();
  4297. }, function () {
  4298. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  4299. return;
  4300. });
  4301. }
  4302. return;
  4303. };
  4304. // 表达式判断
  4305. $('#pos-camount-expr').change(function () {
  4306. if (this.readOnly) return;
  4307. let validText = $(this).val();
  4308. const sel = posSheet.getSelections()[0];
  4309. const row = sel ? sel.row : -1;
  4310. const col = posSheet.zh_setting.cols[sel.col];
  4311. if (row === -1 || !(col && col.field === 'camount')) return;
  4312. const select = SpreadJsObj.getSelectObject(posSheet);
  4313. if (!select) return;
  4314. const cInfo = _.find(changeList, { id: select.clid });
  4315. if (!cInfo) return;
  4316. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  4317. let orgValue = validText && validText !== ''
  4318. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  4319. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  4320. const orgExprValue = _.clone(select.camount_expr);
  4321. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  4322. return;
  4323. }
  4324. const exprQuantity = {
  4325. expr: '',
  4326. quantity: 0,
  4327. };
  4328. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  4329. if (!valid) {
  4330. toastr.error(msg);
  4331. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  4332. return;
  4333. }
  4334. if (isNaN(exprQuantity.quantity)) {
  4335. toastr.error('不能输入其它非数字类型字符');
  4336. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  4337. return;
  4338. }
  4339. validText = parseFloat(exprQuantity.quantity);
  4340. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4341. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  4342. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  4343. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4344. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  4345. return;
  4346. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  4347. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4348. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  4349. return;
  4350. }
  4351. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  4352. select.camount_expr = exprQuantity.expr;
  4353. select.camount = validText;
  4354. cInfo.spamount = select.spamount;
  4355. cInfo.camount_expr = select.camount_expr;
  4356. cInfo.camount = validText;
  4357. // console.log(select);
  4358. delete cInfo.waitingLoading;
  4359. // 更新至服务器
  4360. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  4361. SpreadJsObj.reLoadRowData(posSheet, row);
  4362. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  4363. const loadResult = {
  4364. update: [node],
  4365. };
  4366. const refreshData = ledgerTree.loadPostData(loadResult);
  4367. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  4368. }, function () {
  4369. select.camount = orgValue;
  4370. select.camount_expr = orgExprValue;
  4371. select.spamount = orgValue;
  4372. cInfo.camount = orgValue;
  4373. cInfo.camount_expr = orgExprValue;
  4374. cInfo.spamount = orgValue;
  4375. SpreadJsObj.reLoadRowData(posSheet, row);
  4376. });
  4377. });
  4378. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  4379. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  4380. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  4381. posSpread.bind(spreadNS.Events.ValueChanged, posSpreadObj.valueChanged);
  4382. posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
  4383. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  4384. // 右键菜单
  4385. $.contextMenu({
  4386. selector: '#ledger-spread',
  4387. build: function ($trigger, e) {
  4388. const target = SpreadJsObj.safeRightClickSelection($trigger, e, ledgerSpread);
  4389. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  4390. },
  4391. items: {
  4392. 'delete': {
  4393. name: '删除',
  4394. icon: 'fa-remove',
  4395. callback: function (key, opt) {
  4396. ledgerTreeSpreadObj.del();
  4397. },
  4398. disabled: function (key, opt) {
  4399. const selection = ledgerSheet.getSelections();
  4400. const sel = selection ? selection[0] : ledgerSheet.getSelections()[0];
  4401. const row = sel ? sel.row : -1;
  4402. const tree = ledgerSheet.zh_tree;
  4403. if (!tree) return true;
  4404. const first = ledgerSheet.zh_tree.nodes[row];
  4405. let last = first, sameParent = true, listValid = true;
  4406. if (sel.rowCount > 1 && first) {
  4407. for (let r = 1; r < sel.rowCount; r++) {
  4408. const rNode = tree.nodes[sel.row + r];
  4409. if (!rNode) {
  4410. sameParent = false;
  4411. break;
  4412. }
  4413. if (!rNode.clid) {
  4414. listValid = false;
  4415. break;
  4416. }
  4417. if (_.find(changeUsedData, { cbid: rNode.clid }) || checkIsSettle(rNode)) {
  4418. listValid = false;
  4419. break;
  4420. }
  4421. if (rNode.level > first.level) continue;
  4422. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  4423. sameParent = false;
  4424. break;
  4425. }
  4426. last = rNode;
  4427. }
  4428. }
  4429. const valid = !ledgerSheet.zh_setting.readOnly;
  4430. return !(valid && first && first.clid && !_.find(changeUsedData, { cbid: first.clid }) && !checkIsSettle(first) && sameParent && listValid);
  4431. }
  4432. },
  4433. // sprEdit: '----',
  4434. // 'allNotValuation': {
  4435. // name: '设置全部清单不计价',
  4436. // icon: 'fa-magic',
  4437. // callback: function (key, opt) {
  4438. // changeSpreadObj.setAllValuation(0);
  4439. // },
  4440. // },
  4441. // 'allValuation': {
  4442. // name: '设置全部清单计价',
  4443. // icon: 'fa-magic',
  4444. // callback: function (key, opt) {
  4445. // changeSpreadObj.setAllValuation(1);
  4446. // },
  4447. // },
  4448. }
  4449. });
  4450. // 右键菜单
  4451. $.contextMenu({
  4452. selector: '#pos-spread',
  4453. build: function ($trigger, e) {
  4454. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  4455. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  4456. },
  4457. items: {
  4458. 'delete': {
  4459. name: '删除',
  4460. icon: 'fa-remove',
  4461. callback: function (key, opt) {
  4462. posSpreadObj.del();
  4463. },
  4464. disabled: function (key, opt) {
  4465. const selection = posSheet.getSelections();
  4466. const sel = selection ? selection[0] : posSheet.getSelections()[0];
  4467. const row = sel && sel.row !== undefined ? sel.row : -1;
  4468. if (readOnly || row === -1 || sel.row + sel.rowCount > posSheet.zh_data.length) {
  4469. return true;
  4470. }
  4471. let isUsed = false;
  4472. for (let r = 0; r < sel.rowCount; r++) {
  4473. const select = posSheet.zh_data[row + r];
  4474. if(!select || _.find(changeUsedData, { cbid: select.clid })) {
  4475. isUsed = true;
  4476. }
  4477. if (checkIsSettle(select)) {
  4478. isUsed = true;
  4479. }
  4480. }
  4481. return isUsed;
  4482. }
  4483. },
  4484. // sprEdit: '----',
  4485. // 'allNotValuation': {
  4486. // name: '设置全部清单不计价',
  4487. // icon: 'fa-magic',
  4488. // callback: function (key, opt) {
  4489. // changeSpreadObj.setAllValuation(0);
  4490. // },
  4491. // },
  4492. // 'allValuation': {
  4493. // name: '设置全部清单计价',
  4494. // icon: 'fa-magic',
  4495. // callback: function (key, opt) {
  4496. // changeSpreadObj.setAllValuation(1);
  4497. // },
  4498. // },
  4499. }
  4500. });
  4501. }
  4502. if (shenpiPower) {
  4503. changeSpreadObj.editEnded = function (e, info) {
  4504. if (!info.sheet.zh_setting) {
  4505. changeSpreadObj.reloadRow(info.sheet, info.row);
  4506. return;
  4507. }
  4508. const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  4509. if (!select || !select.id) {
  4510. toastr.error('该变更清单无法编辑');
  4511. changeSpreadObj.reloadRow(info.sheet, info.row);
  4512. return;
  4513. }
  4514. const cInfo = _.find(changeList, { id: select.id });
  4515. if (!cInfo) {
  4516. toastr.error('数据错误,请刷新页面重试');
  4517. changeSpreadObj.reloadRow(info.sheet, info.row);
  4518. return;
  4519. }
  4520. const col = info.sheet.zh_setting.cols[info.col];
  4521. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  4522. const orgValue = select[col.field];
  4523. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  4524. changeSpreadObj.reloadRow(info.sheet, info.row);
  4525. return;
  4526. }
  4527. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  4528. if (!node) {
  4529. toastr.error('数据错误,请选择清单节点后再试');
  4530. changeSpreadObj.reloadRow(info.sheet, info.row);
  4531. return;
  4532. }
  4533. if (col.type === 'Number') {
  4534. if (isNaN(validText)) {
  4535. toastr.error('不能输入其它非数字类型字符');
  4536. changeSpreadObj.reloadRow(info.sheet, info.row);
  4537. return;
  4538. }
  4539. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  4540. if (col.field !== 'oamount2') {
  4541. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4542. const usedInfo = _.find(changeUsedData, {cbid: select.id});
  4543. if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
  4544. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4545. changeSpreadObj.reloadRow(info.sheet, info.row);
  4546. return;
  4547. } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
  4548. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4549. changeSpreadObj.reloadRow(info.sheet, info.row);
  4550. return;
  4551. }
  4552. }
  4553. }
  4554. cInfo[col.field] = validText;
  4555. select[col.field] = validText;
  4556. if (col.field !== 'oamount2') {
  4557. cInfo.spamount = validText;
  4558. select.spamount = validText;
  4559. }
  4560. const data = {
  4561. id: select.id,
  4562. };
  4563. if (col.field === 'oamount2') {
  4564. data[col.field] = select[col.field];
  4565. } else {
  4566. data.spamount = select.spamount;
  4567. }
  4568. console.log(data, col.field);
  4569. // 更新至服务器
  4570. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  4571. changeSpreadObj.calcOneSum(select);
  4572. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4573. changeSpreadObj.refreshXmjData();
  4574. changeSpreadObj.countSum();
  4575. if (info.row === info.sheet.zh_data.length - 1) {
  4576. // console.log(info);
  4577. // changeSpreadSheet.setSelection(info.row, info.col, 1, 1);
  4578. // changeSpreadObj.reloadRow(changeSpreadSheet, info.row, 0, true);
  4579. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  4580. changeSpreadObj.reloadSheet(newChangeList);
  4581. }
  4582. }, function () {
  4583. select[col.field] = orgValue;
  4584. cInfo[col.field] = orgValue;
  4585. if (col.field !== 'oamount2') {
  4586. select.spamount = orgValue;
  4587. cInfo.spamount = orgValue;
  4588. }
  4589. changeSpreadObj.reloadRow(info.sheet, info.row);
  4590. });
  4591. };
  4592. changeSpreadObj.clipboardPasted = function (e, info) {
  4593. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  4594. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  4595. }
  4596. const hint = {
  4597. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  4598. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  4599. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  4600. };
  4601. const range = info.cellRange;
  4602. const sortData = info.sheet.zh_data || [];
  4603. const data = [];
  4604. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  4605. let bPaste = true;
  4606. const curRow = range.row + iRow;
  4607. if (!sortData[curRow] || !sortData[curRow].id) {
  4608. bPaste = false;
  4609. }
  4610. const cLData = { id: sortData[curRow].id };
  4611. const hintRow = range.rowCount >= 1 ? curRow : '';
  4612. let sameCol = 0;
  4613. for (let iCol = 0; iCol < range.colCount; iCol++) {
  4614. const curCol = range.col + iCol;
  4615. let colSetting = info.sheet.zh_setting.cols[curCol];
  4616. if (!colSetting) continue;
  4617. let validText = info.sheet.getText(curRow, curCol);
  4618. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  4619. const orgValue = sortData[curRow][colSetting.field];
  4620. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  4621. sameCol++;
  4622. if (range.colCount === sameCol) {
  4623. bPaste = false;
  4624. }
  4625. continue;
  4626. }
  4627. if (colSetting.type === 'Number') {
  4628. if (isNaN(validText)) {
  4629. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  4630. bPaste = false;
  4631. continue;
  4632. }
  4633. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  4634. if (colSetting.field !== 'oamount2') {
  4635. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4636. const usedInfo = _.find(changeUsedData, {id: sortData[curRow].id});
  4637. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  4638. toastr.error(hintRow ? '清单' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4639. bPaste = false;
  4640. continue;
  4641. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  4642. toastr.error(hintRow ? '清单' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4643. bPaste = false;
  4644. continue;
  4645. }
  4646. }
  4647. }
  4648. sortData[curRow][colSetting.field] = validText;
  4649. if (colSetting.field === 'oamount2') {
  4650. cLData[colSetting.field] = validText;
  4651. } else {
  4652. cLData.spamount = validText;
  4653. sortData[curRow].spamount = validText;
  4654. }
  4655. }
  4656. if (bPaste) {
  4657. data.push(cLData);
  4658. // rowData.push(curRow);
  4659. } else {
  4660. changeSpreadObj.reloadRow(info.sheet, curRow);
  4661. }
  4662. }
  4663. if (data.length === 0) {
  4664. changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  4665. return;
  4666. }
  4667. console.log(data);
  4668. // 更新至服务器
  4669. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  4670. changeList = result;
  4671. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  4672. changeSpreadObj.reloadSheet(newChangeList);
  4673. }, function () {
  4674. changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  4675. return;
  4676. });
  4677. };
  4678. changeSpreadObj.deletePress = function (sheet) {
  4679. if (!sheet.zh_setting) return;
  4680. // 暂时仅支持移除数量
  4681. const sel = sheet.getSelections()[0], datas = [];
  4682. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  4683. let bDel = false;
  4684. const node = sheet.zh_data[iRow];
  4685. const cInfo = _.find(changeList, { id: node.id });
  4686. const data = { id: node.id };
  4687. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  4688. const col = sheet.zh_setting.cols[iCol];
  4689. if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
  4690. node[col.field] = null;
  4691. cInfo[col.field] = null;
  4692. if (col.field !== 'oamount2') {
  4693. data.spamount = null;
  4694. cInfo.spamount = null;
  4695. node.spamount = null;
  4696. } else {
  4697. data[col.field] = null;
  4698. }
  4699. bDel = true;
  4700. }
  4701. }
  4702. if (bDel) datas.push(data);
  4703. }
  4704. if (datas.length > 0) {
  4705. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
  4706. changeList = result;
  4707. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  4708. changeSpreadObj.reloadSheet(newChangeList);
  4709. }, function () {
  4710. changeSpreadObj.reloadRow(sheet, sel.row, sel.rowCount);
  4711. return;
  4712. });
  4713. }
  4714. return;
  4715. };
  4716. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  4717. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  4718. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  4719. xmjSpreadObj.editStarting = function (e, info) {
  4720. xmjSpreadObj.billsNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
  4721. };
  4722. xmjSpreadObj.editEnded = function (e, info) {
  4723. if (!info.sheet.zh_setting) {
  4724. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4725. return;
  4726. }
  4727. const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  4728. const cInfo = _.find(changeList, { id: select.id });
  4729. if (!cInfo) {
  4730. toastr.error('数据错误,请刷新页面重试');
  4731. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4732. return;
  4733. }
  4734. const col = info.sheet.zh_setting.cols[info.col];
  4735. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  4736. const orgValue = select[col.field];
  4737. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  4738. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4739. return;
  4740. }
  4741. const node = xmjSpreadObj.billsNode;
  4742. if (!node) {
  4743. toastr.error('数据错误,请选择清单节点后再试');
  4744. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4745. return;
  4746. }
  4747. if (col.type === 'Number') {
  4748. if (isNaN(validText)) {
  4749. toastr.error('不能输入其它非数字类型字符');
  4750. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4751. return;
  4752. }
  4753. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  4754. if (col.field !== 'oamount2') {
  4755. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4756. const usedInfo = _.find(changeUsedData, {cbid: select.id});
  4757. if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
  4758. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4759. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4760. return;
  4761. } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
  4762. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4763. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4764. return;
  4765. }
  4766. }
  4767. }
  4768. cInfo[col.field] = validText;
  4769. select[col.field] = validText;
  4770. if (col.field !== 'oamount2') {
  4771. cInfo.spamount = validText;
  4772. select.spamount = validText;
  4773. }
  4774. const data = {
  4775. id: select.id,
  4776. };
  4777. if (col.field === 'oamount2') {
  4778. data[col.field] = select[col.field];
  4779. } else {
  4780. data.spamount = select.spamount;
  4781. }
  4782. console.log(data);
  4783. // 更新至服务器
  4784. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  4785. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4786. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  4787. node.children = info.sheet.zh_data;
  4788. changeSpreadObj.calcOneSum(node);
  4789. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  4790. changeSpreadObj.countSum();
  4791. }, function () {
  4792. select[col.field] = orgValue;
  4793. cInfo[col.field] = orgValue;
  4794. if (col.field !== 'oamount2') {
  4795. select.spamount = orgValue;
  4796. cInfo.spamount = orgValue;
  4797. }
  4798. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4799. });
  4800. };
  4801. xmjSpreadObj.clipboardPasted = function (e, info) {
  4802. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  4803. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  4804. }
  4805. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  4806. if (!node) {
  4807. toastr.error('数据错误,请选择清单节点后再试');
  4808. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4809. return;
  4810. }
  4811. const hint = {
  4812. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  4813. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  4814. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  4815. };
  4816. const range = info.cellRange;
  4817. const sortData = info.sheet.zh_data || [];
  4818. const data = [];
  4819. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  4820. let bPaste = true;
  4821. const curRow = range.row + iRow;
  4822. const cLData = { id: sortData[curRow].id };
  4823. const hintRow = range.rowCount >= 1 ? curRow : '';
  4824. let sameCol = 0;
  4825. for (let iCol = 0; iCol < range.colCount; iCol++) {
  4826. const curCol = range.col + iCol;
  4827. let colSetting = info.sheet.zh_setting.cols[curCol];
  4828. if (!colSetting) continue;
  4829. let validText = info.sheet.getText(curRow, curCol);
  4830. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  4831. const orgValue = sortData[curRow][colSetting.field];
  4832. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  4833. sameCol++;
  4834. if (range.colCount === sameCol) {
  4835. bPaste = false;
  4836. }
  4837. continue;
  4838. }
  4839. if (colSetting.type === 'Number') {
  4840. if (isNaN(validText)) {
  4841. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  4842. bPaste = false;
  4843. continue;
  4844. }
  4845. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  4846. if (colSetting.field !== 'oamount2') {
  4847. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4848. const usedInfo = _.find(changeUsedData, {id: sortData[curRow].id});
  4849. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  4850. toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4851. bPaste = false;
  4852. continue;
  4853. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  4854. toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4855. bPaste = false;
  4856. continue;
  4857. }
  4858. }
  4859. }
  4860. sortData[curRow][colSetting.field] = validText;
  4861. if (colSetting.field === 'oamount2') {
  4862. cLData[colSetting.field] = validText;
  4863. } else {
  4864. cLData.spamount = validText;
  4865. sortData[curRow].spamount = validText;
  4866. }
  4867. }
  4868. if (bPaste) {
  4869. data.push(cLData);
  4870. // rowData.push(curRow);
  4871. } else {
  4872. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  4873. }
  4874. }
  4875. if (data.length === 0) {
  4876. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  4877. return;
  4878. }
  4879. console.log(data);
  4880. // 更新至服务器
  4881. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  4882. changeList = result;
  4883. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  4884. node.children = info.sheet.zh_data;
  4885. changeSpreadObj.calcOneSum(node);
  4886. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  4887. changeSpreadObj.countSum();
  4888. xmjSpreadObj.loadCurXmjData();
  4889. }, function () {
  4890. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  4891. return;
  4892. });
  4893. };
  4894. xmjSpreadObj.deletePress = function (sheet) {
  4895. if (!sheet.zh_setting) return;
  4896. const changeNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
  4897. if (!changeNode) {
  4898. toastr.error('数据错误,请选择清单节点后再试');
  4899. SpreadJsObj.reLoadRowData(sheet, info.row);
  4900. return;
  4901. }
  4902. // 暂时仅支持移除数量
  4903. const sel = sheet.getSelections()[0], datas = [];
  4904. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  4905. let bDel = false;
  4906. const node = sheet.zh_data[iRow];
  4907. const cInfo = _.find(changeList, { id: node.id });
  4908. const data = { id: node.id };
  4909. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  4910. const col = sheet.zh_setting.cols[iCol];
  4911. if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
  4912. node[col.field] = null;
  4913. cInfo[col.field] = null;
  4914. if (col.field !== 'oamount2') {
  4915. data.spamount = null;
  4916. cInfo.spamount = null;
  4917. node.spamount = null;
  4918. } else {
  4919. data[col.field] = null;
  4920. }
  4921. bDel = true;
  4922. }
  4923. }
  4924. if (bDel) datas.push(data);
  4925. }
  4926. if (datas.length > 0) {
  4927. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
  4928. changeList = result;
  4929. const billIndex = _.indexOf(changeSpreadSheet.zh_data, changeNode);
  4930. changeNode.children = sheet.zh_data;
  4931. changeSpreadObj.calcOneSum(changeNode);
  4932. console.log(changeNode);
  4933. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  4934. changeSpreadObj.countSum();
  4935. xmjSpreadObj.loadCurXmjData();
  4936. }, function () {
  4937. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  4938. return;
  4939. });
  4940. }
  4941. return;
  4942. };
  4943. xmjSpread.bind(spreadNS.Events.EditStarting, xmjSpreadObj.editStarting);
  4944. xmjSpread.bind(spreadNS.Events.EditEnded, xmjSpreadObj.editEnded);
  4945. xmjSpread.bind(spreadNS.Events.ClipboardPasted, xmjSpreadObj.clipboardPasted);
  4946. SpreadJsObj.addDeleteBind(xmjSpread, xmjSpreadObj.deletePress);
  4947. ledgerTreeSpreadObj.editEnded = function (e, info) {
  4948. if (!info.sheet.zh_setting) {
  4949. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4950. return;
  4951. }
  4952. const col = info.sheet.zh_setting.cols[info.col];
  4953. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  4954. const select = sortData[info.row];
  4955. if (!select || !select.clid) {
  4956. toastr.error('数据错误,请刷新页面重试');
  4957. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4958. return;
  4959. }
  4960. const cInfo = _.find(changeList, { id: select.clid });
  4961. if (!cInfo) {
  4962. toastr.error('数据错误,请刷新页面重试');
  4963. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4964. return;
  4965. }
  4966. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  4967. const orgValue = select[col.field];
  4968. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  4969. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4970. return;
  4971. }
  4972. if (col.type === 'Number') {
  4973. if (isNaN(validText)) {
  4974. toastr.error('不能输入其它非数字类型字符');
  4975. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4976. return;
  4977. }
  4978. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  4979. if (col.field !== 'oamount2') {
  4980. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4981. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  4982. if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
  4983. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4984. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4985. return;
  4986. } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
  4987. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4988. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4989. return;
  4990. }
  4991. }
  4992. }
  4993. cInfo[col.field] = validText;
  4994. select[col.field] = validText;
  4995. if (col.field !== 'oamount2') {
  4996. cInfo.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  4997. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  4998. }
  4999. const data = {
  5000. id: cInfo.id,
  5001. };
  5002. if (col.field === 'oamount2') {
  5003. data[col.field] = select[col.field];
  5004. } else {
  5005. data.spamount = select.spamount;
  5006. }
  5007. // 更新至服务器
  5008. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  5009. const loadResult = {
  5010. update: [select],
  5011. };
  5012. const refreshData = ledgerTree.loadPostData(loadResult);
  5013. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  5014. }, function () {
  5015. select[col.field] = orgValue;
  5016. cInfo[col.field] = orgValue;
  5017. if(col.field !== 'oamount2') {
  5018. select.spamount = orgValue;
  5019. cInfo.spamount = orgValue;
  5020. }
  5021. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5022. });
  5023. };
  5024. ledgerTreeSpreadObj.clipboardPasted = function (e, info) {
  5025. const tree = info.sheet.zh_tree;
  5026. if (!tree) { return; }
  5027. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  5028. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  5029. }
  5030. const hint = {
  5031. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  5032. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  5033. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  5034. };
  5035. const range = info.cellRange;
  5036. const sortData = info.sheet.zh_tree.nodes;
  5037. const selects = [];
  5038. const data = [];
  5039. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  5040. let bPaste = true;
  5041. const curRow = range.row + iRow;
  5042. const node = sortData[curRow];
  5043. if (!node) {
  5044. continue;
  5045. }
  5046. const cLData = { id: sortData[curRow].clid };
  5047. const hintRow = range.rowCount >= 1 ? curRow : '';
  5048. let sameCol = 0;
  5049. for (let iCol = 0; iCol < range.colCount; iCol++) {
  5050. const curCol = range.col + iCol;
  5051. let colSetting = info.sheet.zh_setting.cols[curCol];
  5052. if (!colSetting) continue;
  5053. let validText = info.sheet.getText(curRow, curCol);
  5054. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  5055. const orgValue = sortData[curRow][colSetting.field];
  5056. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  5057. sameCol++;
  5058. if (range.colCount === sameCol) {
  5059. bPaste = false;
  5060. }
  5061. continue;
  5062. }
  5063. if (colSetting.type === 'Number') {
  5064. if (isNaN(validText)) {
  5065. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  5066. bPaste = false;
  5067. continue;
  5068. }
  5069. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  5070. if (colSetting.field !== 'oamount2') {
  5071. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  5072. const usedInfo = _.find(changeUsedData, {id: sortData[curRow].clid});
  5073. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  5074. toastr.error(hintRow ? '台账' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  5075. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  5076. bPaste = false;
  5077. continue;
  5078. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  5079. toastr.error(hintRow ? '台账' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  5080. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  5081. bPaste = false;
  5082. continue;
  5083. }
  5084. }
  5085. }
  5086. sortData[curRow][colSetting.field] = validText;
  5087. if (colSetting.field === 'oamount2') {
  5088. cLData[colSetting.field] = validText;
  5089. } else {
  5090. cLData.spamount = validText;
  5091. sortData[curRow].spamount = cLData.spamount;
  5092. }
  5093. }
  5094. if (bPaste) {
  5095. data.push(cLData);
  5096. selects.push(sortData[curRow]);
  5097. } else {
  5098. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  5099. }
  5100. }
  5101. if (data.length === 0) {
  5102. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  5103. return;
  5104. }
  5105. console.log(data, selects);
  5106. // 更新至服务器
  5107. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  5108. changeList = result;
  5109. const loadResult = {
  5110. update: selects,
  5111. };
  5112. const refreshData = ledgerTree.loadPostData(loadResult);
  5113. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  5114. ledgerTreeSpreadObj.loadExprToInput();
  5115. }, function () {
  5116. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  5117. return;
  5118. });
  5119. };
  5120. ledgerTreeSpreadObj.deletePress = function (sheet) {
  5121. if (!sheet.zh_setting) return;
  5122. // 暂时仅支持移除数量
  5123. const sel = sheet.getSelections()[0], datas = [];
  5124. const selects = [];
  5125. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  5126. let bDel = false;
  5127. const node = sheet.zh_tree.nodes[iRow];
  5128. const cInfo = _.find(changeList, { id: node.clid });
  5129. const data = { id: node.clid };
  5130. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  5131. const col = sheet.zh_setting.cols[iCol];
  5132. if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
  5133. node[col.field] = null;
  5134. cInfo[col.field] = null;
  5135. if (col.field !== 'oamount2') {
  5136. data.spamount = null;
  5137. cInfo.spamount = null;
  5138. node.spamount = null;
  5139. } else {
  5140. data[col.field] = null;
  5141. }
  5142. bDel = true;
  5143. }
  5144. }
  5145. if (bDel) {
  5146. datas.push(data);
  5147. selects.push(node);
  5148. }
  5149. }
  5150. if (datas.length > 0) {
  5151. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
  5152. changeList = result;
  5153. const loadResult = {
  5154. update: selects,
  5155. };
  5156. const refreshData = ledgerTree.loadPostData(loadResult);
  5157. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  5158. ledgerTreeSpreadObj.loadExprToInput();
  5159. }, function () {
  5160. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  5161. return;
  5162. });
  5163. }
  5164. return;
  5165. };
  5166. ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerTreeSpreadObj.editEnded);
  5167. ledgerSpread.bind(spreadNS.Events.ClipboardPasted, ledgerTreeSpreadObj.clipboardPasted);
  5168. SpreadJsObj.addDeleteBind(ledgerSpread, ledgerTreeSpreadObj.deletePress);
  5169. posSpreadObj.editEnded = function (e, info) {
  5170. if (!info.sheet.zh_setting) {
  5171. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5172. return;
  5173. }
  5174. const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  5175. const cInfo = _.find(changeList, { id: select.clid });
  5176. if (!cInfo) {
  5177. toastr.error('数据错误,请刷新页面重试');
  5178. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5179. return;
  5180. }
  5181. const col = info.sheet.zh_setting.cols[info.col];
  5182. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  5183. const orgValue = select[col.field];
  5184. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  5185. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5186. return;
  5187. }
  5188. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  5189. if (!node) {
  5190. toastr.error('数据错误,请选择台账节点后再试');
  5191. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5192. return;
  5193. }
  5194. if (col.type === 'Number') {
  5195. if (isNaN(validText)) {
  5196. toastr.error('不能输入其它非数字类型字符');
  5197. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5198. return;
  5199. }
  5200. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  5201. if (col.field !== 'oamount2') {
  5202. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  5203. const usedInfo = _.find(changeUsedData, {cbid: select.clid});
  5204. if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
  5205. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  5206. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5207. return;
  5208. } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
  5209. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  5210. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5211. return;
  5212. }
  5213. }
  5214. }
  5215. cInfo[col.field] = validText;
  5216. select[col.field] = validText;
  5217. if (col.field !== 'oamount2') {
  5218. cInfo.spamount = validText;
  5219. select.spamount = validText;
  5220. }
  5221. const data = {
  5222. id: select.clid,
  5223. };
  5224. if (col.field === 'oamount2') {
  5225. data[col.field] = select[col.field];
  5226. } else {
  5227. data.spamount = select.spamount;
  5228. }
  5229. // 更新至服务器
  5230. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  5231. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5232. const loadResult = {
  5233. update: [node],
  5234. };
  5235. const refreshData = ledgerTree.loadPostData(loadResult);
  5236. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  5237. }, function () {
  5238. select[col.field] = orgValue;
  5239. cInfo[col.field] = orgValue;
  5240. if (col.field !== 'oamount2') {
  5241. select.spamount = orgValue;
  5242. cInfo.spamount = orgValue;
  5243. }
  5244. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5245. });
  5246. };
  5247. posSpreadObj.clipboardPasted = function (e, info) {
  5248. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  5249. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  5250. }
  5251. const hint = {
  5252. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  5253. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  5254. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  5255. };
  5256. const range = info.cellRange;
  5257. const sortData = info.sheet.zh_data || [];
  5258. const data = [];
  5259. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  5260. let bPaste = true;
  5261. const curRow = range.row + iRow;
  5262. const cLData = { id: sortData[curRow].clid };
  5263. const hintRow = range.rowCount >= 1 ? curRow : '';
  5264. let sameCol = 0;
  5265. for (let iCol = 0; iCol < range.colCount; iCol++) {
  5266. const curCol = range.col + iCol;
  5267. let colSetting = info.sheet.zh_setting.cols[curCol];
  5268. if (!colSetting) continue;
  5269. let validText = info.sheet.getText(curRow, curCol);
  5270. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  5271. const orgValue = sortData[curRow][colSetting.field];
  5272. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  5273. sameCol++;
  5274. if (range.colCount === sameCol) {
  5275. bPaste = false;
  5276. }
  5277. continue;
  5278. }
  5279. if (colSetting.type === 'Number') {
  5280. if (isNaN(validText)) {
  5281. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  5282. bPaste = false;
  5283. continue;
  5284. }
  5285. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  5286. if (colSetting.field !== 'oamount2') {
  5287. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  5288. const usedInfo = _.find(changeUsedData, {id: sortData[curRow].clid});
  5289. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  5290. toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  5291. bPaste = false;
  5292. continue;
  5293. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  5294. toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  5295. bPaste = false;
  5296. continue;
  5297. }
  5298. }
  5299. }
  5300. sortData[curRow][colSetting.field] = validText;
  5301. if (colSetting.field === 'oamount2') {
  5302. cLData[colSetting.field] = validText;
  5303. } else {
  5304. cLData.spamount = validText;
  5305. sortData[curRow].spamount = validText;
  5306. }
  5307. }
  5308. if (bPaste) {
  5309. data.push(cLData);
  5310. // rowData.push(curRow);
  5311. } else {
  5312. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  5313. }
  5314. }
  5315. if (data.length === 0) {
  5316. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  5317. return;
  5318. }
  5319. console.log(data);
  5320. // 更新至服务器
  5321. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  5322. changeList = result;
  5323. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  5324. const loadResult = {
  5325. update: [node],
  5326. };
  5327. const refreshData = ledgerTree.loadPostData(loadResult);
  5328. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  5329. posSpreadObj.loadCurPosData();
  5330. }, function () {
  5331. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  5332. return;
  5333. });
  5334. };
  5335. posSpreadObj.deletePress = function (sheet) {
  5336. if (!sheet.zh_setting) return;
  5337. // 暂时仅支持移除数量
  5338. const sel = sheet.getSelections()[0], datas = [];
  5339. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  5340. let bDel = false;
  5341. const node = sheet.zh_data[iRow];
  5342. const cInfo = _.find(changeList, { id: node.clid });
  5343. const data = { id: node.clid };
  5344. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  5345. const col = sheet.zh_setting.cols[iCol];
  5346. if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
  5347. node[col.field] = null;
  5348. cInfo[col.field] = null;
  5349. if (col.field !== 'oamount2') {
  5350. data.spamount = null;
  5351. cInfo.spamount = null;
  5352. node.spamount = null;
  5353. } else {
  5354. data[col.field] = null;
  5355. }
  5356. bDel = true;
  5357. }
  5358. }
  5359. if (bDel) datas.push(data);
  5360. }
  5361. if (datas.length > 0) {
  5362. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
  5363. changeList = result;
  5364. const billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
  5365. const loadResult = {
  5366. update: [billsNode],
  5367. };
  5368. const refreshData = ledgerTree.loadPostData(loadResult);
  5369. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  5370. posSpreadObj.loadCurPosData();
  5371. }, function () {
  5372. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  5373. return;
  5374. });
  5375. }
  5376. return;
  5377. };
  5378. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  5379. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  5380. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  5381. }
  5382. // 切换清单模式
  5383. $('.change-mode').on('click', async function () {
  5384. if ($(this).hasClass('active')) {
  5385. return;
  5386. }
  5387. $('.change-mode').removeClass('active');
  5388. $(this).addClass('active');
  5389. const type = parseInt($(this).data('type'));
  5390. postData(window.location.pathname + '/save', { type:'change_mode', updateData: type }, function (result) {
  5391. changeList = result;
  5392. changeMode = type;
  5393. showMode(type);
  5394. });
  5395. });
  5396. let firstLoad = true;
  5397. function showMode(type) {
  5398. if (type === 0) {
  5399. $('.judge-hide').show();
  5400. $('.judge-show').attr("style","display:none !important");
  5401. if (changeOrder === 0) {
  5402. $('#upAndMoveBtn').attr("style","display:none !important");
  5403. }
  5404. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  5405. if (updateOrderList.length > 0) {
  5406. postData(window.location.pathname + '/save', { type:'changeOrder', postData: updateOrderList }, function (result) {
  5407. });
  5408. }
  5409. changeSpreadObj.reloadSheet(newChangeList);
  5410. changeSpread.refresh();
  5411. xmjSpread.refresh();
  5412. } else {
  5413. $('.judge-hide').attr("style","display:none !important");
  5414. $('.judge-show').show();
  5415. if (firstLoad) {
  5416. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  5417. if (updateOrderList.length > 0) {
  5418. postData(window.location.pathname + '/save', { type:'changeOrder', postData: updateOrderList }, function (result) {
  5419. });
  5420. }
  5421. firstLoad = false;
  5422. }
  5423. const {changeLedgers, changePoss} = makeLedgerAndPosData();
  5424. ledgerTree.loadDatas(changeLedgers);
  5425. pos.loadDatas(changePoss);
  5426. treeCalc.calculateAll(ledgerTree);
  5427. console.log(ledgerTree);
  5428. SpreadJsObj.loadSheetData(ledgerSheet, SpreadJsObj.DataType.Tree, ledgerTree);
  5429. ledgerTree.expandByCustom(() => { return true; });
  5430. SpreadJsObj.refreshTreeRowVisible(ledgerSheet);
  5431. SpreadJsObj.loadTopAndSelect(ledgerSheet, ckBillsSpread);
  5432. ledgerTreeSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
  5433. posSpreadObj.loadCurPosData();
  5434. SpreadJsObj.resetTopAndSelect(posSheet);
  5435. ledgerTreeSpreadObj.loadExprToInput();
  5436. ledgerSpread.refresh();
  5437. posSpread.refresh();
  5438. }
  5439. }
  5440. // 显示层次
  5441. (function (select, sheet) {
  5442. $(select).click(function () {
  5443. if (!sheet.zh_tree) return;
  5444. const tag = $(this).attr('tag');
  5445. const tree = sheet.zh_tree;
  5446. setTimeout(() => {
  5447. showWaitingView();
  5448. switch (tag) {
  5449. case "1":
  5450. case "2":
  5451. case "3":
  5452. case "4":
  5453. case "5":
  5454. tree.expandByLevel(parseInt(tag));
  5455. SpreadJsObj.refreshTreeRowVisible(sheet);
  5456. break;
  5457. case "last":
  5458. tree.expandByCustom(() => { return true; });
  5459. SpreadJsObj.refreshTreeRowVisible(sheet);
  5460. break;
  5461. case "leafXmj":
  5462. tree.expandToLeafXmj();
  5463. SpreadJsObj.refreshTreeRowVisible(sheet);
  5464. break;
  5465. }
  5466. closeWaitingView();
  5467. }, 100);
  5468. });
  5469. })('a[name=showLevel]', ledgerSheet);
  5470. function makeLedgerAndPosData() {
  5471. const changeLedgers = _.filter(ledgerList, function (item) {
  5472. return _.findIndex(changeList, { gcl_id: item.id}) !== -1;
  5473. });
  5474. // 找出所有父节点
  5475. if (changeLedgers.length > 0) {
  5476. const parentLedgers = [];
  5477. for (const node of changeLedgers) {
  5478. const cl = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  5479. if (cl) {
  5480. const cloneCl = _.cloneDeep(cl);
  5481. delete cloneCl.id;
  5482. delete cloneCl.name;
  5483. delete cloneCl.code;
  5484. node.clid = cl.id;
  5485. // cloneCl 合并到node中
  5486. Object.assign(node, cloneCl);
  5487. }
  5488. if (node.full_path && node.full_path !== '') {
  5489. const parentIds = node.full_path.split('-');
  5490. parentIds.length = parentIds.length - 1;
  5491. for (const id of parentIds) {
  5492. const lid = parseInt(id);
  5493. if (lid !== node.ledger_id && _.findIndex(parentLedgers, { ledger_id: lid }) === -1) {
  5494. parentLedgers.push(_.find(ledgerList, { ledger_id: lid }));
  5495. }
  5496. }
  5497. }
  5498. }
  5499. changeLedgers.push(...parentLedgers);
  5500. }
  5501. // 找出空白清单和签约清单
  5502. const otherChangeList = _.filter(changeList, function (item) {
  5503. return item.gcl_id === '' || item.gcl_id === null || item.gcl_id == 0;
  5504. });
  5505. if (otherChangeList.length > 0) {
  5506. // 判断changeLedgers中是否已经存在第一部分
  5507. let firstChangeLedger = _.find(changeLedgers, { order: 1, level: 1 });
  5508. let firstOrder = 1;
  5509. if (firstChangeLedger) {
  5510. const firstChilds = _.filter(changeLedgers, { ledger_pid: firstChangeLedger.ledger_id });
  5511. firstOrder = _.maxBy(firstChilds, 'order').order + 1;
  5512. }
  5513. let maxLedgerId = changeLedgers.length > 0 ? _.maxBy(changeLedgers, 'ledger_id').ledger_id + 1 : 2;
  5514. if (!firstChangeLedger) {
  5515. const firstLedger = _.find(ledgerList, { order: 1, level: 1 });
  5516. if (firstLedger) {
  5517. changeLedgers.push(firstLedger);
  5518. firstChangeLedger = firstLedger;
  5519. } else {
  5520. 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 };
  5521. changeLedgers.push(firstChangeLedger);
  5522. }
  5523. }
  5524. for (const cl of otherChangeList) {
  5525. const cloneCl = _.cloneDeep(cl);
  5526. cloneCl.b_code = cloneCl.code;
  5527. cloneCl.code = null;
  5528. cloneCl.clid = cl.id;
  5529. cloneCl.level = 2;
  5530. cloneCl.order = firstOrder;
  5531. cloneCl.is_leaf = 1;
  5532. cloneCl.ledger_pid = firstChangeLedger.ledger_id;
  5533. cloneCl.ledger_id = maxLedgerId;
  5534. cloneCl.full_path = firstChangeLedger.full_path + '-' + maxLedgerId;
  5535. changeLedgers.push(cloneCl);
  5536. maxLedgerId++;
  5537. firstOrder++;
  5538. }
  5539. }
  5540. const changePoss = _.filter(posList, function (item) {
  5541. return _.findIndex(changeList, { mx_id: item.id }) !== -1;
  5542. });
  5543. for (const cp of changePoss) {
  5544. const cl = _.find(changeList, { mx_id: cp.id });
  5545. if (cl) {
  5546. const cloneCl = _.cloneDeep(cl);
  5547. delete cloneCl.id;
  5548. delete cloneCl.lid;
  5549. delete cloneCl.name;
  5550. cp.clid = cl.id;
  5551. // cloneCl 合并到cp中
  5552. Object.assign(cp, cloneCl);
  5553. }
  5554. }
  5555. return { changeLedgers, changePoss };
  5556. }
  5557. // 审批流程展示与隐藏
  5558. $('#show-table-detail').on('click', function (e) {
  5559. if($(e.target).is('label')){
  5560. return;
  5561. }
  5562. ledgerTreeSpreadObj.showHideAudit($(this).is(':checked'));
  5563. posSpreadObj.showHideAudit($(this).is(':checked'));
  5564. changeSpreadObj.showHideAudit($(this).is(':checked'));
  5565. xmjSpreadObj.showHideAudit($(this).is(':checked'));
  5566. });
  5567. const cca = getLocalCache('change-checkbox-account-' + accountId);
  5568. if (cca !== null && cca !== undefined) {
  5569. $('#customCheck1').prop('checked', cca !== 'false');
  5570. }
  5571. changeSpreadSheet.setColumnVisible(6,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5572. xmjSheet.setColumnVisible(7,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5573. ledgerSheet.setColumnVisible(6,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5574. posSheet.setColumnVisible(2,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5575. // 变更详情展示和隐藏
  5576. $('.change-detail-checkbox').on('click', function (e) {
  5577. if($(e.target).is('label')){
  5578. return;
  5579. }
  5580. // // 设置用户项目本地记录展示和隐藏情况
  5581. setLocalCache('change-checkbox-account-'+ accountId, $(this).is(':checked'));
  5582. changeSpreadSheet.setColumnVisible(6,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5583. xmjSheet.setColumnVisible(7,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5584. ledgerSheet.setColumnVisible(6,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5585. posSheet.setColumnVisible(2,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5586. });
  5587. $.subMenu({
  5588. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  5589. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  5590. key: 'menu.1.0.0',
  5591. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  5592. callback: function (info) {
  5593. if (info.mini) {
  5594. $('.panel-title').addClass('fluid');
  5595. $('#sub-menu').removeClass('panel-sidebar');
  5596. } else {
  5597. $('.panel-title').removeClass('fluid');
  5598. $('#sub-menu').addClass('panel-sidebar');
  5599. }
  5600. autoFlashHeight();
  5601. changeSpread.refresh();
  5602. xmjSpread.refresh();
  5603. ledgerSpread.refresh();
  5604. posSpread.refresh();
  5605. }
  5606. });
  5607. $.divResizer({
  5608. select: '#right-spr',
  5609. callback: function () {
  5610. changeSpread.refresh();
  5611. xmjSpread.refresh();
  5612. ledgerSpread.refresh();
  5613. posSpread.refresh();
  5614. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  5615. setLocalCache('change_information_width', width);
  5616. $('#left-header').css('min-width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
  5617. }
  5618. });
  5619. $('.sjs-height-change').height($('.sjs-height-1').height() - $('#list-tab').outerHeight() - 10);
  5620. changeSpread.refresh();
  5621. xmjSpread.refresh();
  5622. ledgerSpread.refresh();
  5623. posSpread.refresh();
  5624. // 根据浏览器记录展开收起
  5625. if (getLocalCache('change_information_width')) {
  5626. $('#left-view').css('width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
  5627. $('#right-view').css('width', getLocalCache('change_information_width') + '%');
  5628. $('#left-header').css('min-width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
  5629. changeSpread.refresh();
  5630. xmjSpread.refresh();
  5631. ledgerSpread.refresh();
  5632. posSpread.refresh();
  5633. } else {
  5634. $('#left-header').css('min-width', '33.33%');
  5635. }
  5636. $.divResizer({
  5637. select: '#change-pos-resize',
  5638. callback: function () {
  5639. $('.sjs-height-change').height($('.sjs-height-1').height() - $('#list-tab').outerHeight() - 10);
  5640. changeSpread.refresh();
  5641. ledgerSpread.refresh();
  5642. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  5643. $(".sp-wrap").height(bcontent-30);
  5644. posSpread.refresh();
  5645. xmjSpread.refresh();
  5646. }
  5647. });
  5648. if (!readOnly) {
  5649. // 自动编号
  5650. $('.reduction-code').click(function () {
  5651. const code = $(this).attr('data-code');
  5652. $('input[name="code"]').val(code);
  5653. changeInfo.code = $('input[name="code"]').val();
  5654. judgeChange();
  5655. });
  5656. // 记录变更信息操作
  5657. $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
  5658. changeInfo[$(this).attr('name')] = $(this).val();
  5659. judgeChange();
  5660. });
  5661. $('body').on('valuechange', '#change_form textarea', function (e, previous) {
  5662. changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
  5663. judgeChange();
  5664. });
  5665. $('body').on('change', '#change_form select', function (e, previous) {
  5666. changeInfo[$(this).attr('name')] = $(this).val();
  5667. judgeChange();
  5668. });
  5669. $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
  5670. changeInfo[$(this).attr('name')] = $(this).val();
  5671. judgeChange();
  5672. });
  5673. $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
  5674. const typecheck = [];
  5675. $.each($('#change_form input[name="type[]"]:checked'), function () {
  5676. typecheck.push($(this).val());
  5677. });
  5678. changeInfo.type = typecheck.join(',');
  5679. judgeChange();
  5680. });
  5681. // 保存修改ajax提交(不刷新页面)
  5682. $('.save_change_btn').on('click', function () {
  5683. // 保存修改modal
  5684. if ($('input[name="code"]').val() === '') {
  5685. toastr.error('申请编号不能为空!');
  5686. return;
  5687. }
  5688. if ($('input[name="name"]').val() === '') {
  5689. toastr.error('变更工程名称不能为空!');
  5690. return;
  5691. }
  5692. // 换行更改并提交
  5693. changeInfo.content = changeInfo.content.replace(/<br><br>/g, '\r\n');
  5694. changeInfo.basis = changeInfo.basis.replace(/<br><br>/g, '\r\n');
  5695. changeInfo.expr = changeInfo.expr.replace(/<br><br>/g, '\r\n');
  5696. changeInfo.memo = changeInfo.memo.replace(/<br><br>/g, '\r\n');
  5697. changeInfo.company = $('#change_form select[name="company"]').val();
  5698. // 后改为br
  5699. // 更新至服务器
  5700. postData(window.location.pathname + '/save', { type:'info', updateData: changeInfo }, function (result) {
  5701. $('.reduction-code').attr('data-code', $('input[name="code"]').val());
  5702. toastr.success(result ? result.msg : '');
  5703. $('#show-save-btn').hide();
  5704. $('#sp-btn').show();
  5705. $('.title-main').removeClass('bg-warning');
  5706. changeInfo.content = changeInfo.content.replace(/[\r\n]/g, '<br>');
  5707. changeInfo.basis = changeInfo.basis.replace(/[\r\n]/g, '<br>');
  5708. changeInfo.expr = changeInfo.expr.replace(/[\r\n]/g, '<br>');
  5709. changeInfo.memo = changeInfo.memo.replace(/[\r\n]/g, '<br>');
  5710. back_changeInfo = Object.assign({}, changeInfo);
  5711. if (result.changeList) {
  5712. deLimit = result.deLimit;
  5713. changeList = result.changeList;
  5714. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  5715. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  5716. const [newChangeList] = changeSpreadObj.makeNewChangeList();
  5717. changeSpreadObj.reloadSheet(newChangeList);
  5718. }
  5719. });
  5720. return false;
  5721. });
  5722. $('#cancel_change').on('click', function () {
  5723. $('#show-save-btn').hide();
  5724. $('#sp-btn').show();
  5725. $('.title-main').removeClass('bg-warning');
  5726. if (!isObjEqual(changeInfo, back_changeInfo)) {
  5727. changeFormRemake();
  5728. }
  5729. toastr.success('已还原到上次保存状态');
  5730. });
  5731. // 判断是否有更改过
  5732. function judgeChange() {
  5733. let change = false;
  5734. console.log(changeInfo, back_changeInfo);
  5735. if (!isObjEqual(changeInfo, back_changeInfo)) {
  5736. change = true;
  5737. }
  5738. if (change) {
  5739. $('#show-save-btn').show();
  5740. $('#sp-btn').hide();
  5741. $('.title-main').addClass('bg-warning');
  5742. } else {
  5743. $('#show-save-btn').hide();
  5744. $('#sp-btn').show();
  5745. $('.title-main').removeClass('bg-warning');
  5746. }
  5747. }
  5748. function changeFormRemake() {
  5749. changeInfo = Object.assign({}, back_changeInfo);
  5750. $('#change_form input[name="code"]').val(changeInfo.code);
  5751. $('#change_form input[name="name"]').val(changeInfo.name);
  5752. $('#change_form input[name="peg"]').val(changeInfo.peg);
  5753. $('#change_form input[name="org_name"]').val(changeInfo.org_name);
  5754. $('#change_form input[name="org_code"]').val(changeInfo.org_code);
  5755. $('#change_form input[name="new_name"]').val(changeInfo.new_name);
  5756. $('#change_form input[name="new_code"]').val(changeInfo.new_code);
  5757. $('#change_form textarea[name="content"]').val(changeInfo.content.replace(/<br><br>/g, '\r\n'));
  5758. $('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/<br><br>/g, '\r\n'));
  5759. $('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/<br><br>/g, '\r\n'));
  5760. $('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/<br><br>/g, '\r\n'));
  5761. $('#change_form select[name="type"]').val(changeInfo.type);
  5762. $('#change_form select[name="class"]').val(changeInfo.class);
  5763. $('#change_form select[name="quality"]').val(changeInfo.quality);
  5764. $('#change_form select[name="company"]').val(changeInfo.company);
  5765. $('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
  5766. $('#change_form input[name="state"][value="'+ changeInfo.state +'"]').prop('checked', true);
  5767. $('#change_form input[name="type[]"]').prop('checked', false);
  5768. const typecheck = changeInfo.type.split(',');
  5769. for (const type of typecheck) {
  5770. $('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
  5771. }
  5772. }
  5773. $('.checkChangeFrom').on('click', function () {
  5774. let returnFlag = false;
  5775. // 表单判断
  5776. if ($('input[name="code"]').val() === '') {
  5777. toastr.error('申请编号不能为空!');
  5778. returnFlag = true;
  5779. }
  5780. if ($('input[name="name"]').val() === '') {
  5781. toastr.error('变更工程名称不能为空!');
  5782. returnFlag = true;
  5783. }
  5784. if ($('textarea[name="content"]').val() === '') {
  5785. toastr.error('工程变更理由及内容不能为空!');
  5786. returnFlag = true;
  5787. }
  5788. if (changeList.length === 0) {
  5789. toastr.error('请添加变更清单!');
  5790. returnFlag = true;
  5791. } else {
  5792. const whiteList = _.filter(changeList, item => item.lid == 0 && (item.name === '' || item.name === null));
  5793. if (whiteList.length > 0) {
  5794. toastr.error('存在空白清单未完整填写数据(名称不可为空)');
  5795. returnFlag = true;
  5796. }
  5797. // for (const [i,cl] of changeSpreadSheet.zh_data.entries()) {
  5798. // if (cl.name === '') {
  5799. // toastr.error('清单第' + (i+1) + '行未完整填写数据(名称不可为空)');
  5800. // returnFlag = true;
  5801. // }
  5802. // }
  5803. }
  5804. if(!checkAuditorFrom ()) {
  5805. returnFlag = true;
  5806. }
  5807. // 判断非空白变更清单是否有重复值(gcl_id及mx_id),如果存在完全相同则需要提示并删除,上报失败,这功能主要是因为清单数据过多服务器处理不过来偶然出现
  5808. const doubleList = findDuplicates(_.filter(changeList, item => item.lid != 0));
  5809. console.log(doubleList);
  5810. if (doubleList.length > 0) {
  5811. for (const double of doubleList) {
  5812. const msgIndex = [];
  5813. for (const one of double) {
  5814. const index = _.findIndex(changeSpreadSheet.zh_data[double[0].order - 1].children, { id: one.id });
  5815. if (index !== -1) msgIndex.push(index+1);
  5816. }
  5817. if (msgIndex.length > 0) {
  5818. toastr.error('第 ' + double[0].order + ' 行' + double[0].code + '清单项目节第 ' + msgIndex.splice(',') + '行重复,请只保留一条数据');
  5819. }
  5820. }
  5821. returnFlag = true;
  5822. }
  5823. if (returnFlag) {
  5824. return false;
  5825. }
  5826. postData(window.location.pathname + '/audit/start', {}, function (result) {
  5827. window.location.reload();
  5828. })
  5829. });
  5830. // 检查上报情况
  5831. function checkAuditorFrom () {
  5832. if ($('#auditList li').length === 0) {
  5833. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  5834. toastr.error('请联系管理员添加审批人');
  5835. } else {
  5836. toastr.error('请先选择审批人,再上报数据');
  5837. }
  5838. return false;
  5839. }
  5840. return true;
  5841. }
  5842. // 找出数组中相同的清单
  5843. function findDuplicates(arr, keys = ['lid', 'gcl_id', 'mx_id']) {
  5844. const groupedData = _.groupBy(arr, item => JSON.stringify(_.pick(item, keys)));
  5845. const duplicates = _.filter(groupedData, group => group.length > 1);
  5846. return _.values(duplicates);
  5847. }
  5848. }
  5849. if (shenpiPower) {
  5850. // 审批提交与判断
  5851. $('.approval-btn').on('click', function () {
  5852. // 判断审批状态
  5853. let returnflag = true;
  5854. const pData = {
  5855. change_id: $('#changeId').val(),
  5856. w_code: $.trim($('#w_code').val()),
  5857. }
  5858. if ($(this).hasClass('btn-success')) {
  5859. const sdesc = $('#success-approval').find('textarea').val();
  5860. if (sdesc === '') {
  5861. toastr.error('审批意见不能为空!');
  5862. returnflag = false;
  5863. }
  5864. if ($('input[name="p_code"]').val() === '') {
  5865. toastr.error('变更令号(批复编号)不能为空!');
  5866. returnflag = false;
  5867. } else if ($('input[name="p_code"]').val() !== undefined) {
  5868. $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
  5869. const postData2 = {
  5870. p_code: $('input[name="p_code"]').val(),
  5871. };
  5872. postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData2, function (result) {
  5873. }, function (data) {
  5874. returnflag = false;
  5875. });
  5876. pData.p_code = $('input[name="p_code"]').val();
  5877. }
  5878. if(returnflag) {
  5879. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  5880. $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  5881. if ($('#warning-text').length) $('#warning-text').remove();
  5882. // $('#success-approval').submit();
  5883. pData.status = auditConst.status.checked;
  5884. pData.sdesc = sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  5885. }
  5886. } else {
  5887. const sdesc = $('#fail-approval').find('textarea').val();
  5888. if (sdesc === '') {
  5889. toastr.error('审批意见不能为空!');
  5890. returnflag = false;
  5891. }
  5892. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  5893. if (type === undefined) {
  5894. // toastr.error('请选择退回类型!');
  5895. if (!$('#warning-text').length) {
  5896. $('#change-back-content').append('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  5897. }
  5898. returnflag = false;
  5899. }
  5900. if(returnflag) {
  5901. $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  5902. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  5903. // $('#fail-approval').submit();
  5904. pData.status = type;
  5905. pData.sdesc = sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  5906. }
  5907. }
  5908. if (pData.status) {
  5909. console.log(pData);
  5910. postData('/tender/' + $('#tenderId').val() + '/change/approval', pData, function (result) {
  5911. window.location.reload();
  5912. });
  5913. }
  5914. });
  5915. const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  5916. if (showWaiting) showWaitingView();
  5917. $.ajax({
  5918. type:"POST",
  5919. url: url,
  5920. data: {'data': JSON.stringify(data)},
  5921. dataType: 'json',
  5922. cache: false,
  5923. async: false,
  5924. timeout: 60000,
  5925. beforeSend: function(xhr) {
  5926. let csrfToken = Cookies.get('csrfToken_j');
  5927. xhr.setRequestHeader('x-csrf-token', csrfToken);
  5928. },
  5929. success: function(result){
  5930. if (result.err === 0) {
  5931. if (successCallback) {
  5932. successCallback(result.data);
  5933. }
  5934. } else {
  5935. toastr.error(result.msg);
  5936. if (errorCallBack) {
  5937. errorCallBack(result.msg);
  5938. }
  5939. }
  5940. if (showWaiting) closeWaitingView();
  5941. },
  5942. error: function(jqXHR, textStatus, errorThrown){
  5943. toastr.error('error: ' + textStatus + " " + errorThrown);
  5944. if (errorCallBack) {
  5945. errorCallBack();
  5946. }
  5947. if (showWaiting) closeWaitingView();
  5948. }
  5949. });
  5950. };
  5951. }
  5952. // 重新审批获取手机验证码
  5953. // 获取验证码
  5954. let isPosting = false;
  5955. $(".get-code").on('click', function() {
  5956. if (isPosting) {
  5957. return false;
  5958. }
  5959. const btn = $(this);
  5960. $.ajax({
  5961. url: '/profile/code?_csrf_j=' + csrf,
  5962. type: 'post',
  5963. data: { mobile: authMobile, type: 'shenpi' },
  5964. dataTye: 'json',
  5965. error: function() {
  5966. isPosting = false;
  5967. },
  5968. beforeSend: function() {
  5969. isPosting = true;
  5970. },
  5971. success: function(response) {
  5972. isPosting = false;
  5973. if (response.err === 0) {
  5974. codeSuccess(btn);
  5975. $("input[name='code']").removeAttr('readonly');
  5976. $("#re-shenpi-btn").removeAttr('disabled');
  5977. $("#re-shenpi-btn2").removeAttr('disabled');
  5978. } else {
  5979. toast(response.msg, 'error');
  5980. }
  5981. }
  5982. });
  5983. });
  5984. if (readOnly && !shenpiPower) {
  5985. // 记录变更信息操作
  5986. $('body').on('valuechange', '#w_code', function (e, previous) {
  5987. const new_w_code = $(this).val();
  5988. if (new_w_code !== w_code) {
  5989. $('#show-save-btn').show();
  5990. $('#sp-btn').hide();
  5991. $('.title-main').addClass('bg-warning');
  5992. } else {
  5993. $('#show-save-btn').hide();
  5994. $('#sp-btn').show();
  5995. $('.title-main').removeClass('bg-warning');
  5996. }
  5997. });
  5998. // 保存修改ajax提交(不刷新页面)
  5999. $('.save_change_btn').on('click', function () {
  6000. const new_w_code = $('#w_code').val();
  6001. // 后改为br
  6002. // 更新至服务器
  6003. postData(window.location.pathname + '/save', { type:'info', updateData: { w_code: new_w_code } }, function (result) {
  6004. toastr.success(result ? result.msg : '');
  6005. $('#show-save-btn').hide();
  6006. $('#sp-btn').show();
  6007. $('.title-main').removeClass('bg-warning');
  6008. w_code = new_w_code;
  6009. });
  6010. return false;
  6011. });
  6012. $('#cancel_change').on('click', function () {
  6013. $('#show-save-btn').hide();
  6014. $('#sp-btn').show();
  6015. $('.title-main').removeClass('bg-warning');
  6016. $('#w_code').val(w_code);
  6017. // toastr.success('已还原到上次保存状态');
  6018. });
  6019. }
  6020. });
  6021. /**
  6022. * 获取成功后的操作
  6023. *
  6024. * @param {Object} btn - 点击的按钮
  6025. * @return {void}
  6026. */
  6027. function codeSuccess(btn) {
  6028. let counter = 60;
  6029. btn.addClass('disabled').text('重新获取 ' + counter + 'S');
  6030. btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
  6031. const bindBtn = $("#bind-btn");
  6032. bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
  6033. const countDown = setInterval(function() {
  6034. const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
  6035. // 倒数结束后
  6036. if (countString === '') {
  6037. clearInterval(countDown);
  6038. btn.removeClass('disabled');
  6039. }
  6040. const text = '重新获取' + countString;
  6041. btn.text(text);
  6042. counter -= 1;
  6043. }, 1000);
  6044. }
  6045. function calcChangePrice() {
  6046. let positive_tp = 0;
  6047. let negative_tp = 0;
  6048. let valuation_tp = 0;
  6049. let unvaluation_tp = 0;
  6050. let new_tp = 0;
  6051. // 先汇总再统计金额
  6052. const gclChangeList = _.uniq(_.map(changeList, 'gcl_id'));
  6053. for (const g of gclChangeList) {
  6054. if (g) {
  6055. const list = _.filter(changeList, { gcl_id: g });
  6056. let spamount = 0;
  6057. let valuation_amount = 0;
  6058. let unvaluation_amount = 0;
  6059. let unitPrice = 0;
  6060. for (const c of list) {
  6061. if (c.spamount) {
  6062. spamount = ZhCalc.add(spamount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
  6063. unitPrice = c.unit_price;
  6064. if (c.is_valuation) {
  6065. valuation_amount = ZhCalc.add(valuation_amount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
  6066. } else {
  6067. unvaluation_amount = ZhCalc.add(unvaluation_amount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
  6068. }
  6069. }
  6070. }
  6071. const price = ZhCalc.round(ZhCalc.mul(spamount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit);
  6072. const valuation_price = ZhCalc.round(ZhCalc.mul(valuation_amount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit) || 0;
  6073. const unvaluation_price = ZhCalc.round(ZhCalc.mul(unvaluation_amount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit) || 0;
  6074. valuation_tp = ZhCalc.add(valuation_tp, valuation_price);
  6075. unvaluation_tp = ZhCalc.add(unvaluation_tp, unvaluation_price);
  6076. new_tp = ZhCalc.add(new_tp, price);
  6077. if (price >= 0) {
  6078. positive_tp = ZhCalc.add(positive_tp, price);
  6079. } else {
  6080. negative_tp = ZhCalc.add(negative_tp, price);
  6081. }
  6082. } else {
  6083. const list = _.filter(changeList, { gcl_id: g });
  6084. for (const c of list) {
  6085. if (c.spamount) {
  6086. const price = ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
  6087. new_tp = ZhCalc.add(new_tp, price);
  6088. if (price >= 0) {
  6089. positive_tp = ZhCalc.add(positive_tp, price);
  6090. } else {
  6091. negative_tp = ZhCalc.add(negative_tp, price);
  6092. }
  6093. if (c.is_valuation) {
  6094. valuation_tp = ZhCalc.add(valuation_tp, price);
  6095. } else {
  6096. unvaluation_tp = ZhCalc.add(unvaluation_tp, price);
  6097. }
  6098. }
  6099. }
  6100. }
  6101. }
  6102. const updateTpList = {};
  6103. let updateFlag = false;
  6104. if (changeTp !== new_tp) {
  6105. updateTpList.total_price = new_tp;
  6106. updateFlag = true;
  6107. }
  6108. if (positive_tp !== changePp) {
  6109. updateTpList.positive_tp = positive_tp;
  6110. updateFlag = true;
  6111. }
  6112. if (negative_tp !== changeNp) {
  6113. updateTpList.negative_tp = negative_tp;
  6114. updateFlag = true;
  6115. }
  6116. if (valuation_tp !== changeVp) {
  6117. updateTpList.valuation_tp = valuation_tp;
  6118. updateFlag = true;
  6119. }
  6120. if (unvaluation_tp !== changeUp) {
  6121. updateTpList.unvaluation_tp = unvaluation_tp;
  6122. updateFlag = true;
  6123. }
  6124. if (updateFlag) {
  6125. console.log(updateTpList);
  6126. postData(window.location.pathname + '/save', { type:'update_tp', updateData: updateTpList }, function () {
  6127. changePp = positive_tp;
  6128. changeNp = negative_tp;
  6129. changeVp = valuation_tp;
  6130. changeUp = unvaluation_tp;
  6131. changeTp = new_tp;
  6132. });
  6133. }
  6134. }
  6135. function checkAndChange(changeListData) {
  6136. // 根据已添加的清单显示
  6137. if (changeList.length > 0 && changeList[0]) {
  6138. const removeList = [];
  6139. const updateList = [];
  6140. const updateGclIdList = [];
  6141. for (const [index,clinfo] of changeList.entries()) {
  6142. if (clinfo.lid != 0) {
  6143. let listinfo = changeListData.find(function (item) {
  6144. 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);
  6145. });
  6146. if (listinfo === undefined || (clinfo.lid && clinfo.gcl_id && clinfo.lid !== clinfo.gcl_id)) {
  6147. // 有可能这部分台账发生变化,此时要更新清单lid信息,防止数据丢失
  6148. const newlistinfo = changeListData.find(function (item) {
  6149. 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 }));
  6150. });
  6151. if ((listinfo === undefined && newlistinfo) || (listinfo && newlistinfo && !isObjEqual(listinfo, newlistinfo))) {
  6152. listinfo = newlistinfo;
  6153. updateList.push({id: clinfo.id, lid: newlistinfo.leafXmjs[0].gcl_id});
  6154. // 更新lid
  6155. changeList[index].lid = newlistinfo.leafXmjs[0].gcl_id;
  6156. }
  6157. }
  6158. if (listinfo === undefined) {
  6159. // 针对旧数据获取清单信息
  6160. listinfo = changeListData[clinfo.lid - 1];
  6161. if (listinfo === undefined) {
  6162. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  6163. if (changeStatus !== auditConst.status.revise) {
  6164. removeList.push(clinfo);
  6165. } else {
  6166. updateList.push(makeWhiteList(clinfo));
  6167. }
  6168. continue;
  6169. }
  6170. }
  6171. const info = makePushBwmx(clinfo, listinfo, removeList, updateList);
  6172. if (info && _.findIndex(changeLedgerList, { id: clinfo.gcl_id }) !== -1) {
  6173. // 可能因为升降级关系:细目,分部分项等会发生变化,更新清单
  6174. const updateInfo = {};
  6175. if (info.code !== clinfo.xmj_code) {
  6176. updateInfo.xmj_code = info.code;
  6177. changeList[index].xmj_code = info.code;
  6178. }
  6179. if (info.jldy !== clinfo.xmj_jldy) {
  6180. updateInfo.xmj_jldy = info.jldy;
  6181. changeList[index].xmj_jldy = info.jldy;
  6182. }
  6183. if (info.dwgc !== clinfo.xmj_dwgc) {
  6184. updateInfo.xmj_dwgc = info.dwgc;
  6185. changeList[index].xmj_dwgc = info.dwgc;
  6186. }
  6187. if (info.fbgc !== clinfo.xmj_fbgc) {
  6188. updateInfo.xmj_fbgc = info.fbgc;
  6189. changeList[index].xmj_fbgc = info.fbgc;
  6190. }
  6191. if (info.fxgc !== clinfo.xmj_fxgc) {
  6192. updateInfo.xmj_fxgc = info.fxgc;
  6193. changeList[index].xmj_fxgc = info.fxgc;
  6194. }
  6195. if (!_.isEmpty(updateInfo) && _.indexOf(updateGclIdList, clinfo.gcl_id) === -1) {
  6196. updateGclIdList.push(clinfo.gcl_id);
  6197. // updateInfo.gcl_id = info.id;
  6198. updateList.push({ row: updateInfo, where: { tid: tenderId, gcl_id: clinfo.gcl_id } });
  6199. }
  6200. }
  6201. }
  6202. }
  6203. if(updateList.length > 0) {
  6204. console.log(updateList);
  6205. postData(window.location.pathname + '/save', { type:'update_list', updateData: updateList }, function (result) {
  6206. }, function () {
  6207. });
  6208. }
  6209. if(removeList.length > 0) {
  6210. _.pullAll(changeList, removeList);
  6211. postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
  6212. }, function () {
  6213. });
  6214. }
  6215. }
  6216. }
  6217. function makePushBwmx(clinfo, listinfo, removeList, updateList) {
  6218. let info = '';
  6219. const checkKey = ['name', 'code', 'unit', 'unit_price'];
  6220. const checkLeafKey = ['oamount', 'bwmx', 'code', 'dwgc', 'fbgc', 'fxgc', 'jldy'];
  6221. if (listinfo.leafXmjs !== undefined) {
  6222. const leafInfo = listinfo.leafXmjs.find(function (item) {
  6223. // 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));
  6224. const flag = item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id));
  6225. if (flag && item.code === clinfo.xmj_code) {
  6226. return flag && item.code === clinfo.xmj_code;
  6227. }
  6228. return flag;
  6229. });
  6230. if (leafInfo) {
  6231. const oneUpdate = { id: clinfo.id };
  6232. let needUpdate = false;
  6233. // 判断要不要更新名称,单位,原数量,单价
  6234. checkKey.forEach(function (key) {
  6235. if ((key === 'name' || key === 'unit') && listinfo[key] === null) {
  6236. listinfo[key] = '';
  6237. }
  6238. if (listinfo[key] !== clinfo[key]) {
  6239. oneUpdate[key] = listinfo[key];
  6240. clinfo[key] = listinfo[key];
  6241. if (key === 'unit') {
  6242. const changeKey = ['oamount', 'oamount2', 'camount'];
  6243. changeKey.forEach(function (key) {
  6244. const value = ZhCalc.round(clinfo[key], findDecimal(listinfo[key]));
  6245. if (value !== clinfo[key]) {
  6246. oneUpdate[key] = value;
  6247. clinfo[key] = value;
  6248. }
  6249. });
  6250. }
  6251. // else if (key === 'unit_price') {
  6252. // // 可能要更新总金额了
  6253. // oneUpdate[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
  6254. // clinfo[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
  6255. // }
  6256. needUpdate = true;
  6257. }
  6258. });
  6259. checkLeafKey.forEach(function (key) {
  6260. // 只有数量是对比leafInfo,其它对比listinfo,且有些值需要重新计算
  6261. if (key === 'oamount') {
  6262. if (leafInfo.quantity !== clinfo[key]) {
  6263. oneUpdate[key] = leafInfo.quantity;
  6264. clinfo[key] = leafInfo.quantity;
  6265. needUpdate = true;
  6266. }
  6267. } else if (key === 'bwmx') {
  6268. if (leafInfo[key] !== undefined && leafInfo[key] !== clinfo[key]) {
  6269. oneUpdate[key] = leafInfo[key];
  6270. clinfo[key] = leafInfo[key];
  6271. needUpdate = true;
  6272. } else if (leafInfo[key] === undefined && leafInfo.jldy !== clinfo[key]) {
  6273. oneUpdate[key] = leafInfo.jldy;
  6274. clinfo[key] = leafInfo.jldy;
  6275. needUpdate = true;
  6276. }
  6277. } else {
  6278. if (leafInfo[key] !== clinfo['xmj_' + key]) {
  6279. oneUpdate['xmj_' + key] = leafInfo[key];
  6280. clinfo['xmj_' + key] = leafInfo[key];
  6281. needUpdate = true;
  6282. }
  6283. }
  6284. });
  6285. if (needUpdate) {
  6286. updateList.push(oneUpdate);
  6287. }
  6288. info = leafInfo;
  6289. } else {
  6290. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  6291. if (changeStatus !== auditConst.status.revise) {
  6292. removeList.push(clinfo);
  6293. } else {
  6294. updateList.push(makeWhiteList(clinfo));
  6295. }
  6296. return false;
  6297. }
  6298. }
  6299. return info;
  6300. }
  6301. function makeWhiteList(clinfo) {
  6302. clinfo.lid = 0;
  6303. clinfo.xmj_code = null;
  6304. clinfo.xmj_jldy = null;
  6305. clinfo.xmj_dwgc = null;
  6306. clinfo.xmj_fbgc = null;
  6307. clinfo.xmj_fxgc = null;
  6308. clinfo.gcl_id = '';
  6309. clinfo.mx_id = '';
  6310. return clinfo;
  6311. }
  6312. function isObjEqual(o1,o2){
  6313. var props1 = Object.getOwnPropertyNames(o1);
  6314. var props2 = Object.getOwnPropertyNames(o2);
  6315. if (props1.length != props2.length) {
  6316. return false;
  6317. }
  6318. for (var i = 0,max = props1.length; i < max; i++) {
  6319. var propName = props1[i];
  6320. if (o1[propName] !== o2[propName]) {
  6321. return false;
  6322. }
  6323. }
  6324. return true;
  6325. }
  6326. function findDecimal(unit) {
  6327. let value = precision.other.value;
  6328. const changeUnits = precision;
  6329. for (const d in changeUnits) {
  6330. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  6331. value = changeUnits[d].value;
  6332. break;
  6333. }
  6334. }
  6335. return value;
  6336. }
  6337. // 生成附件列表
  6338. function getAllList(currPageNum = 1) {
  6339. // 每页最多几个附件
  6340. const pageCount = 20;
  6341. // 附件总数
  6342. const total = attData.length;
  6343. // 总页数
  6344. const pageNum = Math.ceil(total/pageCount);
  6345. $('#totalPage').text(pageNum);
  6346. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  6347. // 当前页附件内容
  6348. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  6349. currPageFileData = currPageAttData;
  6350. let html = '';
  6351. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  6352. for(const [index,att] of currPageAttData.entries()) {
  6353. html += `<tr>
  6354. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  6355. <td>${((currPageNum-1)*pageCount)+index+1}</td>
  6356. <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>
  6357. <td>${moment(att.in_time * 1000).format('YYYY-MM-DD')}<br>${bytesToSize(att.filesize)}</td>
  6358. <td>
  6359. <a href="/change/download/file/${att.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`
  6360. html += (att.uid === accountId && ((changeStatus === auditConst.status.checked ? Boolean(att.extra_upload) : true) || deleteFilePermission)) ?
  6361. `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
  6362. html += `</td>`;
  6363. }
  6364. $('#attList').html(html);
  6365. $('#attList').on('click', 'tr', function() {
  6366. $('#attList tr').removeClass('bg-light');
  6367. $(this).addClass('bg-light');
  6368. })
  6369. }
  6370. function bytesToSize(bytes) {
  6371. if (parseInt(bytes) === 0) return '0 B';
  6372. const k = 1024;
  6373. const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  6374. const i = Math.floor(Math.log(bytes) / Math.log(k));
  6375. // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
  6376. return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
  6377. }
  6378. // 判断是否是已结算清单
  6379. function checkIsSettle(data) {
  6380. const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
  6381. if (info && info.settle_status && info.settle_status === settleStatus.finish) {
  6382. return true;
  6383. }
  6384. return false;
  6385. }