PriceSwitch.vue 2.36 KB
<template>
  <div class="price-select">
    <div class="type-plugin">
      <div class="trend-type-box" @click.stop="switchType">
        <div class="text">{{ selectType || priceList[0].label }}</div>
        <div class="trangle-icon"></div>
      </div>
      <SelectBox :isShow="isShow" :defaultValue.sync="priceList[0].value" @clickOutside="clickOutside" :dataList.sync="priceList" isObject :boxWidth="boxWidth" @selectVal="selectPrice"></SelectBox>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PriceSwitch',
  props: {
    selectList: {
      type: Array,
      default: () => []
    },
    boxWidth: {
      type: String,
      default: ''
    },
    unit: {
      type: String,
      default: '元'
    }
  },
  data() {
    return {
      isShow: false,
      selectType: '',
      priceList: []
    }
  },

  watch: {
    selectList: {
      handler(newVal) {
        console.log(newVal)
        // this.priceList = newVal
        // this.priceList = []
        // newVal.forEach(item => {
        //   this.priceList.push(item + this.unit)
        // })
        // if (!this.unit) return (this.priceList = newVal)
        if (this.unit) {
          this.priceList.unshift({
            label: '全部',
            value: ''
          })
        }
        this.priceList = this.priceList.concat(newVal)
      },
      immediate: true
    }
  },

  mounted() {},

  methods: {
    switchType() {
      this.isShow = !this.isShow
    },
    clickOutside() {
      this.isShow = false
    },
    selectPrice(val) {
      this.selectType = val.label
      this.$emit('selectPrice', val)
      this.switchType()
    }
  }
}
</script>

<style lang="scss" scoped>
.price-select {
  .type-plugin {
    position: relative;
  }
  .trend-type-box {
    display: flex;
    width: fit-content;
    height: 2.22vh;
    line-height: 2.22vh;
    padding: 0 0.83vw;
    box-sizing: border-box;
    .text {
      font-weight: 600;
      font-size: 10px;
      color: #ffffff;
      margin-right: 0.83vw;
    }
    .trangle-icon {
      width: 0px;
      height: 0px;
      border: 4px solid transparent;
      border-top: 4px solid #fff;
      margin-top: 8%;
    }
  }
  /deep/.select-box {
    top: 2vh;
    padding: 0.2vw 0;
    .select-item {
      padding: 0 0.5vw;
      font-size: 10px;
      margin-bottom: 0.5vh;
    }
    .select-item:last-child {
      margin-bottom: 0;
    }
  }
}
</style>