stage.js 285 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746
  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. sumLoadSpr: '---',
  1995. importStageGcl: {
  1996. name: '导入(其他标段)工程量清单计量数据',
  1997. icon: 'fa-link',
  1998. disabled: function (key, opt) {
  1999. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2000. return readOnly || !node || !stageTree.isLeafXmj(node);
  2001. },
  2002. callback: function (key, opt) {
  2003. tenderSelect.showSelect(SpreadJsObj.getSelectObject(slSpread.getActiveSheet()));
  2004. }
  2005. },
  2006. batchImportStageGcl: {
  2007. name: '批量导入(其他标段)工程量清单计量数据',
  2008. icon: 'fa-link',
  2009. disabled: function (key, opt) {
  2010. return readOnly;
  2011. },
  2012. callback: function (key, opt){
  2013. batchImport.show();
  2014. }
  2015. },
  2016. percentSpr: '---',
  2017. percentCalc: {
  2018. name: '根据(其他标段)计量比例计量',
  2019. disabled: function(key, opt) {
  2020. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2021. const posRange = stagePos.getLedgerPos(node.id) || [];
  2022. return readOnly || !node || !node.is_tp || posRange.length > 0;
  2023. },
  2024. callback: function(key, opt) {
  2025. spssTenderSelect.showSelect();
  2026. }
  2027. },
  2028. shoufangdanSpr: '---',
  2029. shoufangdan: {
  2030. name: '生成收方单',
  2031. visible: function(key, opt) {
  2032. if (cur_uid === stage.user_id) return true;
  2033. },
  2034. disabled: function (key, opt) {
  2035. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2036. if (!node || !node.b_code || !node.is_leaf || cur_uid !== stage.user_id) return true;
  2037. },
  2038. callback: function (key, opt) {
  2039. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2040. $('#shoufang-lid').val(node.id);
  2041. $('#shoufang-pid').val('');
  2042. $('#shoufang-ledger').text('清单:' + node.b_code);
  2043. $('#shoufang-pos').text('').hide();
  2044. $('#addshoufang').modal('show');
  2045. }
  2046. },
  2047. lockedSpr: '----',
  2048. lockedHint: {
  2049. name: '检查审批状态',
  2050. visible: function (key, opt) {
  2051. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2052. return node.locked;
  2053. },
  2054. callback: function (key, opt) {
  2055. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2056. const lockedInfo = stageTree.getLockedInfo(node);
  2057. toastr.warning(`审批人 ${lockedInfo.map(x => { return x.name; }).join(',')} 审批通过,如需修改,请联系审批人重新审批`);
  2058. }
  2059. },
  2060. }
  2061. });
  2062. const stagePosSpreadObj = {
  2063. loadExprToInput(sheet) {
  2064. const sel = sheet.getSelections()[0];
  2065. if (!sel) return;
  2066. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  2067. if (col && col.type === 'Number') {
  2068. const data = SpreadJsObj.getSelectObject(sheet);
  2069. if (data) {
  2070. const exprInfo = getExprInfo(col.field);
  2071. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  2072. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  2073. .attr('readOnly', readOnly || cell.locked());
  2074. $('#pos-expr').attr('data-row', sel.row);
  2075. } else {
  2076. $('#pos-expr').val('').attr('readOnly', true);
  2077. $('#pos-expr').removeAttr('data-row');
  2078. }
  2079. } else {
  2080. $('#pos-expr').val('').attr('readOnly', true);
  2081. $('#pos-expr').removeAttr('data-row');
  2082. }
  2083. },
  2084. /**
  2085. * 加载计量单元 根据当前台账选择节点
  2086. */
  2087. loadCurPosData: function () {
  2088. const sheet = slSpread.getActiveSheet();
  2089. const node = SpreadJsObj.getSelectObject(sheet);
  2090. if (node) {
  2091. const posReadOnly = node.lock || (node.children && node.children.length > 0) || !node.b_code;
  2092. spSpread.getActiveSheet().zh_setting.readOnly = posReadOnly;
  2093. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  2094. const posMeasure = $('#pos-measure')[0].checked;
  2095. const posUnMeasure = $('#pos-un-measure')[0].checked;
  2096. posData.forEach(x => {
  2097. x.visible = true;
  2098. if (posMeasure && x.visible) {
  2099. x.visible = !!x.contract_qty || !!x.qc_qty || !!x.qc_minus_qty;
  2100. }
  2101. if (posUnMeasure && x.visible) {
  2102. // 不考虑不计价
  2103. x.visible = !x.end_contract_qty && !x.end_qc_qty && !x.end_gather_qty; // && !x.qc_minus_qty;
  2104. }
  2105. });
  2106. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData, posReadOnly);
  2107. getNodeList(node.id);
  2108. } else {
  2109. spSpread.getActiveSheet().zh_setting.readOnly = true;
  2110. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', [], true);
  2111. }
  2112. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  2113. },
  2114. editEnded: function (e, info) {
  2115. if (info.sheet.zh_setting) {
  2116. // 未改变过,则直接跳过
  2117. const sortData = info.sheet.zh_data;
  2118. const posData = sortData ? sortData[info.row] : null;
  2119. const col = info.sheet.zh_setting.cols[info.col];
  2120. const orgText = posData ? posData[col.field] : null;
  2121. const newText = trimInvalidChar(info.editingText);
  2122. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  2123. return;
  2124. }
  2125. // 台账模式下,不可新增
  2126. if (checkTzMeasureType() && !posData) {
  2127. toastr.error('台账模式不可新增计量单元数据');
  2128. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2129. return ;
  2130. }
  2131. // 不同节点下,计量单元检查输入
  2132. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2133. const node = stagePosSpreadObj.stageTreeNode;
  2134. if (!node) {
  2135. toastr.warning('数据错误, 请刷新页面后再试');
  2136. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2137. return;
  2138. } else if (newText !== '' && node.children && node.children.length > 0) {
  2139. toastr.error('父节点不可插入计量单元');
  2140. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2141. return;
  2142. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  2143. toastr.error('项目节不可插入计量单元');
  2144. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2145. return;
  2146. }
  2147. // 生成提交数据
  2148. const data = {};
  2149. if (col.field === 'name') {
  2150. if ((!newText || newText === '') && posData) {
  2151. toastr.error('部位名称不可为空');
  2152. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2153. return;
  2154. } else if (!posData) {
  2155. if (newText !== '') {
  2156. data.updateType = 'add';
  2157. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  2158. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  2159. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2160. return;
  2161. }
  2162. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  2163. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  2164. } else {
  2165. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2166. return;
  2167. }
  2168. } else {
  2169. data.updateType = 'update';
  2170. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  2171. }
  2172. } else if (!posData) {
  2173. toastr.warning('新增计量单元请先输入名称');
  2174. } else if (['ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  2175. data.updateType = 'update';
  2176. data.updateData = {pid: posData.id, lid: posData.lid};
  2177. data.updateData[col.field] = newText;
  2178. } else {
  2179. data.updateType = 'update';
  2180. data.updateData = {pid: posData.id, lid: posData.lid};
  2181. if (col.type === 'Number') {
  2182. const exprInfo = getExprInfo(col.field);
  2183. const num = _.toNumber(newText);
  2184. if (_.isFinite(num)) {
  2185. data.updateData[col.field] = num;
  2186. if (exprInfo) {
  2187. data.updateData[exprInfo.expr] = '';
  2188. }
  2189. } else {
  2190. try {
  2191. data.updateData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
  2192. if (exprInfo) {
  2193. data.updateData[exprInfo.expr] = newText;
  2194. }
  2195. } catch(err) {
  2196. toastr.error('输入的表达式非法');
  2197. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2198. return;
  2199. }
  2200. }
  2201. } else if (col.field.indexOf('_expr') > 0) {
  2202. const exprInfo = getExprInfo(col.field, true);
  2203. if (!exprInfo) return;
  2204. if (newText) {
  2205. try {
  2206. data.updateData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
  2207. data.updateData[exprInfo.expr] = newText;
  2208. } catch(err) {
  2209. toastr.error('输入的表达式非法');
  2210. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2211. return;
  2212. }
  2213. } else {
  2214. data.updateData[exprInfo.qty] = 0;
  2215. data.updateData[exprInfo.expr] = '';
  2216. }
  2217. } else {
  2218. data.updateData[col.field] = newText;
  2219. }
  2220. }
  2221. // 提交数据到服务器
  2222. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2223. if (result.pos) {
  2224. stagePos.updateDatas(result.pos.pos);
  2225. stagePos.loadCurStageData(result.pos.curStageData);
  2226. }
  2227. const refreshData = stageTree.loadPostStageData(result.ledger);
  2228. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2229. stagePosSpreadObj.loadCurPosData();
  2230. if (detail) {
  2231. detail.loadStagePosUpdateData(result, refreshData);
  2232. } else {
  2233. stageIm.loadUpdatePosData(result, refreshData);
  2234. }
  2235. }, function () {
  2236. stagePosSpreadObj.loadCurPosData();
  2237. });
  2238. }
  2239. },
  2240. editStarting: function (e, info) {
  2241. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2242. const sel = info.sheet.getSelections();
  2243. if (!sel || !sel[0]) return;
  2244. const col = info.sheet.zh_setting.cols[sel[0].col];
  2245. const node = SpreadJsObj.getSelectObject(info.sheet);
  2246. const exprInfo = getExprInfo(col.field);
  2247. if (exprInfo && node) {
  2248. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  2249. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  2250. }
  2251. }
  2252. switch (col.field) {
  2253. case 'contract_qty':
  2254. case 'contract_expr':
  2255. case 'qc_qty':
  2256. case 'qc_minus_qty':
  2257. info.cancel = node.settle_status === settleStatus.finish;
  2258. break;
  2259. }
  2260. },
  2261. clipboardPasting: function (e, info) {
  2262. if (info.sheet.zh_setting) {
  2263. const sortData = info.sheet.zh_data;
  2264. const range = info.cellRange;
  2265. const validField = ['contract_qty', 'contract_expr', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3', 'ex_stage_qty1'];
  2266. if (!checkTzMeasureType()) {
  2267. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  2268. }
  2269. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  2270. const col = info.sheet.zh_setting.cols[iCol];
  2271. if (validField.indexOf(col.field) === -1) {
  2272. if (checkTzMeasureType()) {
  2273. toastr.error('不可修改此数据');
  2274. info.cancel = true;
  2275. return;
  2276. } else {
  2277. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  2278. const pos = sortData(iRow);
  2279. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  2280. toastr.error('不可修改此数据');
  2281. info.cancel = true;
  2282. return;
  2283. }
  2284. }
  2285. }
  2286. }
  2287. }
  2288. }
  2289. },
  2290. clipboardPasted: function (e, info) {
  2291. const hint = {
  2292. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2293. };
  2294. if (info.sheet.zh_setting) {
  2295. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2296. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2297. }
  2298. const data = { updateType: '', updateData: [], };
  2299. const sortData = info.sheet.zh_data;
  2300. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2301. if (node.children && node.children.length > 0) return;
  2302. if (sortData && (info.cellRange.row >= sortData.length)) {
  2303. data.updateType = 'add';
  2304. if (info.cellRange.col !== 0) {
  2305. toastr.warning('新增计量单元请先输入名称');
  2306. stagePosSpreadObj.loadCurPosData();
  2307. return;
  2308. }
  2309. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  2310. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  2311. stagePosSpreadObj.loadCurPosData();
  2312. return;
  2313. }
  2314. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2315. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2316. const curRow = info.cellRange.row + iRow;
  2317. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  2318. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2319. const curCol = info.cellRange.col + iCol;
  2320. const colSetting = info.sheet.zh_setting.cols[curCol];
  2321. if (!colSetting) continue;
  2322. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2323. if (colSetting.type === 'Number') {
  2324. const exprInfo = getExprInfo(colSetting.field);
  2325. if (newValue) {
  2326. const num = _.toNumber(newValue);
  2327. if (num) {
  2328. newData[colSetting.field] = num;
  2329. if (exprInfo) {
  2330. newData[exprInfo.expr] = '';
  2331. }
  2332. } else {
  2333. try {
  2334. newData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2335. if (exprInfo) {
  2336. newData[exprInfo.expr] = newValue;
  2337. }
  2338. } catch(err) {
  2339. toastr.error('输入的表达式非法');
  2340. stagePosSpreadObj.loadCurPosData();
  2341. return;
  2342. }
  2343. }
  2344. } else {
  2345. newData[colSetting.field] = null;
  2346. if (exprInfo) newData[exprInfo.expr] = '';
  2347. }
  2348. } else if (colSetting.field.indexOf('_expr') > 0) {
  2349. try {
  2350. const exprInfo = getExprInfo(colSetting.field, true);
  2351. newData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2352. if (newData[exprInfo.expr] || newData[exprInfo.qty] === undefined) {
  2353. newData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newData[exprInfo.expr]));
  2354. }
  2355. } catch (err) {
  2356. toastMessageUniq(hint.expr);
  2357. }
  2358. } else {
  2359. newData[colSetting.field] = newValue;
  2360. }
  2361. }
  2362. data.updateData.push(newData);
  2363. }
  2364. } else {
  2365. data.updateType = 'update';
  2366. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2367. const curRow = info.cellRange.row + iRow;
  2368. const curPos = sortData[curRow];
  2369. if (curPos) {
  2370. const newData = {pid: curPos.id, lid: curPos.lid};
  2371. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2372. const curCol = info.cellRange.col + iCol;
  2373. const colSetting = info.sheet.zh_setting.cols[curCol];
  2374. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2375. if (colSetting.type === 'Number') {
  2376. if (curPos.settle_status === settleStatus.finish) {
  2377. newData.error = 1;
  2378. continue;
  2379. }
  2380. const exprInfo = getExprInfo(colSetting.field);
  2381. if (!newValue) {
  2382. newData[colSetting.field] = newValue;
  2383. if (exprInfo) newData[exprInfo.expr] = '';
  2384. continue;
  2385. }
  2386. const num = _.toNumber(newValue);
  2387. if (num) {
  2388. newData[colSetting.field] = num;
  2389. if (exprInfo) newData[exprInfo.expr] = '';
  2390. } else {
  2391. try {
  2392. newData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2393. const exprInfo = getExprInfo(colSetting.field);
  2394. if (exprInfo) newData[exprInfo.expr] = newValue;
  2395. } catch(err) {
  2396. toastr.error('输入的表达式非法');
  2397. stagePosSpreadObj.loadCurPosData();
  2398. return;
  2399. }
  2400. }
  2401. } else if (colSetting.field.indexOf('_expr') > 0) {
  2402. try {
  2403. const exprInfo = getExprInfo(colSetting.field, true);
  2404. newData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2405. if (newData[exprInfo.expr] || newData[exprInfo.qty] === undefined) {
  2406. newData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newData[exprInfo.expr]));
  2407. }
  2408. } catch (err) {
  2409. toastMessageUniq(hint.expr);
  2410. }
  2411. } else {
  2412. newData[colSetting.field] = newValue;
  2413. }
  2414. }
  2415. if (newData.error === undefined) data.updateData.push(newData);
  2416. }
  2417. }
  2418. }
  2419. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2420. if (result.pos) {
  2421. stagePos.updateDatas(result.pos.pos);
  2422. stagePos.loadCurStageData(result.pos.curStageData);
  2423. }
  2424. const nodes = stageTree.loadPostStageData(result.ledger);
  2425. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2426. stagePosSpreadObj.loadCurPosData();
  2427. if (detail) {
  2428. detail.loadStagePosUpdateData(result, nodes);
  2429. } else {
  2430. stageIm.loadUpdatePosData(result, nodes);
  2431. }
  2432. }, function () {
  2433. stagePosSpreadObj.loadCurPosData();
  2434. });
  2435. }
  2436. },
  2437. deletePress: function (sheet) {
  2438. if (sheet.zh_setting.readOnly) return;
  2439. if (sheet.zh_setting && sheet.zh_data) {
  2440. const sortData = sheet.zh_data;
  2441. if (!sortData || sortData.length === 0) { return; }
  2442. const sel = sheet.getSelections()[0];
  2443. const validCols = [];
  2444. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2445. const colSetting = sheet.zh_setting.cols[iCol];
  2446. if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
  2447. validCols.push(iCol);
  2448. }
  2449. }
  2450. if (validCols.length === 0) { return; }
  2451. const datas = [], posSelects = [];
  2452. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2453. const node = sortData[iRow];
  2454. if (node) {
  2455. const data = {pid: node.id, lid: node.lid};
  2456. for (const iCol of validCols) {
  2457. const colSetting = sheet.zh_setting.cols[iCol];
  2458. if (colSetting.field === 'name') {
  2459. toastr.error('部位名称不能为空');
  2460. return;
  2461. }
  2462. if (colSetting.Type === 'Number' && node.settle_status === settleStatus.finish) {
  2463. toastr.error('已结算节点不可计量');
  2464. return;
  2465. }
  2466. if (colSetting.field.indexOf('_expr') > 0) {
  2467. const exprInfo = getExprInfo(colSetting.field, true);
  2468. if (!exprInfo) continue;
  2469. data[exprInfo.expr] = '';
  2470. data[exprInfo.qty] = 0;
  2471. } else {
  2472. data[colSetting.field] = null;
  2473. const exprInfo = getExprInfo(colSetting.field);
  2474. if (exprInfo) {
  2475. data[exprInfo.expr] = '';
  2476. }
  2477. }
  2478. }
  2479. datas.push(data);
  2480. posSelects.push(node);
  2481. }
  2482. }
  2483. if (datas.length > 0) {
  2484. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  2485. if (result.pos) {
  2486. stagePos.updateDatas(result.pos.pos);
  2487. stagePos.loadCurStageData(result.pos.curStageData);
  2488. }
  2489. const nodes = stageTree.loadPostStageData(result.ledger);
  2490. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2491. if (detail) {
  2492. detail.loadStagePosUpdateData(result, nodes);
  2493. } else {
  2494. stageIm.loadUpdatePosData(result, nodes);
  2495. }
  2496. // todo 只加载改变项
  2497. stagePosSpreadObj.loadCurPosData();
  2498. });
  2499. }
  2500. }
  2501. },
  2502. deletePos: function (sheet) {
  2503. const sels = sheet.getSelections();
  2504. const sel = sels ? sels[0] : null;
  2505. if (sheet.zh_data && sel) {
  2506. const data = {updateType: 'delete', updateData: []};
  2507. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  2508. const posData = sheet.zh_data[sel.row + iRow];
  2509. if (posData) {
  2510. data.updateData.push(posData.id);
  2511. }
  2512. }
  2513. if (data.updateData.length > 0) {
  2514. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2515. stagePos.removeDatas(result.pos.pos);
  2516. const refreshData = stageTree.loadPostStageData(result.ledger);
  2517. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2518. stagePosSpreadObj.loadCurPosData();
  2519. if (detail) {
  2520. detail.loadStagePosUpdateData(result, refreshData);
  2521. } else {
  2522. stageIm.loadUpdatePosData(result, refreshData);
  2523. }
  2524. });
  2525. }
  2526. }
  2527. },
  2528. selectionChanged: function (e, info) {
  2529. stagePosSpreadObj.loadExprToInput(info.sheet);
  2530. },
  2531. addPegs: function (pegs) {
  2532. if (!pegs || pegs.length <= 0) return;
  2533. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2534. if (!node) return;
  2535. const sheet = spSpread.getActiveSheet();
  2536. const sortData = sheet.zh_data || [];
  2537. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2538. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2539. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  2540. if (result.pos) {
  2541. stagePos.updateDatas(result.pos.pos);
  2542. }
  2543. stagePosSpreadObj.loadCurPosData();
  2544. });
  2545. }
  2546. };
  2547. $('#pos-measure').click(stagePosSpreadObj.loadCurPosData);
  2548. $('#pos-un-measure').click(stagePosSpreadObj.loadCurPosData);
  2549. // 加载上下窗口resizer
  2550. $.divResizer({
  2551. select: '#main-resize',
  2552. callback: function () {
  2553. slSpread.refresh();
  2554. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2555. $(".sp-wrap").height(bcontent-30);
  2556. spSpread.refresh();
  2557. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2558. }
  2559. });
  2560. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  2561. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;stageChange;import_change;tag;reCalcChange' }, function (result) {
  2562. // 加载树结构
  2563. stageTree.loadDatas(result.ledgerData, result.locked);
  2564. if (stage.assist) {
  2565. stageTree.loadFilter(stage.assist.ass_ledger_id);
  2566. } else if (stage.relaAuditor && stage.relaAuditor.audit_ledger_id) {
  2567. stageTree.loadFilter(stage.relaAuditor.audit_ledger_id);
  2568. }
  2569. // 加载部位明细
  2570. stagePos.loadDatas(result.posData);
  2571. stageTreeSpreadObj.loadChangeData(stageTree, stagePos, result.reCalcChange);
  2572. checkShowLast(result.ledgerData.length);
  2573. treeCalc.calculateAll(stageTree);
  2574. for (const t of result.tags) {
  2575. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  2576. }
  2577. billsTag.loadDatas(result.tags);
  2578. stagePos.calculateAll();
  2579. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  2580. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  2581. stagePosSpreadObj.loadCurPosData();
  2582. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  2583. TreeExprCalc.init({
  2584. tree: stageTree,
  2585. decimal: tenderInfo.decimal,
  2586. precision: tenderInfo.precision,
  2587. calcField: { qty: 'contract_qty', tp: 'contract_tp' }, calcType: TreeExprCalc.calcType.sortCache,
  2588. exprFieldsIndex: {
  2589. tzsl: 'quantity', tzje: 'total_price', qysl: 'deal_qty', qyje: 'deal_tp',
  2590. bqhtje: 'contract_tp',
  2591. },
  2592. exprCacheKey: ['bqhtje'],
  2593. });
  2594. // 加载中间计量
  2595. stageIm.init(tenderInfo, stage, imType, tenderInfo.decimal);
  2596. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.stageChange, result.import_change, result.detailAtt);
  2597. if (stage.assist) {
  2598. stageIm.loadFilter(stage.assist.ass_ledger_id);
  2599. } else if (stage.relaAuditor) {
  2600. stageIm.loadFilter(stage.relaAuditor.audit_ledger_id);
  2601. }
  2602. errorList.loadHisErrorData();
  2603. checkList.loadHisCheckData();
  2604. sumLoadMiss.loadHisMissData();
  2605. // 收方单赋值
  2606. ledgerData = result.ledgerData;
  2607. posData = result.posData;
  2608. makeShouFang();
  2609. }, null, true);
  2610. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  2611. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  2612. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  2613. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  2614. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  2615. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  2616. if (!readOnly) {
  2617. $('#pos-expr').bind('change onblur', function () {
  2618. if (this.readOnly) return;
  2619. const expr = $(this);
  2620. const posSheet = spSpread.getActiveSheet();
  2621. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2622. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2623. if (!select) return;
  2624. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2625. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2626. const data = {pid: select.id, lid: select.lid};
  2627. const exprInfo = getExprInfo(field);
  2628. if (newValue !== '') {
  2629. const num = _.toNumber(newValue);
  2630. if (num) {
  2631. data[field] = num;
  2632. if (exprInfo) data[exprInfo.expr] = '';
  2633. } else {
  2634. try {
  2635. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2636. if (exprInfo) data[exprInfo.expr] = newValue;
  2637. } catch (err) {
  2638. toastr.error('输入的表达式非法');
  2639. return;
  2640. }
  2641. }
  2642. } else {
  2643. data[field] = null;
  2644. if (exprInfo) data[exprInfo.expr] = '';
  2645. }
  2646. // 提交数据到服务器
  2647. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  2648. if (result.pos) {
  2649. stagePos.updateDatas(result.pos.pos);
  2650. stagePos.loadCurStageData(result.pos.curStageData);
  2651. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2652. }
  2653. const refreshData = stageTree.loadPostStageData(result.ledger);
  2654. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2655. if (detail) {
  2656. detail.loadStagePosUpdateData(result, refreshData);
  2657. } else {
  2658. stageIm.loadUpdatePosData(result, refreshData);
  2659. }
  2660. });
  2661. });
  2662. }
  2663. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  2664. $.contextMenu({
  2665. selector: '#stage-pos',
  2666. build: function ($trigger, e) {
  2667. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  2668. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2669. },
  2670. items: {
  2671. 'del': {
  2672. name: '删除',
  2673. icon: 'fa-remove',
  2674. visible: function (key, opt) {
  2675. return !checkTzMeasureType();
  2676. },
  2677. disabled: function (key, opt) {
  2678. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2679. if (!node || node.lock) return true;
  2680. const sheet = spSpread.getActiveSheet();
  2681. if (sheet.zh_data && !readOnly) {
  2682. const selection = sheet.getSelections();
  2683. if (selection && selection[0]) {
  2684. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2685. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  2686. const posData = sheet.zh_data[selection[0].row + iRow];
  2687. if (posData) {
  2688. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2689. valid = true;
  2690. break;
  2691. }
  2692. } else {
  2693. valid = true;
  2694. break;
  2695. }
  2696. }
  2697. return valid;
  2698. } else {
  2699. return true;
  2700. }
  2701. } else {
  2702. return true;
  2703. }
  2704. },
  2705. callback: function (key, opt) {
  2706. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2707. }
  2708. },
  2709. 'sort': {
  2710. name: '排序',
  2711. items: {
  2712. "addStageReverse": {
  2713. name: '按新增期倒序',
  2714. icon: 'fa-sort-amount-desc',
  2715. callback: function (key, opt) {
  2716. stagePos.sort = [['add_stage_order', 'desc'], ['porder', 'asc']];
  2717. const spSheet = spSpread.getActiveSheet();
  2718. if (spSheet.zh_data) {
  2719. spSheet.zh_data.sort((x, y) => { return y.add_stage_order - x.add_stage_order || x.porder - y.porder; });
  2720. SpreadJsObj.reLoadSheetData(spSheet);
  2721. }
  2722. }
  2723. }
  2724. }
  2725. },
  2726. 'merge-peg': {
  2727. name: '合并起讫桩号',
  2728. visible: function (key, opt) {
  2729. return !checkTzMeasureType();
  2730. },
  2731. disabled: function (key, opt) {
  2732. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2733. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2734. },
  2735. callback: function (key, opt) {
  2736. mergePeg.show();
  2737. }
  2738. },
  2739. 'calcByRatio': {
  2740. name: '按比例计量',
  2741. visible: function (key, opt) {
  2742. const data = spSpread.getActiveSheet().zh_data;
  2743. return checkTzMeasureType() && data && data.length > 0;
  2744. },
  2745. disabled: function (key, opt) {
  2746. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2747. return node.lock;
  2748. },
  2749. callback: function (key, opt) {
  2750. $('#cbr-ratio').val('');
  2751. $('#apply2sibling')[0].checked = false;
  2752. $('#cbr-check-all')[0].checked = false;
  2753. const html = [];
  2754. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2755. html.push('<tr>');
  2756. html.push('<td>', i+1, '</td>');
  2757. html.push('<td>', p.name, '</td>');
  2758. html.push('<td>', p.quantity, '</td>');
  2759. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2760. html.push('</tr>');
  2761. }
  2762. $('#cbr-pos-list').html(html.join(''));
  2763. $('#calc-by-ratio').modal('show');
  2764. }
  2765. },
  2766. 'remainCur': {
  2767. name: '填剩余量(选中行)',
  2768. disabled: function (key, opt) {
  2769. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2770. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2771. return readOnly || node.lock || !curPos;
  2772. },
  2773. callback: function (key, opt) {
  2774. const sheet = spSpread.getActiveSheet();
  2775. const sels = sheet.getSelections();
  2776. if (!sels || !sels[0]) return;
  2777. const data = { updateType: 'update', updateData: [] };
  2778. for (let iRow = 0; iRow < sels[0].rowCount; iRow++) {
  2779. const curRow = iRow + sels[0].row;
  2780. const curPos = SpreadJsObj.getRowObject(sheet, curRow);
  2781. if (!curPos) continue;
  2782. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2783. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2784. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2785. }
  2786. if (data.updateData.length > 0) {
  2787. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2788. if (result.pos) {
  2789. stagePos.updateDatas(result.pos.pos);
  2790. stagePos.loadCurStageData(result.pos.curStageData);
  2791. }
  2792. const nodes = stageTree.loadPostStageData(result.ledger);
  2793. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2794. stagePosSpreadObj.loadCurPosData();
  2795. if (detail) {
  2796. detail.loadStagePosUpdateData(result, nodes);
  2797. } else {
  2798. stageIm.loadUpdatePosData(result, nodes);
  2799. }
  2800. });
  2801. }
  2802. },
  2803. visible: function(key, opt) {
  2804. return checkTzMeasureType();
  2805. },
  2806. },
  2807. 'remainAll': {
  2808. name: '填剩余量(全部行)',
  2809. disabled: function (key, opt) {
  2810. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2811. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2812. return readOnly || node.lock || !curPos;
  2813. },
  2814. callback: function (key, opt) {
  2815. const sheet = spSpread.getActiveSheet();
  2816. if (!sheet.zh_data || sheet.zh_data.length === 0) return;
  2817. const data = { updateType: 'update', updateData: [] };
  2818. for (const curPos of sheet.zh_data) {
  2819. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2820. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2821. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2822. }
  2823. if (data.updateData.length > 0) {
  2824. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2825. if (result.pos) {
  2826. stagePos.updateDatas(result.pos.pos);
  2827. stagePos.loadCurStageData(result.pos.curStageData);
  2828. }
  2829. const nodes = stageTree.loadPostStageData(result.ledger);
  2830. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2831. stagePosSpreadObj.loadCurPosData();
  2832. if (detail) {
  2833. detail.loadStagePosUpdateData(result, nodes);
  2834. } else {
  2835. stageIm.loadUpdatePosData(result, nodes);
  2836. }
  2837. });
  2838. }
  2839. },
  2840. visible: function(key, opt) {
  2841. return checkTzMeasureType();
  2842. },
  2843. },
  2844. 'shoufangdan': {
  2845. name: '生成收方单',
  2846. visible: function(key, opt) {
  2847. if (cur_uid === stage.user_id) return true;
  2848. },
  2849. disabled: function (key, opt) {
  2850. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2851. if (!node || cur_uid !== stage.user_id) return true;
  2852. },
  2853. callback: function (key, opt) {
  2854. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2855. const ledgerNode = _.find(ledgerData, { id: node.lid });
  2856. $('#shoufang-lid').val(node.lid);
  2857. $('#shoufang-pid').val(node.id);
  2858. $('#shoufang-ledger').text('清单:' + ledgerNode.b_code);
  2859. $('#shoufang-pos').text('计量单元:' + node.name).show();
  2860. $('#addshoufang').modal('show');
  2861. }
  2862. }
  2863. }
  2864. });
  2865. $.subMenu({
  2866. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2867. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2868. key: 'menu.1.0.0',
  2869. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2870. callback: function (info) {
  2871. if (info.mini) {
  2872. $('.panel-title').addClass('fluid');
  2873. $('#sub-menu').removeClass('panel-sidebar');
  2874. } else {
  2875. $('.panel-title').removeClass('fluid');
  2876. $('#sub-menu').addClass('panel-sidebar');
  2877. }
  2878. autoFlashHeight();
  2879. slSpread.refresh();
  2880. spSpread.refresh();
  2881. if (searchLedger) searchLedger.spread.refresh();
  2882. if (detail) detail.spread.refresh();
  2883. if (checkedChanges) checkedChanges.refresh();
  2884. if (errorList && errorList.spread) errorList.spread.refresh();
  2885. if (checkList) checkList.spread.refresh();
  2886. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2887. }
  2888. });
  2889. $('#row-view').on('show.bs.modal', function () {
  2890. const html = [], customDisplay = customColDisplay();
  2891. for (const cd of customDisplay) {
  2892. html.push('<tr>');
  2893. html.push('<td>', cd.title, '</td>');
  2894. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2895. html.push('</tr>');
  2896. }
  2897. $('#row-view-list').html(html.join(''));
  2898. });
  2899. $('#row-view-ok').click(function () {
  2900. const customDisplay = customColDisplay();
  2901. const cvl = $('#row-view-list').children();
  2902. for (const cv of cvl) {
  2903. const title = $(cv).children()[0].innerHTML;
  2904. const check = $('input', cv)[0].checked;
  2905. const cd = customDisplay.find(function (c) {
  2906. return c.title === title;
  2907. });
  2908. cd.visible = check;
  2909. }
  2910. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  2911. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  2912. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  2913. $('#row-view').modal('hide');
  2914. });
  2915. const posSearch = (function () {
  2916. let resultArr = [];
  2917. const search = function () {
  2918. resultArr = [];
  2919. const keyword = $('#pos-search-keyword').val();
  2920. const checkOver = $('#pos-over-search')[0].checked;
  2921. const checkEmpty = $('#pos-empty-search')[0].checked;
  2922. const sortData = spSpread.getActiveSheet().zh_data;
  2923. if (checkOver || checkEmpty) {
  2924. if (sortData) {
  2925. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2926. const sd = sortData[i];
  2927. let match = false;
  2928. if (checkOver) {
  2929. if (sd.end_gather_qty) {
  2930. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  2931. }
  2932. }
  2933. if (checkEmpty) {
  2934. if (sd.quantity) {
  2935. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  2936. }
  2937. }
  2938. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  2939. if (match) {
  2940. resultArr.push({index: i, data: sd});
  2941. }
  2942. }
  2943. }
  2944. } else if (keyword && keyword !== '') {
  2945. if (sortData) {
  2946. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2947. const sd = sortData[i];
  2948. if (sd.name && sd.name.indexOf(keyword) > -1) {
  2949. resultArr.push({index: i, data: sd});
  2950. }
  2951. }
  2952. }
  2953. }
  2954. $('#pos-search-result').html('结果:' + resultArr.length);
  2955. };
  2956. const searchAndLocate = function () {
  2957. search();
  2958. if (resultArr.length > 0) {
  2959. const sheet = spSpread.getActiveSheet();
  2960. const sel = sheet.getSelections()[0];
  2961. const curRow = sel ? sel.row : 0;
  2962. const pos = resultArr[0];
  2963. if (pos.index !== curRow) {
  2964. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  2965. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  2966. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  2967. }
  2968. }
  2969. };
  2970. const locateNext = function () {
  2971. if (resultArr.length > 0) {
  2972. const sheet = spSpread.getActiveSheet();
  2973. const sel = sheet.getSelections()[0];
  2974. const curRow = sel ? sel.row : 0;
  2975. let next = _.find(resultArr, function (d) {
  2976. return d.index > curRow;
  2977. });
  2978. if (!next) next = resultArr[0];
  2979. if (next.index !== curRow) {
  2980. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2981. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2982. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2983. }
  2984. }
  2985. };
  2986. const locatePre = function () {
  2987. if (resultArr.length > 0) {
  2988. const sheet = spSpread.getActiveSheet();
  2989. const sel = sheet.getSelections()[0];
  2990. const curRow = sel ? sel.row : 0;
  2991. let next = _.findLast(resultArr, function (d) {
  2992. return d.index < curRow;
  2993. });
  2994. if (!next) next = resultArr[resultArr.length - 1];
  2995. if (next.index !== curRow) {
  2996. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2997. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2998. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2999. }
  3000. }
  3001. };
  3002. return {search, searchAndLocate, locateNext, locatePre};
  3003. })();
  3004. $('#pos-search-keyword').bind('keydown', function(e){
  3005. if (e.keyCode == 13) posSearch.searchAndLocate();
  3006. });
  3007. $('#pos-empty-search').click(function () {
  3008. if (this.checked) {
  3009. $('[for=' + this.id +']').addClass('text-warning');
  3010. } else {
  3011. $('[for=' + this.id +']').removeClass('text-warning');
  3012. }
  3013. if (this.checked) {
  3014. if ($('#pos-over-search')[0].checked) {
  3015. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3016. } else {
  3017. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  3018. }
  3019. } else {
  3020. if ($('#pos-over-search')[0].checked) {
  3021. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  3022. } else {
  3023. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3024. }
  3025. }
  3026. posSearch.searchAndLocate();
  3027. });
  3028. $('#pos-over-search').click(function () {
  3029. if (this.checked) {
  3030. $('[for=' + this.id +']').addClass('text-danger');
  3031. } else {
  3032. $('[for=' + this.id +']').removeClass('text-danger');
  3033. }
  3034. if (this.checked) {
  3035. if ($('#pos-empty-search')[0].checked) {
  3036. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3037. } else {
  3038. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  3039. }
  3040. } else {
  3041. if ($('#pos-empty-search')[0].checked) {
  3042. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  3043. } else {
  3044. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3045. }
  3046. }
  3047. posSearch.searchAndLocate();
  3048. });
  3049. $('#pos-search-next').click(() => {posSearch.locateNext()});
  3050. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  3051. $.divResizer({
  3052. select: '#right-spr',
  3053. callback: function () {
  3054. slSpread.refresh();
  3055. spSpread.refresh();
  3056. if (searchLedger) {
  3057. searchLedger.spread.refresh();
  3058. }
  3059. if (detail) {
  3060. detail.spread.refresh();
  3061. }
  3062. if (checkedChanges) checkedChanges.refresh();
  3063. if (errorList && errorList.spread) errorList.spread.refresh();
  3064. if (checkList) checkList.spread.refresh();
  3065. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3066. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3067. }
  3068. });
  3069. // 中间计量加载上下窗口resizer
  3070. $.divResizer({
  3071. select: '#zhongjian-spr',
  3072. callback: function () {
  3073. if (detail) {
  3074. detail.spread.refresh();
  3075. }
  3076. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  3077. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3078. }
  3079. });
  3080. // 附件加载上下窗口resizer
  3081. $.divResizer({
  3082. select: '#file-spr',
  3083. callback: function () {
  3084. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3085. }
  3086. });
  3087. // 变更令加载上下窗口resizer
  3088. $.divResizer({
  3089. select: '#change-spr',
  3090. callback: function () {
  3091. if (checkedChanges) checkedChanges.refresh();
  3092. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3093. }
  3094. });
  3095. class Detail {
  3096. constructor (obj) {
  3097. const self = this;
  3098. this.spreadSetting = {
  3099. cols: [
  3100. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3101. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3102. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  3103. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  3104. {
  3105. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  3106. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  3107. },
  3108. {
  3109. title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
  3110. normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
  3111. return data.attachment ? data.attachment.length : 0;
  3112. }
  3113. },
  3114. ],
  3115. headRows: 1,
  3116. emptyRows: 0,
  3117. headRowHeight: [32],
  3118. headColWidth: [30],
  3119. defaultRowHeight: 21,
  3120. headerFont: '12px 微软雅黑',
  3121. font: '12px 微软雅黑',
  3122. readOnly: readOnly,
  3123. selectedBackColor: '#fffacd',
  3124. imageClick: function (data) {
  3125. self.makeAttTable(data);
  3126. $('#im-file').modal('show');
  3127. }
  3128. };
  3129. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  3130. this.sheet = this.spread.getActiveSheet();
  3131. this.spread.options.allowUserDragFill = true;
  3132. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  3133. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  3134. this.detailObj = {
  3135. selectionChanged: function (e, info) {
  3136. self.reLoadDetailData();
  3137. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  3138. self.loadLocateInfo();
  3139. }
  3140. },
  3141. editEnded: function(e, info) {
  3142. if (info.sheet.zh_setting) {
  3143. const col = info.sheet.zh_setting.cols[info.col];
  3144. if (col.field !== 'doc_code') {
  3145. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3146. return;
  3147. }
  3148. const data = SpreadJsObj.getSelectObject(info.sheet);
  3149. if (data) {
  3150. const updateData = {lid: data.lid, pid: data.pid};
  3151. if (data.uuid) {
  3152. updateData.uuid = data.uuid;
  3153. } else {
  3154. updateData.code = data.code;
  3155. updateData.name = data.name;
  3156. updateData.unit = data.unit;
  3157. updateData.unit_price = data.unit_price;
  3158. updateData.pid = data.pid;
  3159. updateData.pos_name = data.pos_name;
  3160. updateData.im_type = data.im_type;
  3161. }
  3162. if (data.custom_define.indexOf('doc_code') === -1) {
  3163. updateData.custom_define = data.custom_define;
  3164. updateData.custom_define.push('doc_code');
  3165. updateData.custom_define = updateData.custom_define.join(',');
  3166. }
  3167. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  3168. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3169. stageIm.loadUpdateDetailData(result);
  3170. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3171. }, function () {
  3172. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3173. });
  3174. } else {
  3175. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3176. }
  3177. }
  3178. },
  3179. clipboardPasted: function (e, info) {
  3180. if (info.sheet.zh_setting && info.sheet.zh_data) {
  3181. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  3182. if (info.cellRange.colCount > 1) {
  3183. toastr.warning('请勿同时复制粘贴多列数据');
  3184. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  3185. return;
  3186. }
  3187. if (col.field !== 'doc_code') {
  3188. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  3189. return;
  3190. }
  3191. const datas = [];
  3192. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3193. const curRow = info.cellRange.row + iRow;
  3194. const data = info.sheet.zh_data[curRow];
  3195. if (data) {
  3196. const updateData = {lid: data.lid, pid: data.pid};
  3197. if (data.uuid) {
  3198. updateData.uuid = data.uuid;
  3199. } else {
  3200. updateData.code = data.code;
  3201. updateData.name = data.name;
  3202. updateData.unit = data.unit;
  3203. updateData.unit_price = data.unit_price;
  3204. updateData.pid = data.pid;
  3205. updateData.pos_name = data.pos_name;
  3206. updateData.im_type = data.im_type;
  3207. }
  3208. if (data.custom_define.indexOf('doc_code') === -1) {
  3209. updateData.custom_define = data.custom_define;
  3210. updateData.custom_define.push('doc_code');
  3211. updateData.custom_define = updateData.custom_define.join(',');
  3212. }
  3213. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  3214. datas.push(updateData);
  3215. }
  3216. }
  3217. if (datas.length > 0) {
  3218. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3219. stageIm.loadUpdateDetailData(result);
  3220. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3221. }, function () {
  3222. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3223. })
  3224. }
  3225. }
  3226. },
  3227. deletePress: function (sheet) {
  3228. if (sheet.zh_setting) {
  3229. const datas = [];
  3230. const sel = sheet.getSelections()[0];
  3231. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  3232. const col = sheet.zh_setting.cols[iCol];
  3233. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  3234. const data = sheet.zh_data[iRow];
  3235. if (col.field === 'doc_code') {
  3236. const updateData = {lid: data.lid};
  3237. if (data.uuid) {
  3238. updateData.uuid = data.uuid;
  3239. updateData.doc_code = '';
  3240. datas.push(updateData);
  3241. }
  3242. }
  3243. }
  3244. }
  3245. if (datas.length > 0) {
  3246. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3247. stageIm.loadUpdateDetailData(result);
  3248. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  3249. }, function () {
  3250. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  3251. });
  3252. }
  3253. }
  3254. },
  3255. dragFillBlock: function (e, info) {
  3256. info.cancel = true;
  3257. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  3258. const sel = info.sheet.getSelections()[0];
  3259. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  3260. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  3261. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  3262. if (text === '') return;
  3263. const regRst = /(\d+)$/g.exec(text), datas = [];
  3264. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  3265. const curRow = info.fillRange.row + iRow;
  3266. const data = info.sheet.zh_data[curRow];
  3267. if (data) {
  3268. const updateData = {lid: data.lid};
  3269. if (data.uuid) {
  3270. updateData.uuid = data.uuid;
  3271. } else {
  3272. updateData.code = data.code;
  3273. updateData.name = data.name;
  3274. updateData.unit = data.unit;
  3275. updateData.unit_price = data.unit_price;
  3276. updateData.pid = data.pid;
  3277. updateData.pos_name = data.pos_name;
  3278. updateData.im_type = data.im_type;
  3279. }
  3280. if (regRst) {
  3281. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  3282. } else {
  3283. updateData.doc_code = text.replace('\n', '');
  3284. }
  3285. if (data.custom_define.indexOf('doc_code') === -1) {
  3286. updateData.custom_define = data.custom_define;
  3287. updateData.custom_define.push('doc_code');
  3288. updateData.custom_define = updateData.custom_define.join(',');
  3289. }
  3290. datas.push(updateData);
  3291. }
  3292. }
  3293. if (datas.length > 0) {
  3294. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3295. stageIm.loadUpdateDetailData(result);
  3296. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  3297. }, function () {
  3298. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  3299. })
  3300. }
  3301. },
  3302. };
  3303. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  3304. if (!readOnly) {
  3305. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  3306. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  3307. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  3308. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  3309. }
  3310. this._initImTypeSetRela();
  3311. this._initModifyDetail();
  3312. this._initLocateRela();
  3313. this._initAttRela();
  3314. // 草图相关
  3315. this._initImageRela();
  3316. this.reBuildImData();
  3317. }
  3318. makeAttTable (data) {
  3319. let html = [];
  3320. if (data.attachment) {
  3321. for (const att of data.attachment) {
  3322. const delHtml = (parseInt(att.uid) === userID && (att.renew || stage.status !== auditConst.status.checked || deleteFilePermission))
  3323. ? '<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>'
  3324. : '';
  3325. const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
  3326. 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>';
  3327. 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>',
  3328. '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
  3329. }
  3330. }
  3331. $('#im-attList').html(html.join(''));
  3332. }
  3333. _initAttRela() {
  3334. // 上传附件
  3335. const self = this;
  3336. $('#upload-im-file').change(function () {
  3337. const files = this.files;
  3338. const sels = self.sheet.getSelections();
  3339. const select = SpreadJsObj.getSelectObject(self.sheet);
  3340. if (!select) return;
  3341. const formData = new FormData();
  3342. const baseInfo = {};
  3343. if (select.att_uuid) {
  3344. baseInfo.uuid = select.att_uuid;
  3345. } else {
  3346. baseInfo.im_type = select.im_type;
  3347. baseInfo.lid = select.lid;
  3348. baseInfo.pid = select.pid;
  3349. baseInfo.code = select.code;
  3350. baseInfo.name = select.name;
  3351. baseInfo.unit = select.unit;
  3352. baseInfo.unit_price = select.unit_price;
  3353. baseInfo.pos_name = select.pos_name;
  3354. }
  3355. formData.append('base', JSON.stringify(baseInfo));
  3356. for (const file of files) {
  3357. if (file === undefined) {
  3358. toast('未选择上传文件!', 'error');
  3359. return false;
  3360. }
  3361. const filesize = file.size;
  3362. if (filesize > 50 * 1024 * 1024) {
  3363. toast('存在上传文件大小过大!', 'error');
  3364. return false;
  3365. }
  3366. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3367. if (whiteList.indexOf(fileext) === -1) {
  3368. toast('只能上传指定格式的附件!', 'error');
  3369. return false;
  3370. }
  3371. formData.append('size', filesize);
  3372. formData.append('file[]', file);
  3373. }
  3374. postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
  3375. stageIm.loadUpdateDetailAtt(data);
  3376. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  3377. self.makeAttTable(select);
  3378. $('#upload-im-file').val('');
  3379. });
  3380. });
  3381. // 删除附件
  3382. $('body').on('click', '.delete-att' ,function () {
  3383. const sels = self.sheet.getSelections();
  3384. const select = SpreadJsObj.getSelectObject(self.sheet);
  3385. if (!select) return;
  3386. const uuid = $(this).attr('data-imid');
  3387. const file_id = $(this).attr('data-attid');
  3388. const att = select.attachment.find(x => {
  3389. return x.file_id === file_id;
  3390. });
  3391. deleteAfterHint(function () {
  3392. postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
  3393. stageIm.loadUpdateDetailAtt(result);
  3394. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  3395. self.makeAttTable(select);
  3396. });
  3397. }, `确认删除附件「${att.filename}」?`);
  3398. });
  3399. // 预览附件
  3400. $('body').on('click', '.preview-att', function () {
  3401. const uuid = $(this).attr('data-imid');
  3402. const file_id = $(this).attr('data-attid');
  3403. postData(window.location.pathname + `/im-file/preview?uuid=${uuid}&file_id=${file_id}`, {}, function (result) {
  3404. const { filepath } = result;
  3405. $('#load-file').attr('href', filepath);
  3406. $('#load-file')[0].click();
  3407. });
  3408. });
  3409. $('#batch-download-im-file').click(function() {
  3410. const select = $('[name=sia-check]:checked');
  3411. if (select.length === 0) {
  3412. toastr.warning('请选择需要批量下载的文件');
  3413. return;
  3414. }
  3415. const files = [];
  3416. const curIm = SpreadJsObj.getSelectObject(self.sheet);
  3417. for (const s of select) {
  3418. const att = curIm.attachment.find(x => { return x.file_id === s.getAttribute('fid')});
  3419. if (att) files.push(att);
  3420. }
  3421. if (files.length === 0) return;
  3422. AliOss.zipFiles(files, `中间计量[${curIm.code}].zip`, (fails) => {
  3423. $(self).removeAttr('disabled');
  3424. if (fails.length === 0) {
  3425. toastr.success('下载成功');
  3426. } else {
  3427. toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
  3428. }
  3429. }, () => {
  3430. $(self).removeAttr('disabled');
  3431. toastr.error('批量下载失败');
  3432. });
  3433. });
  3434. }
  3435. _initImTypeSetRela() {
  3436. const self = this;
  3437. const gatherConfirmPopover = {
  3438. reBind: function (obj, eventName, fun) {
  3439. obj.unbind(eventName);
  3440. obj.bind(eventName, fun);
  3441. },
  3442. check: function (pos, hint, okCallback) {
  3443. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  3444. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  3445. this.reBind(cancelObj, 'click', function () {
  3446. confirmObj.hide();
  3447. });
  3448. this.reBind(okObj, 'click', function () {
  3449. okCallback();
  3450. confirmObj.hide();
  3451. });
  3452. hintObj.text(hint);
  3453. confirmObj.css("top", pos.y).css("left", pos.x).show();
  3454. }
  3455. };
  3456. this.gsTree = stageIm.getGsTree();
  3457. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  3458. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3459. jlCol.title = '本期计量金额';
  3460. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3461. $('[name=type-title-contract]').text('本期合同计量金额');
  3462. $('[name=type-title-qc]').text('本期变更计量金额');
  3463. if ($('#show-qc-minus-jl').length > 0) {
  3464. $('#show-qc-minus-jl').parent().hide();
  3465. $('#qc-minus-jl').parent().hide();
  3466. }
  3467. } else {
  3468. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3469. jlCol.title = '本期计量数量';
  3470. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3471. $('[name=type-title-contract]').text('本期合同计量数量');
  3472. $('[name=type-title-qc]').text('本期变更计量数量');
  3473. if ($('#show-qc-minus-jl').length > 0) {
  3474. $('#show-qc-minus-jl').parent().show();
  3475. $('#qc-minus-jl').parent().show();
  3476. }
  3477. }
  3478. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  3479. $('#show-jldy').parent().show();
  3480. $('#jldy').parent().show();
  3481. $('#show-xm-name').parent().hide();
  3482. $('#xm-name').parent().hide();
  3483. } else {
  3484. $('#show-jldy').parent().hide();
  3485. $('#jldy').parent().hide();
  3486. $('#show-xm-name').parent().show();
  3487. $('#xm-name').parent().show();
  3488. }
  3489. // 选择中间计量模式
  3490. $('div[name="im-type"]').click(function () {
  3491. function chooseType(obj) {
  3492. obj.style.cursor = 'default';
  3493. $(obj).children().addClass('text-primary');
  3494. $(obj).addClass('border-primary');
  3495. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  3496. }
  3497. function validType(obj) {
  3498. obj.style.cursor = 'pointer';
  3499. $(obj).children().removeClass('text-primary');
  3500. $(obj).removeClass('border-primary');
  3501. $('i', obj).remove();
  3502. }
  3503. if (this.style.cursor === 'pointer') {
  3504. const typeArr = $('div[name="im-type"]');
  3505. for (const t of typeArr) {
  3506. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  3507. chooseType(t);
  3508. } else {
  3509. validType(t)
  3510. }
  3511. }
  3512. }
  3513. });
  3514. $('#choose').on('show.bs.modal', function () {
  3515. function chooseType(obj) {
  3516. obj.style.cursor = 'default';
  3517. $(obj).children().addClass('text-primary');
  3518. $('i', obj).remove();
  3519. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  3520. }
  3521. function validType(obj) {
  3522. obj.style.cursor = 'pointer';
  3523. $(obj).children().removeClass('text-primary');
  3524. $('i', obj).remove();
  3525. }
  3526. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  3527. $('#im-start-num').val(stage.im_start_num ? stage.im_start_num : '');
  3528. const typeArr = $('div[name="im-type"]');
  3529. for (const t of typeArr) {
  3530. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  3531. chooseType(t);
  3532. } else {
  3533. validType(t)
  3534. }
  3535. }
  3536. });
  3537. // 提交 中间计量模式
  3538. $('#choose-ok').click(() => {
  3539. let startNum;
  3540. try {
  3541. startNum = parseInt($('#im-start-num').val());
  3542. if (!startNum || startNum <= 0) throw '起始编号请输入正整数';
  3543. } catch (err) {
  3544. toastr.error("起始编号请输入正整数");
  3545. return;
  3546. }
  3547. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  3548. return it.style.cursor !== 'pointer';
  3549. });
  3550. const data = {
  3551. im_type: parseInt($(chooseType).attr('im-type')),
  3552. im_pre: $('#im-pre').val(),
  3553. im_start_num: startNum,
  3554. };
  3555. postData(window.location.pathname + '/detail/build', data, function (result) {
  3556. stage.im_type = data.im_type;
  3557. stage.im_pre = data.im_pre;
  3558. stage.im_start_num = data.im_start_num;
  3559. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  3560. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3561. jlCol.title = '本期计量金额';
  3562. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3563. $('[name=type-title-contract]').text('本期合同计量金额');
  3564. $('[name=type-title-qc]').text('本期变更计量金额');
  3565. if ($('#show-qc-minus-jl').length > 0) {
  3566. $('#show-qc-minus-jl').parent().hide();
  3567. $('#qc-minus-jl').parent().hide();
  3568. }
  3569. } else {
  3570. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3571. jlCol.title = '本期计量数量';
  3572. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3573. $('[name=type-title-contract]').text('本期合同计量数量');
  3574. $('[name=type-title-qc]').text('本期变更计量数量');
  3575. if ($('#show-qc-minus-jl').length > 0) {
  3576. $('#show-qc-minus-jl').parent().show();
  3577. $('#qc-minus-jl').parent().show();
  3578. }
  3579. }
  3580. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  3581. $('#show-jldy').parent().show();
  3582. $('#jldy').parent().show();
  3583. $('#show-xm-name').parent().hide();
  3584. $('#xm-name').parent().hide();
  3585. } else {
  3586. $('#show-jldy').parent().hide();
  3587. $('#jldy').parent().hide();
  3588. $('#show-xm-name').parent().show();
  3589. $('#xm-name').parent().show();
  3590. }
  3591. // 加载生成数据
  3592. self.reBuildImData();
  3593. $('#choose').modal('hide');
  3594. });
  3595. });
  3596. // 显示树结构信息
  3597. $('#choose2').on('shown.bs.modal', function () {
  3598. if (!self.gsSpread) {
  3599. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  3600. const setting = {
  3601. cols: [
  3602. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  3603. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  3604. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3605. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  3606. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  3607. ],
  3608. headRows: 1,
  3609. emptyRows: 0,
  3610. headRowHeight: [32],
  3611. defaultRowHeight: 21,
  3612. headerFont: '12px 微软雅黑',
  3613. font: '12px 微软雅黑',
  3614. };
  3615. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  3616. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  3617. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  3618. function checkParent(node) {
  3619. const parent = self.gsTree.getParent(node);
  3620. if (parent) {
  3621. return parent.check ? parent.check : checkParent(parent);
  3622. } else {
  3623. return false;
  3624. }
  3625. }
  3626. function checkChildren(node) {
  3627. for (const child of node.children) {
  3628. if (child.check) {
  3629. return true;
  3630. } else if (checkChildren(child)) {
  3631. return true;
  3632. }
  3633. }
  3634. return false;
  3635. }
  3636. if (!$('#im-gather-check')[0].checked) { return; }
  3637. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  3638. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  3639. if (sheet.isEditing()) {
  3640. sheet.endEdit(true);
  3641. }
  3642. }
  3643. if (info.sheet.zh_setting) {
  3644. const col = info.sheet.zh_setting.cols[info.col];
  3645. if (col.field !== 'check') {
  3646. return;
  3647. }
  3648. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  3649. const node = sortData[info.row];
  3650. if (!node.check) {
  3651. if (checkParent(node)) {
  3652. const rect = info.sheet.getCellRect(info.row, info.col);
  3653. gatherConfirmPopover.check({
  3654. x: rect.x + rect.width / 2 + 25,
  3655. y: rect.y + rect.height / 2 + 3,
  3656. }, '父项已勾选,继续将取消父项勾选。', function () {
  3657. node.check = true;
  3658. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  3659. const rows = [self.gsTree.nodes.indexOf(node)];
  3660. for (const p of parents) {
  3661. if (p.check) {
  3662. p.check = false;
  3663. rows.push(self.gsTree.nodes.indexOf(p));
  3664. }
  3665. }
  3666. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3667. });
  3668. } else if (checkChildren(node)) {
  3669. const rect = info.sheet.getCellRect(info.row, info.col);
  3670. gatherConfirmPopover.check({
  3671. x: rect.x + rect.width / 2 + 25,
  3672. y: rect.y + rect.height / 2 + 3,
  3673. }, '子项已勾选,继续将取消子项勾选。', function () {
  3674. node.check = true;
  3675. const posterity = self.gsTree.getPosterity(node);
  3676. const rows = [self.gsTree.nodes.indexOf(node)];
  3677. for (const p of posterity) {
  3678. if (p.check) {
  3679. rows.push(self.gsTree.nodes.indexOf(p));
  3680. p.check = false;
  3681. }
  3682. }
  3683. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3684. });
  3685. } else {
  3686. node.check = true;
  3687. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3688. }
  3689. } else {
  3690. node.check = false;
  3691. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3692. }
  3693. }
  3694. });
  3695. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3696. for (const node of self.gsTree.datas) {
  3697. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3698. }
  3699. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  3700. self.gsTree.expandByLevel(4);
  3701. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  3702. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  3703. } else {
  3704. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3705. for (const node of self.gsTree.datas) {
  3706. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3707. }
  3708. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  3709. }
  3710. });
  3711. // 提交 高级设置
  3712. $('#choose2-ok').click(() => {
  3713. if (!self.gsTree) { return; }
  3714. const nodes = [];
  3715. for (const node of self.gsTree.datas) {
  3716. if (node.check) {
  3717. nodes.push(node.id);
  3718. }
  3719. }
  3720. const data = {
  3721. im_gather: $('#im-gather-check')[0].checked,
  3722. im_gather_node: nodes.join(','),
  3723. };
  3724. postData(window.location.pathname + '/detail/adv', data, function (result) {
  3725. stage.im_gather = data.im_gather;
  3726. stage.im_gather_node = data.im_gather_node;
  3727. $('#choose2').modal('hide');
  3728. });
  3729. });
  3730. }
  3731. _initLocateRela() {
  3732. const self = this;
  3733. $('#im-locate2bills').click(function () {
  3734. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3735. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3736. if (select && select.source) {
  3737. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  3738. stagePosSpreadObj.loadCurPosData();
  3739. if (select.source[curIndex-1].pos_id) {
  3740. SpreadJsObj.locateDataBy(spSpread.getActiveSheet(), function(data){ return data.id === select.source[curIndex-1].pos_id});
  3741. }
  3742. }
  3743. });
  3744. $('#im-locate-pre').click(function () {
  3745. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3746. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3747. if (select && select.source) {
  3748. const targetIndex = Math.max(curIndex-1, 1);
  3749. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3750. stagePosSpreadObj.loadCurPosData();
  3751. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3752. }
  3753. });
  3754. $('#im-locate-next').click(function () {
  3755. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3756. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3757. if (select && select.source) {
  3758. const targetIndex = Math.min(curIndex+1, select.source.length);
  3759. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3760. stagePosSpreadObj.loadCurPosData();
  3761. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3762. }
  3763. });
  3764. }
  3765. _initModifyDetail() {
  3766. const self = this;
  3767. // 重置
  3768. $('#reset-detail-ok').click(function () {
  3769. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3770. if (!data.uuid) return;
  3771. const updateData = {
  3772. lid: data.lid, pid: data.pid,
  3773. uuid: data.uuid,
  3774. custom_define: [],
  3775. };
  3776. for (const f of data.custom_define) {
  3777. if (stageIm.resetFields.indexOf(f) >= 0) {
  3778. updateData[f] = null;
  3779. } else {
  3780. updateData.custom_define.push(f);
  3781. }
  3782. }
  3783. updateData.custom_define = updateData.custom_define.join(',');
  3784. $('#reset-detail-modal').modal('hide');
  3785. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3786. stageIm.loadUpdateDetailData(result);
  3787. self.reLoadDetailData();
  3788. });
  3789. });
  3790. // 编辑
  3791. $('#edit-detail').click(function () {
  3792. $(this).hide();
  3793. $('#save-detail').show();
  3794. $('#cancel-detail').show();
  3795. $('#detail-show').hide();
  3796. $('#detail-edit').show();
  3797. self.updateImageData = null;
  3798. });
  3799. // 保存
  3800. $('#save-detail').click(() => {
  3801. function check(field, obj, org, update) {
  3802. const newValue = obj.val();
  3803. if (!org[field]) {
  3804. if (newValue !== '') {
  3805. update[field] = newValue;
  3806. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3807. return true;
  3808. }
  3809. } else if (newValue !== org[field]){
  3810. update[field] = newValue;
  3811. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3812. return true;
  3813. }
  3814. return false;
  3815. }
  3816. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3817. const updateData = {lid: data.lid, pid: data.pid};
  3818. if (data.uuid) {
  3819. updateData.uuid = data.uuid;
  3820. updateData.custom_define = data.custom_define;
  3821. } else {
  3822. updateData.code = data.code;
  3823. updateData.name = data.name;
  3824. updateData.unit = data.unit;
  3825. updateData.unit_price = data.unit_price;
  3826. updateData.pid = data.pid;
  3827. updateData.pos_name = data.pos_name;
  3828. updateData.im_type = data.im_type;
  3829. updateData.custom_define = [];
  3830. }
  3831. let infoUpdate = false;
  3832. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  3833. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  3834. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  3835. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  3836. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  3837. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  3838. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  3839. updateData.custom_define = updateData.custom_define.join(',');
  3840. if (infoUpdate) {
  3841. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3842. stageIm.loadUpdateDetailData(result);
  3843. self.reLoadDetailData();
  3844. if (!self.updateImageData) return;
  3845. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  3846. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3847. stageIm.loadUpdateDetailData(result);
  3848. self.reLoadDetailData();
  3849. });
  3850. });
  3851. } else if (self.updateImageData) {
  3852. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3853. stageIm.loadUpdateDetailData(result);
  3854. self.reLoadDetailData();
  3855. });
  3856. } else {
  3857. self.reLoadDetailData();
  3858. }
  3859. });
  3860. // 取消
  3861. $('#cancel-detail').click(() => {
  3862. self.reLoadDetailData();
  3863. });
  3864. }
  3865. _initImageRela() {
  3866. const self = this;
  3867. $('#edit-detail').click(function () {
  3868. loadImageItem();
  3869. });
  3870. function setdraggrable(){
  3871. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  3872. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  3873. stop: function( event, ui ) {
  3874. }
  3875. });
  3876. }
  3877. function upload(formData) {
  3878. if (formData.length < 1) {
  3879. return;
  3880. }
  3881. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  3882. const html = [];
  3883. html.push('<div class="img-item">');
  3884. html.push('<div class="img-bar">');
  3885. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3886. html.push('</div>');
  3887. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  3888. html.push('</div>');
  3889. $('.img-view').append(html.join(''));
  3890. $('.img-bar').click(removeImageItem);
  3891. setdraggrable();
  3892. $('#upload-img-file').val('');
  3893. });
  3894. }
  3895. function dragFile(e) {
  3896. var file = null,
  3897. data = e.dataTransfer.types;
  3898. for (var i = 0; i < data.length; i += 1) {
  3899. if (data[i] === 'Files') {
  3900. file = e.dataTransfer.files; //获取文件
  3901. break;
  3902. }
  3903. }
  3904. if (file && file[0].type.indexOf('image') !== -1) {
  3905. var formData = new FormData();
  3906. formData.append('file', file[0]); //上传单个文件的添加方式
  3907. upload(formData); //upload 异步上传
  3908. }
  3909. }
  3910. // 移动图片
  3911. const moveImageItem = function (ev) {
  3912. const item = this;
  3913. const view = $('.img-view')[0];
  3914. let oEvent = ev;
  3915. // 浏览器有一些图片的默认事件,这里要阻止
  3916. oEvent.preventDefault();
  3917. let disX = oEvent.clientX - item.offsetLeft;
  3918. let disY = oEvent.clientY - item.offsetTop;
  3919. view.onmousemove = function (ev) {
  3920. oEvent = ev;
  3921. oEvent.preventDefault();
  3922. let x = oEvent.clientX -disX;
  3923. let y = oEvent.clientY -disY;
  3924. // 图形移动的边界判断
  3925. x = x <= 0 ? 0 : x;
  3926. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  3927. y = y <= 0 ? 0 : y;
  3928. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  3929. item.style.left = x + 'px';
  3930. item.style.top = y + 'px';
  3931. };
  3932. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  3933. view.onmouseleave = function () {
  3934. view.onmousemove = null;
  3935. view.onmouseup = null;
  3936. };
  3937. // 鼠标弹起后停止移动
  3938. view.onmouseup=function() {
  3939. view.onmousemove = null;
  3940. view.onmouseup = null;
  3941. };
  3942. };
  3943. const removeImageItem = function () {
  3944. $(this).parent().remove();
  3945. };
  3946. // 加载草图组成
  3947. const loadImageItem = function () {
  3948. self.updateImageData = null;
  3949. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3950. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  3951. const html = [];
  3952. for (const item of items) {
  3953. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  3954. html.push('<div class="img-item" style="' + itemStyle + '">');
  3955. html.push('<div class="img-bar">');
  3956. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3957. html.push('</div>');
  3958. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  3959. html.push('</div>');
  3960. }
  3961. $('.img-view').html(html.join(''));
  3962. $('.img-bar').click(removeImageItem);
  3963. setdraggrable();
  3964. };
  3965. // 上传图片
  3966. $('#upload-img').click(function () {
  3967. $('#upload-img-file').trigger('click');
  3968. });
  3969. // 拖拽上传
  3970. //拖拽上传文件
  3971. const dragbox = document.querySelector('#upload-img');
  3972. dragbox.addEventListener('dragover', function(e) {
  3973. e.preventDefault(); // 必须阻止默认事件
  3974. }, false);
  3975. dragbox.addEventListener('drop', function(e) {
  3976. e.preventDefault(); // 阻止默认事件
  3977. dragFile(e);
  3978. }, false);
  3979. //拖拽上传文件
  3980. const dragbox2 = document.querySelector('.img-view');
  3981. dragbox2.addEventListener('dragover', function(e) {
  3982. e.preventDefault(); // 必须阻止默认事件
  3983. }, false);
  3984. dragbox2.addEventListener('drop', function(e) {
  3985. e.preventDefault(); // 阻止默认事件
  3986. dragFile(e);
  3987. }, false);
  3988. // 粘贴上传
  3989. $(".img-view").on('paste', function(ev) {
  3990. let file = null;
  3991. const data = (event.clipboardData || window.clipboardData).items;
  3992. for (let i = 0; i < data.length; i += 1) {
  3993. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  3994. file = data[i].getAsFile(); //读取图片文件
  3995. break;
  3996. }
  3997. }
  3998. if (file) {
  3999. const formData = new FormData();
  4000. formData.append('file', file); //上传单个文件的添加方式
  4001. upload(formData); //异步上传文件
  4002. }
  4003. });
  4004. $('#upload-img-file').change(function () {
  4005. const file = this.files[0];
  4006. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  4007. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  4008. if (!imgStr.test(ext)) {
  4009. toastr.error('请上传正确的图片格式文件');
  4010. return
  4011. }
  4012. if ($(this).val()) {
  4013. const formData = new FormData();
  4014. formData.append('file', this.files[0]);
  4015. upload(formData);
  4016. }
  4017. });
  4018. // 保存草图修改结果
  4019. $('#edit-img-ok').click(function () {
  4020. // 记录上传的图片的信息
  4021. const items = $('.img-item');
  4022. const img_remark = $('#text-edit').val();
  4023. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  4024. // 生成上传数据
  4025. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid, calc_img_remark: img_remark};
  4026. if (data.uuid) {
  4027. updateData.uuid = data.uuid;
  4028. } else {
  4029. updateData.code = data.code;
  4030. updateData.name = data.name;
  4031. updateData.unit = data.unit;
  4032. updateData.unit_price = data.unit_price;
  4033. updateData.pid = data.pid;
  4034. updateData.pos_name = data.pos_name;
  4035. updateData.im_type = data.im_type;
  4036. }
  4037. if (items.length === 1) {
  4038. const itemInfo = [];
  4039. for (const item of items) {
  4040. const itemData = {
  4041. src: $('img', item).attr('src'),
  4042. left: item.style.left,
  4043. top: item.style.top,
  4044. width: item.style.width,
  4045. height: item.style.height,
  4046. };
  4047. itemInfo.push(itemData);
  4048. }
  4049. // 获取合并好的图片数据
  4050. const canvas = document.createElement('canvas');
  4051. const view = $('.img-view')[0];
  4052. const b = items[0];
  4053. const pos = $(b).position();
  4054. const img = $('img', b)[0];
  4055. canvas.height = Math.max(view.clientHeight, Math.ceil(pos.top + img.naturalHeight));
  4056. canvas.width = Math.max(view.clientWidth, Math.ceil(pos.left + img.naturalWidth));
  4057. const ctx = canvas.getContext('2d');
  4058. ctx.fillStyle = '#ffffff';
  4059. ctx.fillRect(0, 0, canvas.width, canvas.height);
  4060. ctx.drawImage(img, pos.left, pos.top);
  4061. updateData.img = canvas.toDataURL('image/png');
  4062. updateData.imgInfo = itemInfo;
  4063. self.updateImageData = updateData;
  4064. $('#calc-img').attr('src', updateData.img);
  4065. $('#calc-remark').html(img_remark);
  4066. $('#view-calc-img').attr('src', updateData.img);
  4067. $('#show-calc-img').attr('src', updateData.img);
  4068. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  4069. $('#view-calc-remark').text(img_remark);
  4070. $('#edit-img').modal('hide');
  4071. } else if (items.length > 0) {
  4072. const itemInfo = [];
  4073. for (const item of items) {
  4074. const itemData = {
  4075. src: $('img', item).attr('src'),
  4076. left: item.style.left,
  4077. top: item.style.top,
  4078. width: item.style.width,
  4079. height: item.style.height,
  4080. };
  4081. itemInfo.push(itemData);
  4082. }
  4083. // 获取合并好的图片数据
  4084. const canvas = document.createElement('canvas');
  4085. const view = $('.img-view')[0];
  4086. canvas.height = view.clientHeight;
  4087. canvas.width = view.clientWidth;
  4088. const ctx = canvas.getContext('2d');
  4089. ctx.fillStyle = '#ffffff';
  4090. ctx.fillRect(0, 0, canvas.width, canvas.height);
  4091. for (const b of $('.img-item')) {
  4092. const pos = $(b).position();
  4093. const img = $('img', b)[0];
  4094. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  4095. }
  4096. updateData.img = canvas.toDataURL('image/png');
  4097. updateData.imgInfo = itemInfo;
  4098. self.updateImageData = updateData;
  4099. $('#calc-img').attr('src', updateData.img);
  4100. $('#calc-remark').html(img_remark);
  4101. $('#view-calc-img').attr('src', updateData.img);
  4102. $('#show-calc-img').attr('src', updateData.img);
  4103. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  4104. $('#view-calc-remark').text(img_remark);
  4105. $('#edit-img').modal('hide');
  4106. // });
  4107. } else if (data.calc_img) {
  4108. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid, calc_img_remark: img_remark};
  4109. $('#show-calc-img').attr('src', '');
  4110. $('#show-calc-remark').html('');
  4111. $('#calc-img').attr('src', '');
  4112. $('#calc-remark').html(img_remark);
  4113. $('#view-calc-img').attr('src', '');
  4114. $('#view-calc-remark').val(img_remark);
  4115. $('#text-edit').val(img_remark);
  4116. $('#edit-img').modal('hide');
  4117. } else {
  4118. self.updateImageData = updateData;
  4119. $('#show-calc-img').attr('src', '');
  4120. $('#show-calc-remark').html('');
  4121. $('#calc-img').attr('src', '');
  4122. $('#calc-remark').html(img_remark);
  4123. $('#view-calc-img').attr('src', '');
  4124. $('#view-calc-remark').val(img_remark);
  4125. $('#text-edit').val(img_remark);
  4126. $('#edit-img').modal('hide');
  4127. }
  4128. });
  4129. }
  4130. reBuildImData() {
  4131. const imData = stageIm.buildImData();
  4132. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4133. this.reLoadDetailData();
  4134. this.loadLocateInfo();
  4135. }
  4136. loadStageLedgerUpdateData(data, nodes) {
  4137. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  4138. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4139. this.reLoadDetailData();
  4140. }
  4141. loadStagePosUpdateData(data, nodes) {
  4142. const imData = stageIm.loadUpdatePosData(data, nodes);
  4143. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4144. this.reLoadDetailData();
  4145. }
  4146. loadStageChangeUpdateData(data, nodes) {
  4147. const imData = stageIm.loadUpdateChangeData(data, nodes);
  4148. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4149. this.reLoadDetailData();
  4150. }
  4151. loadLocateInfo() {
  4152. const select = SpreadJsObj.getSelectObject(this.sheet);
  4153. if (select && select.source.length > 1) {
  4154. $('#im-locate2bills').next().show();
  4155. } else {
  4156. $('#im-locate2bills').next().hide();
  4157. }
  4158. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  4159. }
  4160. reLoadDetailData() {
  4161. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  4162. $('#reset-detail').hide();
  4163. if (data) {
  4164. for (const f of data.custom_define) {
  4165. if (stageIm.resetFields.indexOf(f) >= 0) {
  4166. $('#reset-detail').show();
  4167. break;
  4168. }
  4169. }
  4170. $('#edit-detail').show();
  4171. $('#modify-img').show();
  4172. } else {
  4173. $('#edit-detail').hide();
  4174. $('#modify-img').hide();
  4175. }
  4176. $('#save-detail').hide();
  4177. $('#cancel-detail').hide();
  4178. $('#detail-show').show();
  4179. $('#detail-edit').hide();
  4180. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  4181. $('#show-contract-jl').text(contractJl);
  4182. $('#contract-jl').val(contractJl);
  4183. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  4184. $('#show-qc-jl').text(qcJl);
  4185. $('#qc-jl').val(qcJl);
  4186. const qcMinusJl = data && data.qc_minus_jl ? data.qc_minus_jl : '';
  4187. $('#show-qc-minus-jl').text(qcMinusJl);
  4188. $('#qc-minus-jl').val(qcMinusJl);
  4189. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  4190. $('#show-bgl-code').text(bglCode);
  4191. $('#bgl-code').val(bglCode);
  4192. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  4193. $('#show-bgl-drawing-code').text(bglDrawingCode);
  4194. $('#bgl-drawing-code').val(bglDrawingCode);
  4195. const bwName = data && data.bw ? data.bw : '';
  4196. $('#show-bw-name').text(bwName);
  4197. $('#bw-name').val(bwName);
  4198. const position = data && data.position ? data.position : '';
  4199. $('#show-position').text(position);
  4200. $('#position').val(position);
  4201. const peg = data && data.peg ? data.peg : '';
  4202. $('#show-peg').text(peg);
  4203. $('#peg').val(peg);
  4204. const xmName = data && data.xm ? data.xm: '';
  4205. $('#show-xm-name').text(xmName);
  4206. $('#xm-name').val(xmName);
  4207. const jldy = data && data.jldy ? data.jldy: '';
  4208. $('#show-jldy').text(jldy);
  4209. $('#jldy').val(jldy);
  4210. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  4211. $('#show-drawing-code').text(drawingCode);
  4212. $('#drawing-code').val(drawingCode);
  4213. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  4214. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  4215. $('#calc-memo').val(calcMemo);
  4216. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  4217. $('#show-calc-img').attr('src', calcImgSrc);
  4218. $('#calc-img').attr('src', calcImgSrc);
  4219. $('#view-calc-img').attr('src', calcImgSrc);
  4220. const calcImgRemark = data && data.calc_img_remark || '';
  4221. $('#view-calc-remark').val(calcImgRemark);
  4222. $('#show-calc-remark').html((calcImgRemark ? '<td colspan="2">'+ calcImgRemark +'</td>' : ''));
  4223. $('#calc-remark').html(calcImgRemark);
  4224. $("#view-calc-remark").attr('readonly', true);
  4225. // 处理 编辑 -> 添加草图中textarea多余的空格
  4226. $('#text-edit').val(calcImgRemark)
  4227. }
  4228. }
  4229. class CheckedChange {
  4230. constructor (setting) {
  4231. const self = this;
  4232. this.changeSpreadSetting = {
  4233. cols: [
  4234. {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}` : ''; }},
  4235. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  4236. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  4237. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  4238. ],
  4239. emptyRows: 0,
  4240. headRows: 1,
  4241. headRowHeight: [32],
  4242. headColWidth: [30],
  4243. defaultRowHeight: 21,
  4244. headerFont: '12px 微软雅黑',
  4245. font: '12px 微软雅黑',
  4246. readOnly: true,
  4247. getColor: function (sheet, data, row, col, defaultColor) {
  4248. if (data && data.is_import) {
  4249. return '#eee';
  4250. } else {
  4251. return defaultColor;
  4252. }
  4253. }
  4254. };
  4255. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  4256. this.changeSheet = this.changeSpread.getActiveSheet();
  4257. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  4258. const getTipText = function (data) {
  4259. if (!data) return '';
  4260. const tips = [];
  4261. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  4262. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  4263. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  4264. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  4265. return tips.join('-');
  4266. };
  4267. this.changeBillsSpreadSetting = {
  4268. cols: [
  4269. {title: '计价', colSpan: '1', rowSpan: '1', field: 'is_valuation', hAlign: 1, width: 30, cellType: 'checkbox'},
  4270. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  4271. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, cellType: 'delayTip', getTip: getTipText},
  4272. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  4273. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  4274. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  4275. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  4276. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  4277. ],
  4278. emptyRows: 0,
  4279. headRows: 1,
  4280. headRowHeight: [32],
  4281. defaultRowHeight: 21,
  4282. headerFont: '12px 微软雅黑',
  4283. font: '12px 微软雅黑',
  4284. readOnly: true
  4285. };
  4286. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  4287. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  4288. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  4289. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  4290. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  4291. if (change) self.refreshChangeDetailData(change);
  4292. });
  4293. this.changes = null;
  4294. this.reloadChangeData();
  4295. setting.reloadObj.click(function() {
  4296. self.reloadChangeData();
  4297. });
  4298. $.contextMenu({
  4299. selector: '#' + setting.changeBillsObj.attr('id'),
  4300. build: function ($trigger, e) {
  4301. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  4302. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  4303. },
  4304. items: {
  4305. 'locateZjjl': {
  4306. name: '定位至台账',
  4307. icon: 'fa-sign-in',
  4308. callback: function (key, opt) {
  4309. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  4310. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4311. if (change.is_import) {
  4312. if (changeBills.pos && changeBills.pos.length > 0) {
  4313. const node = stageTree.getItems(changeBills.pos[0].ledger_id);
  4314. if (!node || node.filter) return;
  4315. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), changeBills.pos[0].ledger_id, true);
  4316. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4317. stagePosSpreadObj.loadCurPosData();
  4318. }
  4319. } else if (changeBills.gcl_id) {
  4320. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  4321. if (!node || node.filter) return;
  4322. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id, true);
  4323. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4324. stagePosSpreadObj.loadCurPosData();
  4325. const posData = spSpread.getActiveSheet().zh_data;
  4326. if (!posData || posData.length === 0) return;
  4327. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  4328. if (changePos) SpreadJsObj.locateData(spSpread.getActiveSheet(), changePos);
  4329. } else {
  4330. const cb = {
  4331. b_code: changeBills.code || '',
  4332. name: changeBills.name || '',
  4333. unit: changeBills.unit || '',
  4334. unit_price: changeBills.unit_price || 0,
  4335. };
  4336. for (const node of stageTree.nodes) {
  4337. if (node.children && node.children.length > 0) continue;
  4338. if (node.filter) continue;
  4339. const b = {
  4340. b_code: node.b_code || '',
  4341. name: node.name || '',
  4342. unit: node.unit || '',
  4343. unit_price: node.unit_price || 0,
  4344. };
  4345. if (_.isMatch(cb, b)) {
  4346. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  4347. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4348. stagePosSpreadObj.loadCurPosData();
  4349. return;
  4350. }
  4351. }
  4352. }
  4353. },
  4354. disabled: function (key, opt) {
  4355. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4356. return !changeBills;
  4357. }
  4358. },
  4359. 'autoUse': {
  4360. name: '调用',
  4361. icon: 'fa-play',
  4362. callback: function (key, opt) {
  4363. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4364. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4365. const billsPos = self.findBillsPos(curChange, changeBills);
  4366. if (!billsPos) {
  4367. toastr.warning('无可调用的清单或计量单元');
  4368. return;
  4369. }
  4370. const data = { autoType: 'bills', bills: [{ ...billsPos, cid: changeBills.cid, cbid: changeBills.id }] };
  4371. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  4372. if (result.pos) {
  4373. stagePos.loadCurStageData(result.pos.curStageData);
  4374. }
  4375. const nodes = stageTree.loadPostStageData(result.bills);
  4376. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  4377. stagePosSpreadObj.loadCurPosData();
  4378. if (detail) {
  4379. detail.loadStageChangeUpdateData(result, nodes);
  4380. } else {
  4381. stageIm.loadUpdateChangeData(result, nodes)
  4382. }
  4383. });
  4384. },
  4385. disabled: function (key, opt) {
  4386. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4387. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4388. return !changeBills || curChange.is_import;
  4389. },
  4390. visible: function (key, opt) {
  4391. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4392. }
  4393. },
  4394. }
  4395. });
  4396. $.contextMenu({
  4397. selector: '#' + setting.changeObj.attr('id'),
  4398. build: function ($trigger, e) {
  4399. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeSpread);
  4400. const change = target.cellTypeHintInfo ? self.changes[target.cellTypeHitInfo.row] : null;
  4401. if (change) self.refreshChangeDetailData(change);
  4402. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  4403. },
  4404. items: {
  4405. 'autoUseCur': {
  4406. name: '自动调用',
  4407. icon: 'fa-play',
  4408. callback: function (key, opt) {
  4409. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4410. const changeBills = self.changeBillsSheet.zh_data;
  4411. const data = { bills: [], autoType: 'bills' };
  4412. for (const cb of changeBills) {
  4413. const billsPos = self.findBillsPos(curChange, cb);
  4414. if (billsPos) data.bills.push({ ...billsPos, cid: cb.cid, cbid: cb.id })
  4415. }
  4416. if (data.bills.length === 0) {
  4417. toastr.warning('无可调用的清单或计量单元');
  4418. return;
  4419. }
  4420. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  4421. if (result.pos) {
  4422. stagePos.loadCurStageData(result.pos.curStageData);
  4423. }
  4424. const nodes = stageTree.loadPostStageData(result.bills);
  4425. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  4426. stagePosSpreadObj.loadCurPosData();
  4427. if (detail) {
  4428. detail.loadStageChangeUpdateData(result, nodes);
  4429. } else {
  4430. stageIm.loadUpdateChangeData(result, nodes)
  4431. }
  4432. });
  4433. },
  4434. disabled: function (key, opt) {
  4435. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4436. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4437. return !curChange || !changeBills || curChange.is_import;
  4438. },
  4439. visible: function (key, opt) {
  4440. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4441. }
  4442. },
  4443. 'autoUseAll': {
  4444. name: '自动调用(全部变更令)',
  4445. icon: 'fa-play',
  4446. callback: function (key, opt) {
  4447. postData(window.location.pathname + '/auto-use-change', { autoType: 'all' }, function(result) {
  4448. window.location.reload();
  4449. });
  4450. },
  4451. disabled: function (key, opt) {
  4452. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4453. return !curChange || curChange.is_import;
  4454. },
  4455. visible: function (key, opt) {
  4456. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4457. }
  4458. }
  4459. }
  4460. });
  4461. }
  4462. refreshChangeDetailData(data) {
  4463. const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
  4464. if (change.cid === this.curChangeId) return;
  4465. this.curChangeId = change.cid;
  4466. const self = this;
  4467. if (change.detail) {
  4468. self.loadChangeDetailData();
  4469. } else {
  4470. postData(window.location.pathname + '/change/detail', {cid: change.cid, is_import: change.is_import}, function (result) {
  4471. change.detail = result;
  4472. self.analyzeChange(change);
  4473. self.loadChangeDetailData();
  4474. });
  4475. }
  4476. }
  4477. loadChangeDetailData(data) {
  4478. const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
  4479. if (change) {
  4480. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  4481. } else {
  4482. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  4483. }
  4484. }
  4485. refresh() {
  4486. this.changeSpread.refresh();
  4487. this.changeBillsSpread.refresh();
  4488. }
  4489. reloadChangeData() {
  4490. const self = this;
  4491. postData(window.location.pathname + '/change/data', null, function (result) {
  4492. self.changes = [];
  4493. result.changes.forEach(x => { x.is_import = 0; self.changes.push(x); });
  4494. result.import_changes.forEach(x => { x.is_import = 1; delete x.total_price; self.changes.push(x); });
  4495. if (result.changes.length > 0) self.analyzeChange(result.changes[0]);
  4496. if (result.import_changes.length > 0) self.analyzeChange(result.import_changes[0]);
  4497. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  4498. self.changeSheet.setSelection(0, 0, 1, 1);
  4499. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  4500. self.loadChangeDetailData();
  4501. });
  4502. }
  4503. _analyzeCommon(change) {
  4504. for (const b of change.bills) {
  4505. const eub = change.detail.endUsedBills.find(function (x) {
  4506. return x.cbid === b.id;
  4507. });
  4508. if (eub) b.used_qty = eub.qty;
  4509. b.qty = _.toNumber(b.samount);
  4510. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  4511. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  4512. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  4513. b.cur_qty = 0;
  4514. for (const p of b.pos) {
  4515. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  4516. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  4517. }
  4518. }
  4519. }
  4520. _analyzeImport(change) {
  4521. for (const b of change.bills) {
  4522. const eub = change.detail.endUsedBills.find(function (x) {
  4523. return x.rela_cbid === b.id;
  4524. });
  4525. if (eub) b.used_qty = eub.rela_qty;
  4526. b.qty = _.toNumber(b.samount);
  4527. delete b.unit_price;
  4528. // b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  4529. b.pos = _.filter(change.detail.curUsedBills, { rela_cbid: b.id });
  4530. b.cur_qty = 0;
  4531. for (const p of b.pos) {
  4532. p.qty = p.rela_qty;
  4533. const node = stageTree.datas.find(x => { return x.id === p.lid; });
  4534. p.ledger_id = node.ledger_id;
  4535. p.f_qty = node.quantity;
  4536. b.cur_qty = ZhCalc.add(b.cur_qty, p.rela_qty);
  4537. }
  4538. }
  4539. }
  4540. analyzeChange(change) {
  4541. change.bills = change.detail.bills;
  4542. if (change.is_import) {
  4543. this._analyzeImport(change);
  4544. } else {
  4545. this._analyzeCommon(change);
  4546. }
  4547. }
  4548. findBillsPos(change, changeBills) {
  4549. if (change.is_import) {
  4550. return null;
  4551. } else if (changeBills.gcl_id) {
  4552. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  4553. if (node.filter) return null;
  4554. if (node.settle_status === settleStatus.finish) return null;
  4555. const posData = stagePos.getLedgerPos(node.id) || [];
  4556. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  4557. if (changePos && changePos.settle_status) return null;
  4558. let defaultPos;
  4559. if (posData.length > 0) {
  4560. defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
  4561. if (!defaultPos) return null;
  4562. } else {
  4563. defaultPos = { id: '-1' };
  4564. }
  4565. return { lid: node.id, pid: changePos ? changePos.id : defaultPos.id };
  4566. } else {
  4567. const cb = {
  4568. b_code: changeBills.code || '',
  4569. name: changeBills.name || '',
  4570. unit: changeBills.unit || '',
  4571. unit_price: changeBills.unit_price || 0,
  4572. };
  4573. for (const node of stageTree.nodes) {
  4574. if (node.children && node.children.length > 0) continue;
  4575. if (node.filter) continue;
  4576. if (node.settle_status === settleStatus.finish) continue;
  4577. const b = {
  4578. b_code: node.b_code || '',
  4579. name: node.name || '',
  4580. unit: node.unit || '',
  4581. unit_price: node.unit_price || 0,
  4582. };
  4583. if (_.isMatch(cb, b)) {
  4584. posData = stagePos.getLedgerPos(node.id) || [];
  4585. let defaultPos;
  4586. if (posData.length > 0) {
  4587. defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
  4588. if (!defaultPos) return null;
  4589. } else {
  4590. defaultPos = { id: '-1' };
  4591. }
  4592. return { lid: node.id, pid: defaultPos.id };
  4593. }
  4594. }
  4595. return null;
  4596. }
  4597. }
  4598. }
  4599. // 展开收起附件
  4600. $('a', '.right-nav').bind('click', function () {
  4601. //const main = $('#main-view'), tool = $('#tools-view');
  4602. const tab = $(this), tabPanel = $(tab.attr('content'));
  4603. if (!tab.hasClass('active')) {
  4604. $('a', '.side-menu').removeClass('active');
  4605. $('.tab-content .tab-select-show').removeClass('active');
  4606. tab.addClass('active');
  4607. tabPanel.addClass('active');
  4608. showSideTools(tab.hasClass('active'));
  4609. if (tab.attr('content') === '#search' && !searchLedger) {
  4610. searchLedger = $.ledgerSearch({
  4611. selector: '#search',
  4612. ledger: { billsTree: stageTree, pos: stagePos },
  4613. searchOver: true,
  4614. searchEmpty: true,
  4615. resultSpreadSetting: {
  4616. cols: [
  4617. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  4618. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  4619. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  4620. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  4621. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4622. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  4623. {title: '完成率(%)', field: completePerField, hAlign: 2, width: 70},
  4624. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  4625. ],
  4626. emptyRows: 0,
  4627. headRows: 1,
  4628. headRowHeight: [32],
  4629. headColWidth: [30],
  4630. defaultRowHeight: 21,
  4631. headerFont: '12px 微软雅黑',
  4632. font: '12px 微软雅黑',
  4633. selectedBackColor: '#fffacd',
  4634. readOnly: true,
  4635. },
  4636. locate: function(cur) {
  4637. if (!cur.lid) return;
  4638. SpreadJsObj.locateTreeNode(slSheet, cur.lid, true);
  4639. stageTreeSpreadObj.loadRelaData();
  4640. if (cur.pid && cur.pid !== -1) {
  4641. const pIndex = spSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
  4642. SpreadJsObj.locateRow(spSheet, pIndex);
  4643. }
  4644. },
  4645. customSearch: [
  4646. {
  4647. key: 'less', title: '漏计', valid: true,
  4648. check: function (node) {
  4649. if (node.quantity) {
  4650. return ZhCalc.sub(ZhCalc.sum([node.quantity, node.end_qc_qty, node.end_qc_minus_qty]), node.end_gather_qty) > 0;
  4651. } else if (node.total_price) {
  4652. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  4653. }
  4654. }
  4655. }, {
  4656. key: 'over', title: '超计', valid: true,
  4657. check: function (node) {
  4658. return checkUtils.billsOver(node, stagePos, tenderInfo.checkOverInfo);
  4659. }
  4660. }, {
  4661. key: 'empty', title: '漏计', valid: false,
  4662. check: function (node) {
  4663. if (node.quantity) {
  4664. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  4665. } else if (node.total_price) {
  4666. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  4667. }
  4668. }
  4669. }, {
  4670. key: 'estimate', title: '预计变更', valid: true,
  4671. check: function (node) {
  4672. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  4673. if (posRange.length > 0) {
  4674. for (const p of posRange) {
  4675. if (!checkZero(p.estimate_qty)) return true;
  4676. }
  4677. return false;
  4678. } else {
  4679. return false;
  4680. }
  4681. }
  4682. }
  4683. ],
  4684. });
  4685. searchLedger.spread.refresh();
  4686. }
  4687. if (tab.attr('content') === '#fujian') {
  4688. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4689. node && getNodeList(node.id);
  4690. }
  4691. if (tab.attr('content') === '#zhongjian') {
  4692. if (!detail) {
  4693. detail = new Detail($('#detail-spread'));
  4694. detail.spread.refresh();
  4695. $('#zhongjian .sjs-bottom').height('400px');
  4696. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  4697. } else {
  4698. detail.spread.refresh();
  4699. }
  4700. }
  4701. if (tab.attr('content') === '#checked-change') {
  4702. if (!checkedChanges) {
  4703. checkedChanges = new CheckedChange({
  4704. changeObj: $('#cc-spread'),
  4705. changeBillsObj: $('#ccb-spread'),
  4706. reloadObj: $('#refresh-cc'),
  4707. });
  4708. checkedChanges.refresh();
  4709. } else {
  4710. $('#ccb-spread').height('400px');
  4711. checkedChanges.refresh();
  4712. }
  4713. }
  4714. if (tab.attr('content') === '#error-list') {
  4715. errorList.spread.refresh();
  4716. }
  4717. if (tab.attr('content') === '#check-list') {
  4718. checkList.spread.refresh();
  4719. }
  4720. if (tab.attr('content') === '#sum-load-miss') sumLoadMiss.spread.refresh();
  4721. } else {
  4722. tab.removeClass('active');
  4723. tabPanel.removeClass('active');
  4724. showSideTools(tab.hasClass('active'));
  4725. }
  4726. slSpread.refresh();
  4727. spSpread.refresh();
  4728. });
  4729. // 切换附件里节点和所有附件
  4730. $('#fujian .nav-link').on('click', function () {
  4731. const tabPanel = $(this).attr('fujian-content');
  4732. if (tabPanel !== 'syfujian') {
  4733. $('#showPage').hide();
  4734. $('#bach-download').prop('type', 'curr');
  4735. } else {
  4736. $('#showPage').show();
  4737. $('#bach-download').prop('type', 'all')
  4738. }
  4739. $('#showAttachment').hide();
  4740. });
  4741. // 上传附件
  4742. $('#upload-file-btn').click(function () {
  4743. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4744. if (!node) return
  4745. const files = $('#upload-file')[0].files;
  4746. const formData = new FormData();
  4747. formData.append('lid', node.id);
  4748. for (const file of files) {
  4749. if (file === undefined) {
  4750. toastr.error('未选择上传文件!');
  4751. return false;
  4752. }
  4753. const filesize = file.size;
  4754. if (filesize > 50 * 1024 * 1024) {
  4755. toastr.error('存在上传文件大小过大!');
  4756. return false;
  4757. }
  4758. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  4759. if (whiteList.indexOf(fileext) === -1) {
  4760. toastr.error('只能上传指定格式的附件!');
  4761. return false;
  4762. }
  4763. formData.append('size', filesize);
  4764. formData.append('file[]', file);
  4765. }
  4766. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  4767. $('#upload').modal('hide');
  4768. // 插入到attData中
  4769. attData = data.concat(attData);
  4770. // 重新生成List
  4771. getAllList();
  4772. getNodeList(node.id);
  4773. }, function () {
  4774. toastr.error('附件上传失败');
  4775. });
  4776. $('#upload-file').val('');
  4777. });
  4778. // 获取附件信息
  4779. $('.list-table').on('click', '.att-file-name', function () {
  4780. const fid = $(this).attr('file-id');
  4781. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  4782. return;
  4783. }
  4784. const att = attData.find(function (item) {
  4785. return item.id === parseInt(fid);
  4786. });
  4787. $('#edit-att').hide();
  4788. $('#show-att').show();
  4789. if (att !== undefined) {
  4790. // 进来先把编辑功能隐藏
  4791. $('#btn-att a').eq(3).hide()
  4792. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  4793. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4794. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  4795. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  4796. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  4797. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  4798. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  4799. $('#show-att tr').eq(3).children('td').text(att.remark);
  4800. // 附件uid等于当前用户id, 附件上传本人
  4801. if (parseInt(cur_uid) === att.uid) {
  4802. $('#btn-att').show();
  4803. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  4804. if (showDel) $('#btn-att a').eq(3).show();
  4805. // $('#btn-att a').eq(3).show();
  4806. $('#btn-att a').eq(2).hide();
  4807. $('#btn-att a').eq(4).hide();
  4808. $('#btn-att a').eq(5).hide();
  4809. } else {
  4810. $('#btn-att').hide();
  4811. $('#btn-att a').eq(3).hide();
  4812. $('#btn-att a').eq(2).hide();
  4813. $('#btn-att a').eq(4).hide();
  4814. $('#btn-att a').eq(5).hide();
  4815. }
  4816. $('#showAttachment').attr('file-id', fid);
  4817. $('#showAttachment').show();
  4818. } else {
  4819. $('#showAttachment').hide();
  4820. $('#showAttachment').attr('file-id', '');
  4821. toastr.error('附件信息获取失败');
  4822. }
  4823. });
  4824. // $('body').on('click', '.alllist-table a', handleFileList);
  4825. $('body').on('click', '#btn-att a', function () {
  4826. const content = $(this).attr('content');
  4827. const fid = $('#showAttachment').attr('file-id');
  4828. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4829. if (content === 'edit') {
  4830. $('#btn-att a').eq(3).hide();
  4831. $('#btn-att a').eq(2).show();
  4832. $('#btn-att a').eq(4).show();
  4833. $('#btn-att a').eq(5).show();
  4834. $('#show-att').hide();
  4835. $('#edit-att').show();
  4836. const att = attData.find(function (item) {
  4837. return item.id === parseInt(fid);
  4838. });
  4839. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  4840. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  4841. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4842. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  4843. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  4844. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  4845. } else if (content === 'cancel') {
  4846. $('#show-att').show();
  4847. $('#edit-att').hide();
  4848. $('#btn-att a').eq(3).show();
  4849. $('#btn-att a').eq(2).hide();
  4850. $('#btn-att a').eq(4).hide();
  4851. $('#btn-att a').eq(5).hide();
  4852. } else if (content === 'save') {
  4853. const formData = new FormData();
  4854. formData.append('id', fid);
  4855. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  4856. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  4857. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  4858. const file = $('#change-att-btn')[0];
  4859. if (file.files[0] !== undefined) {
  4860. const filesize = file.files[0].size;
  4861. formData.append('size', filesize);
  4862. formData.append('file', file.files[0]);
  4863. }
  4864. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  4865. // 替换到attData中
  4866. const att_index = attData.findIndex(function (item) {
  4867. return item.id === parseInt(fid);
  4868. });
  4869. attData.splice(att_index, 1, data);
  4870. // 重新生成List
  4871. getAllList(parseInt($('#currentPage').text()));
  4872. getNodeList(node.id);
  4873. $('#show-att').show();
  4874. $('#edit-att').hide();
  4875. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  4876. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  4877. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  4878. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  4879. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  4880. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  4881. $('#show-att tr').eq(4).children('td').text(data.remark);
  4882. $('#btn-att a').eq(3).show();
  4883. $('#btn-att a').eq(2).hide();
  4884. $('#btn-att a').eq(4).hide();
  4885. $('#btn-att a').eq(5).hide();
  4886. }, function () {
  4887. toastr.error('附件上传失败');
  4888. });
  4889. $('#change-att-btn').val('');
  4890. } else if (content === 'del') {
  4891. const data = {id: fid};
  4892. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  4893. // 删除到attData中
  4894. const att_index = attData.findIndex(function (item) {
  4895. return item.id === parseInt(fid);
  4896. });
  4897. attData.splice(att_index, 1);
  4898. // 重新生成List
  4899. if ($('#alllist-table tr').length === 1) {
  4900. getAllList(parseInt($('#currentPage').text()) - 1);
  4901. } else {
  4902. getAllList(parseInt($('#currentPage').text()));
  4903. }
  4904. getNodeList(node.id);
  4905. $('#showAttachment').hide();
  4906. $('#showAttachment').attr('file-id', '');
  4907. });
  4908. } else if (content === 'view') {
  4909. const data = {id: fid};
  4910. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  4911. const { filepath } = result
  4912. $('#load-file').attr('href', filepath);
  4913. $('#load-file')[0].click();
  4914. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  4915. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  4916. });
  4917. } else if (content === 'location') {
  4918. const att = attData.find(item => item.id === parseInt(fid));
  4919. if (Object.keys(att).length) {
  4920. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  4921. stagePosSpreadObj.loadCurPosData();
  4922. }
  4923. }
  4924. });
  4925. // 替换附件
  4926. $('#change-att-btn').on('change', function () {
  4927. const file = $('#change-att-btn')[0].files[0];
  4928. const name = file.name;
  4929. const filename = name.substring(0, name.lastIndexOf("."));
  4930. const fileext = name.substr(name.indexOf("."));
  4931. const filesize = file.size;
  4932. if (filesize > 50 * 1024 * 1024) {
  4933. toastr.error('文件大小过大!');
  4934. $('#change-att-btn').val('');
  4935. return false;
  4936. }
  4937. if (whiteList.indexOf(fileext) === -1) {
  4938. toastr.error('只能上传指定格式的附件!');
  4939. $('#change-att-btn').val('');
  4940. return false;
  4941. }
  4942. $('#edit-att .form-group').eq(0).find('input').val(filename);
  4943. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  4944. });
  4945. // 切换页数
  4946. $('.page-select').on('click', function () {
  4947. const totalPageNum = parseInt($('#totalPage').text());
  4948. const lastPageNum = parseInt($('#currentPage').text());
  4949. const status = $(this).attr('content');
  4950. if (status === 'pre' && lastPageNum > 1) {
  4951. getAllList(lastPageNum-1);
  4952. $('#showAttachment').hide();
  4953. $('#syfujian .check-all-file').prop('checked', false)
  4954. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4955. getAllList(lastPageNum+1);
  4956. $('#showAttachment').hide();
  4957. $('#syfujian .check-all-file').prop('checked', false)
  4958. }
  4959. });
  4960. // 批量下载
  4961. $('#bach-download').click(function() {
  4962. const fileIds = [];
  4963. const type = $(this).attr('type');
  4964. let node = ''
  4965. if (type === 'curr') {
  4966. node = '#nodelist-table .check-file:checked'
  4967. } else {
  4968. node = '#alllist-table .check-file:checked'
  4969. }
  4970. $(node).each(function() {
  4971. const fileId = $(this).attr('file-id');
  4972. fileId && fileIds.push(fileId);
  4973. });
  4974. if (fileIds.length) {
  4975. if (fileIds.length > 20) {
  4976. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  4977. }
  4978. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  4979. $(this).attr('disabled', "true")
  4980. const btn = $(this);
  4981. const fileArr = [];
  4982. for (const id of fileIds) {
  4983. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  4984. fileArr.push({
  4985. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  4986. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  4987. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  4988. });
  4989. }
  4990. const packageName = `${tender.name}-计量台账-第${stage.order}期-附件.zip`;
  4991. try {
  4992. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  4993. } catch (e) {
  4994. btn.removeAttr('disabled');
  4995. toastr.clear();
  4996. toastr.error('批量下载失败');
  4997. }
  4998. // postCompressFile(`/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file`, {fileIds}, function(result) {
  4999. // toastr.clear()
  5000. // toastr.success('压缩文件成功')
  5001. // btn.removeAttr('disabled')
  5002. // const href = window.URL.createObjectURL(result)
  5003. // $('#zipDown').attr('href', href);
  5004. // $('#zipDown').attr('download', `${tender.name}-计量台账-第${stage.order}期-附件.zip`);
  5005. // $("#zipDown")[0].click();
  5006. // }, () => {
  5007. // btn.removeAttr('disabled')
  5008. // toastr.clear()
  5009. // toastr.error('批量下载失败')
  5010. // });
  5011. // const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  5012. // $('#zipDown').attr('href', url);
  5013. // $("#zipDown")[0].click();
  5014. }
  5015. });
  5016. // 监听附件check是否选中
  5017. $('.list-table').on('click', '.check-file', function() {
  5018. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  5019. const childs = $(this).parents('.list-table').children().length;
  5020. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  5021. if (checkedList.length === childs) {
  5022. checkBox.prop("checked", true);
  5023. } else {
  5024. checkBox.prop("checked", false);
  5025. }
  5026. });
  5027. $('.check-all-file').click(function() {
  5028. const isCheck = $(this).is(':checked');
  5029. $(this).parents('table').find('.list-table').each(function() {
  5030. $(this).find('input:checkbox').prop("checked", isCheck);
  5031. })
  5032. });
  5033. // 显示层次
  5034. (function (select, sheet) {
  5035. $(select).click(function () {
  5036. if (!sheet.zh_tree) return;
  5037. const tag = $(this).attr('tag');
  5038. const tree = sheet.zh_tree;
  5039. setTimeout(() => {
  5040. showWaitingView();
  5041. switch (tag) {
  5042. case "1":
  5043. case "2":
  5044. case "3":
  5045. case "4":
  5046. case "5":
  5047. tree.expandByLevel(parseInt(tag));
  5048. SpreadJsObj.refreshTreeRowVisible(sheet);
  5049. break;
  5050. case "last":
  5051. tree.expandByCustom(() => { return true; });
  5052. SpreadJsObj.refreshTreeRowVisible(sheet);
  5053. break;
  5054. case "leafXmj":
  5055. tree.expandToLeafXmj();
  5056. SpreadJsObj.refreshTreeRowVisible(sheet);
  5057. break;
  5058. case "curMeasure":
  5059. tree.expandByCustom(function (node) {
  5060. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  5061. if (node[field]) {
  5062. return true;
  5063. }
  5064. }
  5065. return false;
  5066. });
  5067. SpreadJsObj.refreshTreeRowVisible(sheet);
  5068. break;
  5069. case "endMeasure":
  5070. tree.expandByCustom(function (node) {
  5071. 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']) {
  5072. if (node[field]) {
  5073. return true;
  5074. }
  5075. }
  5076. return false;
  5077. });
  5078. SpreadJsObj.refreshTreeRowVisible(sheet);
  5079. break;
  5080. }
  5081. closeWaitingView();
  5082. }, 100);
  5083. });
  5084. })('a[name=showLevel]', slSpread.getActiveSheet());
  5085. const stageCheckerSetting = {
  5086. ledgerTree: stageTree,
  5087. ledgerPos: stagePos,
  5088. checkList: checkList,
  5089. decimal: tenderInfo.decimal,
  5090. checkOption: checkOption,
  5091. };
  5092. if (!checkTzMeasureType()) {
  5093. stageCheckerSetting.checkOption.tp.fields.push(
  5094. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  5095. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  5096. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  5097. {qty: 'quantity', tp: 'total_price'},
  5098. );
  5099. }
  5100. $('#ledger-check2').click(() => {
  5101. ledgerCheck2(stageCheckerSetting).then(result => {
  5102. check2Viewing({
  5103. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  5104. randomWait: true,
  5105. prefix: 'check2-',
  5106. checks: result,
  5107. checkList: checkList,
  5108. });
  5109. });
  5110. });
  5111. const dataChecker = DataChecker({
  5112. checkUrl: window.location.pathname + '/check',
  5113. completeData: function (data) {
  5114. stagePos.updateDatas({pos: data.source.pos});
  5115. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  5116. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  5117. stagePosSpreadObj.loadCurPosData();
  5118. for (const e of data.error) {
  5119. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  5120. }
  5121. },
  5122. errorList: errorList,
  5123. });
  5124. $('[name=stage-start]').submit(function (e) {
  5125. if (checkAuditorFrom()) {
  5126. // 再检查多人协同确认情况
  5127. const list = stage.relaAssists.find(x => {return !x.confirm });
  5128. if(list) {
  5129. toastr.error('请检查多人协同确认情况再上报');
  5130. $('#hide-all').hide();
  5131. return false;
  5132. }
  5133. $(this).parent().parent().parent().modal('hide');
  5134. dataChecker.checkAndPost(this.action, {});
  5135. $('#hide-all').hide();
  5136. }
  5137. return false;
  5138. });
  5139. $('#audit-check0').submit(function (e) {
  5140. // 再检查多人协同确认情况
  5141. const list = stage.relaAssists.find(x => {return !x.confirm && stageAssistRela.checkAssistPartUsed(x) });
  5142. if(list) {
  5143. toastr.error('请检查多人协同确认情况再审批通过');
  5144. $('#hide-all').hide();
  5145. return false;
  5146. }
  5147. const checkType = parseInt($('[name=checkType]').val());
  5148. const noUsed = stage.relaAssists.filter(x => {return !stageAssistRela.checkAssistPartUsed(x) });
  5149. const data = {
  5150. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  5151. coop_noUsed: noUsed && noUsed.length > 0 ? noUsed.map(x => { return x.ass_ledger_id; }) : [],
  5152. checkType,
  5153. };
  5154. $('#sp-done').modal('hide');
  5155. checkType && dataChecker.checkAndPost(this.action, data);
  5156. $('#hide-all').hide();
  5157. return false;
  5158. });
  5159. $('#audit-check1').submit(function (e) {
  5160. const checkType = parseInt($('[name=checkType]:checked').val());
  5161. const confirm = stage.relaAssists.filter(x => { return x.confirm });
  5162. const data = {
  5163. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  5164. coop_checked: confirm && confirm.length > 0 ? confirm.map(x => { return x.id; }) : [],
  5165. checkType,
  5166. };
  5167. if ($('#warning-text').length) $('#warning-text').remove();
  5168. if (!checkType && !$('#warning-text').length) {
  5169. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  5170. return false
  5171. }
  5172. $('#sp-back').modal('hide');
  5173. checkType && dataChecker.checkAndPost(this.action, data);
  5174. $('#hide-all').hide();
  5175. return false;
  5176. });
  5177. $('#exportExcel').click(function () {
  5178. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  5179. });
  5180. $('#cbr-check-all').click(function () {
  5181. if (this.checked) {
  5182. $('input', '#cbr-pos-list').attr('checked', 'checked');
  5183. } else {
  5184. $('input', '#cbr-pos-list').removeAttr('checked');
  5185. }
  5186. });
  5187. $('#cbr-ok').click(() => {
  5188. const ratio = parseInt($('#cbr-ratio').val());
  5189. if (!ratio) {
  5190. toastr.warning('请输入计量比例');
  5191. return;
  5192. } else if (ratio < 1) {
  5193. toastr.warning('计量比例不可小于1');
  5194. return;
  5195. } else if (ratio > 100) {
  5196. toastr.warning('计量比例不可大于100');
  5197. return;
  5198. }
  5199. const apply2sibling = $('#apply2sibling')[0].checked;
  5200. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  5201. if (posName.length === 0) {
  5202. toastr.warning('请勾选需要按计量比例的计量单元');
  5203. return;
  5204. }
  5205. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  5206. });
  5207. // 收方单生成
  5208. $('#setshoufang').click(function () {
  5209. const lid = $('#shoufang-lid').val();
  5210. const pid = $('#shoufang-pid').val() !== '' ? $('#shoufang-pid').val() : null;
  5211. // 修改线上
  5212. postData(window.location.pathname + '/save/shoufang', { type: 'add', postData: { lid, pid } }, function (result) {
  5213. // 收方单tab打开并显示在最新
  5214. if (!$('#shoufang-tab').hasClass('active')) {
  5215. $('#shoufang-tab').click();
  5216. }
  5217. const data = makeOneShouFang(result);
  5218. data.filenum = 0;
  5219. sfData = _.concat(data, sfData);
  5220. getShouFangList();
  5221. });
  5222. });
  5223. $('body').on('click', '.del-shoufang', function () {
  5224. const id = $(this).attr('data-id');
  5225. $('#del-shoufang-id').val(id);
  5226. const name = $(this).parents('tr').children('td').eq(0).text();
  5227. const ledger_code = name.split(' / ')[0];
  5228. const pos_name = name.split(' / ')[1] ? name.split(' / ')[1] : '';
  5229. $('#del-shoufang-ledger').text('清单:' + ledger_code);
  5230. if (pos_name) {
  5231. $('#del-shoufang-pos').text('计量单元:' + pos_name).show();
  5232. } else {
  5233. $('#del-shoufang-pos').text('').hide();
  5234. }
  5235. });
  5236. // 收方单删除
  5237. $('#delshoufang').click(function () {
  5238. const sfid = $('#del-shoufang-id').val();
  5239. // 修改线上
  5240. postData(window.location.pathname + '/save/shoufang', { type: 'del', postData: { sfid } }, function (result) {
  5241. // 删除到sfData中
  5242. const att_index = sfData.findIndex(function (item) {
  5243. return item.id === parseInt(sfid);
  5244. });
  5245. sfData.splice(att_index, 1);
  5246. // 重新生成List
  5247. if ($('#shoufang-table tr').length === 1) {
  5248. getShouFangList(parseInt($('#shoufang-currentPage').text()) - 1);
  5249. } else {
  5250. getShouFangList(parseInt($('#shoufang-currentPage').text()));
  5251. }
  5252. $('#shoufangdelete').modal('hide');
  5253. });
  5254. });
  5255. // 切换页数
  5256. $('.shoufang-page-select').on('click', function () {
  5257. const totalPageNum = parseInt($('#shoufang-totalPage').text());
  5258. const lastPageNum = parseInt($('#shoufang-currentPage').text());
  5259. const status = $(this).attr('content');
  5260. if (status === 'pre' && lastPageNum > 1) {
  5261. getShouFangList(lastPageNum-1);
  5262. } else if (status === 'next' && lastPageNum < totalPageNum) {
  5263. getShouFangList(lastPageNum+1);
  5264. }
  5265. });
  5266. // 获取单个收方单附件列表
  5267. $('body').on('click', '.show-shoufang-att', function () {
  5268. const id = parseInt($(this).attr('data-id'));
  5269. let html = '';
  5270. $('#shoufang-flie-list').html(html);
  5271. postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
  5272. for (const att of result) {
  5273. html += `<tr><td>${att.filename}${att.fileext} ` + makeEditHtml(att.id, att.filename, att.fileext, att.extra_upload) +
  5274. `<td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
  5275. `<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>`;
  5276. }
  5277. $('#shoufang-flie-list').html(html);
  5278. $('[data-toggle="tooltip"]').tooltip()
  5279. });
  5280. function makeViewHtml(viewpath) {
  5281. 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>` : '';
  5282. }
  5283. function makeDelHtml(fid, extra_upload) {
  5284. return sfAttDelPower &&
  5285. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5286. '<a href="javascript:void(0)" data-sfid="'+ id +'" data-id="'+ fid +'" title="删除" class="del-shoufang-att pull-right text-danger mr-2">' +
  5287. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  5288. }
  5289. });
  5290. function makeEditHtml(fid, filename, fileext, extra_upload) {
  5291. return sfAttDelPower &&
  5292. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5293. '<a href="javascript:void(0)" data-filename="' + filename + '" data-fileext="'+ fileext +'" data-id="'+ fid +'" class="edit-shoufang-att ml-1">' +
  5294. '<i data-toggle="tooltip" data-placement="left" data-original-title="修改文件名" class="fa fa-pencil"></i></a></td>' : ''
  5295. }
  5296. // 修改收方单附件文件名
  5297. $('body').on('click', '.edit-shoufang-att', function () {
  5298. $(this).children('i').tooltip('hide');
  5299. const fid = $(this).data('id');
  5300. const filename = $(this).data('filename');
  5301. const fileext = $(this).data('fileext');
  5302. const html = `<div class="input-group input-group-sm">
  5303. <input type="text" class="form-control" value="${filename}" placeholder="输入文件名" aria-describedby="button-${fid}" style="width:50px">
  5304. <div class="input-group-append" id="button-${fid}">
  5305. <button class="btn btn-outline-primary shoufang-att-confirm-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">确认</button>
  5306. <button class="btn btn-outline-secondary shoufang-att-cancel-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">取消</button>
  5307. </div>
  5308. </div>`;
  5309. $(this).parents('td').html(html);
  5310. });
  5311. // 确认修改文件名
  5312. $('body').on('click', '.shoufang-att-confirm-btn', function () {
  5313. const validText = $.trim($(this).parents('td').find('input').val());
  5314. const orgValue = $.trim($(this).data('filename'));
  5315. const fileext = $(this).data('fileext');
  5316. const fid = $(this).data('fid');
  5317. if (!validText) {
  5318. toastr.error('文件名不能为空');
  5319. return;
  5320. }
  5321. // const reg = /^[0-9a-zA-Z\-_\u4e00-\u9fa5]+$/;
  5322. if(validText.indexOf('.') !== -1 || validText.indexOf(' ') !== -1) {
  5323. toastr.error('文件名中不能包含.字符和空格');
  5324. return;
  5325. }
  5326. if(validText == orgValue) {
  5327. const html = `${orgValue}${fileext} ` + makeEditHtml(fid, orgValue, fileext, 1);
  5328. $(this).parents('td').html(html);
  5329. return;
  5330. }
  5331. const data = {
  5332. id: fid,
  5333. filename: validText,
  5334. };
  5335. const _self = $(this);
  5336. postData('/wap/shoufang/editfile', data, function (result) {
  5337. const html = `${validText}${fileext} ` + makeEditHtml(fid, validText, fileext, 1);
  5338. _self.parents('td').html(html);
  5339. });
  5340. });
  5341. // 取消修改文件名
  5342. $('body').on('click', '.shoufang-att-cancel-btn', function () {
  5343. const fid = $(this).data('fid');
  5344. const filename = $(this).data('filename');
  5345. const fileext = $(this).data('fileext');
  5346. const html = `${filename}${fileext} ` + makeEditHtml(fid, filename, fileext, 1);
  5347. $(this).parents('td').html(html);
  5348. });
  5349. // 删除收方单附件
  5350. $('body').on('click', '.del-shoufang-att', function () {
  5351. const id = $(this).data('id');
  5352. const _self = $(this);
  5353. const data = { id };
  5354. const sfid = $(this).data('sfid');
  5355. postData('/wap/shoufang/delfile', data, function (result) {
  5356. _self.parents('tr').remove();
  5357. // 附件个数更新
  5358. $('#shoufang-table').find('.show-shoufang-att[data-id="'+ sfid +'"]').text($('#shoufang-flie-list tr').length);
  5359. const sfInfo = _.find(sfData, { id: sfid });
  5360. sfInfo.filenum = $('#shoufang-flie-list tr').length;
  5361. });
  5362. });
  5363. // 定位到对应的清单或计量单元
  5364. $('body').on('click', '.show-shoufang-node', function () {
  5365. const id = parseInt($(this).attr('data-id'));
  5366. const sfInfo = _.find(sfData, { id });
  5367. if (sfInfo) {
  5368. const lData = _.find(ledgerData, { id: sfInfo.lid });
  5369. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), lData.ledger_id, true);
  5370. stagePosSpreadObj.loadCurPosData();
  5371. if (sfInfo.pid) {
  5372. const posData = _.find(spSpread.getActiveSheet().zh_data, { id: sfInfo.pid });
  5373. SpreadJsObj.locateData(spSpread.getActiveSheet(), posData);
  5374. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  5375. }
  5376. }
  5377. });
  5378. // 定位到对应的清单或计量单元
  5379. $('body').on('click', '.show-shoufang-report', function () {
  5380. const id = parseInt($(this).attr('data-id'));
  5381. const [qrCodePath, replace_key_params, req_params, rpt_name] = makeReportData(id);
  5382. sessionStorage.qrCodePath = qrCodePath;
  5383. sessionStorage.replace_key_params = JSON.stringify(replace_key_params);
  5384. sessionStorage.req_params = JSON.stringify(req_params);
  5385. sessionStorage.rpt_name = rpt_name;
  5386. window.open('/individualReport/A4');
  5387. });
  5388. $('#importExcel').click(() => {
  5389. importExcel.doImport({
  5390. template: {
  5391. hint: '计量台账',
  5392. url: 'https://jl-assets.oss-cn-shenzhen.aliyuncs.com/template/导入计量台账Excel格式.xlsx',
  5393. },
  5394. callback: function (sheet) {
  5395. postDataCompress(window.location.pathname + '/importStageSheet', {sheet}, function (result) {
  5396. window.location.reload();
  5397. }, null);
  5398. }
  5399. });
  5400. });
  5401. const stageAssistRela = {
  5402. refreshAssConfirmBtn: function () {
  5403. if (stage.assist) {
  5404. const caption = stage.assist.user_id === stage.user_id
  5405. ? (stage.assist.confirm ? '撤销上报' : '确认上报')
  5406. : (stage.assist.confirm ? '重新审批' : '审批通过');
  5407. if (!stage.readOnly || stage.assist.locked) $('#ass-confirm-btn').show().html(caption);
  5408. } else {
  5409. $('#ass-confirm-btn').hide();
  5410. }
  5411. },
  5412. checkAssistPartUsed(assist) {
  5413. const ass_lid = assist.ass_ledger_id.split(',');
  5414. for (const lid of ass_lid) {
  5415. const node = stageTree.getItems(lid);
  5416. if (!node) continue;
  5417. if (checkUsed(stageTree, stagePos, node)) return true;
  5418. }
  5419. return false;
  5420. },
  5421. refreshAssistTable: function () {
  5422. const html = [];
  5423. for (const ra of stage.relaAssists) {
  5424. const used = this.checkAssistPartUsed(ra);
  5425. const hint = used
  5426. ? (ra.confirm ? `<td class="text-success">${moment(ra.update_time).format('YYYY-MM-DD HH:mm')}</td>` : '<td class="text-warning">待确认</td>')
  5427. : '<td>本期未计量</td>';
  5428. html.push(`<tr><td>${ra.name}</td><td>${ra.company}</td>${hint}</tr>`);
  5429. }
  5430. return $('#assistList').html(html.join(''));
  5431. },
  5432. refreshAssists: function () {
  5433. if (stage.relaAssists.length > 0) {
  5434. $('#assistCount').html(stage.relaAssists.length || '').parent().show();
  5435. } else {
  5436. $('#assistCount').parent().hide();
  5437. }
  5438. },
  5439. refreshReadOnly(){
  5440. stageTreeSpreadObj.assistReadOnly = stage.readOnly || stage.revising || (!!stage.assist && !!stage.assist.confirm);
  5441. SpreadJsObj.refreshSheetReadOnly(slSpread.getActiveSheet());
  5442. stagePosSpreadObj.loadCurPosData();
  5443. },
  5444. init: function() {
  5445. this.refreshAssConfirmBtn();
  5446. this.refreshReadOnly();
  5447. this.refreshAssists();
  5448. },
  5449. };
  5450. stageAssistRela.init();
  5451. $('#ass-confirm-btn').click(() => {
  5452. const data = { user_id: stage.assist.user_id, ass_user_id: stage.assist.ass_user_id, confirm: !stage.assist.confirm, type: 'stage' };
  5453. postData(window.location.pathname + '/ass-confirm', data, function(result) {
  5454. window.location.reload();
  5455. // stage.assist = result;
  5456. // stageAssistRela.refreshAssConfirmBtn();
  5457. // stageAssistRela.refreshReadOnly();
  5458. });
  5459. });
  5460. $('#assists').on('show.bs.modal', function(){
  5461. postData(window.location.pathname + '/ass', { user_id: userID, type: 'stage' }, function (result) {
  5462. stage.relaAssists = result;
  5463. stageAssistRela.refreshAssistTable();
  5464. });
  5465. });
  5466. $('body').on('click', 'a[name=att-delete]', function() {
  5467. const fid = this.getAttribute('file-id');
  5468. if (!fid) return;
  5469. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  5470. const data = {id: fid};
  5471. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  5472. // 删除到attData中
  5473. const att_index = attData.findIndex(function (item) {
  5474. return item.id === parseInt(fid);
  5475. });
  5476. attData.splice(att_index, 1);
  5477. // 重新生成List
  5478. if ($('#alllist-table tr').length === 1) {
  5479. getAllList(parseInt($('#currentPage').text()) - 1);
  5480. } else {
  5481. getAllList(parseInt($('#currentPage').text()));
  5482. }
  5483. getNodeList(node.id);
  5484. $('#showAttachment').hide();
  5485. $('#showAttachment').attr('file-id', '');
  5486. });
  5487. });
  5488. });
  5489. function makeOneShouFang(sf) {
  5490. const lData = _.find(ledgerData, { id: sf.lid });
  5491. sf.name = lData.b_code;
  5492. if (sf.pid) {
  5493. const pData = _.find(posData, { id: sf.pid });
  5494. if (pData && pData.name) {
  5495. sf.name = lData.b_code + ' / ' + pData.name;
  5496. }
  5497. }
  5498. return sf;
  5499. }
  5500. function makeShouFang() {
  5501. for (const sf of sfData) {
  5502. makeOneShouFang(sf);
  5503. }
  5504. getShouFangList();
  5505. }
  5506. // 生成收方单列表
  5507. function getShouFangList(currPageNum = 1) {
  5508. // 每页最多几个附件
  5509. const pageCount = 20;
  5510. // 附件总数
  5511. const total = sfData.length;
  5512. // 总页数
  5513. const pageNum = Math.ceil(total/pageCount);
  5514. $('#shoufang-totalPage').text(pageNum);
  5515. $('#shoufang-currentPage').text(total === 0 ? 0 : currPageNum);
  5516. // 当前页附件内容
  5517. const currPageAttData = sfData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  5518. let html = '';
  5519. for(const att of currPageAttData) {
  5520. html += '<tr><td>' + att.name + '</td>' +
  5521. '<td width="40"><a href="#shoufangfile" class="show-shoufang-att" data-id="'+ att.id +'" data-toggle="modal" data-target="#shoufangfile">'+ att.filenum +'</a></td>' +
  5522. '<td width="100">' +
  5523. '<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> ' +
  5524. '<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> ' +
  5525. // '<a href="javascript:void(0);"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a> ' +
  5526. makeDelHtml(att.id, att.extra_upload) +
  5527. '</td></tr>';
  5528. }
  5529. function makeDelHtml(id, extra_upload) {
  5530. return cur_uid === stage.user_id &&
  5531. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5532. '<a href="javascript:void(0);" data-id="'+ id +'" data-toggle="modal" data-target="#shoufangdelete" class="ml-3 text-danger del-shoufang">' +
  5533. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  5534. }
  5535. $('#shoufang-table').html(html);
  5536. $('[data-toggle="tooltip"]').tooltip();
  5537. }
  5538. function makeReportData(sfid) {
  5539. const sfInfo = _.find(sfData, { id: sfid });
  5540. const ledger_code = sfInfo.name.split(' / ')[0];
  5541. const pos_name = sfInfo.name.split(' / ')[1] ? sfInfo.name.split(' / ')[1] : '';
  5542. const replace_key_params = {
  5543. 'KEY_标段名称': tenderInfo.deal_info.buildName,
  5544. 'KEY_总承包单位': tenderInfo.construction_unit.contract1.company,
  5545. 'KEY_合同段': tenderInfo.deal_info.dealName,
  5546. 'KEY_监理单位': tenderInfo.construction_unit.supervision1.company,
  5547. 'KEY_编号': '',
  5548. 'KEY_设计工程数量': 0,
  5549. };
  5550. // if (sfInfo.pid) {
  5551. // const pData = _.find(posData, { id: sfInfo.pid });
  5552. // replace_key_params['KEY_设计工程数量'] = pData.quantity;
  5553. // } else {
  5554. const lData = _.find(ledgerData, { id: sfInfo.lid });
  5555. // }
  5556. replace_key_params['KEY_子目号及子目名称'] = ledger_code + ' ' + lData.name;
  5557. replace_key_params['KEY_桩号及工程部位'] = pos_name;
  5558. const req_params = {
  5559. 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)
  5560. pageSize: 'A4',
  5561. project_id: tender.project_id,
  5562. tender_id: tender.id,
  5563. stage_id: stage.id,
  5564. sp_id: spid,
  5565. };
  5566. const rpt_name = tender.name + '-第' + stage.order + '期-' + ledger_code + (pos_name ? '/' + pos_name : '-' + lData.name);
  5567. const qrCodePath = sfInfo.qrcode;
  5568. return [qrCodePath, replace_key_params, req_params, rpt_name];
  5569. }