stage.js 284 KB

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