change_information.js 309 KB

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