import{aq as t,az as e,q as i,o as r,c as s,w as a,t as l,G as n,C as o,F as u,D as h,R as d,v as c,x as f,A as m,i as b,a5 as p}from"./index-DL8B2Mxu.js";import{_ as y}from"./u-badge.B5SA0J9t.js";import{r as g}from"./uni-app.es.BSVEa1f2.js";import{_ as x}from"./_plugin-vue_export-helper.BCo6x5W8.js";const S=x({name:"u-tabs",emits:["update:modelValue","input","change"],props:{value:{type:[Number,String],default:0},modelValue:{type:[Number,String],default:0},current:{type:[Number,String],default:0},isScroll:{type:Boolean,default:!0},list:{type:Array,default:()=>[]},height:{type:[String,Number],default:80},fontSize:{type:[String,Number],default:30},duration:{type:[String,Number],default:.5},activeColor:{type:String,default:"#2979ff"},inactiveColor:{type:String,default:"#303133"},barWidth:{type:[String,Number],default:40},barHeight:{type:[String,Number],default:6},gutter:{type:[String,Number],default:30},bgColor:{type:String,default:"#ffffff"},name:{type:String,default:"name"},count:{type:String,default:"count"},offset:{type:Array,default:()=>[5,20]},bold:{type:Boolean,default:!0},activeItemStyle:{type:Object,default:()=>({})},showBar:{type:Boolean,default:!0},barStyle:{type:Object,default:()=>({})},itemWidth:{type:[Number,String],default:"auto"}},data(){return{scrollLeft:0,tabQueryInfo:[],componentWidth:0,scrollBarLeft:0,parentLeft:0,id:this.$u.guid(),currentIndex:this.current,barFirstTimeMove:!0}},watch:{list(t,e){t.length!==e.length&&(this.currentIndex=0),this.$nextTick((()=>{this.init()}))},current:{immediate:!0,handler(t,e){this.$nextTick((()=>{this.currentIndex=t,this.scrollByIndex()}))}},valueCom:{immediate:!0,handler(t,e){this.$nextTick((()=>{this.currentIndex=t,this.scrollByIndex()}))}}},computed:{valueCom(){return this.modelValue},tabBarStyle(){let t={width:this.barWidth+"rpx",transform:`translate(${this.scrollBarLeft}px, -100%)`,"transition-duration":`${this.barFirstTimeMove?0:this.duration}s`,"background-color":this.activeColor,height:this.barHeight+"rpx","border-radius":this.barHeight/2+"px"};return Object.assign(t,this.barStyle),t},tabItemStyle(){return t=>{let e={height:this.height+"rpx","line-height":this.height+"rpx","font-size":this.fontSize+"rpx","transition-duration":`${this.duration}s`,padding:this.isScroll?`0 ${this.gutter}rpx`:"",flex:this.isScroll?"auto":"1",width:this.$u.addUnit(this.itemWidth)};return t==this.currentIndex&&this.bold&&(e.fontWeight="bold"),t==this.currentIndex?(e.color=this.activeColor,e=Object.assign(e,this.activeItemStyle)):e.color=this.inactiveColor,e}}},methods:{async init(){let t=await this.$uGetRect("#"+this.id);this.parentLeft=t.left,this.componentWidth=t.width,this.getTabRect()},clickTab(t){t!=this.currentIndex&&(this.$emit("change",t),this.$emit("input",t),this.$emit("update:modelValue",t))},getTabRect(){let e=t().in(this);for(let t=0;t<this.list.length;t++)e.select(`#u-tab-item-${t}`).fields({size:!0,rect:!0});e.exec(function(t){this.tabQueryInfo=t,this.scrollByIndex()}.bind(this))},scrollByIndex(){let t=this.tabQueryInfo[this.currentIndex];if(!t)return;let i=t.width,r=t.left-this.parentLeft-(this.componentWidth-i)/2;this.scrollLeft=r<0?0:r;let s=t.left+t.width/2-this.parentLeft;this.scrollBarLeft=s-e(this.barWidth)/2,1==this.barFirstTimeMove&&setTimeout((()=>{this.barFirstTimeMove=!1}),100)}},mounted(){this.init()}},[["render",function(t,e,x,S,I,v){const B=g(i("u-badge"),y),$=b,_=p;return r(),s($,{class:"u-tabs",style:d({background:x.bgColor})},{default:a((()=>[l($,{id:I.id},{default:a((()=>[l(_,{"scroll-x":"",class:"u-scroll-view","scroll-left":I.scrollLeft,"scroll-with-animation":""},{default:a((()=>[l($,{class:n(["u-scroll-box",{"u-tabs-scroll-flex":!x.isScroll}]),id:I.id},{default:a((()=>[(r(!0),o(u,null,h(x.list,((t,e)=>(r(),s($,{class:"u-tab-item u-line-1",id:"u-tab-item-"+e,key:e,onClick:t=>v.clickTab(e),style:d([v.tabItemStyle(e)])},{default:a((()=>[l(B,{count:t[x.count]||t.count||0,offset:x.offset,size:"mini"},null,8,["count","offset"]),c(" "+f(t[x.name]||t.name),1)])),_:2},1032,["id","onClick","style"])))),128)),x.showBar?(r(),s($,{key:0,class:"u-tab-bar",style:d([v.tabBarStyle])},null,8,["style"])):m("",!0)])),_:1},8,["id","class"])])),_:1},8,["scroll-left"])])),_:1},8,["id"])])),_:1},8,["style"])}],["__scopeId","data-v-1621c930"]]);export{S as _};
