2025-08-12 09:13:50 +08:00

327 lines
12 KiB
Vue

<template>
<div class="consumptionLevel">
<div class="gender">
<div class="top">
<image class="icon" src="https://eshangtech.com/ShopICO/ahyd-BID/commercial/man.svg"></image>
<p class="title">{{genderList[0].name}}</p>
</div>
<div class="progress">
<div class="small" v-if="genderList[0].small" :style="{background:'#CAD0DA',width:genderList[0].small + '%'}" @click="handleShow('man',0,genderList[0].small,$event)">{{genderList[0].small<16?'':genderList[0].small + '%'}}</div>
<div class="normal" v-if="genderList[0].normal" :style="{background:'#ACB9CD',width:(genderList[0].normal + '%'),left:`calc(${genderList[0].small}% + 2px)`}" @click="handleShow('man',1,genderList[0].normal,$event)">{{genderList[0].normal<16?'':genderList[0].normal+'%'}}</div>
<div class="big" v-if="genderList[0].big" :style="{background:'#1E80FF',left:`calc(${Number(genderList[0].small) +Number(genderList[0].normal) }% + 4px)`,width:genderList[0].big + '%'}" @click="handleShow('man',2,genderList[0].big,$event)">{{genderList[0].big<16?'':genderList[0].big + '%'}}</div>
</div>
<div class="meng" :style="position==='left'?`left:${positionWidth}`:`right:${positionWidth}`" v-if="isShowMan">{{manText}}</div>
<div class="imgKey">
<div style="margin: 0 auto;display: flex">
<div class="item">
<div class="icon" style="background:#CAD0DA"></div>
<p class="consume">低消费</p>
</div>
<div class="item">
<div class="icon" style="background:#ACB9CD"></div>
<p class="consume">普通消费</p>
</div>
<div class="item">
<div class="icon" style="background:#1E80FF"></div>
<p class="consume">高消费</p>
</div>
</div>
</div>
</div>
<div class="gender">
<div class="top">
<image class="icon" src="https://eshangtech.com/ShopICO/ahyd-BID/commercial/woman.svg"></image>
<p class="title">{{genderList[1].name}}</p>
</div>
<div class="progress">
<div class="small" v-if="genderList[1].small" :style="{background:'#C6D3D7',width:genderList[1].small + '%'}" @click="handleShow('woman',0,genderList[0].small,$event)">{{genderList[1].small<16?'':genderList[1].small + '%'}}</div>
<div class="normal" v-if="genderList[1].normal" :style="{background:'#AFC1C6',width:(genderList[1].normal + '%'),left:`calc(${genderList[1].small}% + 2px)`}" @click="handleShow('woman',1,genderList[0].normal,$event)">{{genderList[1].normal<16?'':genderList[1].normal+'%'}}</div>
<div class="big" v-if="genderList[1].big" :style="{background:'#00C2FF',left:`calc(${Number(genderList[1].small) +Number(genderList[1].normal) }% + 4px)`,width:genderList[1].big + '%'}" @click="handleShow('woman',2,genderList[0].big,$event)">{{genderList[1].big<16?'':genderList[1].big + '%'}}</div>
</div>
<div class="meng" :style="positionWoman==='left'?`left:${positionWidthWoman}`:`right:${positionWidthWoman}`" v-if="isShowWoman">{{womanText}}</div>
<div class="imgKey">
<div style="margin: 0 auto;display: flex">
<div class="item">
<div class="icon" style="background:#C6D3D7"></div>
<p class="consume">低消费</p>
</div>
<div class="item">
<div class="icon" style="background:#AFC1C6"></div>
<p class="consume">普通消费</p>
</div>
<div class="item">
<div class="icon" style="background:#00C2FF"></div>
<p class="consume">高消费</p>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: "consumptionLevel",
data() {
return {
genderList:[],//数据
list:[{name:'man',list:[false,false,false]},{name:'woman',list:[false,false,false]}],
position:'',//left 或者 right
positionWidth:'',// 定位百分比
isShowMan:false,//男性提示框
isShowWoman:false,//女性提示框
positionWoman:'',//left 或者 right
positionWidthWoman:'',// 定位百分比
womanText:'',//女性提示框文字
manText:'',//男性提示框文字
}
},
props: {
data: {
type: Array,
default: () => []
}
},
watch: {
data: {
handler(value) {
console.log('ssksjdks',value)
this.genderList = value
this.genderList.forEach(item=>{
item.showList = [false,false,false]
})
},
deep:true,
immediate: true
}
},
methods: {
handleShow(type,index,value,e){
let phoneInfo = uni.getStorageSync('phoneInfo')
let width = phoneInfo.screenWidth
let startWidth = width * 0.2
let endWidth = width * 0.6
let now = e.detail.x
if (type === 'man'){
this.isShowMan = true
if (index === 0){
this.manText = '低消费' + value + '%'
}else if (index === 1){
this.manText = '普通消费' + value + '%'
}else if (index === 2){
this.manText = '高消费' + value + '%'
}
if (now<startWidth){
this.position = 'left'
this.positionWidth = 0
}else if(now>startWidth && now<endWidth){
this.position = 'left'
this.positionWidth = `calc(${now}px - 16px)`
}else if(now>endWidth){
this.position = 'right'
this.positionWidth = 0
}
}else if(type==='woman'){
this.isShowWoman = true
if (index === 0){
this.womanText = '低消费' + value + '%'
}else if (index === 1){
this.womanText = '普通消费' + value + '%'
}else if (index === 2){
this.womanText = '高消费' + value + '%'
}
if (now<startWidth){
this.positionWoman = 'left'
this.positionWidthWoman = 0
}else if(now>startWidth && now<endWidth){
this.positionWoman = 'left'
this.positionWidthWoman = `calc(${now}px - 16px)`
}else if(now>endWidth){
this.positionWoman = 'right'
this.positionWidthWoman = 0
}
}
this.$forceUpdate()
}
}
}
</script>
<style scoped lang="scss">
.consumptionLevel{
width: 100%;
margin-top: 12px;
.gender{
width: 100%;
margin-bottom: 12px;
position: relative;
.top{
display: flex;
align-items: center;
.icon{
width: 16px;
height: 16px;
margin-right: 4px;
}
.title{
font-size: 14px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #160002;
line-height: 20px;
}
}
.progress{
width: 100%;
box-sizing: border-box;
height: 20px;
margin-top: 6px;
position: relative;
font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #FFFFFF;
.text{
position: absolute;
padding: 0 5px;
z-index: 9;
left: 50px;top: -25px;
background: rgba(0,0,0,0.6);
color:#fff;
border-radius: 2px;
display: flex;
align-items: center;
.icon{
width: 10px;
height: 10px;
background: #1E80FF;
margin-right: 4px;
}
}
.big{
display: flex;
align-items: center;
height: 100%;
position: absolute;
top: 0;
left: 0;
border-radius:0 2px 2px 0;
box-sizing: border-box;
text-indent: 0.25rem;
.text{
width: 120px;
height: 26px;
position: absolute;
z-index: 9;
left: 0;top: 0;
transform: translateX(-100%);
background: rgba(0,0,0,0.6);
color:#fff;
border-radius: 2px;
display: flex;
align-items: center;
.icon{
width: 10px;
height: 10px;
margin-right: 4px;
}
}
}
.normal{
display: flex;
align-items: center;
height: 100%;
position: absolute;
box-sizing: border-box;
text-indent: 0.25rem;
.text{
width: 130px;
height: 26px;
position: absolute;
z-index: 9;
left: 0;top: 0;
transform: translateX(-100%);
background: rgba(0,0,0,0.6);
color:#fff;
border-radius: 2px;
display: flex;
align-items: center;
.icon{
width: 10px;
height: 10px;
background: #1E80FF;
margin-right: 4px;
}
}
}
.small{
display: flex;
align-items: center;
height: 100%;
position: absolute;
box-sizing: border-box;
text-indent: 0.25rem;
border-radius:2px 0 0 2px;
.text{
position: absolute;
width: 130px;
height: 26px;
z-index: 9;
left: 50px;top: -25px;
background: rgba(0,0,0,0.6);
color:#fff;
border-radius: 2px;
display: flex;
align-items: center;
.icon{
width: 10px;
height: 10px;
background: #1E80FF;
margin-right: 4px;
}
}
}
}
.meng{
position: absolute;
display: inline-block;
padding: 0 5px;
z-index: 9;
top: 0;
background: rgba(0,0,0,0.6);
color:#fff;
border-radius: 2px;
}
.imgKey{
display: flex;
margin-top: 8px;
.item{
display: flex;
align-items: center;
margin-right: 12px;
.icon{
width: 12px;
height: 12px;
border-radius: 2px;
margin-right: 4px;
}
.consume{
font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #786B6C;
line-height: 18px;
}
}
}
}
}
</style>