stage.js 292 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. function checkTzMeasureType () {
  11. return tender.measure_type === measureType.tz.value;
  12. }
  13. function transExpr(expr) {
  14. return $.trim(expr).replace('\t', '').replace('=', '').replace(new RegExp('%', 'gm'), '/100');
  15. }
  16. function getExprInfo (field, converse = false) {
  17. const exprField = [
  18. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  19. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  20. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  21. {qty: 'contract_qty', expr: 'contract_expr'},
  22. ];
  23. if (converse) return _.find(exprField, { expr: field });
  24. return _.find(exprField, {qty: field});
  25. }
  26. /**
  27. * 从cookie中读取缓存的列显示设置,没有则取默认
  28. * @returns {*[]}
  29. */
  30. function customColDisplay () {
  31. const defaultSetting = [
  32. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  33. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl', 'qc_minus_qty'], visible: true },
  34. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  35. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  36. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl', 'end_qc_minus_qty'], visible: true },
  37. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent', 'end_final_1_precent'], visible: true },
  38. { title: '本期批注', fields: ['postil'], visible: true },
  39. { title: '图册号', fields: ['drawing_code'], visible: true },
  40. { title: '备注', fields: ['memo'], visible: true },
  41. { title: '总额计量', fields: ['is_tp'], visible: true},
  42. ];
  43. if (!checkTzMeasureType()) {
  44. defaultSetting.unshift({ title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true }, { title: '台账', fields: ['quantity', 'total_price'], visible: true});
  45. }
  46. const settingStr = Cookies.get(ckColSetting);
  47. if (settingStr) {
  48. const customSetting = JSON.parse(settingStr);
  49. for (const ds of defaultSetting) {
  50. const cs = customSetting.find(x => {return x.title === ds.title});
  51. if (cs) ds.visible = cs.visible;
  52. }
  53. }
  54. return defaultSetting;
  55. }
  56. /**
  57. * 根据列显示设置,调整setting中的列是否显示
  58. * @param setting
  59. * @param customDisplay
  60. */
  61. function customizeStageTreeSetting(setting, customDisplay) {
  62. for (const cd of customDisplay) {
  63. for (const c of setting.cols) {
  64. if (cd.fields.indexOf(c.field) !== -1) {
  65. c.visible = c.defaultVisible === undefined ? cd.visible : c.defaultVisible && cd.visible;
  66. }
  67. }
  68. }
  69. }
  70. /**
  71. * 初始化 树结构 列事件
  72. * @param setting
  73. */
  74. function initTreeColSettingEvents(setting) {
  75. const Events = {
  76. readOnly: {
  77. measureData: function (node) {
  78. return node.children && node.children.length > 0;
  79. },
  80. },
  81. };
  82. const getEvent = function (eventName) {
  83. const names = eventName.split('.');
  84. let event = Events;
  85. for (let name of names) {
  86. if (event[name]) {
  87. event = event[name];
  88. } else {
  89. return null;
  90. }
  91. }
  92. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  93. return null;
  94. } else {
  95. return event;
  96. }
  97. };
  98. for (const col of setting.cols) {
  99. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  100. col.readOnly = getEvent(col.readOnly);
  101. }
  102. }
  103. }
  104. // 生成所有附件列表
  105. function getAllList(currPageNum = 1) {
  106. // 每页最多几个附件
  107. const pageCount = 20;
  108. // 附件总数
  109. const total = attData.length;
  110. // 总页数
  111. const pageNum = Math.ceil(total/pageCount);
  112. $('#totalPage').text(pageNum);
  113. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  114. // 当前页附件内容
  115. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  116. currPageFileData = currPageAttData;
  117. let html = '';
  118. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  119. for(const att of currPageAttData) {
  120. const delHtml = deleteFilePermission && parseInt(cur_uid) === att.uid
  121. ? `<a class="ml-1 text-danger" href="javascript:void(0)" name="att-delete" file-id="${att.id}"><i class="fa fa-close" title="删除"></i></a>`
  122. : '';
  123. html += `<tr>
  124. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  125. <td>
  126. <div class="d-flex">
  127. <a href="javascript:void(0)" class="pl-0 col-10 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  128. <div class="att-file-btn col-2"><a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="pl-0"><i class="fa fa-download"></i></a>${delHtml}</div>
  129. </div>
  130. </td><td>${att.username}</td></tr>`
  131. }
  132. $('#alllist-table').html(html);
  133. $('#alllist-table').on('click', 'tr', function() {
  134. $('#alllist-table tr').removeClass('bg-light')
  135. $(this).addClass('bg-light')
  136. });
  137. }
  138. // 生成当前节点列表
  139. function getNodeList(node) {
  140. let html = '';
  141. for(const att of attData) {
  142. if (node === att.lid) {
  143. const delHtml = deleteFilePermission && parseInt(cur_uid) === att.uid
  144. ? `<a class="ml-1 text-danger" href="javascript:void(0)" name="att-delete" file-id="${att.id}"><i class="fa fa-close" title="删除"></i></a>`
  145. : '';
  146. // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  147. html += `<tr>
  148. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  149. <td>
  150. <div class="d-flex">
  151. <a href="javascript:void(0)" class="pl-0 col-10 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  152. <div class="att-file-btn col-2"><a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="pl-0"><i class="fa fa-download"></i></a>${delHtml}</div>
  153. </div>
  154. </td><td>${att.username}</td></tr>`
  155. }
  156. }
  157. $('#nodelist-table').html(html);
  158. $('#nodelist-table').on('click', 'tr', function() {
  159. $('#nodelist-table tr').removeClass('bg-light');
  160. $(this).addClass('bg-light');
  161. })
  162. }
  163. function getGxbyText(data) {
  164. const def = thirdParty.gxby.find(function (x) {
  165. return x.value === data.gxby_status;
  166. });
  167. return def ? def.name : '';
  168. }
  169. function getDaglText(data) {
  170. const def = thirdParty.dagl.find(function (x) {
  171. return x.value === data.dagl_status;
  172. });
  173. return def ? def.name : '';
  174. }
  175. function getWbsText(data) {
  176. return '';
  177. }
  178. function getHintMsg () {
  179. return {
  180. invalidExpr: {type: 'warning', msg: '粘贴了非法表达式,已过滤'},
  181. disableChange: {type: 'error', msg: '不可修改此数据'},
  182. }
  183. }
  184. let ledgerData, posData = '';
  185. $(document).ready(() => {
  186. const completePerField = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent';
  187. const exportExcelSetting = {
  188. cols: [
  189. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
  190. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  191. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'pos_code', hAlign: 0, width: 70, formatter: '@'},
  192. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  193. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  194. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  195. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  196. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  197. {title: '本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  198. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'contract_tp', hAlign: 2, width: 60, type: 'Number'},
  199. {title: '本期数量变更|数量', colSpan: '3|1', rowSpan: '1|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'},
  200. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 60, type: 'Number'},
  201. {title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 60, type: 'Number'},
  202. {title: '本期完成计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  203. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 60, type: 'Number'},
  204. {title: '截止本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number'},
  205. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, type: 'Number'},
  206. {title: '截止本期数量变更|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, type: 'Number'},
  207. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
  208. {title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'end_qc_minus_qty', hAlign: 2, width: 60, type: 'Number'},
  209. {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
  210. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
  211. {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_final_1_percent', hAlign: 2, width: 80, type: 'Number'},
  212. {title: '合同|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  213. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  214. {title: '变更|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  215. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'c_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  216. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'final_dgn_price', hAlign: 2, width: 60, type: 'Number'},
  217. {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'},
  218. {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  219. {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
  220. {title: '位置', colSpan: '1', rowSpan: '2', field: 'position', hAlign: 0, width: 80, formatter: '@'},
  221. ],
  222. headRows: 2,
  223. headRowHeight: [25, 25],
  224. defaultRowHeight: 21,
  225. headerFont: 'bold 10px 微软雅黑',
  226. font: '10px 微软雅黑'
  227. };
  228. let detail, searchLedger, checkedChanges;
  229. const tpCalcFields = [{qty: 'qc_qty', tp: 'qc_tp'}];
  230. if (tenderInfo.calc_type === 'up' && !correctCalcContractTp) tpCalcFields.unshift({qty: 'contract_qty', tp: 'contract_tp'});
  231. const checkOption = {
  232. sibling: { enable: 0 },
  233. empty_code: { enable: 0 },
  234. calc: {
  235. enable: 1,
  236. fields: ['contract_qty', 'qc_qty', 'qc_minus_qty'],
  237. },
  238. zero: { enable: 0 },
  239. tp: {
  240. enable: 1,
  241. fields: tpCalcFields,
  242. filter: function (node) {
  243. return node.is_tp;
  244. }
  245. },
  246. over: { enable: 1, isTz: checkTzMeasureType(), checkInfo: tenderInfo.checkOverInfo },
  247. limit3f: { enable: 1, checkType: [], status: thirdParty, },
  248. minus_cb: { enable: hintMinusCb },
  249. change_detail: { enable: is_debug },
  250. // change_over: { enable: 1 },
  251. };
  252. if (tender.s2b_gxby_check) checkOption.limit3f.checkType.push('gxby');
  253. if (tender.s2b_dagl_check) checkOption.limit3f.checkType.push('dagl');
  254. if (tender.s2b_multi_check) checkOption.multiLimit3f = { enable: 1, limits };
  255. // 界面布局
  256. autoFlashHeight();
  257. let featureDisplay;
  258. const changeFeaturesDisplay = function (show, init = false) {
  259. $('#features-show').html(show ? '<i class="fa fa-eye-slash"></i> 隐藏特征' : '<i class="fa fa-eye"></i> 显示特征');
  260. const featureCols = ledgerSpreadSetting.cols.find(x => { return x.field === 'features'; });
  261. if (!featureCols) return;
  262. featureCols.visible = show ? true : false;
  263. if (!init) {
  264. featureDisplay = show;
  265. setLocalCache(featureShowCache, show ? 1 : 0);
  266. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet(), 1);
  267. }
  268. };
  269. const reloadFeaturesDisplayCache = function () {
  270. const featureCols = ledgerSpreadSetting.cols.find(x => { return x.field === 'features'; });
  271. if (featureCols) {
  272. $('#features-show').show();
  273. featureDisplay = getLocalCache(featureShowCache);
  274. featureDisplay = featureDisplay ? parseInt(featureDisplay) : 1;
  275. changeFeaturesDisplay(featureDisplay, true);
  276. } else {
  277. $('#features-show').hide();
  278. }
  279. };
  280. reloadFeaturesDisplayCache();
  281. $('#features-show').click(function() {
  282. changeFeaturesDisplay(!featureDisplay);
  283. });
  284. // 初始化 台账树结构 数据结构
  285. removeLocalCache('bills-fold');
  286. const stageTreeSetting = {
  287. id: 'ledger_id',
  288. pid: 'ledger_pid',
  289. order: 'order',
  290. level: 'level',
  291. rootId: -1,
  292. keys: ['id', 'tender_id', 'ledger_id'],
  293. stageId: 'id',
  294. autoExpand: 3,
  295. // markFoldKey: 'bills-fold',
  296. // markFoldSubKey: window.location.pathname.split('/')[2],
  297. markExpandKey: 'stage-bills-expand',
  298. markExpandSubKey: window.location.pathname.split('/')[2],
  299. };
  300. // 台账树结构计算相关设置
  301. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty', 'postil', 'used', 'contract_expr', 'ex_stage_qty1', 'ex_stage_tp1'];
  302. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'contract_pc_tp', 'qc_pc_tp', 'pc_tp',
  303. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp',
  304. 'final_1_tp', 'end_final_1_tp', 'ex_tp1', 'ex_stage_tp1', 'end_ex_stage_tp1', 'tz2_tp', 'tz_qc_tp', 'tz_qc_minus_tp'];
  305. stageTreeSetting.calcFun = function (node) {
  306. if (!node.children || node.children.length === 0) {
  307. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  308. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  309. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  310. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  311. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  312. node.end_qc_minus_qty = ZhCalc.add(node.pre_qc_minus_qty, node.qc_minus_qty);
  313. node.final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.quantity);
  314. node.final_1_tp = ZhCalc.mul(node.final_1_qty, node.unit_price, tenderInfo.decimal.tp);
  315. node.deal_final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.deal_qty);
  316. node.end_final_1_qty = ZhCalc.add(node.end_qc_qty, node.final_1_qty);
  317. node.end_ex_stage_qty1 = ZhCalc.add(node.ex_stage_qty1, node.pre_ex_stage_qty1);
  318. node.tz2_qty = ZhCalc.sum([node.quantity, node.tz_qc_qty, node.tz_qc_minus_qty]);
  319. }
  320. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  321. node.gather_tp = ZhCalc.sum([node.contract_tp, node.qc_tp, node.pc_tp]);
  322. node.end_contract_tp = ZhCalc.sum([node.pre_contract_tp, node.contract_tp, node.contract_pc_tp]);
  323. node.end_qc_tp = ZhCalc.sum([node.pre_qc_tp, node.qc_tp, node.qc_pc_tp]);
  324. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  325. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  326. node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.final_1_tp);
  327. node.end_ex_stage_tp1 = ZhCalc.add(node.ex_stage_tp1, node.pre_ex_stage_tp1);
  328. if (!node.children || node.children.length === 0) {
  329. if (node.end_contract_qty) {
  330. node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  331. } else {
  332. node.end_correct_tp = node.end_gather_tp;
  333. }
  334. }
  335. if (tenderInfo.calc_type === 'tp') {
  336. node.tz2_tp = ZhCalc.sum([node.total_price, node.tz_qc_tp]);
  337. } else if (tenderInfo.calc_type === 'up') {
  338. node.tz2_tp = ZhCalc.sum([node.total_price, node.tz_qc_tp, node.tz_qc_minus_tp]);
  339. }
  340. // node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  341. // node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
  342. node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
  343. // node.end_final_1_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_1_tp), 100, 2);
  344. // node.end_correct_1_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_1_tp), 100, 2);
  345. // Task #5256要求修改
  346. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.tz2_tp), 100, 2);
  347. node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.tz2_tp), 100, 2);
  348. node.end_final_1_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.tz2_tp), 100, 2);
  349. node.end_correct_1_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.tz2_tp), 100, 2);
  350. };
  351. const stageTree = createNewPathTree('stage', stageTreeSetting);
  352. // 初始化 计量单元 数据结构
  353. const stagePosSetting = {
  354. id: 'id', ledgerId: 'lid',
  355. updateFields: ['contract_qty', 'qc_qty', 'qc_minus_qty', 'postil', 'contract_expr', 'ex_stage_qty1'],
  356. };
  357. stagePosSetting.calcFun = function (pos) {
  358. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  359. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  360. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  361. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  362. pos.end_qc_minus_qty = ZhCalc.add(pos.pre_qc_minus_qty, pos.qc_minus_qty);
  363. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  364. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  365. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  366. pos.end_contract_percent = ZhCalc.mul(ZhCalc.div(pos.end_contract_qty, pos.quantity), 100, 2);
  367. pos.estimate_qty = !checkZero(pos.real_qty)
  368. ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
  369. : null;
  370. pos.final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.quantity);
  371. pos.deal_final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.deal_qty);
  372. pos.end_final_1_qty = ZhCalc.add(pos.end_qc_qty, pos.final_1_qty);
  373. pos.end_ex_stage_qty1 = ZhCalc.add(pos.pre_ex_stage_qty1, pos.ex_stage_qty1);
  374. pos.tz2_qty = ZhCalc.sum([pos.quantity, pos.tz_qc_qty, pos.tz_qc_minus_qty]);
  375. };
  376. const stagePos = new StagePosData(stagePosSetting);
  377. function checkUsed(tree, pos, node) {
  378. if (node.children && node.children.length > 0) {
  379. const posterity = tree.getPosterity(node);
  380. for (const p of posterity) {
  381. if (p.children && p.children.length > 0) continue;
  382. if (!checkZero(p.contract_qty) || !checkZero(p.contract_tp) ||
  383. !checkZero(p.qc_qty) || !checkZero(p.qc_tp) || !checkZero(p.qc_minus_qty))
  384. return true;
  385. const pPos = pos.getLedgerPos(p.id);
  386. if (!pPos || pPos.length === 0) continue;
  387. for (const pp of pPos) {
  388. if (!checkZero(pp.contract_qty) || !checkZero(pp.qc_qty) || !checkZero(pp.qc_minus_qty)) return true;
  389. }
  390. }
  391. return false;
  392. } else {
  393. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp) ||
  394. !checkZero(node.qc_qty) || !checkZero(node.qc_tp) || !checkZero(node.qc_minus_qty))
  395. return true;
  396. const pPos = pos.getLedgerPos(node.id);
  397. if (!pPos || pPos.length === 0) return false;
  398. for (const pp of pPos) {
  399. if (!checkZero(pp.contract_qty) || !checkZero(pp.qc_qty) || !checkZero(pp.qc_minus_qty)) return true;
  400. }
  401. }
  402. };
  403. class Changes {
  404. constructor(obj) {
  405. const self = this;
  406. this.obj = obj;
  407. // 初始化 清单编号窗口 参数
  408. this.spreadSetting = {
  409. cols: [
  410. {title: '已用', field: 'select', width: 45, formatter: '@', cellType: 'checkbox', hAlign: 1, indent: 14, getValue: function (data) {return data.uamount && !checkZero(data.uamount);}},
  411. {title: '变更令号', field: 'p_code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  412. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  413. {title: '变更部位', field: 'b_bwmx', width: 100, formatter: '@', readOnly: true, hAlign: 0,},
  414. {title: '批复数量', field: 'b_amount', width: 60, readOnly: true, hAlign: 2, },
  415. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, type: 'Number', getValue: function (data) {return data.vamount ? data.vamount + '' : '0';}},
  416. {title: '本期计量', field: 'uamount', width: 60, hAlign: 2, type: 'Number', },
  417. ],
  418. emptyRows: 0,
  419. headRows: 1,
  420. headRowHeight: [32],
  421. headerFont: '12px 微软雅黑',
  422. font: '12px 微软雅黑',
  423. getColor: function (sheet, data, row, col, defaultColor) {
  424. if (col.field === 'uamount') {
  425. if (data.bamount > 0) {
  426. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  427. return usedAmount < 0 || usedAmount > data.limitAmount ? spreadColor.stage.over : defaultColor;
  428. } else if (data.bamount < 0) {
  429. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  430. return usedAmount > 0 || usedAmount < data.limitAmount ? spreadColor.stage.over : defaultColor;
  431. } else {
  432. return data.uamount ? spreadColor.stage.over : defaultColor;
  433. }
  434. } else {
  435. return defaultColor;
  436. }
  437. }
  438. };
  439. this.curChangeId = '';
  440. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  441. this.firstView = true;
  442. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  443. // 初次显示,需刷新spread界面,保证界面绘制正确
  444. this.obj.bind('shown.bs.modal', function () {
  445. if (self.firstView) {
  446. self.firstView = false;
  447. self.spread.refresh();
  448. }
  449. });
  450. // 切换变更令,加载右侧明细数据
  451. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  452. const change = SpreadJsObj.getSelectObject(info.sheet);
  453. if(change) self._loadChangeDetail(change);
  454. });
  455. // 填写本期计量
  456. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  457. if (info.sheet.zh_setting) {
  458. const col = info.sheet.zh_setting.cols[info.col];
  459. if (col.cellType === 'checkbox') return;
  460. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  461. const node = sortData[info.row];
  462. if (col.type === 'Number') {
  463. const num = _.toNumber(info.editingText);
  464. if (_.isFinite(num)) {
  465. node[col.field] = num;
  466. } else {
  467. try {
  468. node[col.field] = ZhCalc.mathCalcExpr(transExpr(info.editingText));
  469. } catch(err) {
  470. toastr.error('输入的表达式非法');
  471. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  472. return;
  473. }
  474. }
  475. } else {
  476. node[col.field] = info.editingText;
  477. }
  478. // 刷新界面
  479. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  480. }
  481. });
  482. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  483. if (info.sheet.zh_setting) {
  484. const sortData = SpreadJsObj.getSortData(info.sheet);
  485. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  486. const curRow = iRow + info.cellRange.row;
  487. const curCol = info.cellRange.col;
  488. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  489. if (col.type === 'Number') {
  490. const num = _.toNumber(info.sheet.getText(curRow, curCol));
  491. if (_.isFinite(num)) {
  492. sortData[curRow][col.field] = num;
  493. } else {
  494. try {
  495. sortData[curRow][col.field] = ZhCalc.mathCalcExpr(transExpr(info.sheet.getText(curRow, curCol)));
  496. } catch(err) {
  497. // toastr.error('输入的表达式非法');
  498. }
  499. }
  500. } else {
  501. sortData[curRow][col.field] = info.sheet.getText(curRow, curCol);
  502. }
  503. }
  504. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  505. }
  506. });
  507. this.spread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
  508. if (!info.sheet.zh_setting) return;
  509. const col = info.sheet.zh_setting.cols[info.col];
  510. if (col.cellType === 'checkbox') {
  511. if (info.sheet.isEditing()) {
  512. info.sheet.endEdit(true);
  513. }
  514. const select = info.sheet.zh_data[info.row];
  515. select.uamount = select.uamount ? 0 : select.vamount;
  516. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  517. }
  518. });
  519. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  520. if (sheet.zh_setting) {
  521. const sel = sheet.getSelections()[0];
  522. const sortData = SpreadJsObj.getSortData(sheet);
  523. // 仅本期计量可删除
  524. if (sel.col === 5 && sel.colCount === 1) {
  525. const col = sheet.zh_setting.cols[sel.col];
  526. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  527. const data = sortData[iRow];
  528. data[col.field] = null;
  529. }
  530. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  531. }
  532. }
  533. });
  534. // 过滤可变更数量为0
  535. $('#filterEmpty').click(function () {
  536. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  537. });
  538. // 匹配编号
  539. $('#matchPos').click(function () {
  540. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  541. });
  542. // 展开收起 变更令详细信息
  543. $('#show-bgl-detail').bind('click', function () {
  544. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  545. if (detail.hasClass('col-4')) {
  546. detail.attr('class', 'col').hide();
  547. bgl.attr('class', 'col-12');
  548. $('a', obj).attr('title', '展开侧栏');
  549. $('i', obj).attr('class', 'fa fa-chevron-left');
  550. self.spread.refresh();
  551. } else {
  552. detail.attr('class', 'col-4').show();
  553. bgl.attr('class', 'col-8');
  554. $('a', obj).attr('title', '收起侧栏');
  555. $('i', obj).attr('class', 'fa fa-chevron-right');
  556. self.spread.refresh();
  557. }
  558. });
  559. // 添加调用变更令
  560. $('#usg-bg-ok').click(function () {
  561. const data = { target: self.callData, change: [] };
  562. for (const c of self.displayChanges) {
  563. if (c.uamount) {
  564. if (c.bamount > 0) {
  565. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  566. if (usedAmount < 0 || usedAmount > c.limitAmount) {
  567. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  568. return;
  569. }
  570. } else if (c.bamount < 0) {
  571. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  572. if (usedAmount > 0 || usedAmount < c.limitAmount) {
  573. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  574. return;
  575. }
  576. } else {
  577. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  578. return;
  579. }
  580. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount, minus: c.bamount < 0 });
  581. }
  582. }
  583. // 提交数据到后端
  584. postData(window.location.pathname + '/use-change', data, function(result) {
  585. if (result.pos) {
  586. stagePos.loadCurStageData(result.pos.curStageData);
  587. }
  588. const nodes = stageTree.loadPostStageData(result.bills);
  589. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  590. stagePosSpreadObj.loadCurPosData();
  591. if (detail) {
  592. detail.loadStageChangeUpdateData(result, nodes);
  593. } else {
  594. stageIm.loadUpdateChangeData(result, nodes)
  595. }
  596. self.obj.modal('hide');
  597. });
  598. })
  599. }
  600. findDecimal(unit) {
  601. let value = 3;
  602. if (unit !== '') {
  603. value = precision.other.value;
  604. const changeUnits = precision;
  605. for (const d in changeUnits) {
  606. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  607. value = changeUnits[d].value;
  608. break;
  609. }
  610. }
  611. }
  612. return value;
  613. }
  614. _calculateAmount() {
  615. for (const c of this.changes) {
  616. c.bamount = _.toNumber(c.b_amount);
  617. const qtyDecimal = this.findDecimal(c.b_unit);
  618. c.limitAmount = ZhCalc.mul(c.bamount, ZhCalc.div(c.delimit, 100, 2), qtyDecimal);
  619. c.vamount = ZhCalc.sub(ZhCalc.sub(c.limitAmount, c.used_amount), c.stage_used_amount);
  620. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid, no_value: this.callData.noValue});
  621. if (uc) {
  622. c.org_uamount = uc.qty;
  623. c.uamount = uc.qty;
  624. c.vamount = ZhCalc.add(c.vamount, uc.qty);
  625. }
  626. c.pre_amount = ZhCalc.sub(ZhCalc.add(c.used_amount, c.stage_used_amount), c.uamount);
  627. }
  628. }
  629. _loadChangeDetail(change) {
  630. if (change) {
  631. if (change.cid === this.curChangeId) { return; }
  632. this.curChangeId = change.cid;
  633. const inputs = $('input[type!=checkbox][type!=radio]', this.obj);
  634. for (const i of inputs) {
  635. const field = $(i).attr('name');
  636. const text = (field && change[field]) ? change[field] : '';
  637. $(i).val(text);
  638. }
  639. const textareas = $('textarea', this.obj);
  640. for (const ta of textareas) {
  641. const field = $(ta).attr('name');
  642. const text = (field && change[field]) ? change[field].replace(/<br><br>/g, '\r\n') : '';
  643. ta.textContent = text;
  644. }
  645. const html = [];
  646. for (const a of change.attachments) {
  647. html.push('<tr>');
  648. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  649. html.push('<td>', a.u_name, '</td>');
  650. html.push('</tr>');
  651. }
  652. // 变更类型
  653. if (change.type) {
  654. const cType = change.type.split(',');
  655. $('input[name="type"]').prop("checked", false);
  656. for (const c of cType) {
  657. $('input[name="type"][value='+ c +']').prop("checked", true);
  658. }
  659. }
  660. // 变更类别
  661. $('select[name=class]').val(change.class);
  662. // 变更性质
  663. $('select[name=quality]').val(change.quality);
  664. // 变更单位
  665. $('select[name=company]').html('<option>' + (change.company ? change.company : '') + '</option>');
  666. // 费用承担方
  667. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  668. // 附件
  669. $('#attachment').html(html.join(''));
  670. } else {
  671. const inputs = $('input', this.obj);
  672. for (const i of inputs) {
  673. $(i).val('');
  674. }
  675. const textareas = $('textarea', this.obj);
  676. for (const ta of textareas) {
  677. ta.innerText = '';
  678. }
  679. $('#attachment').html('');
  680. }
  681. }
  682. _viewChanges() {
  683. const sheet = this.spread.getActiveSheet();
  684. if (this.changes) {
  685. sheet.setSelection(0, 0, 1, 1);
  686. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  687. this._loadChangeDetail(this.displayChanges[0]);
  688. } else {
  689. toastr.error('查询变更令有误,请刷新页面后重试');
  690. }
  691. }
  692. _matchPos(match, change) {
  693. return match && this.callData.pos
  694. ? (change.gcl_id === this.callData.bills.id && change.b_bwmx === this.callData.pos.name)
  695. : true;
  696. }
  697. _matchBillsParent(match, change) {
  698. return match ? (!change.b_bwmx || change.b_bwmx === (this.callData.leafXmj ? this.callData.leafXmj.name : '')) : true;
  699. }
  700. _filterChange(filterEmpty, matchPosName) {
  701. this.displayChanges = [];
  702. for (const c of this.changes) {
  703. const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
  704. const matchVisible = this.callData.pos ? this._matchPos(matchPosName, c) : this._matchBillsParent(matchPosName, c);
  705. if ((filterVisible && matchVisible) || (c.org_uamount)) {
  706. this.displayChanges.push(c);
  707. }
  708. }
  709. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), SpreadJsObj.DataType.Data, this.displayChanges);
  710. this._loadChangeDetail(this.displayChanges[0]);
  711. }
  712. loadChanges(data) {
  713. this.callData = data;
  714. // if (this.callData.pos) {
  715. // $('#matchPos').parent().show();
  716. // } else {
  717. // $('#matchPos').parent().hide();
  718. // }
  719. $('#matchPos').parent().show();
  720. const self = this;
  721. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  722. postData(window.location.pathname + '/valid-change', data, function (result) {
  723. self.changes = result.changes;
  724. self.useChanges = result.useChanges;
  725. self._calculateAmount();
  726. self._viewChanges();
  727. self.obj.modal('show');
  728. });
  729. }
  730. }
  731. const changesObj = new Changes($('#use-bg'));
  732. // 初始化 台账 spread
  733. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  734. const slSheet = slSpread.getActiveSheet();
  735. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  736. // 数量变更列,添加按钮
  737. const qcColShowImage = function (data) {
  738. if (!data || (data.children && data.children.length > 0) || !(data.b_code && data.b_code !== '')) {
  739. return false;
  740. } else {
  741. const nodePos = stagePos.getLedgerPos(data.id);
  742. return !(nodePos && nodePos.length > 0);
  743. }
  744. };
  745. sjsSettingObj.setQcCols(ledgerSpreadSetting.cols, [
  746. {field: 'qc_qty', showImage: qcColShowImage},
  747. {field: 'qc_minus_qty', showImage: qcColShowImage},
  748. ]);
  749. sjsSettingObj.setOrgPriceCol(ledgerSpreadSetting.cols, [ {field: 'org_price'} ]);
  750. // const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_gather_percent' || x.field === 'end_correct_percent'});
  751. // if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_percent' : 'end_gather_percent';
  752. const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_final_1_percent' || x.field === 'end_correct_1_percent'});
  753. if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent';
  754. ledgerSpreadSetting.imageClick = function (data, hitinfo) {
  755. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  756. switch (col.field) {
  757. case 'dagl': data.dagl_url && window.open(data.dagl_url); break;
  758. case 'gxby': data.gxby_url && window.open(data.gxby_url); break;
  759. case 'wbs_url': data.wbs_url && window.open(data.wbs_url, '_target'); break;
  760. case 'qc_qty':
  761. case 'qc_minus_qty':
  762. if (data.children && data.children.length > 0 || data.lock || data.is_import || data.settle_status === settleStatus.finish) return;
  763. const nodePos = stagePos.getLedgerPos(data.id);
  764. if (nodePos && nodePos.length > 0) return;
  765. const minus = col.field === 'qc_minus_qty' ? 1 : 0;
  766. const leafXmj = stageTree.getLeafXmjParent(data);
  767. changesObj.loadChanges({bills: data, minus, noValue: minus, leafXmj: leafXmj});
  768. break;
  769. default: return;
  770. }
  771. };
  772. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  773. ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  774. if (data) {
  775. if (col.field === 'gxby') {
  776. const def = thirdParty.gxby.find(function (x) {
  777. return x.value === data.gxby_status;
  778. });
  779. if (def && def.color) return def.color;
  780. } else if (col.field === 'dagl') {
  781. const def = thirdParty.dagl.find(function (x) {
  782. return x.value === data.dagl_status;
  783. });
  784. if (def && def.color) return def.color;
  785. }
  786. if (data.settle_status === settleStatus.finish) {
  787. return spreadColor.stage.settle;
  788. }
  789. return hintOver && checkUtils.billsOver(data, stagePos, tenderInfo.checkOverInfo) ? spreadColor.stage.over : defaultColor;
  790. } else {
  791. return defaultColor;
  792. }
  793. };
  794. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  795. sjsSettingObj.set3FCols(ledgerSpreadSetting.cols, [
  796. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  797. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  798. {field: 'wbs_url', getValue: getWbsText, url_field: 'wbs_url', cellType: 'imageBtn', indent: 20},
  799. ]);
  800. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  801. ledgerSpreadSetting.headColWidth = [50];
  802. ledgerSpreadSetting.rowHeader = [
  803. {
  804. rowHeaderType: 'tag',
  805. setting: {
  806. indent: 14,
  807. tagSize: 0.8,
  808. tagFont: '8px 微软雅黑',
  809. getColor: function (index, data) {
  810. if (!data) return;
  811. return billsTag.getBillsTagsColor(data.id);
  812. },
  813. getTagHtml: function (index, data) {
  814. if (!data) return;
  815. const getHtml = function (list) {
  816. if (!list || list.length === 0) return '';
  817. const html = [];
  818. for (const l of list) {
  819. html.push('<div class="mr-1">');
  820. html.push(`<div class="float-left ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  821. html.push('<div class="ml-4">', '<p style="word-wrap: break-word">', l.comment, '</p>', '</div>');
  822. html.push('</div>');
  823. }
  824. return html.join('');
  825. };
  826. return getHtml(billsTag.getBillsTagsInfo(data.id));
  827. }
  828. },
  829. },
  830. ];
  831. // sjsSettingObj.setIsTpCol(ledgerSpreadSetting.cols, [ {field: 'is_tp'} ]);
  832. ledgerSpreadSetting.readOnly = function (data) {
  833. if (!data) return false;
  834. return data.lock || stageTreeSpreadObj.assistReadOnly;
  835. };
  836. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  837. //初始化所有附件列表
  838. getAllList();
  839. // 初始化 计量单元 Spread
  840. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  841. const spSheet = spSpread.getActiveSheet();
  842. const posQcColShowImage = function (data) {
  843. return data !== undefined && data !== null;
  844. };
  845. sjsSettingObj.setQcCols(posSpreadSetting.cols, [
  846. { field: 'qc_qty', showImage: posQcColShowImage },
  847. { field: 'qc_minus_qty', showImage: posQcColShowImage }
  848. ]);
  849. posSpreadSetting.imageClick = function (data, hitinfo) {
  850. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  851. switch (col.field) {
  852. case 'gxby': data.gxby_url && window.open(data.gxby_url); break;
  853. case 'dagl': data.dagl_url && window.open(data.dagl_url); break;
  854. case 'wbs_url': data.wbs_url && window.open(data.wbs_url, '_blank'); break;
  855. case 'qc_qty':
  856. case 'qc_minus_qty':
  857. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  858. if (node.lock || node.settle_status === settleStatus.finish) return;
  859. const minus = col.field === 'qc_minus_qty' ? 1 : 0;
  860. changesObj.loadChanges({bills: node, pos: data, minus, noValue: minus});
  861. break;
  862. default: return;
  863. }
  864. };
  865. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  866. if (data) {
  867. if (col.field === 'gxby') {
  868. const def = thirdParty.gxby.find(function (x) {
  869. return x.value === data.gxby_status;
  870. });
  871. if (def && def.color) return def.color;
  872. } else if (col.field === 'dagl') {
  873. const def = thirdParty.dagl.find(function (x) {
  874. return x.value === data.dagl_status;
  875. });
  876. if (def && def.color) return def.color;
  877. }
  878. if (data.settle_status === settleStatus.finish) {
  879. return spreadColor.stage.settle;
  880. }
  881. }
  882. return hintOver && checkUtils.posOver(data, tenderInfo.checkOverInfo) ? spreadColor.stage.over : defaultColor;
  883. };
  884. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  885. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  886. sjsSettingObj.set3FCols(posSpreadSetting.cols, [
  887. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  888. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  889. {field: 'wbs_url', getValue: getWbsText, url_field: 'wbs_url', cellType: 'imageBtn', indent: 20},
  890. ]);
  891. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  892. const billsTag = $.billsTag({
  893. relaTree: stageTree,
  894. selector: '#bills-tag',
  895. relaSpread: slSpread,
  896. updateUrl: window.location.pathname + '/tag',
  897. afterModify: function (nodes) {
  898. SpreadJsObj.repaintNodesRowHeader(slSpread.getActiveSheet(), nodes);
  899. },
  900. afterLocated: function () {
  901. stagePosSpreadObj.loadCurPosData();
  902. },
  903. afterShow: function () {
  904. slSpread.refresh();
  905. if (spSpread) spSpread.refresh();
  906. },
  907. });
  908. const errorList = $.cs_errorList({
  909. tabSelector: '#error-list-tab',
  910. selector: '#error-list',
  911. relaSpread: slSpread,
  912. storeKey: 'stage-error-' + stage.id,
  913. afterLocated: function () {
  914. stagePosSpreadObj.loadCurPosData();
  915. },
  916. afterShow: function () {
  917. slSpread.refresh();
  918. if (spSpread) spSpread.refresh();
  919. },
  920. });
  921. const checkList = $.ledger_checkList({
  922. id: 'check-list',
  923. tabSelector: '#check-list-tab',
  924. selector: '#check-list',
  925. relaSpread: slSpread,
  926. storeKey: 'stage-check-' + window.location.pathname.split('/')[2] + '-' + window.location.pathname.split('/')[4],
  927. checkType: getCheckType(checkOption),
  928. afterLocated: function () {
  929. stagePosSpreadObj.loadCurPosData();
  930. },
  931. afterShow: function () {
  932. slSpread.refresh();
  933. if (spSpread) spSpread.refresh();
  934. },
  935. });
  936. const sumLoadMiss = $.sumLoadMiss({
  937. tabSelector: '#sum-load-miss-tab',
  938. selector: '#sum-load-miss',
  939. relaSpread: slSpread,
  940. storeKey: 'stage-slm-' + stage.id,
  941. id: 'stage-slm',
  942. type: 'stage',
  943. afterLocated: function () {
  944. stagePosSpreadObj.loadCurPosData();
  945. },
  946. afterShow: function () {
  947. slSpread.refresh();
  948. if (spSpread) spSpread.refresh();
  949. },
  950. });
  951. const stageTreeSpreadObj = {
  952. cut: function (sheet, sel, callback) {
  953. callback(true);
  954. },
  955. loadExprToInput(sheet) {
  956. const sel = sheet.getSelections()[0];
  957. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  958. if (col.type === 'Number') {
  959. const data = SpreadJsObj.getSelectObject(sheet);
  960. if (!data) {
  961. $('#bills-expr').val('').attr('readOnly', true);
  962. $('#bills-expr').removeAttr('data-row');
  963. return;
  964. }
  965. const nodePos = stagePos.getLedgerPos(data.id);
  966. if (nodePos && nodePos.length > 0) {
  967. $('#bills-expr').val('').attr('readOnly', true);
  968. } else {
  969. if ((!data.is_tp && col.field.indexOf('tp') >= 0) || (data.is_tp && col.field.indexOf('tp') < 0)) {
  970. $('#bills-expr').val('').attr('readOnly', true);
  971. $('#bills-expr').removeAttr('data-row');
  972. return;
  973. }
  974. const exprInfo = getExprInfo(col.field);
  975. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  976. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  977. if (col.field.indexOf('tp') >= 0) {
  978. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp !== 1);
  979. } else {
  980. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp === 1)
  981. }
  982. }
  983. $('#bills-expr').attr('data-row', sel.row);
  984. } else {
  985. $('#bills-expr').val('').attr('readOnly', true);
  986. $('#bills-expr').removeAttr('data-row');
  987. }
  988. },
  989. refreshTreeNodes: function (sheet, nodes) {
  990. const tree = sheet.zh_tree;
  991. if (!tree) { return }
  992. const rows = [];
  993. for (const node of nodes) {
  994. rows.push(tree.nodes.indexOf(node));
  995. }
  996. SpreadJsObj.reLoadRowsData(sheet, rows);
  997. },
  998. editEnded: function (e, info) {
  999. if (info.sheet.zh_setting) {
  1000. const col = info.sheet.zh_setting.cols[info.col];
  1001. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  1002. const node = sortData[info.row], updateData = {};
  1003. const orgValue = node[col.field];
  1004. let newValue = trimInvalidChar(info.editingText);
  1005. if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
  1006. return;
  1007. }
  1008. if (col.type === 'Number' && newValue && newValue !== '') {
  1009. const num = _.toNumber(newValue);
  1010. if (_.isFinite(num)) {
  1011. newValue = num;
  1012. } else {
  1013. try {
  1014. newValue = ZhCalc.mathCalcExpr(transExpr(newValue));
  1015. } catch(err) {
  1016. toastr.error('输入的表达式非法');
  1017. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1018. return;
  1019. }
  1020. }
  1021. }
  1022. if (col.field.indexOf('_dgn_') > 0) {
  1023. if (node.b_code && node.b_code !== '') {
  1024. toastr.error('仅项目节可输入项目节数量');
  1025. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1026. return;
  1027. }
  1028. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) === -1) {
  1029. if (node.children && node.children.length > 0) {
  1030. toastr.error('清单父项不可计量');
  1031. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1032. return;
  1033. } else {
  1034. const nodePos = stagePos.getLedgerPos(node.id);
  1035. if (nodePos && nodePos.length > 0) {
  1036. toastr.error('该清单有计量单元,请在计量单元处计量');
  1037. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1038. return;
  1039. }
  1040. }
  1041. }
  1042. if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  1043. updateData.main = {
  1044. id: node.id
  1045. };
  1046. updateData.main[col.field] = newValue;
  1047. } else if (col.field.indexOf('_dgn_') > 0) {
  1048. updateData.dgn = {
  1049. id: node.id
  1050. };
  1051. updateData.dgn[col.field] = newValue;
  1052. } else if (col.field !== 'is_tp') {
  1053. updateData.stage = {
  1054. lid: node.id
  1055. };
  1056. updateData.stage[col.field] = newValue;
  1057. const exprInfo = getExprInfo(col.field);
  1058. if (exprInfo) {
  1059. updateData.stage[exprInfo.expr] = info.editingText !== newValue+ '' ? trimInvalidChar(info.editingText) : '';
  1060. }
  1061. }
  1062. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  1063. // tag update
  1064. const nodes = stageTree.loadPostStageData(data);
  1065. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1066. if (detail) {
  1067. detail.loadStageLedgerUpdateData(data, nodes);
  1068. } else {
  1069. stageIm.loadUpdateLedgerData(data, nodes);
  1070. }
  1071. }, function () {
  1072. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1073. });
  1074. }
  1075. },
  1076. updateNodeData: function(data) {
  1077. postData(window.location.href + '/update', { bills: data }, function(data) {
  1078. const nodes = stageTree.loadPostStageData(data);
  1079. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1080. if (detail) {
  1081. detail.loadStageLedgerUpdateData(data, nodes);
  1082. } else {
  1083. stageIm.loadUpdateLedgerData(data, nodes);
  1084. }
  1085. });
  1086. },
  1087. loadRelaData: function () {
  1088. const billsSheet = slSpread.getActiveSheet();
  1089. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  1090. const posSheet = spSpread.getActiveSheet();
  1091. SpreadJsObj.resetTopAndSelect(posSheet);
  1092. stagePosSpreadObj.loadCurPosData();
  1093. if (posSearch) posSearch.search();
  1094. },
  1095. selectionChanged: function (e, info) {
  1096. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  1097. stageTreeSpreadObj.loadRelaData();
  1098. // 全选去除
  1099. $('#dqjiedian').find('.check-all-file').prop('checked', false);
  1100. }
  1101. stageTreeSpreadObj.loadExprToInput(info.sheet);
  1102. },
  1103. deletePress(sheet) {
  1104. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  1105. const tree = sheet.zh_tree;
  1106. if (!tree) { return; }
  1107. const sel = sheet.getSelections()[0];
  1108. const validCols = [];
  1109. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1110. const colSetting = sheet.zh_setting.cols[iCol];
  1111. if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
  1112. validCols.push(iCol);
  1113. }
  1114. }
  1115. if (validCols.length === 0) { return; }
  1116. const sortData = sheet.zh_tree.nodes;
  1117. const datas = [], dgnDatas = [], mainDatas = [];
  1118. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1119. const node = sortData[iRow];
  1120. if (node && !node.lock) {
  1121. const data = { lid: node.id }, dgnData = { id: node.id }, mainData = { id: node.id };
  1122. let filter = true, filterDgn = true, filterMain = true;
  1123. for (const iCol of validCols) {
  1124. const colSetting = sheet.zh_setting.cols[iCol];
  1125. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  1126. if (node.b_code && node.b_code !== '') continue;
  1127. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(colSetting.field) < 0) {
  1128. if (colSetting.field === 'contract_qty') {
  1129. if (node.is_tp || node.settle_status === settleStatus.finish) continue;
  1130. } else if (colSetting.field === 'contract_tp') {
  1131. if (!node.is_tp || node.settle_status === settleStatus.finish) continue;
  1132. }
  1133. if (node.children && node.children.length > 0) {
  1134. continue;
  1135. }
  1136. const nodePos = stagePos.getLedgerPos(node.id);
  1137. if (nodePos && nodePos.length > 0) {
  1138. continue;
  1139. }
  1140. }
  1141. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  1142. if (node[colSetting.field] && node[colSetting.field] !== 0) {
  1143. dgnData[colSetting.field] = 0;
  1144. filterDgn = false;
  1145. }
  1146. } else if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(colSetting.field) >= 0) {
  1147. mainData[colSetting.field] = null;
  1148. filterMain = false;
  1149. } else {
  1150. data[colSetting.field] = colSetting.type === 'Number' ? 0 : '';
  1151. const exprInfo = getExprInfo(colSetting.field);
  1152. if (exprInfo) {
  1153. data[exprInfo.expr] = '';
  1154. }
  1155. filter = false;
  1156. }
  1157. }
  1158. if (!filter) datas.push(data);
  1159. if (!filterDgn) dgnDatas.push(dgnData);
  1160. if (!filterMain) mainDatas.push(mainData);
  1161. }
  1162. }
  1163. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  1164. const bills = {};
  1165. if (datas.length > 0) bills.stage = datas;
  1166. if (dgnDatas.length > 0) bills.dgn = dgnDatas;
  1167. if (mainDatas.length > 0) bills.main = mainDatas;
  1168. postData(window.location.href + '/update', {bills: bills}, function (result) {
  1169. const nodes = stageTree.loadPostStageData(result);
  1170. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1171. if (detail) {
  1172. detail.loadStageLedgerUpdateData(result, nodes);
  1173. } else {
  1174. stageIm.loadUpdateLedgerData(result, nodes);
  1175. }
  1176. stageTreeSpreadObj.loadExprToInput(sheet);
  1177. });
  1178. }
  1179. }
  1180. },
  1181. clipboardPasting(e, info) {
  1182. if (info.sheet.zh_setting) {
  1183. const setting = info.sheet.zh_setting;
  1184. const range = info.cellRange;
  1185. const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_minus_qty', 'postil', 'ex_stage_qty1', 'ex_stage_tp1'].concat(['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'], setting.dgnUpFields);
  1186. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1187. const col = info.sheet.zh_setting.cols[iCol];
  1188. if ((validField.indexOf(col.field) === -1)) {
  1189. toastr.error('不可修改此数据');
  1190. info.cancel = true;
  1191. return;
  1192. }
  1193. }
  1194. }
  1195. },
  1196. clipboardPasted(e, info) {
  1197. const pasteHint = getHintMsg();
  1198. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  1199. const sheet = info.sheet, setting = info.sheet.zh_setting;
  1200. const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
  1201. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1202. const curRow = iRow + info.cellRange.row;
  1203. const node = sheet.zh_tree.getItemsByIndex(curRow);
  1204. const data = {lid: node.id}, dgnData = {id: node.id}, mainData = {id: node.id};
  1205. let filter = true, filterDgn = true, filterMain = true;
  1206. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1207. const curCol = info.cellRange.col + iCol;
  1208. const col = info.sheet.zh_setting.cols[curCol];
  1209. if (col.field === 'contract_tp') {
  1210. if (!node.is_tp || node.settle_status === settleStatus.finish) continue;
  1211. } else if (col.field === 'contract_qty') {
  1212. if (node.is_tp || node.settle_status === settleStatus.finish) continue;
  1213. }
  1214. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  1215. if (node.b_code && node.b_code !== '') continue;
  1216. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) === -1) {
  1217. if (node.children && node.children.length > 0) continue;
  1218. const nodePos = stagePos.getLedgerPos(node.id);
  1219. if (nodePos && nodePos.length > 0) continue;
  1220. }
  1221. const text = trimInvalidChar(sheet.getText(curRow, curCol));
  1222. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  1223. const num = _.toNumber(text);
  1224. if (num) {
  1225. dgnData[col.field] = num;
  1226. filterDgn = false;
  1227. } else {
  1228. try {
  1229. dgnData[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
  1230. filterDgn = false;
  1231. } catch(err) {
  1232. toastMessageUniq(pasteHint.invalidExpr);
  1233. }
  1234. }
  1235. } else if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  1236. mainData[col.field] = text;
  1237. filterMain = false;
  1238. } else {
  1239. if (col.type === 'Number') {
  1240. const exprInfo = getExprInfo(col.field);
  1241. if (text) {
  1242. const num = _.toNumber(text);
  1243. data[col.field] = num;
  1244. if (exprInfo) data[exprInfo.expr] = '';
  1245. if (_.isFinite(num)) {
  1246. filter = false;
  1247. } else {
  1248. try {
  1249. data[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
  1250. if (exprInfo) data[exprInfo.expr] = text;
  1251. filter = false;
  1252. } catch(err) {
  1253. toastMessageUniq(pasteHint.invalidExpr);
  1254. }
  1255. }
  1256. } else {
  1257. data[col.field] = null;
  1258. if (exprInfo) data[exprInfo.expr] = '';
  1259. filter = false;
  1260. }
  1261. } else {
  1262. data[col.field] = text;
  1263. }
  1264. }
  1265. }
  1266. if (filter && filterDgn && filterMain) {
  1267. filterNodes.push(node);
  1268. } else {
  1269. if (!filter) datas.push(data);
  1270. if (!filterDgn) dgnDatas.push(dgnData);
  1271. if (!filterMain) mainDatas.push(mainData);
  1272. }
  1273. }
  1274. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  1275. const updateData = {};
  1276. if (datas.length > 0) updateData.stage = datas;
  1277. if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
  1278. if (mainDatas.length > 0) updateData.main = mainDatas;
  1279. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  1280. const nodes = stageTree.loadPostStageData(data);
  1281. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  1282. if (detail) {
  1283. detail.loadStageLedgerUpdateData(data, nodes);
  1284. } else {
  1285. stageIm.loadUpdateLedgerData(data, nodes);
  1286. }
  1287. stageTreeSpreadObj.loadExprToInput(sheet);
  1288. }, function () {
  1289. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  1290. });
  1291. } else {
  1292. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  1293. }
  1294. }
  1295. },
  1296. measureAllPosInNode(node, ratio = 1) {
  1297. const posterity = stageTree.getPosterity(node);
  1298. const data = {updateType: 'update', updateData: []};
  1299. for (const p of posterity) {
  1300. if (p.children && p.children.length > 0) continue;
  1301. const posRange = stagePos.getLedgerPos(p.id);
  1302. if (posRange && posRange.length > 0) {
  1303. for (const pr of posRange) {
  1304. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  1305. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  1306. if (validValue <= 0) continue;
  1307. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  1308. const pData = {
  1309. pid: pr.id,
  1310. lid: pr.lid,
  1311. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  1312. };
  1313. data.updateData.push(pData);
  1314. }
  1315. }
  1316. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
  1317. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  1318. break;
  1319. }
  1320. }
  1321. if (data.updateData.length === 0) {
  1322. toastr.info('其下全部计量单元均已计量');
  1323. return;
  1324. }
  1325. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1326. if (result.pos) {
  1327. stagePos.updateDatas(result.pos.pos);
  1328. stagePos.loadCurStageData(result.pos.curStageData);
  1329. }
  1330. const nodes = stageTree.loadPostStageData(result.ledger);
  1331. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1332. stagePosSpreadObj.loadCurPosData();
  1333. if (detail) {
  1334. detail.loadStagePosUpdateData(result, nodes);
  1335. } else {
  1336. stageIm.loadUpdatePosData(result, nodes);
  1337. }
  1338. toastr.success('已计量' + data.updateData.length + '条');
  1339. }, function () {
  1340. stagePosSpreadObj.loadCurPosData();
  1341. });
  1342. },
  1343. topRowChanged(e, info) {
  1344. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1345. },
  1346. editStarting(e, info) {
  1347. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1348. const col = info.sheet.zh_setting.cols[info.col];
  1349. const node = info.sheet.zh_tree.nodes[info.row];
  1350. switch (col.field) {
  1351. case 'contract_qty':
  1352. case 'qc_qty':
  1353. case 'qc_minus_qty':
  1354. info.cancel = node.is_tp || node.settle_status === settleStatus.finish;
  1355. break;
  1356. case 'ex_stage_qty1':
  1357. info.cancel = node.is_tp;
  1358. break;
  1359. case 'contract_tp':
  1360. info.cancel = !node.is_tp || node.settle_status === settleStatus.finish;
  1361. break;
  1362. case 'qc_tp':
  1363. info.cancel = !node.is_tp || node.settle_status === settleStatus.finish || qcTpReadOnly || node.qc_qty || node.qc_minus_qty;
  1364. break;
  1365. case 'is_tp':
  1366. info.cancel = true;
  1367. break;
  1368. }
  1369. if (!info.cancel) {
  1370. const exprInfo = getExprInfo(col.field);
  1371. if (exprInfo) {
  1372. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1373. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1374. }
  1375. }
  1376. }
  1377. },
  1378. buttonClicked: function (e, info) {
  1379. if (info.sheet.zh_setting) {
  1380. const node = SpreadJsObj.getSelectObject(info.sheet);
  1381. const col = info.sheet.zh_setting.cols[info.col];
  1382. const posRange = stagePos.getLedgerPos(node.id);
  1383. const tpUnit = ['总额', '元', '台', '个', '处', '月', '棵', '套', '组', '辆', '项', '座', '根', '块', '系统'];
  1384. if (node.pre_used === 1 ||
  1385. (node.children && node.children.length > 0) ||
  1386. // (tpUnit.indexOf(node.unit) < 0) ||
  1387. (posRange && posRange.length > 0) /*|| !checkZero(node.qc_qty)*/) {
  1388. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1389. return;
  1390. }
  1391. const postIsTp = function () {
  1392. const data = { calcType: {id: node.id} };
  1393. data.calcType.is_tp = info.sheet.getValue(info.row, info.col) || false;
  1394. // 更新至服务器
  1395. postData(window.location.pathname + '/update', {bills: data}, function (result) {
  1396. const nodes = stageTree.loadPostStageData(result);
  1397. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1398. if (detail) {
  1399. detail.loadStageLedgerUpdateData(result, nodes);
  1400. } else {
  1401. stageIm.loadUpdateLedgerData(result, nodes);
  1402. }
  1403. });
  1404. };
  1405. if (col.field === 'is_tp') {
  1406. if (info.sheet.isEditing()) {
  1407. info.sheet.endEdit(true);
  1408. }
  1409. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp) || !checkZero(node.ex_stage_qty1) || !checkZero(node.ex_stage_tp1)) {
  1410. $.msgBox({
  1411. id: 'calc-type',
  1412. title: '提示',
  1413. message: '切换计量模式,已计量数据会被清空。',
  1414. ok: {
  1415. caption: '确定',
  1416. callback: postIsTp,
  1417. },
  1418. cancel: {
  1419. caption: '取消',
  1420. callback: function () {
  1421. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1422. }
  1423. }
  1424. });
  1425. } else {
  1426. postIsTp();
  1427. }
  1428. }
  1429. }
  1430. },
  1431. measureByBatch: function (posNames, ratio, apply2sibling) {
  1432. if (posNames.length <= 0) return;
  1433. if (ratio <= 0) return;
  1434. const fRatio = ZhCalc.div(ratio, 100);
  1435. const sheet = slSpread.getActiveSheet();
  1436. const node = SpreadJsObj.getSelectObject(sheet);
  1437. const parent = stageTree.getParent(node);
  1438. const nodes = apply2sibling === true ? (parent ? parent.children : stageTree.children) : [node];
  1439. const data = {updateType: 'batchUpdate', updateData: []};
  1440. for (const node of nodes) {
  1441. const posRange = stagePos.getLedgerPos(node.id);
  1442. if (!posRange || posRange <= 0) continue;
  1443. for (const p of posRange) {
  1444. if (posNames.indexOf(p.name) < 0) continue;
  1445. data.updateData.push({
  1446. pid: p.id, lid: p.lid,
  1447. contract_qty: ZhCalc.mul(p.quantity, fRatio),
  1448. contract_expr: `${p.quantity}*${ratio}%`,
  1449. });
  1450. }
  1451. }
  1452. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1453. if (result.pos) {
  1454. stagePos.updateDatas(result.pos.pos);
  1455. stagePos.loadCurStageData(result.pos.curStageData);
  1456. }
  1457. const nodes = stageTree.loadPostStageData(result.ledger);
  1458. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1459. stagePosSpreadObj.loadCurPosData();
  1460. if (detail) {
  1461. detail.loadStagePosUpdateData(result, nodes);
  1462. } else {
  1463. stageIm.loadUpdatePosData(result, nodes);
  1464. }
  1465. $('#calc-by-ratio').modal('hide');
  1466. }, function () {
  1467. stagePosSpreadObj.loadCurPosData();
  1468. $('#calc-by-ratio').modal('hide');
  1469. });
  1470. },
  1471. exportExcel: function (filename, nodes, withPos = true) {
  1472. stageTree.recursiveExe(function(node) {
  1473. if (node.children && node.children.length > 0) {
  1474. node._export_group = _.sum(node.children.map(x => { return x._export_group; })) + node.children.length;
  1475. } else {
  1476. const posRange = stagePos.getLedgerPos(node.id);
  1477. node._export_group = posRange ? posRange.length : 0;
  1478. }
  1479. });
  1480. const exportNodesData = function (data, nodes, groupData) {
  1481. for (const node of nodes) {
  1482. data.push({
  1483. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  1484. unit_price: node.unit_price, quantity: node.quantity, total_price: node.total_price,
  1485. contract_qty: node.contract_qty, contract_tp: node.contract_tp,
  1486. qc_qty: node.qc_qty, qc_tp: node.qc_tp, qc_minus_qty: node.qc_minus_qty,
  1487. gather_qty: node.gather_qty, gather_tp: node.gather_tp,
  1488. end_contract_qty: node.end_contract_qty, end_contract_tp: node.end_contract_tp,
  1489. end_qc_qty: node.end_qc_qty, end_qc_tp: node.end_qc_tp, end_qc_minus_qty: node.end_qc_minus_qty,
  1490. end_gather_qty: node.end_gather_qty, end_gather_tp: node.end_gather_tp, end_final_1_percent: node.end_final_1_percent,
  1491. deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2,
  1492. c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2,
  1493. final_dgn_price: node.final_dgn_price,
  1494. postil: node.postil, drawing_code: node.drawing_code, memo: node.memo,
  1495. contract_expr_str: node.calc_expr ? TreeExprCalc.expr2ExprStr(node.calc_expr) : '',
  1496. });
  1497. if (node.children && node.children.length > 0) {
  1498. exportNodesData(data, node.children, groupData);
  1499. } else {
  1500. if (!withPos) continue;
  1501. const posRange = stagePos.getLedgerPos(node.id);
  1502. if (!posRange || posRange.length === 0) continue;
  1503. if (node._export_group) groupData.push({ code: node.code, b_code: node.b_code, start: data.length, count: node._export_group });
  1504. for (const [i, p] of posRange.entries()) {
  1505. data.push({
  1506. pos_code: (i + 1) + '', name: p.name,
  1507. quantity: p.quantity,
  1508. contract_qty: p.contract_qty, qc_qty: p.qc_qty, gather_qty: p.gather_qty,
  1509. end_contract_qty: p.end_contract_qty, end_qc_qty: p.end_qc_qty, end_gather_qty: p.end_gather_qty,
  1510. qc_minus_qty: p.qc_minus_qty, end_qc_minus_qty: p.end_qc_minus_qty,
  1511. drawing_code: p.drawing_code, memo: p.memo, postil: p.postil, position: p.position,
  1512. });
  1513. }
  1514. }
  1515. }
  1516. };
  1517. const data = [], groupData = [];
  1518. exportNodesData(data, nodes ? nodes : stageTree.children, groupData);
  1519. SpreadExcelObj.exportSimpleXlsxSheet(exportExcelSetting, data, filename, groupData);
  1520. },
  1521. loadChangeData: function(tree, pos, changes) {
  1522. const findEmptyBills = function(tree, change, changeBills) {
  1523. const cb = {
  1524. b_code: changeBills.code || '',
  1525. name: changeBills.name || '',
  1526. unit: changeBills.unit || '',
  1527. unit_price: changeBills.unit_price || 0,
  1528. };
  1529. for (const node of tree.nodes) {
  1530. if (node.children && node.children.length > 0) continue;
  1531. const b = {
  1532. b_code: node.b_code || '',
  1533. name: node.name || '',
  1534. unit: node.unit || '',
  1535. unit_price: node.unit_price || 0,
  1536. };
  1537. if (_.isMatch(cb, b)) return node;
  1538. }
  1539. return null;
  1540. };
  1541. for (const change of changes) {
  1542. for (const changeBills of change.bills) {
  1543. const node = changeBills.gcl_id
  1544. ? tree.nodes.find(x => {return x.id === changeBills.gcl_id})
  1545. : findEmptyBills(tree, change, changeBills);
  1546. if (!node) continue;
  1547. if (!node.changeBills) node.changeBills = [];
  1548. node.tz_qc_qty = ZhCalc.add(node.tz_qc_qty, changeBills.checked_amount);
  1549. if (tenderInfo.calc_type === 'up') {
  1550. node.tz_qc_tp = ZhCalc.add(node.tz_qc_tp, changeBills.checked_price);
  1551. } else {
  1552. node.tz_qc_tp = ZhCalc.add(node.tz_qc_tp, changeBills.tp);
  1553. }
  1554. const posData = pos.getLedgerPos(node.id);
  1555. if (posData && posData.length > 0) {
  1556. for (const p of changeBills.pos) {
  1557. const changePos = p.bwmx ? posData.find(x => { return x.name === p.bwmx; }) : posData[0];
  1558. if (changePos) {
  1559. changePos.tz_qc_qty = ZhCalc.add(changePos.tz_qc_qty, p.checked_amount);
  1560. if (!changePos.changeBills) changePos.changeBills = [];
  1561. changePos.changeBills.push({
  1562. code: change.code || '', name: change.name || '', is_valuation: p.is_valuation,
  1563. qty: p.checked_amount || 0, tp: p.checked_price || 0, pos: changePos.name,
  1564. });
  1565. node.changeBills.push({
  1566. code: change.code || '', name: change.name || '', is_valuation: p.is_valuation,
  1567. qty: p.checked_amount || 0, tp: p.checked_price || 0, pos: changePos.name,
  1568. });
  1569. }
  1570. }
  1571. } else {
  1572. for (const p of changeBills.pos) {
  1573. node.changeBills.push({
  1574. code: change.code || '', name: change.name || '', is_valuation: p.is_valuation,
  1575. qty: p.checked_amount || 0, tp: p.checked_price || 0, pos: '',
  1576. });
  1577. }
  1578. }
  1579. }
  1580. }
  1581. }
  1582. };
  1583. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  1584. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  1585. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  1586. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  1587. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  1588. slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
  1589. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  1590. SpreadJsObj.addCutEvents(slSpread, stageTreeSpreadObj.cut);
  1591. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  1592. if (!readOnly) {
  1593. $('#bills-expr').bind('change onblur', function () {
  1594. if (this.readOnly) return;
  1595. const expr = $(this);
  1596. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1597. const select = stageTree.getItemsByIndex(row);
  1598. if (!select) return;
  1599. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  1600. let newValue = expr.val();
  1601. const num = _.toNumber(newValue);
  1602. if (_.isFinite(num)) {
  1603. newValue = num;
  1604. } else {
  1605. try {
  1606. newValue = ZhCalc.mathCalcExpr(transExpr(newValue));
  1607. } catch(err) {
  1608. toastr.error('输入的表达式非法');
  1609. return;
  1610. }
  1611. }
  1612. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1613. if (field.indexOf('_dgn_') > 0) {
  1614. updateData.dgn = {
  1615. id: select.id
  1616. };
  1617. updateData.dgn[field] = newValue;
  1618. } else {
  1619. updateData.stage = {
  1620. lid: select.id
  1621. };
  1622. updateData.stage[field] = newValue;
  1623. const exprInfo = getExprInfo(field);
  1624. if (exprInfo) {
  1625. updateData.stage[exprInfo.expr] = expr.val();
  1626. }
  1627. }
  1628. // 更新至服务器
  1629. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  1630. const nodes = stageTree.loadPostStageData(result);
  1631. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1632. if (detail) {
  1633. detail.loadStageLedgerUpdateData(result, nodes);
  1634. } else {
  1635. stageIm.loadUpdateLedgerData(result, nodes);
  1636. }
  1637. });
  1638. });
  1639. }
  1640. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  1641. const addTag = newTag({ledgerSheet: slSpread.getActiveSheet(), billsTag});
  1642. const tenderSelect = TenderSelect({
  1643. type: 'stage',
  1644. afterLoad: function (result, select) {
  1645. const nodes = stageTree.loadPostStageData(result);
  1646. const posterity = stageTree.getPosterity(select);
  1647. for (const p of posterity) {
  1648. p.is_import = !!result.import_change.data.find(x => { return x.lid === p.id });
  1649. }
  1650. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1651. if (detail) {
  1652. detail.loadStageLedgerUpdateData(result, nodes);
  1653. } else {
  1654. stageIm.loadUpdateLedgerData(result, nodes);
  1655. }
  1656. if (result.sumLoadHis.errors.length > 0) {
  1657. sumLoadMiss.loadMissData(result.sumLoadHis.errors);
  1658. sumLoadMiss.show();
  1659. } else {
  1660. sumLoadMiss.clearMissData();
  1661. }
  1662. // todo 优化,仅加载需要刷新的变更令
  1663. if (checkedChanges) checkedChanges.reloadChangeData();
  1664. }
  1665. });
  1666. const batchImport = BatchImportStageGcl({
  1667. stageTree,
  1668. afterLoad: function (result, select) {
  1669. const nodes = stageTree.loadPostStageData(result);
  1670. const posterity = stageTree.getPosterity(select);
  1671. for (const p of posterity) {
  1672. p.is_import = !!result.import_change.data.find(x => { return x.lid === p.id });
  1673. }
  1674. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1675. if (detail) {
  1676. detail.loadStageLedgerUpdateData(result, nodes);
  1677. } else {
  1678. stageIm.loadUpdateLedgerData(result, nodes);
  1679. }
  1680. if (checkedChanges) checkedChanges.reloadChangeData();
  1681. }
  1682. });
  1683. const spssTenderSelect = TenderSelectMulti({
  1684. title: '根据(其他标段)计量比例计量',
  1685. type: 'gather',
  1686. dataType: 'stage',
  1687. afterSelect: function(select) {
  1688. const data = { filter: 'info', tender: select };
  1689. postData(`/sp/${spid}/spss/load`, data, function(result) {
  1690. const postil = result.map(x => { return `${x.name}(${x.stage_filter}) ${x.info.contract_tp || 0}`}).join(';');
  1691. const gatherContractTp = ZhCalc.sum(result.map(x => { return x.info.contract_tp; }));
  1692. const gatherTp = ZhCalc.sum(result.map(x => { return x.info.total_price; }));
  1693. const node = SpreadJsObj.getSelectObject(slSheet);
  1694. const contract_tp = ZhCalc.mul(ZhCalc.div(gatherContractTp, gatherTp), node.total_price);
  1695. const contract_expr = result.length > 1
  1696. ? '(' + result.map(x => { return x.info.contract_tp; }).join('+') + ')/(' + result.map(x => { return x.info.total_price; }).join('+') + ')'
  1697. : result[0].info.contract_tp + '/' + result[0].info.total_price;
  1698. stageTreeSpreadObj.updateNodeData({ stage: { lid: node.id, contract_tp, contract_expr, postil } });
  1699. });
  1700. },
  1701. });
  1702. $.contextMenu({
  1703. selector: '#stage-ledger',
  1704. build: function ($trigger, e) {
  1705. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  1706. stageTreeSpreadObj.loadRelaData();
  1707. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1708. },
  1709. items: {
  1710. 'remainCur': {
  1711. name: '填剩余量',
  1712. disabled: function (key, opt) {
  1713. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1714. return readOnly || !node || node.lock;
  1715. },
  1716. callback: function (key, opt) {
  1717. const sheet = spSpread.getActiveSheet();
  1718. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1719. const updateStage = [];
  1720. const posterity = stageTree.getPosterity(node);
  1721. posterity.unshift(node);
  1722. for (const p of posterity) {
  1723. if (p.children && p.children.length > 0) continue;
  1724. if (!p.b_code) continue;
  1725. const posRange = stagePos.ledgerPos[itemsPre + p.id] || [];
  1726. if (posRange.length > 0) continue;
  1727. if (!p.is_tp) {
  1728. const qty = ZhCalc.sub(p.quantity, p.pre_contract_qty);
  1729. const differ = ZhCalc.sub(p.quantity, p.end_contract_qty);
  1730. if (differ) updateStage.push({ lid: p.id, contract_qty: qty, contract_expr: '' });
  1731. } else {
  1732. const tp = ZhCalc.sub(p.total_price, p.pre_contract_tp);
  1733. const differ = ZhCalc.sub(p.quantity, p.end_contract_qty);
  1734. if (differ) updateStage.push({ lid: p.id, contract_tp: tp });
  1735. }
  1736. }
  1737. if (updateStage.length === 0) {
  1738. toastr.warning('所选节点及子项已全部计量');
  1739. return;
  1740. }
  1741. if (updateStage.length > 0) {
  1742. if (updateStage.length > 1000) {
  1743. toastr.warning('提交的数据太大,仅提交1000条数据');
  1744. updateStage.length = 1000;
  1745. }
  1746. postData(window.location.pathname + '/update', {bills: { stage: updateStage }}, function (result) {
  1747. const nodes = stageTree.loadPostStageData(result);
  1748. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1749. if (detail) {
  1750. detail.loadStageLedgerUpdateData(result, nodes);
  1751. } else {
  1752. stageIm.loadUpdateLedgerData(result, nodes);
  1753. }
  1754. stageTreeSpreadObj.loadExprToInput(sheet);
  1755. });
  1756. }
  1757. }
  1758. },
  1759. 'remainCurPos': {
  1760. name: '填剩余量(计量单元)',
  1761. disabled: function (key, opt) {
  1762. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1763. return readOnly || !node || node.lock;
  1764. },
  1765. callback: function (key, opt) {
  1766. const sheet = spSpread.getActiveSheet();
  1767. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1768. const data = { updateType: 'batchUpdate', updateData: [] };
  1769. const posterity = stageTree.getPosterity(node);
  1770. posterity.unshift(node);
  1771. for (const p of posterity) {
  1772. if (p.children && p.children.length > 0) continue;
  1773. if (!p.b_code) continue;
  1774. const posRange = stagePos.ledgerPos[itemsPre + p.id] || [];
  1775. if (posRange.length === 0) continue;
  1776. for (const pr of posRange) {
  1777. const qty = ZhCalc.sub(pr.quantity, pr.pre_contract_qty);
  1778. const differ = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  1779. if (differ) data.updateData.push({ lid: pr.lid, pid: pr.id, contract_qty: qty, contract_expr: '' });
  1780. }
  1781. }
  1782. if (data.updateData.length === 0) {
  1783. toastr.warning('所选节点及子项已全部计量');
  1784. return;
  1785. }
  1786. if (data.updateData.length > 0) {
  1787. if (data.updateData.length > 1000) {
  1788. toastr.warning('提交的数据太大,仅提交1000条数据');
  1789. data.updateData.length = 1000;
  1790. }
  1791. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1792. if (result.pos) {
  1793. stagePos.updateDatas(result.pos.pos);
  1794. stagePos.loadCurStageData(result.pos.curStageData);
  1795. }
  1796. const nodes = stageTree.loadPostStageData(result.ledger);
  1797. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1798. stagePosSpreadObj.loadCurPosData();
  1799. if (detail) {
  1800. detail.loadStagePosUpdateData(result, nodes);
  1801. } else {
  1802. stageIm.loadUpdatePosData(result, nodes);
  1803. }
  1804. stageTreeSpreadObj.loadExprToInput(sheet);
  1805. });
  1806. }
  1807. }
  1808. },
  1809. 'remainXmjQty': {
  1810. name: '填项目节数量',
  1811. callback: function(key, opt) {
  1812. const sheet = spSpread.getActiveSheet();
  1813. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1814. const updateDgn = [];
  1815. const posterity = stageTree.getPosterity(node);
  1816. posterity.unshift(node);
  1817. for (const p of posterity) {
  1818. if (p.b_code) continue;
  1819. const posRange = stagePos.ledgerPos[itemsPre + p.id] || [];
  1820. if (posRange.length > 0) continue;
  1821. if (p.dgn_qty1 !== p.deal_dgn_qty1 || p.dgn_qty2 !== p.deal_dgn_qty2) updateDgn.push({ id: p.id, deal_dgn_qty1: p.dgn_qty1, deal_dgn_qty2: p.dgn_qty2 });
  1822. }
  1823. if (updateDgn.length === 0) {
  1824. toastr.warning('所选项目节及子项的项目节数量已与台账相等');
  1825. return;
  1826. }
  1827. if (updateDgn.length > 1000) {
  1828. toastr.warning('提交的数据太大,仅提交1000条数据');
  1829. updateDgn.length = 1000;
  1830. }
  1831. postData(window.location.pathname + '/update', {bills: { dgn: updateDgn }}, function (result) {
  1832. const nodes = stageTree.loadPostStageData(result);
  1833. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1834. if (detail) {
  1835. detail.loadStageLedgerUpdateData(result, nodes);
  1836. } else {
  1837. stageIm.loadUpdateLedgerData(result, nodes);
  1838. }
  1839. stageTreeSpreadObj.loadExprToInput(sheet);
  1840. });
  1841. // postData(window.location.pathname + '/update', { dgn: 'all' }, function (result) {
  1842. // const nodes = stageTree.loadPostStageData(result);
  1843. // stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1844. // if (detail) {
  1845. // detail.loadStageLedgerUpdateData(result, nodes);
  1846. // } else {
  1847. // stageIm.loadUpdateLedgerData(result, nodes);
  1848. // }
  1849. // stageTreeSpreadObj.loadExprToInput(sheet);
  1850. // });
  1851. },
  1852. visible: function(key, opt) {
  1853. return !readOnly;
  1854. },
  1855. disabled: function (key, opt) {
  1856. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1857. return !node || !!node.b_code;
  1858. }
  1859. },
  1860. 'remainByExprAll': {
  1861. name: '计算本期合同计量',
  1862. icon: 'fa-forward',
  1863. callback: function(key, opt) {
  1864. const sheet = spSpread.getActiveSheet();
  1865. TreeExprCalc.setCalcType(TreeExprCalc.calcType.sortCache);
  1866. const calcExpr = stageTree.nodes.filter(x => {
  1867. if (x.children && x.children.length > 0) return false;
  1868. const posRange = stagePos.getLedgerPos(x.id);
  1869. if (posRange && posRange.length > 0) return false;
  1870. return !!x.calc_expr;
  1871. }).map(x => { return { id: x.id, expr: x.calc_expr, unit: x.unit, unit_price: x.unit_price, calcField: x.is_tp ? 'tp' : 'qty' }});
  1872. if (calcExpr.length === 0) {
  1873. toastr.warning('沒有可计算的公式');
  1874. return;
  1875. }
  1876. TreeExprCalc.calcAllExpr(calcExpr);
  1877. const updateData = calcExpr.map(x => {
  1878. const data = { lid: x.id, contract_expr: x.formula };
  1879. const field = x.calcField === 'qty' ? 'contract_qty' : 'contract_tp';
  1880. data[field] = x.value;
  1881. return data;
  1882. });
  1883. postData(window.location.pathname + '/update', {bills: { stage: updateData }}, function (result) {
  1884. const nodes = stageTree.loadPostStageData(result);
  1885. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1886. if (detail) {
  1887. detail.loadStageLedgerUpdateData(result, nodes);
  1888. } else {
  1889. stageIm.loadUpdateLedgerData(result, nodes);
  1890. }
  1891. stageTreeSpreadObj.loadExprToInput(sheet);
  1892. });
  1893. },
  1894. visible: function(key, opt) {
  1895. return !readOnly && contractExpr;
  1896. },
  1897. },
  1898. zjjlSpr: '----',
  1899. 'locateZjjl': {
  1900. name: '定位至中间计量',
  1901. icon: 'fa-sign-in',
  1902. callback: function (key, opt) {
  1903. if (!detail) {
  1904. detail = new Detail($('#detail-spread'));
  1905. }
  1906. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1907. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  1908. if (leafUsedBills) {
  1909. if (!$('#zhongjian').hasClass('active')) {
  1910. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  1911. $('a', '.side-menu').removeClass('active');
  1912. $('.tab-content .tab-select-show').removeClass('active');
  1913. tab.addClass('active');
  1914. tabPanel.addClass('active');
  1915. showSideTools(tab.hasClass('active'));
  1916. slSpread.refresh();
  1917. spSpread.refresh();
  1918. }
  1919. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  1920. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  1921. SpreadJsObj.locateData(detail.sheet, im);
  1922. detail.spread.refresh();
  1923. $('#zhongjian .sjs-bottom').height('400px');
  1924. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1925. detail.reLoadDetailData();
  1926. } else {
  1927. toastr.error('无可定位中间计量');
  1928. }
  1929. },
  1930. disabled: function (key, opt) {
  1931. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1932. return !node;
  1933. }
  1934. },
  1935. tagSpr: '----',
  1936. tag: {
  1937. name: '书签',
  1938. callback: function (key, opt, menu, e) {
  1939. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1940. addTag.do(node);
  1941. },
  1942. disabled: function (key, opt) {
  1943. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1944. return !node;
  1945. }
  1946. },
  1947. showSpr: '----',
  1948. showLast: {
  1949. name: '显示至最底层',
  1950. callback: function (key, opt, menu, e) {
  1951. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1952. setTimeout(() => {
  1953. showWaitingView();
  1954. stageTree.expandByCustom(x => {
  1955. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1956. });
  1957. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  1958. closeWaitingView();
  1959. }, 100);
  1960. },
  1961. disabled: function (key, opt) {
  1962. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1963. return !node;
  1964. }
  1965. },
  1966. detail: {
  1967. name: '查看变更后数量明细',
  1968. callback: function(key, opt, menu, e) {
  1969. const curBills = SpreadJsObj.getSelectObject(slSheet);
  1970. $('#tz2d-hint').html(`当前清单:${curBills.b_code || ''} ${curBills.name || ''}`);
  1971. $('#tz2d-tz').html(`台账数量:${ curBills.quantity || 0}`);
  1972. $('#tz2d-qc').html(`变更数量:${ ZhCalc.sub(curBills.tz2_qty, curBills.quantity) || 0}`);
  1973. $('#tz2d-sum').html(`变更后数量:${ curBills.tz2_qty || 0}`);
  1974. const html = [];
  1975. html.push('<tr class="text-center"><th>变更令编号</th><th>变更令名称</th><th>计量单元</th><th>计价</th><th>批复数量</th></tr>');
  1976. if (!curBills.changeBills) curBills.changeBills = [];
  1977. curBills.changeBills.sort((a, b) => {
  1978. if (a.code === b.code) {
  1979. return a.pos > b.pos ? 1 : -1;
  1980. } else {
  1981. return a.code > b.code ? 1 : -1;
  1982. }
  1983. });
  1984. for (const cb of curBills.changeBills) {
  1985. html.push(`<tr><td>${cb.code}</td><td>${cb.name}</td><td>${cb.pos}</td><td class="text-center">${ cb.is_valuation ? '√' : '' }</td><td class="text-right">${cb.qty}</td></tr>`);
  1986. }
  1987. $('#tz2d-list').html(html.join(''));
  1988. $('#tz2-detail').modal('show');
  1989. },
  1990. disabled: function(key, opt) {
  1991. const curBills = SpreadJsObj.getSelectObject(slSheet);
  1992. return !curBills || !curBills.b_code;
  1993. }
  1994. },
  1995. exportSpr: '----',
  1996. exportSelectNodeXlsx: {
  1997. name: '导出选中节点至Excel',
  1998. callback: function (key, opt, menu, e) {
  1999. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2000. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  2001. },
  2002. disabled: function (key, opt) {
  2003. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2004. return !node;
  2005. }
  2006. },
  2007. exportContractExprXlsx: {
  2008. name: '导出本期合同计量公式',
  2009. callback: function(key, opt, menu, e) {
  2010. exportExcelSetting.cols.push({title: '本期合同计量计算式', colSpan: '1', rowSpan: '2', field: 'contract_expr_str', hAlign: 0, width: 140, formatter: '@'});
  2011. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + '本期合同计量公式.xlsx', null, false);
  2012. exportExcelSetting.cols.splice(exportExcelSetting.cols.length - 1, 1);
  2013. },
  2014. visible: function(key, opt) {
  2015. return contractExpr;
  2016. }
  2017. },
  2018. dealLoadSpr: '---',
  2019. exportDealData: {
  2020. name: '导出本期合同计量',
  2021. callback: function (key, opt, menu, e) {
  2022. window.open(window.location.pathname + '/cpd');
  2023. },
  2024. },
  2025. importDealData: {
  2026. name: '导入本期合同计量',
  2027. callback: function (key, opt, menu, e) {
  2028. BaseImportFile.show({
  2029. validList: ['.cpd'],
  2030. url: window.location.pathname + '/cpd/load',
  2031. afterImport: function() {
  2032. window.location.reload();
  2033. }
  2034. });
  2035. },
  2036. disabled: function(key, opt) {
  2037. return readOnly || stage.revising || stage.status !== auditConst.status.uncheck;
  2038. },
  2039. },
  2040. exportTestData: {
  2041. name: '导出测试数据',
  2042. callback: function (key, opt, menu, e) {
  2043. const data = stageTree.nodes.map(x => {
  2044. const parent = stageTree.getParent(x);
  2045. return {
  2046. id: x.id, parentId: parent ? parent.id : '-1', seq: x.order,
  2047. code: x.code || '', b_code: x.b_code || '', name: x.name || '', unit: x.unit || '', unit_price: x.unit_price || 0,
  2048. quantity: x.quantity || 0, total_price: x.total_price || 0,
  2049. is_tp: x.is_tp || 0,
  2050. contract_qty: x.contract_qty || 0, contract_tp: x.contract_tp || 0,
  2051. qc_qty: x.qc_qty || 0, qc_tp: x.qc_tp || 0,
  2052. gather_qty: x.gather_qty || 0, gather_tp: x.gather_tp || 0,
  2053. pre_contract_qty: x.pre_contract_qty || 0, pre_contract_tp: x.pre_contract_tp || 0,
  2054. pre_qc_qty: x.pre_qc_qty || 0, pre_qc_tp: x.pre_qc_tp || 0,
  2055. pre_gather_qty: x.pre_gather_qty || 0, pre_gather_tp: x.pre_gather_tp || 0,
  2056. end_contract_qty: x.end_contract_qty || 0, end_contract_tp: x.end_contract_tp || 0,
  2057. end_qc_qty: x.end_qc_qty || 0, end_qc_tp: x.end_qc_tp || 0,
  2058. end_gather_qty: x.end_gather_qty || 0, end_gather_tp: x.end_gather_tp || 0,
  2059. memo: x.memo || '',
  2060. gxby_status: x.gxby_status || 0, gxby_url: x.gxby_status || '',
  2061. dagl_status: x.gxby_status || 0, dagl_url: x.dagl_url || '',
  2062. wbs_url: x.wbs_url || '',
  2063. };
  2064. });
  2065. const blob = new Blob([JSON.stringify(data, '', '\t')], { type: 'application/text'});
  2066. saveAs(blob, 'test.json');
  2067. },
  2068. visible: function() {
  2069. return is_debug || false;
  2070. }
  2071. },
  2072. sumLoadSpr: '---',
  2073. importStageGcl: {
  2074. name: '导入(其他标段)工程量清单计量数据',
  2075. icon: 'fa-link',
  2076. disabled: function (key, opt) {
  2077. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2078. return readOnly || !node || !stageTree.isLeafXmj(node);
  2079. },
  2080. callback: function (key, opt) {
  2081. tenderSelect.showSelect(SpreadJsObj.getSelectObject(slSpread.getActiveSheet()));
  2082. }
  2083. },
  2084. batchImportStageGcl: {
  2085. name: '批量导入(其他标段)工程量清单计量数据',
  2086. icon: 'fa-link',
  2087. disabled: function (key, opt) {
  2088. return readOnly;
  2089. },
  2090. callback: function (key, opt){
  2091. batchImport.show();
  2092. }
  2093. },
  2094. percentSpr: '---',
  2095. percentCalc: {
  2096. name: '根据(其他标段)计量比例计量',
  2097. disabled: function(key, opt) {
  2098. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2099. const posRange = stagePos.getLedgerPos(node.id) || [];
  2100. return readOnly || !node || !node.is_tp || posRange.length > 0;
  2101. },
  2102. callback: function(key, opt) {
  2103. spssTenderSelect.showSelect();
  2104. }
  2105. },
  2106. shoufangdanSpr: '---',
  2107. shoufangdan: {
  2108. name: '生成收方单',
  2109. visible: function(key, opt) {
  2110. if (cur_uid === stage.user_id) return true;
  2111. },
  2112. disabled: function (key, opt) {
  2113. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2114. if (!node || !node.b_code || !node.is_leaf || cur_uid !== stage.user_id) return true;
  2115. },
  2116. callback: function (key, opt) {
  2117. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2118. $('#shoufang-lid').val(node.id);
  2119. $('#shoufang-pid').val('');
  2120. $('#shoufang-ledger').text('清单:' + node.b_code);
  2121. $('#shoufang-pos').text('').hide();
  2122. $('#addshoufang').modal('show');
  2123. }
  2124. },
  2125. lockedSpr: '----',
  2126. lockedHint: {
  2127. name: '检查审批状态',
  2128. visible: function (key, opt) {
  2129. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2130. return node.locked;
  2131. },
  2132. callback: function (key, opt) {
  2133. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2134. const lockedInfo = stageTree.getLockedInfo(node);
  2135. toastr.warning(`审批人 ${lockedInfo.map(x => { return x.name; }).join(',')} 审批通过,如需修改,请联系审批人重新审批`);
  2136. }
  2137. },
  2138. }
  2139. });
  2140. const stagePosSpreadObj = {
  2141. loadExprToInput(sheet) {
  2142. const sel = sheet.getSelections()[0];
  2143. if (!sel) return;
  2144. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  2145. if (col && col.type === 'Number') {
  2146. const data = SpreadJsObj.getSelectObject(sheet);
  2147. if (data) {
  2148. const exprInfo = getExprInfo(col.field);
  2149. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  2150. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  2151. .attr('readOnly', readOnly || cell.locked());
  2152. $('#pos-expr').attr('data-row', sel.row);
  2153. } else {
  2154. $('#pos-expr').val('').attr('readOnly', true);
  2155. $('#pos-expr').removeAttr('data-row');
  2156. }
  2157. } else {
  2158. $('#pos-expr').val('').attr('readOnly', true);
  2159. $('#pos-expr').removeAttr('data-row');
  2160. }
  2161. },
  2162. /**
  2163. * 加载计量单元 根据当前台账选择节点
  2164. */
  2165. loadCurPosData: function () {
  2166. const sheet = slSpread.getActiveSheet();
  2167. const node = SpreadJsObj.getSelectObject(sheet);
  2168. if (node) {
  2169. const posReadOnly = node.lock || (node.children && node.children.length > 0) || !node.b_code;
  2170. spSpread.getActiveSheet().zh_setting.readOnly = posReadOnly;
  2171. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  2172. const posMeasure = $('#pos-measure')[0].checked;
  2173. const posUnMeasure = $('#pos-un-measure')[0].checked;
  2174. posData.forEach(x => {
  2175. x.visible = true;
  2176. if (posMeasure && x.visible) {
  2177. x.visible = !!x.contract_qty || !!x.qc_qty || !!x.qc_minus_qty;
  2178. }
  2179. if (posUnMeasure && x.visible) {
  2180. // 不考虑不计价
  2181. x.visible = !x.end_contract_qty && !x.end_qc_qty && !x.end_gather_qty; // && !x.qc_minus_qty;
  2182. }
  2183. });
  2184. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData, posReadOnly);
  2185. getNodeList(node.id);
  2186. } else {
  2187. spSpread.getActiveSheet().zh_setting.readOnly = true;
  2188. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', [], true);
  2189. }
  2190. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  2191. },
  2192. editEnded: function (e, info) {
  2193. if (info.sheet.zh_setting) {
  2194. // 未改变过,则直接跳过
  2195. const sortData = info.sheet.zh_data;
  2196. const posData = sortData ? sortData[info.row] : null;
  2197. const col = info.sheet.zh_setting.cols[info.col];
  2198. const orgText = posData ? posData[col.field] : null;
  2199. const newText = trimInvalidChar(info.editingText);
  2200. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  2201. return;
  2202. }
  2203. // 台账模式下,不可新增
  2204. if (checkTzMeasureType() && !posData) {
  2205. toastr.error('台账模式不可新增计量单元数据');
  2206. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2207. return ;
  2208. }
  2209. // 不同节点下,计量单元检查输入
  2210. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2211. const node = stagePosSpreadObj.stageTreeNode;
  2212. if (!node) {
  2213. toastr.warning('数据错误, 请刷新页面后再试');
  2214. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2215. return;
  2216. } else if (newText !== '' && node.children && node.children.length > 0) {
  2217. toastr.error('父节点不可插入计量单元');
  2218. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2219. return;
  2220. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  2221. toastr.error('项目节不可插入计量单元');
  2222. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2223. return;
  2224. }
  2225. // 生成提交数据
  2226. const data = {};
  2227. if (col.field === 'name') {
  2228. if ((!newText || newText === '') && posData) {
  2229. toastr.error('部位名称不可为空');
  2230. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2231. return;
  2232. } else if (!posData) {
  2233. if (newText !== '') {
  2234. data.updateType = 'add';
  2235. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  2236. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  2237. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2238. return;
  2239. }
  2240. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  2241. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  2242. } else {
  2243. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2244. return;
  2245. }
  2246. } else {
  2247. data.updateType = 'update';
  2248. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  2249. }
  2250. } else if (!posData) {
  2251. toastr.warning('新增计量单元请先输入名称');
  2252. } else if (['ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  2253. data.updateType = 'update';
  2254. data.updateData = {pid: posData.id, lid: posData.lid};
  2255. data.updateData[col.field] = newText;
  2256. } else {
  2257. data.updateType = 'update';
  2258. data.updateData = {pid: posData.id, lid: posData.lid};
  2259. if (col.type === 'Number') {
  2260. const exprInfo = getExprInfo(col.field);
  2261. const num = _.toNumber(newText);
  2262. if (_.isFinite(num)) {
  2263. data.updateData[col.field] = num;
  2264. if (exprInfo) {
  2265. data.updateData[exprInfo.expr] = '';
  2266. }
  2267. } else {
  2268. try {
  2269. data.updateData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
  2270. if (exprInfo) {
  2271. data.updateData[exprInfo.expr] = newText;
  2272. }
  2273. } catch(err) {
  2274. toastr.error('输入的表达式非法');
  2275. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2276. return;
  2277. }
  2278. }
  2279. } else if (col.field.indexOf('_expr') > 0) {
  2280. const exprInfo = getExprInfo(col.field, true);
  2281. if (!exprInfo) return;
  2282. if (newText) {
  2283. try {
  2284. data.updateData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
  2285. data.updateData[exprInfo.expr] = newText;
  2286. } catch(err) {
  2287. toastr.error('输入的表达式非法');
  2288. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2289. return;
  2290. }
  2291. } else {
  2292. data.updateData[exprInfo.qty] = 0;
  2293. data.updateData[exprInfo.expr] = '';
  2294. }
  2295. } else {
  2296. data.updateData[col.field] = newText;
  2297. }
  2298. }
  2299. // 提交数据到服务器
  2300. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2301. if (result.pos) {
  2302. stagePos.updateDatas(result.pos.pos);
  2303. stagePos.loadCurStageData(result.pos.curStageData);
  2304. }
  2305. const refreshData = stageTree.loadPostStageData(result.ledger);
  2306. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2307. stagePosSpreadObj.loadCurPosData();
  2308. if (detail) {
  2309. detail.loadStagePosUpdateData(result, refreshData);
  2310. } else {
  2311. stageIm.loadUpdatePosData(result, refreshData);
  2312. }
  2313. }, function () {
  2314. stagePosSpreadObj.loadCurPosData();
  2315. });
  2316. }
  2317. },
  2318. editStarting: function (e, info) {
  2319. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2320. const sel = info.sheet.getSelections();
  2321. if (!sel || !sel[0]) return;
  2322. const col = info.sheet.zh_setting.cols[sel[0].col];
  2323. const node = SpreadJsObj.getSelectObject(info.sheet);
  2324. const exprInfo = getExprInfo(col.field);
  2325. if (exprInfo && node) {
  2326. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  2327. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  2328. }
  2329. }
  2330. switch (col.field) {
  2331. case 'contract_qty':
  2332. case 'contract_expr':
  2333. case 'qc_qty':
  2334. case 'qc_minus_qty':
  2335. info.cancel = node.settle_status === settleStatus.finish;
  2336. break;
  2337. }
  2338. },
  2339. clipboardPasting: function (e, info) {
  2340. if (info.sheet.zh_setting) {
  2341. const sortData = info.sheet.zh_data;
  2342. const range = info.cellRange;
  2343. const validField = ['contract_qty', 'contract_expr', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3', 'ex_stage_qty1'];
  2344. if (!checkTzMeasureType()) {
  2345. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  2346. }
  2347. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  2348. const col = info.sheet.zh_setting.cols[iCol];
  2349. if (validField.indexOf(col.field) === -1) {
  2350. if (checkTzMeasureType()) {
  2351. toastr.error('不可修改此数据');
  2352. info.cancel = true;
  2353. return;
  2354. } else {
  2355. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  2356. const pos = sortData(iRow);
  2357. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  2358. toastr.error('不可修改此数据');
  2359. info.cancel = true;
  2360. return;
  2361. }
  2362. }
  2363. }
  2364. }
  2365. }
  2366. }
  2367. },
  2368. clipboardPasted: function (e, info) {
  2369. const hint = {
  2370. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2371. };
  2372. if (info.sheet.zh_setting) {
  2373. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2374. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2375. }
  2376. const data = { updateType: '', updateData: [], };
  2377. const sortData = info.sheet.zh_data;
  2378. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2379. if (node.children && node.children.length > 0) return;
  2380. if (sortData && (info.cellRange.row >= sortData.length)) {
  2381. data.updateType = 'add';
  2382. if (info.cellRange.col !== 0) {
  2383. toastr.warning('新增计量单元请先输入名称');
  2384. stagePosSpreadObj.loadCurPosData();
  2385. return;
  2386. }
  2387. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  2388. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  2389. stagePosSpreadObj.loadCurPosData();
  2390. return;
  2391. }
  2392. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2393. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2394. const curRow = info.cellRange.row + iRow;
  2395. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  2396. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2397. const curCol = info.cellRange.col + iCol;
  2398. const colSetting = info.sheet.zh_setting.cols[curCol];
  2399. if (!colSetting) continue;
  2400. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2401. if (colSetting.type === 'Number') {
  2402. const exprInfo = getExprInfo(colSetting.field);
  2403. if (newValue) {
  2404. const num = _.toNumber(newValue);
  2405. if (num) {
  2406. newData[colSetting.field] = num;
  2407. if (exprInfo) {
  2408. newData[exprInfo.expr] = '';
  2409. }
  2410. } else {
  2411. try {
  2412. newData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2413. if (exprInfo) {
  2414. newData[exprInfo.expr] = newValue;
  2415. }
  2416. } catch(err) {
  2417. toastr.error('输入的表达式非法');
  2418. stagePosSpreadObj.loadCurPosData();
  2419. return;
  2420. }
  2421. }
  2422. } else {
  2423. newData[colSetting.field] = null;
  2424. if (exprInfo) newData[exprInfo.expr] = '';
  2425. }
  2426. } else if (colSetting.field.indexOf('_expr') > 0) {
  2427. try {
  2428. const exprInfo = getExprInfo(colSetting.field, true);
  2429. newData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2430. if (newData[exprInfo.expr] || newData[exprInfo.qty] === undefined) {
  2431. newData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newData[exprInfo.expr]));
  2432. }
  2433. } catch (err) {
  2434. toastMessageUniq(hint.expr);
  2435. }
  2436. } else {
  2437. newData[colSetting.field] = newValue;
  2438. }
  2439. }
  2440. data.updateData.push(newData);
  2441. }
  2442. } else {
  2443. data.updateType = 'update';
  2444. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2445. const curRow = info.cellRange.row + iRow;
  2446. const curPos = sortData[curRow];
  2447. if (curPos) {
  2448. const newData = {pid: curPos.id, lid: curPos.lid};
  2449. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2450. const curCol = info.cellRange.col + iCol;
  2451. const colSetting = info.sheet.zh_setting.cols[curCol];
  2452. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2453. if (colSetting.type === 'Number') {
  2454. if (curPos.settle_status === settleStatus.finish) {
  2455. newData.error = 1;
  2456. continue;
  2457. }
  2458. const exprInfo = getExprInfo(colSetting.field);
  2459. if (!newValue) {
  2460. newData[colSetting.field] = newValue;
  2461. if (exprInfo) newData[exprInfo.expr] = '';
  2462. continue;
  2463. }
  2464. const num = _.toNumber(newValue);
  2465. if (num) {
  2466. newData[colSetting.field] = num;
  2467. if (exprInfo) newData[exprInfo.expr] = '';
  2468. } else {
  2469. try {
  2470. newData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2471. const exprInfo = getExprInfo(colSetting.field);
  2472. if (exprInfo) newData[exprInfo.expr] = newValue;
  2473. } catch(err) {
  2474. toastr.error('输入的表达式非法');
  2475. stagePosSpreadObj.loadCurPosData();
  2476. return;
  2477. }
  2478. }
  2479. } else if (colSetting.field.indexOf('_expr') > 0) {
  2480. try {
  2481. const exprInfo = getExprInfo(colSetting.field, true);
  2482. newData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2483. if (newData[exprInfo.expr] || newData[exprInfo.qty] === undefined) {
  2484. newData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newData[exprInfo.expr]));
  2485. }
  2486. } catch (err) {
  2487. toastMessageUniq(hint.expr);
  2488. }
  2489. } else {
  2490. newData[colSetting.field] = newValue;
  2491. }
  2492. }
  2493. if (newData.error === undefined) data.updateData.push(newData);
  2494. }
  2495. }
  2496. }
  2497. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2498. if (result.pos) {
  2499. stagePos.updateDatas(result.pos.pos);
  2500. stagePos.loadCurStageData(result.pos.curStageData);
  2501. }
  2502. const nodes = stageTree.loadPostStageData(result.ledger);
  2503. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2504. stagePosSpreadObj.loadCurPosData();
  2505. if (detail) {
  2506. detail.loadStagePosUpdateData(result, nodes);
  2507. } else {
  2508. stageIm.loadUpdatePosData(result, nodes);
  2509. }
  2510. }, function () {
  2511. stagePosSpreadObj.loadCurPosData();
  2512. });
  2513. }
  2514. },
  2515. deletePress: function (sheet) {
  2516. if (sheet.zh_setting.readOnly) return;
  2517. if (sheet.zh_setting && sheet.zh_data) {
  2518. const sortData = sheet.zh_data;
  2519. if (!sortData || sortData.length === 0) { return; }
  2520. const sel = sheet.getSelections()[0];
  2521. const validCols = [];
  2522. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2523. const colSetting = sheet.zh_setting.cols[iCol];
  2524. if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
  2525. validCols.push(iCol);
  2526. }
  2527. }
  2528. if (validCols.length === 0) { return; }
  2529. const datas = [], posSelects = [];
  2530. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2531. const node = sortData[iRow];
  2532. if (node) {
  2533. const data = {pid: node.id, lid: node.lid};
  2534. for (const iCol of validCols) {
  2535. const colSetting = sheet.zh_setting.cols[iCol];
  2536. if (colSetting.field === 'name') {
  2537. toastr.error('部位名称不能为空');
  2538. return;
  2539. }
  2540. if (colSetting.Type === 'Number' && node.settle_status === settleStatus.finish) {
  2541. toastr.error('已结算节点不可计量');
  2542. return;
  2543. }
  2544. if (colSetting.field.indexOf('_expr') > 0) {
  2545. const exprInfo = getExprInfo(colSetting.field, true);
  2546. if (!exprInfo) continue;
  2547. data[exprInfo.expr] = '';
  2548. data[exprInfo.qty] = 0;
  2549. } else {
  2550. data[colSetting.field] = null;
  2551. const exprInfo = getExprInfo(colSetting.field);
  2552. if (exprInfo) {
  2553. data[exprInfo.expr] = '';
  2554. }
  2555. }
  2556. }
  2557. datas.push(data);
  2558. posSelects.push(node);
  2559. }
  2560. }
  2561. if (datas.length > 0) {
  2562. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  2563. if (result.pos) {
  2564. stagePos.updateDatas(result.pos.pos);
  2565. stagePos.loadCurStageData(result.pos.curStageData);
  2566. }
  2567. const nodes = stageTree.loadPostStageData(result.ledger);
  2568. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2569. if (detail) {
  2570. detail.loadStagePosUpdateData(result, nodes);
  2571. } else {
  2572. stageIm.loadUpdatePosData(result, nodes);
  2573. }
  2574. // todo 只加载改变项
  2575. stagePosSpreadObj.loadCurPosData();
  2576. });
  2577. }
  2578. }
  2579. },
  2580. deletePos: function (sheet) {
  2581. const sels = sheet.getSelections();
  2582. const sel = sels ? sels[0] : null;
  2583. if (sheet.zh_data && sel) {
  2584. const data = {updateType: 'delete', updateData: []};
  2585. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  2586. const posData = sheet.zh_data[sel.row + iRow];
  2587. if (posData) {
  2588. data.updateData.push(posData.id);
  2589. }
  2590. }
  2591. if (data.updateData.length > 0) {
  2592. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2593. stagePos.removeDatas(result.pos.pos);
  2594. const refreshData = stageTree.loadPostStageData(result.ledger);
  2595. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2596. stagePosSpreadObj.loadCurPosData();
  2597. if (detail) {
  2598. detail.loadStagePosUpdateData(result, refreshData);
  2599. } else {
  2600. stageIm.loadUpdatePosData(result, refreshData);
  2601. }
  2602. });
  2603. }
  2604. }
  2605. },
  2606. selectionChanged: function (e, info) {
  2607. stagePosSpreadObj.loadExprToInput(info.sheet);
  2608. },
  2609. addPegs: function (pegs) {
  2610. if (!pegs || pegs.length <= 0) return;
  2611. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2612. if (!node) return;
  2613. const sheet = spSpread.getActiveSheet();
  2614. const sortData = sheet.zh_data || [];
  2615. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2616. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2617. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  2618. if (result.pos) {
  2619. stagePos.updateDatas(result.pos.pos);
  2620. }
  2621. stagePosSpreadObj.loadCurPosData();
  2622. });
  2623. }
  2624. };
  2625. $('#pos-measure').click(stagePosSpreadObj.loadCurPosData);
  2626. $('#pos-un-measure').click(stagePosSpreadObj.loadCurPosData);
  2627. // 加载上下窗口resizer
  2628. $.divResizer({
  2629. select: '#main-resize',
  2630. callback: function () {
  2631. slSpread.refresh();
  2632. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2633. $(".sp-wrap").height(bcontent-30);
  2634. spSpread.refresh();
  2635. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2636. }
  2637. });
  2638. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  2639. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;stageChange;import_change;tag;reCalcChange' }, function (result) {
  2640. // 加载树结构
  2641. stageTree.loadDatas(result.ledgerData, result.locked);
  2642. if (stage.assist) {
  2643. stageTree.loadFilter(stage.assist.ass_ledger_id);
  2644. } else if (stage.relaAuditor && stage.relaAuditor.audit_ledger_id) {
  2645. stageTree.loadFilter(stage.relaAuditor.audit_ledger_id);
  2646. }
  2647. // 加载部位明细
  2648. stagePos.loadDatas(result.posData);
  2649. stageTreeSpreadObj.loadChangeData(stageTree, stagePos, result.reCalcChange);
  2650. checkShowLast(result.ledgerData.length);
  2651. treeCalc.calculateAll(stageTree);
  2652. for (const t of result.tags) {
  2653. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  2654. }
  2655. billsTag.loadDatas(result.tags);
  2656. stagePos.calculateAll();
  2657. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  2658. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  2659. stagePosSpreadObj.loadCurPosData();
  2660. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  2661. TreeExprCalc.init({
  2662. tree: stageTree,
  2663. decimal: tenderInfo.decimal,
  2664. precision: tenderInfo.precision,
  2665. calcField: { qty: 'contract_qty', tp: 'contract_tp' }, calcType: TreeExprCalc.calcType.sortCache,
  2666. exprFieldsIndex: {
  2667. tzsl: 'quantity', tzje: 'total_price', qysl: 'deal_qty', qyje: 'deal_tp',
  2668. bqhtje: 'contract_tp',
  2669. },
  2670. exprCacheKey: ['bqhtje'],
  2671. });
  2672. // 加载中间计量
  2673. stageIm.init(tenderInfo, stage, imType, tenderInfo.decimal);
  2674. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.stageChange, result.import_change, result.detailAtt);
  2675. if (stage.assist) {
  2676. stageIm.loadFilter(stage.assist.ass_ledger_id);
  2677. } else if (stage.relaAuditor) {
  2678. stageIm.loadFilter(stage.relaAuditor.audit_ledger_id);
  2679. }
  2680. errorList.loadHisErrorData();
  2681. checkList.loadHisCheckData();
  2682. sumLoadMiss.loadHisMissData();
  2683. // 收方单赋值
  2684. ledgerData = result.ledgerData;
  2685. posData = result.posData;
  2686. makeShouFang();
  2687. }, null, true);
  2688. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  2689. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  2690. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  2691. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  2692. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  2693. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  2694. if (!readOnly) {
  2695. $('#pos-expr').bind('change onblur', function () {
  2696. if (this.readOnly) return;
  2697. const expr = $(this);
  2698. const posSheet = spSpread.getActiveSheet();
  2699. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2700. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2701. if (!select) return;
  2702. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2703. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2704. const data = {pid: select.id, lid: select.lid};
  2705. const exprInfo = getExprInfo(field);
  2706. if (newValue !== '') {
  2707. const num = _.toNumber(newValue);
  2708. if (num) {
  2709. data[field] = num;
  2710. if (exprInfo) data[exprInfo.expr] = '';
  2711. } else {
  2712. try {
  2713. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2714. if (exprInfo) data[exprInfo.expr] = newValue;
  2715. } catch (err) {
  2716. toastr.error('输入的表达式非法');
  2717. return;
  2718. }
  2719. }
  2720. } else {
  2721. data[field] = null;
  2722. if (exprInfo) data[exprInfo.expr] = '';
  2723. }
  2724. // 提交数据到服务器
  2725. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  2726. if (result.pos) {
  2727. stagePos.updateDatas(result.pos.pos);
  2728. stagePos.loadCurStageData(result.pos.curStageData);
  2729. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2730. }
  2731. const refreshData = stageTree.loadPostStageData(result.ledger);
  2732. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2733. if (detail) {
  2734. detail.loadStagePosUpdateData(result, refreshData);
  2735. } else {
  2736. stageIm.loadUpdatePosData(result, refreshData);
  2737. }
  2738. });
  2739. });
  2740. }
  2741. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  2742. $.contextMenu({
  2743. selector: '#stage-pos',
  2744. build: function ($trigger, e) {
  2745. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  2746. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2747. },
  2748. items: {
  2749. 'del': {
  2750. name: '删除',
  2751. icon: 'fa-remove',
  2752. visible: function (key, opt) {
  2753. return !checkTzMeasureType();
  2754. },
  2755. disabled: function (key, opt) {
  2756. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2757. if (!node || node.lock) return true;
  2758. const sheet = spSpread.getActiveSheet();
  2759. if (sheet.zh_data && !readOnly) {
  2760. const selection = sheet.getSelections();
  2761. if (selection && selection[0]) {
  2762. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2763. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  2764. const posData = sheet.zh_data[selection[0].row + iRow];
  2765. if (posData) {
  2766. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2767. valid = true;
  2768. break;
  2769. }
  2770. } else {
  2771. valid = true;
  2772. break;
  2773. }
  2774. }
  2775. return valid;
  2776. } else {
  2777. return true;
  2778. }
  2779. } else {
  2780. return true;
  2781. }
  2782. },
  2783. callback: function (key, opt) {
  2784. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2785. }
  2786. },
  2787. 'sort': {
  2788. name: '排序',
  2789. items: {
  2790. "addStageReverse": {
  2791. name: '按新增期倒序',
  2792. icon: 'fa-sort-amount-desc',
  2793. callback: function (key, opt) {
  2794. stagePos.sort = [['add_stage_order', 'desc'], ['porder', 'asc']];
  2795. if (spSheet.zh_data) {
  2796. spSheet.zh_data.sort((x, y) => { return y.add_stage_order - x.add_stage_order || x.porder - y.porder; });
  2797. SpreadJsObj.reLoadSheetData(spSheet);
  2798. }
  2799. }
  2800. }
  2801. }
  2802. },
  2803. 'merge-peg': {
  2804. name: '合并起讫桩号',
  2805. visible: function (key, opt) {
  2806. return !checkTzMeasureType();
  2807. },
  2808. disabled: function (key, opt) {
  2809. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2810. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2811. },
  2812. callback: function (key, opt) {
  2813. mergePeg.show();
  2814. }
  2815. },
  2816. 'calcByRatio': {
  2817. name: '按比例计量',
  2818. visible: function (key, opt) {
  2819. const data = spSpread.getActiveSheet().zh_data;
  2820. return checkTzMeasureType() && data && data.length > 0;
  2821. },
  2822. disabled: function (key, opt) {
  2823. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2824. return node.lock;
  2825. },
  2826. callback: function (key, opt) {
  2827. $('#cbr-ratio').val('');
  2828. $('#apply2sibling')[0].checked = false;
  2829. $('#cbr-check-all')[0].checked = false;
  2830. const html = [];
  2831. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2832. html.push('<tr>');
  2833. html.push('<td>', i+1, '</td>');
  2834. html.push('<td>', p.name, '</td>');
  2835. html.push('<td>', p.quantity, '</td>');
  2836. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2837. html.push('</tr>');
  2838. }
  2839. $('#cbr-pos-list').html(html.join(''));
  2840. $('#calc-by-ratio').modal('show');
  2841. }
  2842. },
  2843. 'remainCur': {
  2844. name: '填剩余量(选中行)',
  2845. disabled: function (key, opt) {
  2846. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2847. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2848. return readOnly || node.lock || !curPos;
  2849. },
  2850. callback: function (key, opt) {
  2851. const sheet = spSpread.getActiveSheet();
  2852. const sels = sheet.getSelections();
  2853. if (!sels || !sels[0]) return;
  2854. const data = { updateType: 'update', updateData: [] };
  2855. for (let iRow = 0; iRow < sels[0].rowCount; iRow++) {
  2856. const curRow = iRow + sels[0].row;
  2857. const curPos = SpreadJsObj.getRowObject(sheet, curRow);
  2858. if (!curPos) continue;
  2859. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2860. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2861. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2862. }
  2863. if (data.updateData.length > 0) {
  2864. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2865. if (result.pos) {
  2866. stagePos.updateDatas(result.pos.pos);
  2867. stagePos.loadCurStageData(result.pos.curStageData);
  2868. }
  2869. const nodes = stageTree.loadPostStageData(result.ledger);
  2870. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2871. stagePosSpreadObj.loadCurPosData();
  2872. if (detail) {
  2873. detail.loadStagePosUpdateData(result, nodes);
  2874. } else {
  2875. stageIm.loadUpdatePosData(result, nodes);
  2876. }
  2877. });
  2878. }
  2879. },
  2880. visible: function(key, opt) {
  2881. return checkTzMeasureType();
  2882. },
  2883. },
  2884. 'remainAll': {
  2885. name: '填剩余量(全部行)',
  2886. disabled: function (key, opt) {
  2887. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2888. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2889. return readOnly || node.lock || !curPos;
  2890. },
  2891. callback: function (key, opt) {
  2892. const sheet = spSpread.getActiveSheet();
  2893. if (!sheet.zh_data || sheet.zh_data.length === 0) return;
  2894. const data = { updateType: 'update', updateData: [] };
  2895. for (const curPos of sheet.zh_data) {
  2896. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2897. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2898. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2899. }
  2900. if (data.updateData.length > 0) {
  2901. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2902. if (result.pos) {
  2903. stagePos.updateDatas(result.pos.pos);
  2904. stagePos.loadCurStageData(result.pos.curStageData);
  2905. }
  2906. const nodes = stageTree.loadPostStageData(result.ledger);
  2907. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2908. stagePosSpreadObj.loadCurPosData();
  2909. if (detail) {
  2910. detail.loadStagePosUpdateData(result, nodes);
  2911. } else {
  2912. stageIm.loadUpdatePosData(result, nodes);
  2913. }
  2914. });
  2915. }
  2916. },
  2917. visible: function(key, opt) {
  2918. return checkTzMeasureType();
  2919. },
  2920. },
  2921. 'shoufangdan': {
  2922. name: '生成收方单',
  2923. visible: function(key, opt) {
  2924. if (cur_uid === stage.user_id) return true;
  2925. },
  2926. disabled: function (key, opt) {
  2927. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2928. if (!node || cur_uid !== stage.user_id) return true;
  2929. },
  2930. callback: function (key, opt) {
  2931. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2932. const ledgerNode = _.find(ledgerData, { id: node.lid });
  2933. $('#shoufang-lid').val(node.lid);
  2934. $('#shoufang-pid').val(node.id);
  2935. $('#shoufang-ledger').text('清单:' + ledgerNode.b_code);
  2936. $('#shoufang-pos').text('计量单元:' + node.name).show();
  2937. $('#addshoufang').modal('show');
  2938. }
  2939. },
  2940. detail: {
  2941. name: '查看变更后数量明细',
  2942. callback: function(key, opt, menu, e) {
  2943. const curBills = SpreadJsObj.getSelectObject(slSheet);
  2944. const curPos = SpreadJsObj.getSelectObject(spSheet);
  2945. $('#tz2d-hint').html(`当前清单:${curBills.b_code || ''} ${curBills.name || ''} - ${curPos.name || ''}`);
  2946. $('#tz2d-tz').html(`台账数量:${ curPos.quantity || 0}`);
  2947. $('#tz2d-qc').html(`变更数量:${ ZhCalc.sub(curPos.tz2_qty, curPos.quantity) || 0}`);
  2948. $('#tz2d-sum').html(`变更后数量:${ curPos.tz2_qty || 0}`);
  2949. const html = [];
  2950. html.push('<tr class="text-center"><th>变更令编号</th><th>变更令名称</th><th>计价</th><th>批复数量</th></tr>');
  2951. if (!curPos.changeBills) curPos.changeBills = [];
  2952. for (const cb of curPos.changeBills) {
  2953. html.push(`<tr><td>${cb.code}</td><td>${cb.name}</td><td class="text-center">${ cb.is_valuation ? '√' : '' }</td><td class="text-right">${cb.qty}</td></tr>`);
  2954. }
  2955. $('#tz2d-list').html(html.join(''));
  2956. $('#tz2-detail').modal('show');
  2957. },
  2958. disabled: function(key, opt) {
  2959. const curPos = SpreadJsObj.getSelectObject(spSheet);
  2960. return !curPos;
  2961. }
  2962. },
  2963. }
  2964. });
  2965. $.subMenu({
  2966. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2967. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2968. key: 'menu.1.0.0',
  2969. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2970. callback: function (info) {
  2971. if (info.mini) {
  2972. $('.panel-title').addClass('fluid');
  2973. $('#sub-menu').removeClass('panel-sidebar');
  2974. } else {
  2975. $('.panel-title').removeClass('fluid');
  2976. $('#sub-menu').addClass('panel-sidebar');
  2977. }
  2978. autoFlashHeight();
  2979. slSpread.refresh();
  2980. spSpread.refresh();
  2981. if (searchLedger) searchLedger.spread.refresh();
  2982. if (detail) detail.spread.refresh();
  2983. if (checkedChanges) checkedChanges.refresh();
  2984. if (errorList && errorList.spread) errorList.spread.refresh();
  2985. if (checkList) checkList.spread.refresh();
  2986. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2987. }
  2988. });
  2989. $('#row-view').on('show.bs.modal', function () {
  2990. const html = [], customDisplay = customColDisplay();
  2991. for (const cd of customDisplay) {
  2992. html.push('<tr>');
  2993. html.push('<td>', cd.title, '</td>');
  2994. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2995. html.push('</tr>');
  2996. }
  2997. $('#row-view-list').html(html.join(''));
  2998. });
  2999. $('#row-view-ok').click(function () {
  3000. const customDisplay = customColDisplay();
  3001. const cvl = $('#row-view-list').children();
  3002. for (const cv of cvl) {
  3003. const title = $(cv).children()[0].innerHTML;
  3004. const check = $('input', cv)[0].checked;
  3005. const cd = customDisplay.find(function (c) {
  3006. return c.title === title;
  3007. });
  3008. cd.visible = check;
  3009. }
  3010. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  3011. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  3012. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  3013. $('#row-view').modal('hide');
  3014. });
  3015. const posSearch = (function () {
  3016. let resultArr = [];
  3017. const search = function () {
  3018. resultArr = [];
  3019. const keyword = $('#pos-search-keyword').val();
  3020. const checkOver = $('#pos-over-search')[0].checked;
  3021. const checkEmpty = $('#pos-empty-search')[0].checked;
  3022. const sortData = spSpread.getActiveSheet().zh_data;
  3023. if (checkOver || checkEmpty) {
  3024. if (sortData) {
  3025. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  3026. const sd = sortData[i];
  3027. let match = false;
  3028. if (checkOver) {
  3029. if (sd.end_gather_qty) {
  3030. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  3031. }
  3032. }
  3033. if (checkEmpty) {
  3034. if (sd.quantity) {
  3035. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  3036. }
  3037. }
  3038. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  3039. if (match) {
  3040. resultArr.push({index: i, data: sd});
  3041. }
  3042. }
  3043. }
  3044. } else if (keyword && keyword !== '') {
  3045. if (sortData) {
  3046. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  3047. const sd = sortData[i];
  3048. if (sd.name && sd.name.indexOf(keyword) > -1) {
  3049. resultArr.push({index: i, data: sd});
  3050. }
  3051. }
  3052. }
  3053. }
  3054. $('#pos-search-result').html('结果:' + resultArr.length);
  3055. };
  3056. const searchAndLocate = function () {
  3057. search();
  3058. if (resultArr.length > 0) {
  3059. const sheet = spSpread.getActiveSheet();
  3060. const sel = sheet.getSelections()[0];
  3061. const curRow = sel ? sel.row : 0;
  3062. const pos = resultArr[0];
  3063. if (pos.index !== curRow) {
  3064. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  3065. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  3066. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  3067. }
  3068. }
  3069. };
  3070. const locateNext = function () {
  3071. if (resultArr.length > 0) {
  3072. const sheet = spSpread.getActiveSheet();
  3073. const sel = sheet.getSelections()[0];
  3074. const curRow = sel ? sel.row : 0;
  3075. let next = _.find(resultArr, function (d) {
  3076. return d.index > curRow;
  3077. });
  3078. if (!next) next = resultArr[0];
  3079. if (next.index !== curRow) {
  3080. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  3081. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  3082. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  3083. }
  3084. }
  3085. };
  3086. const locatePre = function () {
  3087. if (resultArr.length > 0) {
  3088. const sheet = spSpread.getActiveSheet();
  3089. const sel = sheet.getSelections()[0];
  3090. const curRow = sel ? sel.row : 0;
  3091. let next = _.findLast(resultArr, function (d) {
  3092. return d.index < curRow;
  3093. });
  3094. if (!next) next = resultArr[resultArr.length - 1];
  3095. if (next.index !== curRow) {
  3096. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  3097. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  3098. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  3099. }
  3100. }
  3101. };
  3102. return {search, searchAndLocate, locateNext, locatePre};
  3103. })();
  3104. $('#pos-search-keyword').bind('keydown', function(e){
  3105. if (e.keyCode == 13) posSearch.searchAndLocate();
  3106. });
  3107. $('#pos-empty-search').click(function () {
  3108. if (this.checked) {
  3109. $('[for=' + this.id +']').addClass('text-warning');
  3110. } else {
  3111. $('[for=' + this.id +']').removeClass('text-warning');
  3112. }
  3113. if (this.checked) {
  3114. if ($('#pos-over-search')[0].checked) {
  3115. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3116. } else {
  3117. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  3118. }
  3119. } else {
  3120. if ($('#pos-over-search')[0].checked) {
  3121. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  3122. } else {
  3123. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3124. }
  3125. }
  3126. posSearch.searchAndLocate();
  3127. });
  3128. $('#pos-over-search').click(function () {
  3129. if (this.checked) {
  3130. $('[for=' + this.id +']').addClass('text-danger');
  3131. } else {
  3132. $('[for=' + this.id +']').removeClass('text-danger');
  3133. }
  3134. if (this.checked) {
  3135. if ($('#pos-empty-search')[0].checked) {
  3136. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3137. } else {
  3138. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  3139. }
  3140. } else {
  3141. if ($('#pos-empty-search')[0].checked) {
  3142. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  3143. } else {
  3144. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3145. }
  3146. }
  3147. posSearch.searchAndLocate();
  3148. });
  3149. $('#pos-search-next').click(() => {posSearch.locateNext()});
  3150. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  3151. $.divResizer({
  3152. select: '#right-spr',
  3153. callback: function () {
  3154. autoFlashHeight();
  3155. slSpread.refresh();
  3156. spSpread.refresh();
  3157. if (searchLedger) {
  3158. searchLedger.spread.refresh();
  3159. }
  3160. if (detail) {
  3161. detail.spread.refresh();
  3162. }
  3163. if (checkedChanges) checkedChanges.refresh();
  3164. if (errorList && errorList.spread) errorList.spread.refresh();
  3165. if (checkList) checkList.spread.refresh();
  3166. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3167. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3168. }
  3169. });
  3170. // 中间计量加载上下窗口resizer
  3171. $.divResizer({
  3172. select: '#zhongjian-spr',
  3173. callback: function () {
  3174. if (detail) {
  3175. detail.spread.refresh();
  3176. }
  3177. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  3178. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3179. }
  3180. });
  3181. // 附件加载上下窗口resizer
  3182. $.divResizer({
  3183. select: '#file-spr',
  3184. callback: function () {
  3185. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3186. }
  3187. });
  3188. // 变更令加载上下窗口resizer
  3189. $.divResizer({
  3190. select: '#change-spr',
  3191. callback: function () {
  3192. if (checkedChanges) checkedChanges.refresh();
  3193. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3194. }
  3195. });
  3196. class Detail {
  3197. constructor (obj) {
  3198. const self = this;
  3199. this.spreadSetting = {
  3200. cols: [
  3201. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3202. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3203. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  3204. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  3205. {
  3206. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  3207. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  3208. },
  3209. {
  3210. title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
  3211. normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
  3212. return data.attachment ? data.attachment.length : 0;
  3213. }
  3214. },
  3215. ],
  3216. headRows: 1,
  3217. emptyRows: 0,
  3218. headRowHeight: [32],
  3219. headColWidth: [30],
  3220. defaultRowHeight: 21,
  3221. headerFont: '12px 微软雅黑',
  3222. font: '12px 微软雅黑',
  3223. readOnly: readOnly,
  3224. selectedBackColor: '#fffacd',
  3225. imageClick: function (data) {
  3226. self.makeAttTable(data);
  3227. $('#im-file').modal('show');
  3228. }
  3229. };
  3230. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  3231. this.sheet = this.spread.getActiveSheet();
  3232. this.spread.options.allowUserDragFill = true;
  3233. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  3234. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  3235. this.detailObj = {
  3236. selectionChanged: function (e, info) {
  3237. self.reLoadDetailData();
  3238. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  3239. self.loadLocateInfo();
  3240. }
  3241. },
  3242. editEnded: function(e, info) {
  3243. if (info.sheet.zh_setting) {
  3244. const col = info.sheet.zh_setting.cols[info.col];
  3245. if (col.field !== 'doc_code') {
  3246. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3247. return;
  3248. }
  3249. const data = SpreadJsObj.getSelectObject(info.sheet);
  3250. if (data) {
  3251. const updateData = {lid: data.lid, pid: data.pid};
  3252. if (data.uuid) {
  3253. updateData.uuid = data.uuid;
  3254. } else {
  3255. updateData.code = data.code;
  3256. updateData.name = data.name;
  3257. updateData.unit = data.unit;
  3258. updateData.unit_price = data.unit_price;
  3259. updateData.pid = data.pid;
  3260. updateData.pos_name = data.pos_name;
  3261. updateData.im_type = data.im_type;
  3262. }
  3263. if (data.custom_define.indexOf('doc_code') === -1) {
  3264. updateData.custom_define = data.custom_define;
  3265. updateData.custom_define.push('doc_code');
  3266. updateData.custom_define = updateData.custom_define.join(',');
  3267. }
  3268. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  3269. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3270. stageIm.loadUpdateDetailData(result);
  3271. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3272. }, function () {
  3273. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3274. });
  3275. } else {
  3276. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3277. }
  3278. }
  3279. },
  3280. clipboardPasted: function (e, info) {
  3281. if (info.sheet.zh_setting && info.sheet.zh_data) {
  3282. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  3283. if (info.cellRange.colCount > 1) {
  3284. toastr.warning('请勿同时复制粘贴多列数据');
  3285. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  3286. return;
  3287. }
  3288. if (col.field !== 'doc_code') {
  3289. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  3290. return;
  3291. }
  3292. const datas = [];
  3293. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3294. const curRow = info.cellRange.row + iRow;
  3295. const data = info.sheet.zh_data[curRow];
  3296. if (data) {
  3297. const updateData = {lid: data.lid, pid: data.pid};
  3298. if (data.uuid) {
  3299. updateData.uuid = data.uuid;
  3300. } else {
  3301. updateData.code = data.code;
  3302. updateData.name = data.name;
  3303. updateData.unit = data.unit;
  3304. updateData.unit_price = data.unit_price;
  3305. updateData.pid = data.pid;
  3306. updateData.pos_name = data.pos_name;
  3307. updateData.im_type = data.im_type;
  3308. }
  3309. if (data.custom_define.indexOf('doc_code') === -1) {
  3310. updateData.custom_define = data.custom_define;
  3311. updateData.custom_define.push('doc_code');
  3312. updateData.custom_define = updateData.custom_define.join(',');
  3313. }
  3314. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  3315. datas.push(updateData);
  3316. }
  3317. }
  3318. if (datas.length > 0) {
  3319. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3320. stageIm.loadUpdateDetailData(result);
  3321. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3322. }, function () {
  3323. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3324. })
  3325. }
  3326. }
  3327. },
  3328. deletePress: function (sheet) {
  3329. if (sheet.zh_setting) {
  3330. const datas = [];
  3331. const sel = sheet.getSelections()[0];
  3332. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  3333. const col = sheet.zh_setting.cols[iCol];
  3334. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  3335. const data = sheet.zh_data[iRow];
  3336. if (col.field === 'doc_code') {
  3337. const updateData = {lid: data.lid};
  3338. if (data.uuid) {
  3339. updateData.uuid = data.uuid;
  3340. updateData.doc_code = '';
  3341. datas.push(updateData);
  3342. }
  3343. }
  3344. }
  3345. }
  3346. if (datas.length > 0) {
  3347. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3348. stageIm.loadUpdateDetailData(result);
  3349. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  3350. }, function () {
  3351. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  3352. });
  3353. }
  3354. }
  3355. },
  3356. dragFillBlock: function (e, info) {
  3357. info.cancel = true;
  3358. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  3359. const sel = info.sheet.getSelections()[0];
  3360. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  3361. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  3362. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  3363. if (text === '') return;
  3364. const regRst = /(\d+)$/g.exec(text), datas = [];
  3365. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  3366. const curRow = info.fillRange.row + iRow;
  3367. const data = info.sheet.zh_data[curRow];
  3368. if (data) {
  3369. const updateData = {lid: data.lid};
  3370. if (data.uuid) {
  3371. updateData.uuid = data.uuid;
  3372. } else {
  3373. updateData.code = data.code;
  3374. updateData.name = data.name;
  3375. updateData.unit = data.unit;
  3376. updateData.unit_price = data.unit_price;
  3377. updateData.pid = data.pid;
  3378. updateData.pos_name = data.pos_name;
  3379. updateData.im_type = data.im_type;
  3380. }
  3381. if (regRst) {
  3382. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  3383. } else {
  3384. updateData.doc_code = text.replace('\n', '');
  3385. }
  3386. if (data.custom_define.indexOf('doc_code') === -1) {
  3387. updateData.custom_define = data.custom_define;
  3388. updateData.custom_define.push('doc_code');
  3389. updateData.custom_define = updateData.custom_define.join(',');
  3390. }
  3391. datas.push(updateData);
  3392. }
  3393. }
  3394. if (datas.length > 0) {
  3395. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3396. stageIm.loadUpdateDetailData(result);
  3397. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  3398. }, function () {
  3399. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  3400. })
  3401. }
  3402. },
  3403. };
  3404. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  3405. if (!readOnly) {
  3406. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  3407. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  3408. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  3409. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  3410. }
  3411. this._initImTypeSetRela();
  3412. this._initModifyDetail();
  3413. this._initLocateRela();
  3414. this._initAttRela();
  3415. // 草图相关
  3416. this._initImageRela();
  3417. this.reBuildImData();
  3418. }
  3419. makeAttTable (data) {
  3420. let html = [];
  3421. if (data.attachment) {
  3422. for (const att of data.attachment) {
  3423. const delHtml = (parseInt(att.uid) === userID && (att.renew || stage.status !== auditConst.status.checked || deleteFilePermission))
  3424. ? '<a class="delete-att text-danger ml-1" href="javascript:void(0);" data-imid="'+ data.att_uuid +'" data-attid="'+ att.file_id +'" title="删除"><i class="fa fa-remove "></i></a>'
  3425. : '';
  3426. const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
  3427. const downloadHtml = '<a href="'+ window.location.pathname + '/im-file/download?im_id='+ data.att_uuid +'&file_id='+ att.file_id +'" title="下载"><i class="fa fa-download "></i></a>';
  3428. html.push(`<tr><td><input type="checkbox" name="sia-check" fid="${att.file_id}"></td><td style="width: 200px">` + att.filename + att.fileext + '</td><td>' + att.username + '</td><td>' + att.in_time + '</td>',
  3429. '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
  3430. }
  3431. }
  3432. $('#im-attList').html(html.join(''));
  3433. }
  3434. _initAttRela() {
  3435. // 上传附件
  3436. const self = this;
  3437. $('#upload-im-file').change(function () {
  3438. const files = this.files;
  3439. const sels = self.sheet.getSelections();
  3440. const select = SpreadJsObj.getSelectObject(self.sheet);
  3441. if (!select) return;
  3442. const formData = new FormData();
  3443. const baseInfo = {};
  3444. if (select.att_uuid) {
  3445. baseInfo.uuid = select.att_uuid;
  3446. } else {
  3447. baseInfo.im_type = select.im_type;
  3448. baseInfo.lid = select.lid;
  3449. baseInfo.pid = select.pid;
  3450. baseInfo.code = select.code;
  3451. baseInfo.name = select.name;
  3452. baseInfo.unit = select.unit;
  3453. baseInfo.unit_price = select.unit_price;
  3454. baseInfo.pos_name = select.pos_name;
  3455. }
  3456. formData.append('base', JSON.stringify(baseInfo));
  3457. for (const file of files) {
  3458. if (file === undefined) {
  3459. toast('未选择上传文件!', 'error');
  3460. return false;
  3461. }
  3462. const filesize = file.size;
  3463. if (filesize > 50 * 1024 * 1024) {
  3464. toast('存在上传文件大小过大!', 'error');
  3465. return false;
  3466. }
  3467. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3468. if (whiteList.indexOf(fileext) === -1) {
  3469. toast('只能上传指定格式的附件!', 'error');
  3470. return false;
  3471. }
  3472. formData.append('size', filesize);
  3473. formData.append('file[]', file);
  3474. }
  3475. postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
  3476. stageIm.loadUpdateDetailAtt(data);
  3477. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  3478. self.makeAttTable(select);
  3479. $('#upload-im-file').val('');
  3480. });
  3481. });
  3482. // 删除附件
  3483. $('body').on('click', '.delete-att' ,function () {
  3484. const sels = self.sheet.getSelections();
  3485. const select = SpreadJsObj.getSelectObject(self.sheet);
  3486. if (!select) return;
  3487. const uuid = $(this).attr('data-imid');
  3488. const file_id = $(this).attr('data-attid');
  3489. const att = select.attachment.find(x => {
  3490. return x.file_id === file_id;
  3491. });
  3492. deleteAfterHint(function () {
  3493. postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
  3494. stageIm.loadUpdateDetailAtt(result);
  3495. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  3496. self.makeAttTable(select);
  3497. });
  3498. }, `确认删除附件「${att.filename}」?`);
  3499. });
  3500. // 预览附件
  3501. $('body').on('click', '.preview-att', function () {
  3502. const uuid = $(this).attr('data-imid');
  3503. const file_id = $(this).attr('data-attid');
  3504. postData(window.location.pathname + `/im-file/preview?uuid=${uuid}&file_id=${file_id}`, {}, function (result) {
  3505. const { filepath } = result;
  3506. $('#load-file').attr('href', filepath);
  3507. $('#load-file')[0].click();
  3508. });
  3509. });
  3510. $('#batch-download-im-file').click(function() {
  3511. const select = $('[name=sia-check]:checked');
  3512. if (select.length === 0) {
  3513. toastr.warning('请选择需要批量下载的文件');
  3514. return;
  3515. }
  3516. const files = [];
  3517. const curIm = SpreadJsObj.getSelectObject(self.sheet);
  3518. for (const s of select) {
  3519. const att = curIm.attachment.find(x => { return x.file_id === s.getAttribute('fid')});
  3520. if (att) files.push(att);
  3521. }
  3522. if (files.length === 0) return;
  3523. AliOss.zipFiles(files, `中间计量[${curIm.code}].zip`, (fails) => {
  3524. $(self).removeAttr('disabled');
  3525. if (fails.length === 0) {
  3526. toastr.success('下载成功');
  3527. } else {
  3528. toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
  3529. }
  3530. }, () => {
  3531. $(self).removeAttr('disabled');
  3532. toastr.error('批量下载失败');
  3533. });
  3534. });
  3535. }
  3536. _initImTypeSetRela() {
  3537. const self = this;
  3538. const gatherConfirmPopover = {
  3539. reBind: function (obj, eventName, fun) {
  3540. obj.unbind(eventName);
  3541. obj.bind(eventName, fun);
  3542. },
  3543. check: function (pos, hint, okCallback) {
  3544. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  3545. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  3546. this.reBind(cancelObj, 'click', function () {
  3547. confirmObj.hide();
  3548. });
  3549. this.reBind(okObj, 'click', function () {
  3550. okCallback();
  3551. confirmObj.hide();
  3552. });
  3553. hintObj.text(hint);
  3554. confirmObj.css("top", pos.y).css("left", pos.x).show();
  3555. }
  3556. };
  3557. this.gsTree = stageIm.getGsTree();
  3558. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  3559. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3560. jlCol.title = '本期计量金额';
  3561. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3562. $('[name=type-title-contract]').text('本期合同计量金额');
  3563. $('[name=type-title-qc]').text('本期变更计量金额');
  3564. if ($('#show-qc-minus-jl').length > 0) {
  3565. $('#show-qc-minus-jl').parent().hide();
  3566. $('#qc-minus-jl').parent().hide();
  3567. }
  3568. } else {
  3569. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3570. jlCol.title = '本期计量数量';
  3571. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3572. $('[name=type-title-contract]').text('本期合同计量数量');
  3573. $('[name=type-title-qc]').text('本期变更计量数量');
  3574. if ($('#show-qc-minus-jl').length > 0) {
  3575. $('#show-qc-minus-jl').parent().show();
  3576. $('#qc-minus-jl').parent().show();
  3577. }
  3578. }
  3579. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  3580. $('#show-jldy').parent().show();
  3581. $('#jldy').parent().show();
  3582. $('#show-xm-name').parent().hide();
  3583. $('#xm-name').parent().hide();
  3584. } else {
  3585. $('#show-jldy').parent().hide();
  3586. $('#jldy').parent().hide();
  3587. $('#show-xm-name').parent().show();
  3588. $('#xm-name').parent().show();
  3589. }
  3590. // 选择中间计量模式
  3591. $('div[name="im-type"]').click(function () {
  3592. function chooseType(obj) {
  3593. obj.style.cursor = 'default';
  3594. $(obj).children().addClass('text-primary');
  3595. $(obj).addClass('border-primary');
  3596. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  3597. }
  3598. function validType(obj) {
  3599. obj.style.cursor = 'pointer';
  3600. $(obj).children().removeClass('text-primary');
  3601. $(obj).removeClass('border-primary');
  3602. $('i', obj).remove();
  3603. }
  3604. if (this.style.cursor === 'pointer') {
  3605. const typeArr = $('div[name="im-type"]');
  3606. for (const t of typeArr) {
  3607. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  3608. chooseType(t);
  3609. } else {
  3610. validType(t)
  3611. }
  3612. }
  3613. }
  3614. });
  3615. $('#choose').on('show.bs.modal', function () {
  3616. function chooseType(obj) {
  3617. obj.style.cursor = 'default';
  3618. $(obj).children().addClass('text-primary');
  3619. $('i', obj).remove();
  3620. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  3621. }
  3622. function validType(obj) {
  3623. obj.style.cursor = 'pointer';
  3624. $(obj).children().removeClass('text-primary');
  3625. $('i', obj).remove();
  3626. }
  3627. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  3628. $('#im-start-num').val(stage.im_start_num ? stage.im_start_num : '');
  3629. const typeArr = $('div[name="im-type"]');
  3630. for (const t of typeArr) {
  3631. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  3632. chooseType(t);
  3633. } else {
  3634. validType(t)
  3635. }
  3636. }
  3637. });
  3638. // 提交 中间计量模式
  3639. $('#choose-ok').click(() => {
  3640. let startNum;
  3641. try {
  3642. startNum = parseInt($('#im-start-num').val());
  3643. if (!startNum || startNum <= 0) throw '起始编号请输入正整数';
  3644. } catch (err) {
  3645. toastr.error("起始编号请输入正整数");
  3646. return;
  3647. }
  3648. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  3649. return it.style.cursor !== 'pointer';
  3650. });
  3651. const data = {
  3652. im_type: parseInt($(chooseType).attr('im-type')),
  3653. im_pre: $('#im-pre').val(),
  3654. im_start_num: startNum,
  3655. };
  3656. postData(window.location.pathname + '/detail/build', data, function (result) {
  3657. stage.im_type = data.im_type;
  3658. stage.im_pre = data.im_pre;
  3659. stage.im_start_num = data.im_start_num;
  3660. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  3661. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3662. jlCol.title = '本期计量金额';
  3663. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3664. $('[name=type-title-contract]').text('本期合同计量金额');
  3665. $('[name=type-title-qc]').text('本期变更计量金额');
  3666. if ($('#show-qc-minus-jl').length > 0) {
  3667. $('#show-qc-minus-jl').parent().hide();
  3668. $('#qc-minus-jl').parent().hide();
  3669. }
  3670. } else {
  3671. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3672. jlCol.title = '本期计量数量';
  3673. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3674. $('[name=type-title-contract]').text('本期合同计量数量');
  3675. $('[name=type-title-qc]').text('本期变更计量数量');
  3676. if ($('#show-qc-minus-jl').length > 0) {
  3677. $('#show-qc-minus-jl').parent().show();
  3678. $('#qc-minus-jl').parent().show();
  3679. }
  3680. }
  3681. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  3682. $('#show-jldy').parent().show();
  3683. $('#jldy').parent().show();
  3684. $('#show-xm-name').parent().hide();
  3685. $('#xm-name').parent().hide();
  3686. } else {
  3687. $('#show-jldy').parent().hide();
  3688. $('#jldy').parent().hide();
  3689. $('#show-xm-name').parent().show();
  3690. $('#xm-name').parent().show();
  3691. }
  3692. // 加载生成数据
  3693. self.reBuildImData();
  3694. $('#choose').modal('hide');
  3695. });
  3696. });
  3697. // 显示树结构信息
  3698. $('#choose2').on('shown.bs.modal', function () {
  3699. if (!self.gsSpread) {
  3700. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  3701. const setting = {
  3702. cols: [
  3703. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  3704. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  3705. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3706. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  3707. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  3708. ],
  3709. headRows: 1,
  3710. emptyRows: 0,
  3711. headRowHeight: [32],
  3712. defaultRowHeight: 21,
  3713. headerFont: '12px 微软雅黑',
  3714. font: '12px 微软雅黑',
  3715. };
  3716. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  3717. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  3718. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  3719. function checkParent(node) {
  3720. const parent = self.gsTree.getParent(node);
  3721. if (parent) {
  3722. return parent.check ? parent.check : checkParent(parent);
  3723. } else {
  3724. return false;
  3725. }
  3726. }
  3727. function checkChildren(node) {
  3728. for (const child of node.children) {
  3729. if (child.check) {
  3730. return true;
  3731. } else if (checkChildren(child)) {
  3732. return true;
  3733. }
  3734. }
  3735. return false;
  3736. }
  3737. if (!$('#im-gather-check')[0].checked) { return; }
  3738. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  3739. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  3740. if (sheet.isEditing()) {
  3741. sheet.endEdit(true);
  3742. }
  3743. }
  3744. if (info.sheet.zh_setting) {
  3745. const col = info.sheet.zh_setting.cols[info.col];
  3746. if (col.field !== 'check') {
  3747. return;
  3748. }
  3749. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  3750. const node = sortData[info.row];
  3751. if (!node.check) {
  3752. if (checkParent(node)) {
  3753. const rect = info.sheet.getCellRect(info.row, info.col);
  3754. gatherConfirmPopover.check({
  3755. x: rect.x + rect.width / 2 + 25,
  3756. y: rect.y + rect.height / 2 + 3,
  3757. }, '父项已勾选,继续将取消父项勾选。', function () {
  3758. node.check = true;
  3759. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  3760. const rows = [self.gsTree.nodes.indexOf(node)];
  3761. for (const p of parents) {
  3762. if (p.check) {
  3763. p.check = false;
  3764. rows.push(self.gsTree.nodes.indexOf(p));
  3765. }
  3766. }
  3767. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3768. });
  3769. } else if (checkChildren(node)) {
  3770. const rect = info.sheet.getCellRect(info.row, info.col);
  3771. gatherConfirmPopover.check({
  3772. x: rect.x + rect.width / 2 + 25,
  3773. y: rect.y + rect.height / 2 + 3,
  3774. }, '子项已勾选,继续将取消子项勾选。', function () {
  3775. node.check = true;
  3776. const posterity = self.gsTree.getPosterity(node);
  3777. const rows = [self.gsTree.nodes.indexOf(node)];
  3778. for (const p of posterity) {
  3779. if (p.check) {
  3780. rows.push(self.gsTree.nodes.indexOf(p));
  3781. p.check = false;
  3782. }
  3783. }
  3784. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3785. });
  3786. } else {
  3787. node.check = true;
  3788. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3789. }
  3790. } else {
  3791. node.check = false;
  3792. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3793. }
  3794. }
  3795. });
  3796. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3797. for (const node of self.gsTree.datas) {
  3798. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3799. }
  3800. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  3801. self.gsTree.expandByLevel(4);
  3802. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  3803. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  3804. } else {
  3805. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3806. for (const node of self.gsTree.datas) {
  3807. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3808. }
  3809. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  3810. }
  3811. });
  3812. // 提交 高级设置
  3813. $('#choose2-ok').click(() => {
  3814. if (!self.gsTree) { return; }
  3815. const nodes = [];
  3816. for (const node of self.gsTree.datas) {
  3817. if (node.check) {
  3818. nodes.push(node.id);
  3819. }
  3820. }
  3821. const data = {
  3822. im_gather: $('#im-gather-check')[0].checked,
  3823. im_gather_node: nodes.join(','),
  3824. };
  3825. postData(window.location.pathname + '/detail/adv', data, function (result) {
  3826. stage.im_gather = data.im_gather;
  3827. stage.im_gather_node = data.im_gather_node;
  3828. $('#choose2').modal('hide');
  3829. });
  3830. });
  3831. }
  3832. _initLocateRela() {
  3833. const self = this;
  3834. $('#im-locate2bills').click(function () {
  3835. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3836. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3837. if (select && select.source) {
  3838. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  3839. stagePosSpreadObj.loadCurPosData();
  3840. if (select.source[curIndex-1].pos_id) {
  3841. SpreadJsObj.locateDataBy(spSpread.getActiveSheet(), function(data){ return data.id === select.source[curIndex-1].pos_id});
  3842. }
  3843. }
  3844. });
  3845. $('#im-locate-pre').click(function () {
  3846. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3847. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3848. if (select && select.source) {
  3849. const targetIndex = Math.max(curIndex-1, 1);
  3850. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3851. stagePosSpreadObj.loadCurPosData();
  3852. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3853. }
  3854. });
  3855. $('#im-locate-next').click(function () {
  3856. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3857. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3858. if (select && select.source) {
  3859. const targetIndex = Math.min(curIndex+1, select.source.length);
  3860. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3861. stagePosSpreadObj.loadCurPosData();
  3862. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3863. }
  3864. });
  3865. }
  3866. _initModifyDetail() {
  3867. const self = this;
  3868. // 重置
  3869. $('#reset-detail-ok').click(function () {
  3870. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3871. if (!data.uuid) return;
  3872. const updateData = {
  3873. lid: data.lid, pid: data.pid,
  3874. uuid: data.uuid,
  3875. custom_define: [],
  3876. };
  3877. for (const f of data.custom_define) {
  3878. if (stageIm.resetFields.indexOf(f) >= 0) {
  3879. updateData[f] = null;
  3880. } else {
  3881. updateData.custom_define.push(f);
  3882. }
  3883. }
  3884. updateData.custom_define = updateData.custom_define.join(',');
  3885. $('#reset-detail-modal').modal('hide');
  3886. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3887. stageIm.loadUpdateDetailData(result);
  3888. self.reLoadDetailData();
  3889. });
  3890. });
  3891. // 编辑
  3892. $('#edit-detail').click(function () {
  3893. $(this).hide();
  3894. $('#save-detail').show();
  3895. $('#cancel-detail').show();
  3896. $('#detail-show').hide();
  3897. $('#detail-edit').show();
  3898. self.updateImageData = null;
  3899. });
  3900. // 保存
  3901. $('#save-detail').click(() => {
  3902. function check(field, obj, org, update) {
  3903. const newValue = obj.val();
  3904. if (!org[field]) {
  3905. if (newValue !== '') {
  3906. update[field] = newValue;
  3907. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3908. return true;
  3909. }
  3910. } else if (newValue !== org[field]){
  3911. update[field] = newValue;
  3912. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3913. return true;
  3914. }
  3915. return false;
  3916. }
  3917. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3918. const updateData = {lid: data.lid, pid: data.pid};
  3919. if (data.uuid) {
  3920. updateData.uuid = data.uuid;
  3921. updateData.custom_define = data.custom_define;
  3922. } else {
  3923. updateData.code = data.code;
  3924. updateData.name = data.name;
  3925. updateData.unit = data.unit;
  3926. updateData.unit_price = data.unit_price;
  3927. updateData.pid = data.pid;
  3928. updateData.pos_name = data.pos_name;
  3929. updateData.im_type = data.im_type;
  3930. updateData.custom_define = [];
  3931. }
  3932. let infoUpdate = false;
  3933. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  3934. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  3935. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  3936. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  3937. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  3938. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  3939. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  3940. updateData.custom_define = updateData.custom_define.join(',');
  3941. if (infoUpdate) {
  3942. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3943. stageIm.loadUpdateDetailData(result);
  3944. self.reLoadDetailData();
  3945. if (!self.updateImageData) return;
  3946. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  3947. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3948. stageIm.loadUpdateDetailData(result);
  3949. self.reLoadDetailData();
  3950. });
  3951. });
  3952. } else if (self.updateImageData) {
  3953. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3954. stageIm.loadUpdateDetailData(result);
  3955. self.reLoadDetailData();
  3956. });
  3957. } else {
  3958. self.reLoadDetailData();
  3959. }
  3960. });
  3961. // 取消
  3962. $('#cancel-detail').click(() => {
  3963. self.reLoadDetailData();
  3964. });
  3965. }
  3966. _initImageRela() {
  3967. const self = this;
  3968. $('#edit-detail').click(function () {
  3969. loadImageItem();
  3970. });
  3971. function setdraggrable(){
  3972. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  3973. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  3974. stop: function( event, ui ) {
  3975. }
  3976. });
  3977. }
  3978. function upload(formData) {
  3979. if (formData.length < 1) {
  3980. return;
  3981. }
  3982. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  3983. const html = [];
  3984. html.push('<div class="img-item">');
  3985. html.push('<div class="img-bar">');
  3986. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3987. html.push('</div>');
  3988. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  3989. html.push('</div>');
  3990. $('.img-view').append(html.join(''));
  3991. $('.img-bar').click(removeImageItem);
  3992. setdraggrable();
  3993. $('#upload-img-file').val('');
  3994. });
  3995. }
  3996. function dragFile(e) {
  3997. var file = null,
  3998. data = e.dataTransfer.types;
  3999. for (var i = 0; i < data.length; i += 1) {
  4000. if (data[i] === 'Files') {
  4001. file = e.dataTransfer.files; //获取文件
  4002. break;
  4003. }
  4004. }
  4005. if (file && file[0].type.indexOf('image') !== -1) {
  4006. var formData = new FormData();
  4007. formData.append('file', file[0]); //上传单个文件的添加方式
  4008. upload(formData); //upload 异步上传
  4009. }
  4010. }
  4011. // 移动图片
  4012. const moveImageItem = function (ev) {
  4013. const item = this;
  4014. const view = $('.img-view')[0];
  4015. let oEvent = ev;
  4016. // 浏览器有一些图片的默认事件,这里要阻止
  4017. oEvent.preventDefault();
  4018. let disX = oEvent.clientX - item.offsetLeft;
  4019. let disY = oEvent.clientY - item.offsetTop;
  4020. view.onmousemove = function (ev) {
  4021. oEvent = ev;
  4022. oEvent.preventDefault();
  4023. let x = oEvent.clientX -disX;
  4024. let y = oEvent.clientY -disY;
  4025. // 图形移动的边界判断
  4026. x = x <= 0 ? 0 : x;
  4027. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  4028. y = y <= 0 ? 0 : y;
  4029. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  4030. item.style.left = x + 'px';
  4031. item.style.top = y + 'px';
  4032. };
  4033. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  4034. view.onmouseleave = function () {
  4035. view.onmousemove = null;
  4036. view.onmouseup = null;
  4037. };
  4038. // 鼠标弹起后停止移动
  4039. view.onmouseup=function() {
  4040. view.onmousemove = null;
  4041. view.onmouseup = null;
  4042. };
  4043. };
  4044. const removeImageItem = function () {
  4045. $(this).parent().remove();
  4046. };
  4047. // 加载草图组成
  4048. const loadImageItem = function () {
  4049. self.updateImageData = null;
  4050. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  4051. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  4052. const html = [];
  4053. for (const item of items) {
  4054. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  4055. html.push('<div class="img-item" style="' + itemStyle + '">');
  4056. html.push('<div class="img-bar">');
  4057. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  4058. html.push('</div>');
  4059. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  4060. html.push('</div>');
  4061. }
  4062. $('.img-view').html(html.join(''));
  4063. $('.img-bar').click(removeImageItem);
  4064. setdraggrable();
  4065. };
  4066. // 上传图片
  4067. $('#upload-img').click(function () {
  4068. $('#upload-img-file').trigger('click');
  4069. });
  4070. // 拖拽上传
  4071. //拖拽上传文件
  4072. const dragbox = document.querySelector('#upload-img');
  4073. dragbox.addEventListener('dragover', function(e) {
  4074. e.preventDefault(); // 必须阻止默认事件
  4075. }, false);
  4076. dragbox.addEventListener('drop', function(e) {
  4077. e.preventDefault(); // 阻止默认事件
  4078. dragFile(e);
  4079. }, false);
  4080. //拖拽上传文件
  4081. const dragbox2 = document.querySelector('.img-view');
  4082. dragbox2.addEventListener('dragover', function(e) {
  4083. e.preventDefault(); // 必须阻止默认事件
  4084. }, false);
  4085. dragbox2.addEventListener('drop', function(e) {
  4086. e.preventDefault(); // 阻止默认事件
  4087. dragFile(e);
  4088. }, false);
  4089. // 粘贴上传
  4090. $(".img-view").on('paste', function(ev) {
  4091. let file = null;
  4092. const data = (event.clipboardData || window.clipboardData).items;
  4093. for (let i = 0; i < data.length; i += 1) {
  4094. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  4095. file = data[i].getAsFile(); //读取图片文件
  4096. break;
  4097. }
  4098. }
  4099. if (file) {
  4100. const formData = new FormData();
  4101. formData.append('file', file); //上传单个文件的添加方式
  4102. upload(formData); //异步上传文件
  4103. }
  4104. });
  4105. $('#upload-img-file').change(function () {
  4106. const file = this.files[0];
  4107. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  4108. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  4109. if (!imgStr.test(ext)) {
  4110. toastr.error('请上传正确的图片格式文件');
  4111. return
  4112. }
  4113. if ($(this).val()) {
  4114. const formData = new FormData();
  4115. formData.append('file', this.files[0]);
  4116. upload(formData);
  4117. }
  4118. });
  4119. // 保存草图修改结果
  4120. $('#edit-img-ok').click(function () {
  4121. // 记录上传的图片的信息
  4122. const items = $('.img-item');
  4123. const img_remark = $('#text-edit').val();
  4124. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  4125. // 生成上传数据
  4126. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid, calc_img_remark: img_remark};
  4127. if (data.uuid) {
  4128. updateData.uuid = data.uuid;
  4129. } else {
  4130. updateData.code = data.code;
  4131. updateData.name = data.name;
  4132. updateData.unit = data.unit;
  4133. updateData.unit_price = data.unit_price;
  4134. updateData.pid = data.pid;
  4135. updateData.pos_name = data.pos_name;
  4136. updateData.im_type = data.im_type;
  4137. }
  4138. if (items.length === 1) {
  4139. const itemInfo = [];
  4140. for (const item of items) {
  4141. const itemData = {
  4142. src: $('img', item).attr('src'),
  4143. left: item.style.left,
  4144. top: item.style.top,
  4145. width: item.style.width,
  4146. height: item.style.height,
  4147. };
  4148. itemInfo.push(itemData);
  4149. }
  4150. // 获取合并好的图片数据
  4151. const canvas = document.createElement('canvas');
  4152. const view = $('.img-view')[0];
  4153. const b = items[0];
  4154. const pos = $(b).position();
  4155. const img = $('img', b)[0];
  4156. canvas.height = Math.max(view.clientHeight, Math.ceil(pos.top + img.naturalHeight));
  4157. canvas.width = Math.max(view.clientWidth, Math.ceil(pos.left + img.naturalWidth));
  4158. const ctx = canvas.getContext('2d');
  4159. ctx.fillStyle = '#ffffff';
  4160. ctx.fillRect(0, 0, canvas.width, canvas.height);
  4161. ctx.drawImage(img, pos.left, pos.top);
  4162. updateData.img = canvas.toDataURL('image/png');
  4163. updateData.imgInfo = itemInfo;
  4164. self.updateImageData = updateData;
  4165. $('#calc-img').attr('src', updateData.img);
  4166. $('#calc-remark').html(img_remark);
  4167. $('#view-calc-img').attr('src', updateData.img);
  4168. $('#show-calc-img').attr('src', updateData.img);
  4169. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  4170. $('#view-calc-remark').text(img_remark);
  4171. $('#edit-img').modal('hide');
  4172. } else if (items.length > 0) {
  4173. const itemInfo = [];
  4174. for (const item of items) {
  4175. const itemData = {
  4176. src: $('img', item).attr('src'),
  4177. left: item.style.left,
  4178. top: item.style.top,
  4179. width: item.style.width,
  4180. height: item.style.height,
  4181. };
  4182. itemInfo.push(itemData);
  4183. }
  4184. // 获取合并好的图片数据
  4185. const canvas = document.createElement('canvas');
  4186. const view = $('.img-view')[0];
  4187. canvas.height = view.clientHeight;
  4188. canvas.width = view.clientWidth;
  4189. const ctx = canvas.getContext('2d');
  4190. ctx.fillStyle = '#ffffff';
  4191. ctx.fillRect(0, 0, canvas.width, canvas.height);
  4192. for (const b of $('.img-item')) {
  4193. const pos = $(b).position();
  4194. const img = $('img', b)[0];
  4195. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  4196. }
  4197. updateData.img = canvas.toDataURL('image/png');
  4198. updateData.imgInfo = itemInfo;
  4199. self.updateImageData = updateData;
  4200. $('#calc-img').attr('src', updateData.img);
  4201. $('#calc-remark').html(img_remark);
  4202. $('#view-calc-img').attr('src', updateData.img);
  4203. $('#show-calc-img').attr('src', updateData.img);
  4204. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  4205. $('#view-calc-remark').text(img_remark);
  4206. $('#edit-img').modal('hide');
  4207. // });
  4208. } else if (data.calc_img) {
  4209. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid, calc_img_remark: img_remark};
  4210. $('#show-calc-img').attr('src', '');
  4211. $('#show-calc-remark').html('');
  4212. $('#calc-img').attr('src', '');
  4213. $('#calc-remark').html(img_remark);
  4214. $('#view-calc-img').attr('src', '');
  4215. $('#view-calc-remark').val(img_remark);
  4216. $('#text-edit').val(img_remark);
  4217. $('#edit-img').modal('hide');
  4218. } else {
  4219. self.updateImageData = updateData;
  4220. $('#show-calc-img').attr('src', '');
  4221. $('#show-calc-remark').html('');
  4222. $('#calc-img').attr('src', '');
  4223. $('#calc-remark').html(img_remark);
  4224. $('#view-calc-img').attr('src', '');
  4225. $('#view-calc-remark').val(img_remark);
  4226. $('#text-edit').val(img_remark);
  4227. $('#edit-img').modal('hide');
  4228. }
  4229. });
  4230. }
  4231. reBuildImData() {
  4232. const imData = stageIm.buildImData();
  4233. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4234. this.reLoadDetailData();
  4235. this.loadLocateInfo();
  4236. }
  4237. loadStageLedgerUpdateData(data, nodes) {
  4238. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  4239. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4240. this.reLoadDetailData();
  4241. }
  4242. loadStagePosUpdateData(data, nodes) {
  4243. const imData = stageIm.loadUpdatePosData(data, nodes);
  4244. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4245. this.reLoadDetailData();
  4246. }
  4247. loadStageChangeUpdateData(data, nodes) {
  4248. const imData = stageIm.loadUpdateChangeData(data, nodes);
  4249. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4250. this.reLoadDetailData();
  4251. }
  4252. loadLocateInfo() {
  4253. const select = SpreadJsObj.getSelectObject(this.sheet);
  4254. if (select && select.source.length > 1) {
  4255. $('#im-locate2bills').next().show();
  4256. } else {
  4257. $('#im-locate2bills').next().hide();
  4258. }
  4259. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  4260. }
  4261. reLoadDetailData() {
  4262. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  4263. $('#reset-detail').hide();
  4264. if (data) {
  4265. for (const f of data.custom_define) {
  4266. if (stageIm.resetFields.indexOf(f) >= 0) {
  4267. $('#reset-detail').show();
  4268. break;
  4269. }
  4270. }
  4271. $('#edit-detail').show();
  4272. $('#modify-img').show();
  4273. } else {
  4274. $('#edit-detail').hide();
  4275. $('#modify-img').hide();
  4276. }
  4277. $('#save-detail').hide();
  4278. $('#cancel-detail').hide();
  4279. $('#detail-show').show();
  4280. $('#detail-edit').hide();
  4281. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  4282. $('#show-contract-jl').text(contractJl);
  4283. $('#contract-jl').val(contractJl);
  4284. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  4285. $('#show-qc-jl').text(qcJl);
  4286. $('#qc-jl').val(qcJl);
  4287. const qcMinusJl = data && data.qc_minus_jl ? data.qc_minus_jl : '';
  4288. $('#show-qc-minus-jl').text(qcMinusJl);
  4289. $('#qc-minus-jl').val(qcMinusJl);
  4290. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  4291. $('#show-bgl-code').text(bglCode);
  4292. $('#bgl-code').val(bglCode);
  4293. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  4294. $('#show-bgl-drawing-code').text(bglDrawingCode);
  4295. $('#bgl-drawing-code').val(bglDrawingCode);
  4296. const bwName = data && data.bw ? data.bw : '';
  4297. $('#show-bw-name').text(bwName);
  4298. $('#bw-name').val(bwName);
  4299. const position = data && data.position ? data.position : '';
  4300. $('#show-position').text(position);
  4301. $('#position').val(position);
  4302. const peg = data && data.peg ? data.peg : '';
  4303. $('#show-peg').text(peg);
  4304. $('#peg').val(peg);
  4305. const xmName = data && data.xm ? data.xm: '';
  4306. $('#show-xm-name').text(xmName);
  4307. $('#xm-name').val(xmName);
  4308. const jldy = data && data.jldy ? data.jldy: '';
  4309. $('#show-jldy').text(jldy);
  4310. $('#jldy').val(jldy);
  4311. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  4312. $('#show-drawing-code').text(drawingCode);
  4313. $('#drawing-code').val(drawingCode);
  4314. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  4315. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  4316. $('#calc-memo').val(calcMemo);
  4317. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  4318. $('#show-calc-img').attr('src', calcImgSrc);
  4319. $('#calc-img').attr('src', calcImgSrc);
  4320. $('#view-calc-img').attr('src', calcImgSrc);
  4321. const calcImgRemark = data && data.calc_img_remark || '';
  4322. $('#view-calc-remark').val(calcImgRemark);
  4323. $('#show-calc-remark').html((calcImgRemark ? '<td colspan="2">'+ calcImgRemark +'</td>' : ''));
  4324. $('#calc-remark').html(calcImgRemark);
  4325. $("#view-calc-remark").attr('readonly', true);
  4326. // 处理 编辑 -> 添加草图中textarea多余的空格
  4327. $('#text-edit').val(calcImgRemark)
  4328. }
  4329. }
  4330. class CheckedChange {
  4331. constructor (setting) {
  4332. const self = this;
  4333. this.changeSpreadSetting = {
  4334. cols: [
  4335. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@', cellType: 'tip', getTip: function (x) { return x.t_name ? `所属标段:${x.t_name}` : ''; }},
  4336. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  4337. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  4338. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  4339. ],
  4340. emptyRows: 0,
  4341. headRows: 1,
  4342. headRowHeight: [32],
  4343. headColWidth: [30],
  4344. defaultRowHeight: 21,
  4345. headerFont: '12px 微软雅黑',
  4346. font: '12px 微软雅黑',
  4347. readOnly: true,
  4348. getColor: function (sheet, data, row, col, defaultColor) {
  4349. if (data && data.is_import) {
  4350. return '#eee';
  4351. } else {
  4352. return defaultColor;
  4353. }
  4354. }
  4355. };
  4356. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  4357. this.changeSheet = this.changeSpread.getActiveSheet();
  4358. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  4359. const getTipText = function (data) {
  4360. if (!data) return '';
  4361. const tips = [];
  4362. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  4363. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  4364. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  4365. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  4366. return tips.join('-');
  4367. };
  4368. this.changeBillsSpreadSetting = {
  4369. cols: [
  4370. {title: '计价', colSpan: '1', rowSpan: '1', field: 'is_valuation', hAlign: 1, width: 30, cellType: 'checkbox'},
  4371. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  4372. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, cellType: 'delayTip', getTip: getTipText},
  4373. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  4374. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  4375. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  4376. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  4377. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  4378. ],
  4379. emptyRows: 0,
  4380. headRows: 1,
  4381. headRowHeight: [32],
  4382. defaultRowHeight: 21,
  4383. headerFont: '12px 微软雅黑',
  4384. font: '12px 微软雅黑',
  4385. readOnly: true
  4386. };
  4387. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  4388. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  4389. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  4390. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  4391. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  4392. if (change) self.refreshChangeDetailData(change);
  4393. });
  4394. this.changes = null;
  4395. this.reloadChangeData();
  4396. setting.reloadObj.click(function() {
  4397. self.reloadChangeData();
  4398. });
  4399. $.contextMenu({
  4400. selector: '#' + setting.changeBillsObj.attr('id'),
  4401. build: function ($trigger, e) {
  4402. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  4403. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  4404. },
  4405. items: {
  4406. 'locateZjjl': {
  4407. name: '定位至台账',
  4408. icon: 'fa-sign-in',
  4409. callback: function (key, opt) {
  4410. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  4411. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4412. if (change.is_import) {
  4413. if (changeBills.pos && changeBills.pos.length > 0) {
  4414. const node = stageTree.getItems(changeBills.pos[0].ledger_id);
  4415. if (!node || node.filter) return;
  4416. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), changeBills.pos[0].ledger_id, true);
  4417. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4418. stagePosSpreadObj.loadCurPosData();
  4419. }
  4420. } else if (changeBills.gcl_id) {
  4421. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  4422. if (!node || node.filter) return;
  4423. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id, true);
  4424. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4425. stagePosSpreadObj.loadCurPosData();
  4426. const posData = spSpread.getActiveSheet().zh_data;
  4427. if (!posData || posData.length === 0) return;
  4428. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  4429. if (changePos) SpreadJsObj.locateData(spSpread.getActiveSheet(), changePos);
  4430. } else {
  4431. const cb = {
  4432. b_code: changeBills.code || '',
  4433. name: changeBills.name || '',
  4434. unit: changeBills.unit || '',
  4435. unit_price: changeBills.unit_price || 0,
  4436. };
  4437. for (const node of stageTree.nodes) {
  4438. if (node.children && node.children.length > 0) continue;
  4439. if (node.filter) continue;
  4440. const b = {
  4441. b_code: node.b_code || '',
  4442. name: node.name || '',
  4443. unit: node.unit || '',
  4444. unit_price: node.unit_price || 0,
  4445. };
  4446. if (_.isMatch(cb, b)) {
  4447. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  4448. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4449. stagePosSpreadObj.loadCurPosData();
  4450. return;
  4451. }
  4452. }
  4453. }
  4454. },
  4455. disabled: function (key, opt) {
  4456. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4457. return !changeBills;
  4458. }
  4459. },
  4460. 'autoUse': {
  4461. name: '调用',
  4462. icon: 'fa-play',
  4463. callback: function (key, opt) {
  4464. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4465. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4466. const billsPos = self.findBillsPos(curChange, changeBills);
  4467. if (!billsPos) {
  4468. toastr.warning('无可调用的清单或计量单元');
  4469. return;
  4470. }
  4471. const data = { autoType: 'bills', bills: [{ ...billsPos, cid: changeBills.cid, cbid: changeBills.id }] };
  4472. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  4473. if (result.pos) {
  4474. stagePos.loadCurStageData(result.pos.curStageData);
  4475. }
  4476. const nodes = stageTree.loadPostStageData(result.bills);
  4477. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  4478. stagePosSpreadObj.loadCurPosData();
  4479. if (detail) {
  4480. detail.loadStageChangeUpdateData(result, nodes);
  4481. } else {
  4482. stageIm.loadUpdateChangeData(result, nodes)
  4483. }
  4484. });
  4485. },
  4486. disabled: function (key, opt) {
  4487. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4488. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4489. return !changeBills || curChange.is_import;
  4490. },
  4491. visible: function (key, opt) {
  4492. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4493. }
  4494. },
  4495. }
  4496. });
  4497. $.contextMenu({
  4498. selector: '#' + setting.changeObj.attr('id'),
  4499. build: function ($trigger, e) {
  4500. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeSpread);
  4501. const change = target.cellTypeHintInfo ? self.changes[target.cellTypeHitInfo.row] : null;
  4502. if (change) self.refreshChangeDetailData(change);
  4503. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  4504. },
  4505. items: {
  4506. 'autoUseCur': {
  4507. name: '自动调用',
  4508. icon: 'fa-play',
  4509. callback: function (key, opt) {
  4510. checkAgainHint(function(){
  4511. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4512. const changeBills = self.changeBillsSheet.zh_data;
  4513. const data = { bills: [], autoType: 'bills' };
  4514. for (const cb of changeBills) {
  4515. const billsPos = self.findBillsPos(curChange, cb);
  4516. if (billsPos) data.bills.push({ ...billsPos, cid: cb.cid, cbid: cb.id })
  4517. }
  4518. if (data.bills.length === 0) {
  4519. toastr.warning('无可调用的清单或计量单元');
  4520. return;
  4521. }
  4522. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  4523. if (result.pos) {
  4524. stagePos.loadCurStageData(result.pos.curStageData);
  4525. }
  4526. const nodes = stageTree.loadPostStageData(result.bills);
  4527. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  4528. stagePosSpreadObj.loadCurPosData();
  4529. if (detail) {
  4530. detail.loadStageChangeUpdateData(result, nodes);
  4531. } else {
  4532. stageIm.loadUpdateChangeData(result, nodes)
  4533. }
  4534. });
  4535. }, ['自动调用后,已调用变更令无法批量取消,请谨慎操作。', '确定自动调用变更令?']);
  4536. },
  4537. disabled: function (key, opt) {
  4538. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4539. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4540. return !curChange || !changeBills || curChange.is_import;
  4541. },
  4542. visible: function (key, opt) {
  4543. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4544. }
  4545. },
  4546. 'autoUseAll': {
  4547. name: '自动调用(全部变更令)',
  4548. icon: 'fa-play',
  4549. callback: function (key, opt) {
  4550. checkAgainHint(function(){
  4551. postData(window.location.pathname + '/auto-use-change', { autoType: 'all' }, function(result) {
  4552. window.location.reload();
  4553. });
  4554. }, ['自动调用后,已调用变更令无法批量取消,请谨慎操作。', '确定自动调用变更令?']);
  4555. },
  4556. disabled: function (key, opt) {
  4557. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4558. return !curChange || curChange.is_import;
  4559. },
  4560. visible: function (key, opt) {
  4561. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4562. }
  4563. }
  4564. }
  4565. });
  4566. }
  4567. refreshChangeDetailData(data) {
  4568. const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
  4569. if (change.cid === this.curChangeId) return;
  4570. this.curChangeId = change.cid;
  4571. const self = this;
  4572. if (change.detail) {
  4573. self.loadChangeDetailData();
  4574. } else {
  4575. postData(window.location.pathname + '/change/detail', {cid: change.cid, is_import: change.is_import}, function (result) {
  4576. change.detail = result;
  4577. self.analyzeChange(change);
  4578. self.loadChangeDetailData();
  4579. });
  4580. }
  4581. }
  4582. loadChangeDetailData(data) {
  4583. const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
  4584. if (change) {
  4585. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  4586. } else {
  4587. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  4588. }
  4589. }
  4590. refresh() {
  4591. this.changeSpread.refresh();
  4592. this.changeBillsSpread.refresh();
  4593. }
  4594. reloadChangeData() {
  4595. const self = this;
  4596. postData(window.location.pathname + '/change/data', null, function (result) {
  4597. self.changes = [];
  4598. result.changes.forEach(x => { x.is_import = 0; self.changes.push(x); });
  4599. result.import_changes.forEach(x => { x.is_import = 1; delete x.total_price; self.changes.push(x); });
  4600. if (result.changes.length > 0) self.analyzeChange(result.changes[0]);
  4601. if (result.import_changes.length > 0) self.analyzeChange(result.import_changes[0]);
  4602. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  4603. self.changeSheet.setSelection(0, 0, 1, 1);
  4604. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  4605. self.loadChangeDetailData();
  4606. });
  4607. }
  4608. _analyzeCommon(change) {
  4609. for (const b of change.bills) {
  4610. const eub = change.detail.endUsedBills.find(function (x) {
  4611. return x.cbid === b.id;
  4612. });
  4613. if (eub) b.used_qty = eub.qty;
  4614. b.qty = _.toNumber(b.samount);
  4615. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  4616. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  4617. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  4618. b.cur_qty = 0;
  4619. for (const p of b.pos) {
  4620. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  4621. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  4622. }
  4623. }
  4624. }
  4625. _analyzeImport(change) {
  4626. for (const b of change.bills) {
  4627. const eub = change.detail.endUsedBills.find(function (x) {
  4628. return x.rela_cbid === b.id;
  4629. });
  4630. if (eub) b.used_qty = eub.rela_qty;
  4631. b.qty = _.toNumber(b.samount);
  4632. delete b.unit_price;
  4633. // b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  4634. b.pos = _.filter(change.detail.curUsedBills, { rela_cbid: b.id });
  4635. b.cur_qty = 0;
  4636. for (const p of b.pos) {
  4637. p.qty = p.rela_qty;
  4638. const node = stageTree.datas.find(x => { return x.id === p.lid; });
  4639. p.ledger_id = node.ledger_id;
  4640. p.f_qty = node.quantity;
  4641. b.cur_qty = ZhCalc.add(b.cur_qty, p.rela_qty);
  4642. }
  4643. }
  4644. }
  4645. analyzeChange(change) {
  4646. change.bills = change.detail.bills;
  4647. if (change.is_import) {
  4648. this._analyzeImport(change);
  4649. } else {
  4650. this._analyzeCommon(change);
  4651. }
  4652. }
  4653. findBillsPos(change, changeBills) {
  4654. if (change.is_import) {
  4655. return null;
  4656. } else if (changeBills.gcl_id) {
  4657. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  4658. if (node.filter) return null;
  4659. if (node.settle_status === settleStatus.finish) return null;
  4660. const posData = stagePos.getLedgerPos(node.id) || [];
  4661. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  4662. if (changePos && changePos.settle_status) return null;
  4663. let defaultPos;
  4664. if (posData.length > 0) {
  4665. defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
  4666. if (!defaultPos) return null;
  4667. } else {
  4668. defaultPos = { id: '-1' };
  4669. }
  4670. return { lid: node.id, pid: changePos ? changePos.id : defaultPos.id };
  4671. } else {
  4672. const cb = {
  4673. b_code: changeBills.code || '',
  4674. name: changeBills.name || '',
  4675. unit: changeBills.unit || '',
  4676. unit_price: changeBills.unit_price || 0,
  4677. };
  4678. for (const node of stageTree.nodes) {
  4679. if (node.children && node.children.length > 0) continue;
  4680. if (node.filter) continue;
  4681. if (node.settle_status === settleStatus.finish) continue;
  4682. const b = {
  4683. b_code: node.b_code || '',
  4684. name: node.name || '',
  4685. unit: node.unit || '',
  4686. unit_price: node.unit_price || 0,
  4687. };
  4688. if (_.isMatch(cb, b)) {
  4689. posData = stagePos.getLedgerPos(node.id) || [];
  4690. let defaultPos;
  4691. if (posData.length > 0) {
  4692. defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
  4693. if (!defaultPos) return null;
  4694. } else {
  4695. defaultPos = { id: '-1' };
  4696. }
  4697. return { lid: node.id, pid: defaultPos.id };
  4698. }
  4699. }
  4700. return null;
  4701. }
  4702. }
  4703. }
  4704. // 展开收起附件
  4705. $('a', '.right-nav').bind('click', function () {
  4706. //const main = $('#main-view'), tool = $('#tools-view');
  4707. const tab = $(this), tabPanel = $(tab.attr('content'));
  4708. if (!tab.hasClass('active')) {
  4709. $('a', '.side-menu').removeClass('active');
  4710. $('.tab-content .tab-select-show').removeClass('active');
  4711. tab.addClass('active');
  4712. tabPanel.addClass('active');
  4713. showSideTools(tab.hasClass('active'));
  4714. if (tab.attr('content') === '#search' && !searchLedger) {
  4715. searchLedger = $.ledgerSearch({
  4716. selector: '#search',
  4717. ledger: { billsTree: stageTree, pos: stagePos },
  4718. searchOver: true,
  4719. searchEmpty: true,
  4720. resultSpreadSetting: {
  4721. cols: [
  4722. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  4723. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  4724. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  4725. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  4726. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4727. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  4728. {title: '完成率(%)', field: completePerField, hAlign: 2, width: 70},
  4729. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  4730. ],
  4731. emptyRows: 0,
  4732. headRows: 1,
  4733. headRowHeight: [32],
  4734. headColWidth: [30],
  4735. defaultRowHeight: 21,
  4736. headerFont: '12px 微软雅黑',
  4737. font: '12px 微软雅黑',
  4738. selectedBackColor: '#fffacd',
  4739. readOnly: true,
  4740. },
  4741. locate: function(cur) {
  4742. if (!cur.lid) return;
  4743. SpreadJsObj.locateTreeNode(slSheet, cur.lid, true);
  4744. stageTreeSpreadObj.loadRelaData();
  4745. if (cur.pid && cur.pid !== -1) {
  4746. const pIndex = spSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
  4747. SpreadJsObj.locateRow(spSheet, pIndex);
  4748. }
  4749. },
  4750. customSearch: [
  4751. {
  4752. key: 'less', title: '漏计', valid: true,
  4753. check: function (node) {
  4754. if (node.quantity) {
  4755. return ZhCalc.sub(ZhCalc.sum([node.quantity, node.end_qc_qty, node.end_qc_minus_qty]), node.end_gather_qty) > 0;
  4756. } else if (node.total_price) {
  4757. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  4758. }
  4759. }
  4760. }, {
  4761. key: 'over', title: '超计', valid: true,
  4762. check: function (node) {
  4763. return checkUtils.billsOver(node, stagePos, tenderInfo.checkOverInfo);
  4764. }
  4765. }, {
  4766. key: 'empty', title: '漏计', valid: false,
  4767. check: function (node) {
  4768. if (node.quantity) {
  4769. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  4770. } else if (node.total_price) {
  4771. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  4772. }
  4773. }
  4774. }, {
  4775. key: 'estimate', title: '预计变更', valid: true,
  4776. check: function (node) {
  4777. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  4778. if (posRange.length > 0) {
  4779. for (const p of posRange) {
  4780. if (!checkZero(p.estimate_qty)) return true;
  4781. }
  4782. return false;
  4783. } else {
  4784. return false;
  4785. }
  4786. }
  4787. }
  4788. ],
  4789. });
  4790. searchLedger.spread.refresh();
  4791. }
  4792. if (tab.attr('content') === '#fujian') {
  4793. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4794. node && getNodeList(node.id);
  4795. }
  4796. if (tab.attr('content') === '#zhongjian') {
  4797. if (!detail) {
  4798. detail = new Detail($('#detail-spread'));
  4799. detail.spread.refresh();
  4800. $('#zhongjian .sjs-bottom').height('400px');
  4801. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  4802. } else {
  4803. detail.spread.refresh();
  4804. }
  4805. }
  4806. if (tab.attr('content') === '#checked-change') {
  4807. if (!checkedChanges) {
  4808. checkedChanges = new CheckedChange({
  4809. changeObj: $('#cc-spread'),
  4810. changeBillsObj: $('#ccb-spread'),
  4811. reloadObj: $('#refresh-cc'),
  4812. });
  4813. checkedChanges.refresh();
  4814. } else {
  4815. $('#ccb-spread').height('400px');
  4816. checkedChanges.refresh();
  4817. }
  4818. }
  4819. if (tab.attr('content') === '#error-list') {
  4820. errorList.spread.refresh();
  4821. }
  4822. if (tab.attr('content') === '#check-list') {
  4823. checkList.spread.refresh();
  4824. }
  4825. if (tab.attr('content') === '#sum-load-miss') sumLoadMiss.spread.refresh();
  4826. } else {
  4827. tab.removeClass('active');
  4828. tabPanel.removeClass('active');
  4829. showSideTools(tab.hasClass('active'));
  4830. }
  4831. autoFlashHeight();
  4832. slSpread.refresh();
  4833. spSpread.refresh();
  4834. });
  4835. // 切换附件里节点和所有附件
  4836. $('#fujian .nav-link').on('click', function () {
  4837. const tabPanel = $(this).attr('fujian-content');
  4838. if (tabPanel !== 'syfujian') {
  4839. $('#showPage').hide();
  4840. $('#bach-download').prop('type', 'curr');
  4841. } else {
  4842. $('#showPage').show();
  4843. $('#bach-download').prop('type', 'all')
  4844. }
  4845. $('#showAttachment').hide();
  4846. });
  4847. // 上传附件
  4848. $('#upload-file-btn').click(function () {
  4849. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4850. if (!node) return
  4851. const files = $('#upload-file')[0].files;
  4852. const formData = new FormData();
  4853. formData.append('lid', node.id);
  4854. for (const file of files) {
  4855. if (file === undefined) {
  4856. toastr.error('未选择上传文件!');
  4857. return false;
  4858. }
  4859. const filesize = file.size;
  4860. if (filesize > 50 * 1024 * 1024) {
  4861. toastr.error('存在上传文件大小过大!');
  4862. return false;
  4863. }
  4864. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  4865. if (whiteList.indexOf(fileext) === -1) {
  4866. toastr.error('只能上传指定格式的附件!');
  4867. return false;
  4868. }
  4869. formData.append('size', filesize);
  4870. formData.append('file[]', file);
  4871. }
  4872. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  4873. $('#upload').modal('hide');
  4874. // 插入到attData中
  4875. attData = data.concat(attData);
  4876. // 重新生成List
  4877. getAllList();
  4878. getNodeList(node.id);
  4879. }, function () {
  4880. toastr.error('附件上传失败');
  4881. });
  4882. $('#upload-file').val('');
  4883. });
  4884. // 获取附件信息
  4885. $('.list-table').on('click', '.att-file-name', function () {
  4886. const fid = $(this).attr('file-id');
  4887. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  4888. return;
  4889. }
  4890. const att = attData.find(function (item) {
  4891. return item.id === parseInt(fid);
  4892. });
  4893. $('#edit-att').hide();
  4894. $('#show-att').show();
  4895. if (att !== undefined) {
  4896. // 进来先把编辑功能隐藏
  4897. $('#btn-att a').eq(3).hide()
  4898. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  4899. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4900. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  4901. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  4902. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  4903. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  4904. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  4905. $('#show-att tr').eq(3).children('td').text(att.remark);
  4906. // 附件uid等于当前用户id, 附件上传本人
  4907. if (parseInt(cur_uid) === att.uid) {
  4908. $('#btn-att').show();
  4909. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  4910. if (showDel) $('#btn-att a').eq(3).show();
  4911. // $('#btn-att a').eq(3).show();
  4912. $('#btn-att a').eq(2).hide();
  4913. $('#btn-att a').eq(4).hide();
  4914. $('#btn-att a').eq(5).hide();
  4915. } else {
  4916. $('#btn-att').hide();
  4917. $('#btn-att a').eq(3).hide();
  4918. $('#btn-att a').eq(2).hide();
  4919. $('#btn-att a').eq(4).hide();
  4920. $('#btn-att a').eq(5).hide();
  4921. }
  4922. $('#showAttachment').attr('file-id', fid);
  4923. $('#showAttachment').show();
  4924. } else {
  4925. $('#showAttachment').hide();
  4926. $('#showAttachment').attr('file-id', '');
  4927. toastr.error('附件信息获取失败');
  4928. }
  4929. });
  4930. // $('body').on('click', '.alllist-table a', handleFileList);
  4931. $('body').on('click', '#btn-att a', function () {
  4932. const content = $(this).attr('content');
  4933. const fid = $('#showAttachment').attr('file-id');
  4934. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4935. if (content === 'edit') {
  4936. $('#btn-att a').eq(3).hide();
  4937. $('#btn-att a').eq(2).show();
  4938. $('#btn-att a').eq(4).show();
  4939. $('#btn-att a').eq(5).show();
  4940. $('#show-att').hide();
  4941. $('#edit-att').show();
  4942. const att = attData.find(function (item) {
  4943. return item.id === parseInt(fid);
  4944. });
  4945. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  4946. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  4947. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4948. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  4949. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  4950. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  4951. } else if (content === 'cancel') {
  4952. $('#show-att').show();
  4953. $('#edit-att').hide();
  4954. $('#btn-att a').eq(3).show();
  4955. $('#btn-att a').eq(2).hide();
  4956. $('#btn-att a').eq(4).hide();
  4957. $('#btn-att a').eq(5).hide();
  4958. } else if (content === 'save') {
  4959. const formData = new FormData();
  4960. formData.append('id', fid);
  4961. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  4962. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  4963. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  4964. const file = $('#change-att-btn')[0];
  4965. if (file.files[0] !== undefined) {
  4966. const filesize = file.files[0].size;
  4967. formData.append('size', filesize);
  4968. formData.append('file', file.files[0]);
  4969. }
  4970. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  4971. // 替换到attData中
  4972. const att_index = attData.findIndex(function (item) {
  4973. return item.id === parseInt(fid);
  4974. });
  4975. attData.splice(att_index, 1, data);
  4976. // 重新生成List
  4977. getAllList(parseInt($('#currentPage').text()));
  4978. getNodeList(node.id);
  4979. $('#show-att').show();
  4980. $('#edit-att').hide();
  4981. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  4982. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  4983. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  4984. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  4985. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  4986. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  4987. $('#show-att tr').eq(4).children('td').text(data.remark);
  4988. $('#btn-att a').eq(3).show();
  4989. $('#btn-att a').eq(2).hide();
  4990. $('#btn-att a').eq(4).hide();
  4991. $('#btn-att a').eq(5).hide();
  4992. }, function () {
  4993. toastr.error('附件上传失败');
  4994. });
  4995. $('#change-att-btn').val('');
  4996. } else if (content === 'del') {
  4997. const att = attData.find(function (item) { return item.id === parseInt(fid); });
  4998. deleteAfterHint(function () {
  4999. const data = {id: fid};
  5000. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  5001. // 删除到attData中
  5002. const att_index = attData.findIndex(function (item) {
  5003. return item.id === parseInt(fid);
  5004. });
  5005. attData.splice(att_index, 1);
  5006. // 重新生成List
  5007. if ($('#alllist-table tr').length === 1) {
  5008. getAllList(parseInt($('#currentPage').text()) - 1);
  5009. } else {
  5010. getAllList(parseInt($('#currentPage').text()));
  5011. }
  5012. getNodeList(node.id);
  5013. $('#showAttachment').hide();
  5014. $('#showAttachment').attr('file-id', '');
  5015. });
  5016. }, `确认删除附件「${att.filename}」?`);
  5017. } else if (content === 'view') {
  5018. const data = {id: fid};
  5019. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  5020. const { filepath } = result
  5021. $('#load-file').attr('href', filepath);
  5022. $('#load-file')[0].click();
  5023. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  5024. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  5025. });
  5026. } else if (content === 'location') {
  5027. const att = attData.find(item => item.id === parseInt(fid));
  5028. if (Object.keys(att).length) {
  5029. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  5030. stagePosSpreadObj.loadCurPosData();
  5031. }
  5032. }
  5033. });
  5034. // 替换附件
  5035. $('#change-att-btn').on('change', function () {
  5036. const file = $('#change-att-btn')[0].files[0];
  5037. const name = file.name;
  5038. const filename = name.substring(0, name.lastIndexOf("."));
  5039. const fileext = name.substr(name.indexOf("."));
  5040. const filesize = file.size;
  5041. if (filesize > 50 * 1024 * 1024) {
  5042. toastr.error('文件大小过大!');
  5043. $('#change-att-btn').val('');
  5044. return false;
  5045. }
  5046. if (whiteList.indexOf(fileext) === -1) {
  5047. toastr.error('只能上传指定格式的附件!');
  5048. $('#change-att-btn').val('');
  5049. return false;
  5050. }
  5051. $('#edit-att .form-group').eq(0).find('input').val(filename);
  5052. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  5053. });
  5054. // 切换页数
  5055. $('.page-select').on('click', function () {
  5056. const totalPageNum = parseInt($('#totalPage').text());
  5057. const lastPageNum = parseInt($('#currentPage').text());
  5058. const status = $(this).attr('content');
  5059. if (status === 'pre' && lastPageNum > 1) {
  5060. getAllList(lastPageNum-1);
  5061. $('#showAttachment').hide();
  5062. $('#syfujian .check-all-file').prop('checked', false)
  5063. } else if (status === 'next' && lastPageNum < totalPageNum) {
  5064. getAllList(lastPageNum+1);
  5065. $('#showAttachment').hide();
  5066. $('#syfujian .check-all-file').prop('checked', false)
  5067. }
  5068. });
  5069. // 批量下载
  5070. $('#bach-download').click(function() {
  5071. const fileIds = [];
  5072. const type = $(this).attr('type');
  5073. let node = ''
  5074. if (type === 'curr') {
  5075. node = '#nodelist-table .check-file:checked'
  5076. } else {
  5077. node = '#alllist-table .check-file:checked'
  5078. }
  5079. $(node).each(function() {
  5080. const fileId = $(this).attr('file-id');
  5081. fileId && fileIds.push(fileId);
  5082. });
  5083. if (fileIds.length) {
  5084. if (fileIds.length > 20) {
  5085. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  5086. }
  5087. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  5088. $(this).attr('disabled', "true")
  5089. const btn = $(this);
  5090. const fileArr = [];
  5091. for (const id of fileIds) {
  5092. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  5093. fileArr.push({
  5094. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  5095. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  5096. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  5097. });
  5098. }
  5099. const packageName = `${tender.name}-计量台账-第${stage.order}期-附件.zip`;
  5100. try {
  5101. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  5102. } catch (e) {
  5103. btn.removeAttr('disabled');
  5104. toastr.clear();
  5105. toastr.error('批量下载失败');
  5106. }
  5107. // postCompressFile(`/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file`, {fileIds}, function(result) {
  5108. // toastr.clear()
  5109. // toastr.success('压缩文件成功')
  5110. // btn.removeAttr('disabled')
  5111. // const href = window.URL.createObjectURL(result)
  5112. // $('#zipDown').attr('href', href);
  5113. // $('#zipDown').attr('download', `${tender.name}-计量台账-第${stage.order}期-附件.zip`);
  5114. // $("#zipDown")[0].click();
  5115. // }, () => {
  5116. // btn.removeAttr('disabled')
  5117. // toastr.clear()
  5118. // toastr.error('批量下载失败')
  5119. // });
  5120. // const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  5121. // $('#zipDown').attr('href', url);
  5122. // $("#zipDown")[0].click();
  5123. }
  5124. });
  5125. // 监听附件check是否选中
  5126. $('.list-table').on('click', '.check-file', function() {
  5127. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  5128. const childs = $(this).parents('.list-table').children().length;
  5129. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  5130. if (checkedList.length === childs) {
  5131. checkBox.prop("checked", true);
  5132. } else {
  5133. checkBox.prop("checked", false);
  5134. }
  5135. });
  5136. $('.check-all-file').click(function() {
  5137. const isCheck = $(this).is(':checked');
  5138. $(this).parents('table').find('.list-table').each(function() {
  5139. $(this).find('input:checkbox').prop("checked", isCheck);
  5140. })
  5141. });
  5142. // 显示层次
  5143. (function (select, sheet) {
  5144. $(select).click(function () {
  5145. if (!sheet.zh_tree) return;
  5146. const tag = $(this).attr('tag');
  5147. const tree = sheet.zh_tree;
  5148. setTimeout(() => {
  5149. showWaitingView();
  5150. switch (tag) {
  5151. case "1":
  5152. case "2":
  5153. case "3":
  5154. case "4":
  5155. case "5":
  5156. tree.expandByLevel(parseInt(tag));
  5157. SpreadJsObj.refreshTreeRowVisible(sheet);
  5158. break;
  5159. case "last":
  5160. tree.expandByCustom(() => { return true; });
  5161. SpreadJsObj.refreshTreeRowVisible(sheet);
  5162. break;
  5163. case "leafXmj":
  5164. tree.expandToLeafXmj();
  5165. SpreadJsObj.refreshTreeRowVisible(sheet);
  5166. break;
  5167. case "curMeasure":
  5168. tree.expandByCustom(function (node) {
  5169. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  5170. if (node[field]) {
  5171. return true;
  5172. }
  5173. }
  5174. return false;
  5175. });
  5176. SpreadJsObj.refreshTreeRowVisible(sheet);
  5177. break;
  5178. case "endMeasure":
  5179. tree.expandByCustom(function (node) {
  5180. for (const field of ['contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp']) {
  5181. if (node[field]) {
  5182. return true;
  5183. }
  5184. }
  5185. return false;
  5186. });
  5187. SpreadJsObj.refreshTreeRowVisible(sheet);
  5188. break;
  5189. }
  5190. closeWaitingView();
  5191. }, 100);
  5192. });
  5193. })('a[name=showLevel]', slSpread.getActiveSheet());
  5194. const stageCheckerSetting = {
  5195. ledgerTree: stageTree,
  5196. ledgerPos: stagePos,
  5197. checkList: checkList,
  5198. decimal: tenderInfo.decimal,
  5199. checkOption: checkOption,
  5200. };
  5201. if (!checkTzMeasureType()) {
  5202. stageCheckerSetting.checkOption.tp.fields.push(
  5203. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  5204. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  5205. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  5206. {qty: 'quantity', tp: 'total_price'},
  5207. );
  5208. }
  5209. $('#ledger-check2').click(() => {
  5210. ledgerCheck2(stageCheckerSetting).then(result => {
  5211. check2Viewing({
  5212. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  5213. randomWait: true,
  5214. prefix: 'check2-',
  5215. checks: result,
  5216. checkList: checkList,
  5217. });
  5218. });
  5219. });
  5220. const dataChecker = DataChecker({
  5221. checkUrl: window.location.pathname + '/check',
  5222. completeData: function (data) {
  5223. stagePos.updateDatas({pos: data.source.pos});
  5224. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  5225. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  5226. stagePosSpreadObj.loadCurPosData();
  5227. for (const e of data.error) {
  5228. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  5229. }
  5230. },
  5231. errorList: errorList,
  5232. });
  5233. $('[name=stage-start]').submit(function (e) {
  5234. if (checkAuditorFrom()) {
  5235. // 再检查多人协同确认情况
  5236. const list = stage.relaAssists.find(x => {return !x.confirm });
  5237. if(list) {
  5238. toastr.error('请检查多人协同确认情况再上报');
  5239. $('#hide-all').hide();
  5240. return false;
  5241. }
  5242. $(this).parent().parent().parent().modal('hide');
  5243. dataChecker.checkAndPost(this.action, {});
  5244. $('#hide-all').hide();
  5245. }
  5246. return false;
  5247. });
  5248. $('#audit-check0').submit(function (e) {
  5249. // 再检查多人协同确认情况
  5250. const list = stage.relaAssists.find(x => {return !x.confirm && stageAssistRela.checkAssistPartUsed(x) });
  5251. if(list) {
  5252. toastr.error('请检查多人协同确认情况再审批通过');
  5253. $('#hide-all').hide();
  5254. return false;
  5255. }
  5256. const checkType = parseInt($('[name=checkType]').val());
  5257. const noUsed = stage.relaAssists.filter(x => {return !stageAssistRela.checkAssistPartUsed(x) });
  5258. const data = {
  5259. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  5260. coop_noUsed: noUsed && noUsed.length > 0 ? noUsed.map(x => { return x.ass_ledger_id; }) : [],
  5261. checkType,
  5262. };
  5263. $('#sp-done').modal('hide');
  5264. checkType && dataChecker.checkAndPost(this.action, data);
  5265. $('#hide-all').hide();
  5266. return false;
  5267. });
  5268. $('#audit-check1').submit(function (e) {
  5269. const checkType = parseInt($('[name=checkType]:checked').val());
  5270. const confirm = stage.relaAssists.filter(x => { return x.confirm });
  5271. const data = {
  5272. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  5273. coop_checked: confirm && confirm.length > 0 ? confirm.map(x => { return x.id; }) : [],
  5274. checkType,
  5275. };
  5276. if ($('#warning-text').length) $('#warning-text').remove();
  5277. if (!checkType && !$('#warning-text').length) {
  5278. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  5279. return false
  5280. }
  5281. $('#sp-back').modal('hide');
  5282. checkType && dataChecker.checkAndPost(this.action, data);
  5283. $('#hide-all').hide();
  5284. return false;
  5285. });
  5286. $('#exportExcel').click(function () {
  5287. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  5288. });
  5289. $('#cbr-check-all').click(function () {
  5290. if (this.checked) {
  5291. $('input', '#cbr-pos-list').attr('checked', 'checked');
  5292. } else {
  5293. $('input', '#cbr-pos-list').removeAttr('checked');
  5294. }
  5295. });
  5296. $('#cbr-ok').click(() => {
  5297. const ratio = parseInt($('#cbr-ratio').val());
  5298. if (!ratio) {
  5299. toastr.warning('请输入计量比例');
  5300. return;
  5301. } else if (ratio < 1) {
  5302. toastr.warning('计量比例不可小于1');
  5303. return;
  5304. } else if (ratio > 100) {
  5305. toastr.warning('计量比例不可大于100');
  5306. return;
  5307. }
  5308. const apply2sibling = $('#apply2sibling')[0].checked;
  5309. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  5310. if (posName.length === 0) {
  5311. toastr.warning('请勾选需要按计量比例的计量单元');
  5312. return;
  5313. }
  5314. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  5315. });
  5316. // 收方单生成
  5317. $('#setshoufang').click(function () {
  5318. const lid = $('#shoufang-lid').val();
  5319. const pid = $('#shoufang-pid').val() !== '' ? $('#shoufang-pid').val() : null;
  5320. // 修改线上
  5321. postData(window.location.pathname + '/save/shoufang', { type: 'add', postData: { lid, pid } }, function (result) {
  5322. // 收方单tab打开并显示在最新
  5323. if (!$('#shoufang-tab').hasClass('active')) {
  5324. $('#shoufang-tab').click();
  5325. }
  5326. const data = makeOneShouFang(result);
  5327. data.filenum = 0;
  5328. sfData = _.concat(data, sfData);
  5329. getShouFangList();
  5330. });
  5331. });
  5332. $('body').on('click', '.del-shoufang', function () {
  5333. const id = $(this).attr('data-id');
  5334. $('#del-shoufang-id').val(id);
  5335. const name = $(this).parents('tr').children('td').eq(0).text();
  5336. const ledger_code = name.split(' / ')[0];
  5337. const pos_name = name.split(' / ')[1] ? name.split(' / ')[1] : '';
  5338. $('#del-shoufang-ledger').text('清单:' + ledger_code);
  5339. if (pos_name) {
  5340. $('#del-shoufang-pos').text('计量单元:' + pos_name).show();
  5341. } else {
  5342. $('#del-shoufang-pos').text('').hide();
  5343. }
  5344. });
  5345. // 收方单删除
  5346. $('#delshoufang').click(function () {
  5347. const sfid = $('#del-shoufang-id').val();
  5348. // 修改线上
  5349. postData(window.location.pathname + '/save/shoufang', { type: 'del', postData: { sfid } }, function (result) {
  5350. // 删除到sfData中
  5351. const att_index = sfData.findIndex(function (item) {
  5352. return item.id === parseInt(sfid);
  5353. });
  5354. sfData.splice(att_index, 1);
  5355. // 重新生成List
  5356. if ($('#shoufang-table tr').length === 1) {
  5357. getShouFangList(parseInt($('#shoufang-currentPage').text()) - 1);
  5358. } else {
  5359. getShouFangList(parseInt($('#shoufang-currentPage').text()));
  5360. }
  5361. $('#shoufangdelete').modal('hide');
  5362. });
  5363. });
  5364. // 切换页数
  5365. $('.shoufang-page-select').on('click', function () {
  5366. const totalPageNum = parseInt($('#shoufang-totalPage').text());
  5367. const lastPageNum = parseInt($('#shoufang-currentPage').text());
  5368. const status = $(this).attr('content');
  5369. if (status === 'pre' && lastPageNum > 1) {
  5370. getShouFangList(lastPageNum-1);
  5371. } else if (status === 'next' && lastPageNum < totalPageNum) {
  5372. getShouFangList(lastPageNum+1);
  5373. }
  5374. });
  5375. // 获取单个收方单附件列表
  5376. $('body').on('click', '.show-shoufang-att', function () {
  5377. const id = parseInt($(this).attr('data-id'));
  5378. let html = '';
  5379. $('#shoufang-flie-list').html(html);
  5380. postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
  5381. for (const att of result) {
  5382. html += `<tr><td>${att.filename}${att.fileext} ` + makeEditHtml(att.id, att.filename, att.fileext, att.extra_upload) +
  5383. `<td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
  5384. `<a href="${att.filepath}" target="_blank"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a>` + makeViewHtml(att.viewpath) + makeDelHtml(att.id, att.extra_upload) +`</td></tr>`;
  5385. }
  5386. $('#shoufang-flie-list').html(html);
  5387. $('[data-toggle="tooltip"]').tooltip()
  5388. });
  5389. function makeViewHtml(viewpath) {
  5390. return viewpath ? `<a href="${viewpath}" target="_blank" class="ml-1"><i data-toggle="tooltip" data-placement="left" data-original-title="预览" class="fa fa-eye"></i></a>` : '';
  5391. }
  5392. function makeDelHtml(fid, extra_upload) {
  5393. return sfAttDelPower &&
  5394. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5395. '<a href="javascript:void(0)" data-sfid="'+ id +'" data-id="'+ fid +'" title="删除" class="del-shoufang-att pull-right text-danger mr-2">' +
  5396. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  5397. }
  5398. });
  5399. function makeEditHtml(fid, filename, fileext, extra_upload) {
  5400. return sfAttDelPower &&
  5401. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5402. '<a href="javascript:void(0)" data-filename="' + filename + '" data-fileext="'+ fileext +'" data-id="'+ fid +'" class="edit-shoufang-att ml-1">' +
  5403. '<i data-toggle="tooltip" data-placement="left" data-original-title="修改文件名" class="fa fa-pencil"></i></a></td>' : ''
  5404. }
  5405. // 修改收方单附件文件名
  5406. $('body').on('click', '.edit-shoufang-att', function () {
  5407. $(this).children('i').tooltip('hide');
  5408. const fid = $(this).data('id');
  5409. const filename = $(this).data('filename');
  5410. const fileext = $(this).data('fileext');
  5411. const html = `<div class="input-group input-group-sm">
  5412. <input type="text" class="form-control" value="${filename}" placeholder="输入文件名" aria-describedby="button-${fid}" style="width:50px">
  5413. <div class="input-group-append" id="button-${fid}">
  5414. <button class="btn btn-outline-primary shoufang-att-confirm-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">确认</button>
  5415. <button class="btn btn-outline-secondary shoufang-att-cancel-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">取消</button>
  5416. </div>
  5417. </div>`;
  5418. $(this).parents('td').html(html);
  5419. });
  5420. // 确认修改文件名
  5421. $('body').on('click', '.shoufang-att-confirm-btn', function () {
  5422. const validText = $.trim($(this).parents('td').find('input').val());
  5423. const orgValue = $.trim($(this).data('filename'));
  5424. const fileext = $(this).data('fileext');
  5425. const fid = $(this).data('fid');
  5426. if (!validText) {
  5427. toastr.error('文件名不能为空');
  5428. return;
  5429. }
  5430. // const reg = /^[0-9a-zA-Z\-_\u4e00-\u9fa5]+$/;
  5431. if(validText.indexOf('.') !== -1 || validText.indexOf(' ') !== -1) {
  5432. toastr.error('文件名中不能包含.字符和空格');
  5433. return;
  5434. }
  5435. if(validText == orgValue) {
  5436. const html = `${orgValue}${fileext} ` + makeEditHtml(fid, orgValue, fileext, 1);
  5437. $(this).parents('td').html(html);
  5438. return;
  5439. }
  5440. const data = {
  5441. id: fid,
  5442. filename: validText,
  5443. };
  5444. const _self = $(this);
  5445. postData('/wap/shoufang/editfile', data, function (result) {
  5446. const html = `${validText}${fileext} ` + makeEditHtml(fid, validText, fileext, 1);
  5447. _self.parents('td').html(html);
  5448. });
  5449. });
  5450. // 取消修改文件名
  5451. $('body').on('click', '.shoufang-att-cancel-btn', function () {
  5452. const fid = $(this).data('fid');
  5453. const filename = $(this).data('filename');
  5454. const fileext = $(this).data('fileext');
  5455. const html = `${filename}${fileext} ` + makeEditHtml(fid, filename, fileext, 1);
  5456. $(this).parents('td').html(html);
  5457. });
  5458. // 删除收方单附件
  5459. $('body').on('click', '.del-shoufang-att', function () {
  5460. const id = $(this).data('id');
  5461. const _self = $(this);
  5462. const data = { id };
  5463. const sfid = $(this).data('sfid');
  5464. postData('/wap/shoufang/delfile', data, function (result) {
  5465. _self.parents('tr').remove();
  5466. // 附件个数更新
  5467. $('#shoufang-table').find('.show-shoufang-att[data-id="'+ sfid +'"]').text($('#shoufang-flie-list tr').length);
  5468. const sfInfo = _.find(sfData, { id: sfid });
  5469. sfInfo.filenum = $('#shoufang-flie-list tr').length;
  5470. });
  5471. });
  5472. // 定位到对应的清单或计量单元
  5473. $('body').on('click', '.show-shoufang-node', function () {
  5474. const id = parseInt($(this).attr('data-id'));
  5475. const sfInfo = _.find(sfData, { id });
  5476. if (sfInfo) {
  5477. const lData = _.find(ledgerData, { id: sfInfo.lid });
  5478. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), lData.ledger_id, true);
  5479. stagePosSpreadObj.loadCurPosData();
  5480. if (sfInfo.pid) {
  5481. const posData = _.find(spSpread.getActiveSheet().zh_data, { id: sfInfo.pid });
  5482. SpreadJsObj.locateData(spSpread.getActiveSheet(), posData);
  5483. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  5484. }
  5485. }
  5486. });
  5487. // 定位到对应的清单或计量单元
  5488. $('body').on('click', '.show-shoufang-report', function () {
  5489. const id = parseInt($(this).attr('data-id'));
  5490. const [qrCodePath, replace_key_params, req_params, rpt_name] = makeReportData(id);
  5491. sessionStorage.qrCodePath = qrCodePath;
  5492. sessionStorage.replace_key_params = JSON.stringify(replace_key_params);
  5493. sessionStorage.req_params = JSON.stringify(req_params);
  5494. sessionStorage.rpt_name = rpt_name;
  5495. window.open('/individualReport/A4');
  5496. });
  5497. $('#importExcel').click(() => {
  5498. importExcel.doImport({
  5499. template: {
  5500. hint: '计量台账',
  5501. url: 'https://jl-assets.oss-cn-shenzhen.aliyuncs.com/template/导入计量台账Excel格式.xlsx',
  5502. },
  5503. callback: function (sheet) {
  5504. postDataCompress(window.location.pathname + '/importStageSheet', {sheet}, function (result) {
  5505. window.location.reload();
  5506. }, null);
  5507. }
  5508. });
  5509. });
  5510. const stageAssistRela = {
  5511. refreshAssConfirmBtn: function () {
  5512. if (stage.assist) {
  5513. const caption = stage.assist.user_id === stage.user_id
  5514. ? (stage.assist.confirm ? '撤销上报' : '确认上报')
  5515. : (stage.assist.confirm ? '重新审批' : '审批通过');
  5516. if (!stage.readOnly || stage.assist.locked) $('#ass-confirm-btn').show().html(caption);
  5517. } else {
  5518. $('#ass-confirm-btn').hide();
  5519. }
  5520. },
  5521. checkAssistPartUsed(assist) {
  5522. const ass_lid = assist.ass_ledger_id.split(',');
  5523. for (const lid of ass_lid) {
  5524. const node = stageTree.getItems(lid);
  5525. if (!node) continue;
  5526. if (checkUsed(stageTree, stagePos, node)) return true;
  5527. }
  5528. return false;
  5529. },
  5530. refreshAssistTable: function () {
  5531. const html = [];
  5532. for (const ra of stage.relaAssists) {
  5533. const used = this.checkAssistPartUsed(ra);
  5534. const hint = used
  5535. ? (ra.confirm ? `<td class="text-success">${moment(ra.update_time).format('YYYY-MM-DD HH:mm')}</td>` : '<td class="text-warning">待确认</td>')
  5536. : '<td>本期未计量</td>';
  5537. html.push(`<tr><td>${ra.name}</td><td>${ra.company}</td>${hint}</tr>`);
  5538. }
  5539. return $('#assistList').html(html.join(''));
  5540. },
  5541. refreshAssists: function () {
  5542. if (stage.relaAssists.length > 0) {
  5543. $('#assistCount').html(stage.relaAssists.length || '').parent().show();
  5544. } else {
  5545. $('#assistCount').parent().hide();
  5546. }
  5547. },
  5548. refreshReadOnly(){
  5549. stageTreeSpreadObj.assistReadOnly = stage.readOnly || stage.revising || (!!stage.assist && !!stage.assist.confirm);
  5550. SpreadJsObj.refreshSheetReadOnly(slSpread.getActiveSheet());
  5551. stagePosSpreadObj.loadCurPosData();
  5552. },
  5553. init: function() {
  5554. this.refreshAssConfirmBtn();
  5555. this.refreshReadOnly();
  5556. this.refreshAssists();
  5557. },
  5558. };
  5559. stageAssistRela.init();
  5560. $('#ass-confirm-btn').click(() => {
  5561. const data = { user_id: stage.assist.user_id, ass_user_id: stage.assist.ass_user_id, confirm: !stage.assist.confirm, type: 'stage' };
  5562. postData(window.location.pathname + '/ass-confirm', data, function(result) {
  5563. window.location.reload();
  5564. // stage.assist = result;
  5565. // stageAssistRela.refreshAssConfirmBtn();
  5566. // stageAssistRela.refreshReadOnly();
  5567. });
  5568. });
  5569. $('#assists').on('show.bs.modal', function(){
  5570. postData(window.location.pathname + '/ass', { user_id: userID, type: 'stage' }, function (result) {
  5571. stage.relaAssists = result;
  5572. stageAssistRela.refreshAssistTable();
  5573. });
  5574. });
  5575. $('body').on('click', 'a[name=att-delete]', function() {
  5576. const fid = this.getAttribute('file-id');
  5577. if (!fid) return;
  5578. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  5579. const data = {id: fid};
  5580. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  5581. // 删除到attData中
  5582. const att_index = attData.findIndex(function (item) {
  5583. return item.id === parseInt(fid);
  5584. });
  5585. attData.splice(att_index, 1);
  5586. // 重新生成List
  5587. if ($('#alllist-table tr').length === 1) {
  5588. getAllList(parseInt($('#currentPage').text()) - 1);
  5589. } else {
  5590. getAllList(parseInt($('#currentPage').text()));
  5591. }
  5592. getNodeList(node.id);
  5593. $('#showAttachment').hide();
  5594. $('#showAttachment').attr('file-id', '');
  5595. });
  5596. });
  5597. });
  5598. function makeOneShouFang(sf) {
  5599. const lData = _.find(ledgerData, { id: sf.lid });
  5600. sf.name = lData.b_code;
  5601. if (sf.pid) {
  5602. const pData = _.find(posData, { id: sf.pid });
  5603. if (pData && pData.name) {
  5604. sf.name = lData.b_code + ' / ' + pData.name;
  5605. }
  5606. }
  5607. return sf;
  5608. }
  5609. function makeShouFang() {
  5610. for (const sf of sfData) {
  5611. makeOneShouFang(sf);
  5612. }
  5613. getShouFangList();
  5614. }
  5615. // 生成收方单列表
  5616. function getShouFangList(currPageNum = 1) {
  5617. // 每页最多几个附件
  5618. const pageCount = 20;
  5619. // 附件总数
  5620. const total = sfData.length;
  5621. // 总页数
  5622. const pageNum = Math.ceil(total/pageCount);
  5623. $('#shoufang-totalPage').text(pageNum);
  5624. $('#shoufang-currentPage').text(total === 0 ? 0 : currPageNum);
  5625. // 当前页附件内容
  5626. const currPageAttData = sfData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  5627. let html = '';
  5628. for(const att of currPageAttData) {
  5629. html += '<tr><td>' + att.name + '</td>' +
  5630. '<td width="40"><a href="#shoufangfile" class="show-shoufang-att" data-id="'+ att.id +'" data-toggle="modal" data-target="#shoufangfile">'+ att.filenum +'</a></td>' +
  5631. '<td width="100">' +
  5632. '<a href="javascript:void(0);" data-id="'+ att.id +'" class="show-shoufang-node mr-1" data-toggle="tooltip" data-placement="left" data-original-title="定位"><i class="fa fa-crosshairs"></i></a> ' +
  5633. '<a href="javascript:void(0);" data-id="'+ att.id +'" class="show-shoufang-report mr-1"><i data-toggle="tooltip" data-placement="left" data-original-title="预览" class="fa fa-eye"></i></a> ' +
  5634. // '<a href="javascript:void(0);"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a> ' +
  5635. makeDelHtml(att.id, att.extra_upload) +
  5636. '</td></tr>';
  5637. }
  5638. function makeDelHtml(id, extra_upload) {
  5639. return cur_uid === stage.user_id &&
  5640. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5641. '<a href="javascript:void(0);" data-id="'+ id +'" data-toggle="modal" data-target="#shoufangdelete" class="ml-3 text-danger del-shoufang">' +
  5642. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  5643. }
  5644. $('#shoufang-table').html(html);
  5645. $('[data-toggle="tooltip"]').tooltip();
  5646. }
  5647. function makeReportData(sfid) {
  5648. const sfInfo = _.find(sfData, { id: sfid });
  5649. const ledger_code = sfInfo.name.split(' / ')[0];
  5650. const pos_name = sfInfo.name.split(' / ')[1] ? sfInfo.name.split(' / ')[1] : '';
  5651. const replace_key_params = {
  5652. 'KEY_标段名称': tenderInfo.deal_info.buildName,
  5653. 'KEY_总承包单位': tenderInfo.construction_unit.contract1.company,
  5654. 'KEY_合同段': tenderInfo.deal_info.dealName,
  5655. 'KEY_监理单位': tenderInfo.construction_unit.supervision1.company,
  5656. 'KEY_编号': '',
  5657. 'KEY_设计工程数量': 0,
  5658. };
  5659. // if (sfInfo.pid) {
  5660. // const pData = _.find(posData, { id: sfInfo.pid });
  5661. // replace_key_params['KEY_设计工程数量'] = pData.quantity;
  5662. // } else {
  5663. const lData = _.find(ledgerData, { id: sfInfo.lid });
  5664. // }
  5665. replace_key_params['KEY_子目号及子目名称'] = ledger_code + ' ' + lData.name;
  5666. replace_key_params['KEY_桩号及工程部位'] = pos_name;
  5667. const req_params = {
  5668. rpt_tpl_id: window.location.host === '127.0.0.1:7002' || window.location.host === 'jlqa.smartcost.com.cn:7002' ? 1784 : (window.location.host === 'jluat.smartcost.com.cn' ? 315 : 2138), // 1784(qa的,外网是2138)
  5669. pageSize: 'A4',
  5670. project_id: tender.project_id,
  5671. tender_id: tender.id,
  5672. stage_id: stage.id,
  5673. sp_id: spid,
  5674. };
  5675. const rpt_name = tender.name + '-第' + stage.order + '期-' + ledger_code + (pos_name ? '/' + pos_name : '-' + lData.name);
  5676. const qrCodePath = sfInfo.qrcode;
  5677. return [qrCodePath, replace_key_params, req_params, rpt_name];
  5678. }