<template>
    <div class="bandLevel">
      <div class="mengBox" v-if="selectName" @click="handleNoShow"></div>
        <div class="bandItem" v-for="(item,index) in dataList" :key="index">
            <p class="title">{{item.name}}</p>
            <div class="progress">
                <div v-if="Number(item.small)!==0" class="small" :style="{width:`calc(${item.small}% - 2px)`}" @click="handleClick($event,'small',item)">{{item.small<16?'':item.small+'%'}}</div>
                <div v-if="Number(item.normal)!==0" class="normal" :style="{width:`calc(${item.normal}% - 2px)`,left:`calc(${item.small}% - 2px)`}" @click="handleClick($event,'normal',item)">{{item.normal<16?'':item.normal + '%'}}</div>
                <div v-if="Number(item.big)!==0" class="big" :style="{width:item.big+'%',left:`calc(${item.normal + item.small}%  - 4px)`}" @click="handleClick($event,'big',item)">{{item.big<16?'':item.big + '%'}}</div>
            </div>
            <div class="meng" :style="position==='left'?`left:${positionWidth}`:`right:${positionWidth}`"  v-if="selectName===item.name">{{typeText}}{{typeValue}}</div>
        </div>
        <div class="key">
            <div class="box">
                <div class="keyItem">
                    <div class="icon" style="background: #CAD0DA"></div>
                    <p class="type">低消费</p>
                </div>
                <div class="keyItem">
                    <div class="icon" style="background: #ACB9CD"></div>
                    <p class="type">普通消费</p>
                </div>
                <div class="keyItem">
                    <div class="icon" style="background: #1E80FF"></div>
                    <p class="type">高消费</p>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
var uChartsInstance = {};
export default {
    name: "bandLevel",
    data() {
        return {
            dataList: [],
            isShow: false,
            typeText:'',
            typeValue:'',
            selectName:'',
            position:'',//left 或者 right
            positionWidth:'',// 定位百分比
        }
    },
    props: {
        data: {
            type: Array,
            default: () => []
        }
    },
    watch: {
        data: {
            handler(value) {
                this.dataList = value
            },
            immediate: true
        }
    },
    methods: {
      handleNoShow(){
        this.selectName = ''
      },
        handleClick(e,type,item){
            this.selectName = item.name
            let phoneInfo = uni.getStorageSync('phoneInfo')
            let width = phoneInfo.screenWidth
            let startWidth = width * 0.2
            let endWidth = width * 0.6
            let now = e.detail.x
            this.isShow = true
            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
            }
            if (type==='small'){
                this.typeText = '低消费'
                this.typeValue = item.small + '%'
            }else if(type === 'normal'){
                this.typeText = '普通消费'
                this.typeValue = item.normal + '%'
            }else if(type === 'big'){
                this.typeText = '高消费'
                this.typeValue = item.big + '%'
            }
        }
    }
}
</script>

<style scoped lang="scss">
.bandLevel{
    width: 100%;
    margin-top: 12px;
  .mengBox{
    position: fixed;
    left: 0;top: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9;
  }
    .bandItem{
        width: 100%;
        position: relative;
        margin-bottom: 12px;
        .title{
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #160002;
            line-height: 20px;
        }
        .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;
        }
        .progress{
            width: 100%;
            height: 20px;
            box-sizing: border-box;
            margin-top: 6px;
            position: relative;
            font-size: 12px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #FFFFFF;
            .big{
                display: flex;
                align-items: center;
                height: 100%;
                position: absolute;
                top: 0;
                border-radius:  0 2px 2px  0  ;
                box-sizing: border-box;
                padding-left: 4px;
                background: #1E80FF;
            }
            .normal{
                display: flex;
                align-items: center;
                height: 100%;
                position: absolute;
                box-sizing: border-box;
                padding-left: 4px;
                background: #ACB9CD;
            }
            .normal:after{
                position: absolute;
                content:'';
                width: 2px;
                height: 100%;
                background: #FFFFFF;
                z-index:9;
                right: 0;
                top: 0;
            }
            .small{
                display: flex;
                align-items: center;
                height: 100%;
                position: absolute;
                box-sizing: border-box;
                padding-left: 4px;
                border-radius:  2px 0 0 2px ;
                background: #CAD0DA;
            }
            .small:after{
                position: absolute;
                content:'';
                width: 2px;
                height: 100%;
                background: #FFFFFF;
                z-index:9;
                right: 0;
                top: 0;
            }
        }
    }
    .key{
        display: flex;
        width: 100%;
        .box{
            display: flex;
            margin: 0 auto;
            .keyItem{
                display: flex;
                align-items: center;
                margin-right: 12px;
                .icon{
                    width: 12px;
                    height: 12px;
                    border-radius: 2px;
                    margin-right: 4px;
                }
                .type{
                    font-size: 12px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #786B6C;
                    line-height: 18px;
                }
            }
        }
    }
}
</style>
