stage.js 287 KB

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