var t,e;import{_ as i}from"./uv-icon.5730d4d2.js";import{G as a,H as n,g as s,o,c,w as l,a as d,B as r,b as u,F as h,r as v,n as m,A as p,m as f,d as g}from"./index-d76b1e7a.js";import{r as _}from"./useRouter.2bdb47a0.js";import{_ as I}from"./_plugin-vue_export-helper.1b428a4d.js";const y=I({name:"uv-rate",mixins:[a,n,{props:{value:{type:[String,Number],default:0},modelValue:{type:[String,Number],default:0},count:{type:[String,Number],default:5},disabled:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},size:{type:[String,Number],default:18},inactiveColor:{type:String,default:"#b2b2b2"},activeColor:{type:String,default:"#FA3534"},gutter:{type:[String,Number],default:4},minCount:{type:[String,Number],default:1},allowHalf:{type:Boolean,default:!1},activeIcon:{type:String,default:"star-fill"},inactiveIcon:{type:String,default:"star"},touchable:{type:Boolean,default:!1},...null==(e=null==(t=uni.$uv)?void 0:t.props)?void 0:e.rate}}],data:()=>({elId:"",elClass:"",rateBoxLeft:0,activeIndex:0,rateWidth:0,moving:!1}),watch:{value(t){this.activeIndex=t},modelValue(t){this.activeIndex=t}},created(){this.activeIndex=Number(this.value||this.modelValue),this.elId=this.$uv.guid(),this.elClass=this.$uv.guid()},mounted(){this.init()},methods:{init(){this.$uv.sleep(200).then((()=>{this.getRateItemRect(),this.getRateIconWrapRect()}))},async getRateItemRect(){await this.$uv.sleep(),this.$uvGetRect("#"+this.elId).then((t=>{this.rateBoxLeft=t.left}))},getRateIconWrapRect(){this.$uvGetRect("."+this.elClass).then((t=>{this.rateWidth=t.width}))},touchMove(t){if(!this.touchable)return;this.preventEvent(t);const e=t.changedTouches&&t.changedTouches[0].pageX||t.detail&&t.detail.pageX;this.getActiveIndex(e)},touchEnd(t){if(!this.touchable)return;this.preventEvent(t);const e=t.changedTouches&&t.changedTouches[0].pageX||t.detail&&t.detail.pageX;this.getActiveIndex(e)},clickHandler(t,e){if("ios"===this.$uv.os()&&this.moving)return;this.preventEvent(t);let i=0;i=t.changedTouches&&t.changedTouches[0].pageX||t.detail&&t.detail.pageX,this.getActiveIndex(i,!0)},changeEvent(){this.$emit("change",this.activeIndex),this.$emit("input",this.activeIndex),this.$emit("update:modelValue",this.activeIndex)},getActiveIndex(t,e=!1){if(this.disabled||this.readonly)return;const i=this.rateWidth*this.count+this.rateBoxLeft,a=t=this.$uv.range(this.rateBoxLeft,i,t)-this.rateBoxLeft;let n;if(this.allowHalf){n=Math.floor(a/this.rateWidth);const t=a%this.rateWidth;t<=this.rateWidth/2&&t>0?n+=.5:t>this.rateWidth/2&&n++}else{n=Math.floor(a/this.rateWidth);const t=a%this.rateWidth;e?t>0&&n++:t>this.rateWidth/2&&n++}this.activeIndex=Math.min(n,this.count),this.activeIndex<this.minCount&&(this.activeIndex=this.minCount),this.changeEvent(),setTimeout((()=>{this.moving=!0}),10),setTimeout((()=>{this.moving=!1}),10)}}},[["render",function(t,e,a,n,I,y){const x=_(s("uv-icon"),i),b=g;return o(),c(b,{class:"uv-rate",id:I.elId,ref:"uv-rate",style:p([t.$uv.addStyle(t.customStyle)])},{default:l((()=>[d(b,{class:"uv-rate__content",onTouchmove:r(y.touchMove,["stop"]),onTouchend:r(y.touchEnd,["stop"])},{default:l((()=>[(o(!0),u(h,null,v(Number(t.count),((e,i)=>(o(),c(b,{class:m(["uv-rate__content__item",[I.elClass]]),key:i},{default:l((()=>[d(b,{class:"uv-rate__content__item__icon-wrap",ref_for:!0,ref:"uv-rate__content__item__icon-wrap",onClick:r((t=>y.clickHandler(t,i+1)),["stop"])},{default:l((()=>[d(x,{name:Math.floor(I.activeIndex)>i?t.activeIcon:t.inactiveIcon,color:t.disabled?"#c8c9cc":Math.floor(I.activeIndex)>i?t.activeColor:t.inactiveColor,"custom-style":{"padding-left":t.$uv.addUnit(t.gutter/2),"padding-right":t.$uv.addUnit(t.gutter/2)},size:t.size},null,8,["name","color","custom-style","size"])])),_:2},1032,["onClick"]),t.allowHalf?(o(),c(b,{key:0,onClick:r((t=>y.clickHandler(t,i+1)),["stop"]),class:"uv-rate__content__item__icon-wrap uv-rate__content__item__icon-wrap--half",style:p([{width:t.$uv.addUnit(I.rateWidth/2)}]),ref_for:!0,ref:"uv-rate__content__item__icon-wrap"},{default:l((()=>[d(x,{name:Math.ceil(I.activeIndex)>i?t.activeIcon:t.inactiveIcon,color:t.disabled?"#c8c9cc":Math.ceil(I.activeIndex)>i?t.activeColor:t.inactiveColor,"custom-style":{"padding-left":t.$uv.addUnit(t.gutter/2),"padding-right":t.$uv.addUnit(t.gutter/2)},size:t.size},null,8,["name","color","custom-style","size"])])),_:2},1032,["onClick","style"])):f("",!0)])),_:2},1032,["class"])))),128))])),_:1},8,["onTouchmove","onTouchend"])])),_:1},8,["id","style"])}],["__scopeId","data-v-8a7d1d7f"]]);export{y as _};
