SelectComponent.vue 1.92 KB
<template>
  <view class="select-box">
    <view
      class="select"
      @click.stop="isSelect = !isSelect"
    >
      {{selectList[selectIndex].label}}
      <view class="sprite-icon icon-arrow-bottom"></view>
    </view>
    <view
      class="pop-box"
      v-if="isSelect"
    >
      <view
        v-for="(i,index) in selectList"
        :key="index"
        class="type-item flex"
        :class="index == selectIndex ? 'active' : ''"
        @click="chooseType(index, i)"
      >{{i[labelKey]}}</view>
    </view>
  </view>
</template>

<script type='text/ecmascript-6'>
export default {
  props: {
    selectList: Array,
    labelKey: {
      type: String,
      default: 'label'
    }
  },
  name: '',
  data () {
    return {
      selectIndex: 0,
      isSelect: false
    }
  },
  mounted () {
  },
  methods: {
    hideSelect () {
      this.isSelect = false
    },
    chooseType (index, item) {
      this.selectIndex = index
      this.isSelect = false
      this.$emit('chooseType', { item, index })
    },
  }
}
</script>

<style scoped lang='scss'>
.select-box {
  position: relative;
  z-index: 5;
  .select {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    height: toRpx(84);
    border-radius: toRpx(16);
    opacity: 1;
    background: #f2f2f2;
    padding: 0 toRpx(24) 0 toRpx(40);
  }
  .arrow-bottom {
    width: toRpx(48);
    height: toRpx(48);
  }
  .pop-box {
    position: absolute;
    top: toRpx(100);
    left: 0;
    width: 100%;
    background: #ffffff;
    box-shadow: 0 0 toRpx(16) 0 #99999933;
    border-radius: toRpx(16);
    padding: toRpx(16) 0;
    text-align: center;
    animation: show-view-opacity 0.15s forwards;
    .type-item {
      padding: 0 toRpx(28);
      margin-bottom: toRpx(8);
      height: toRpx(84);
      justify-content: center;
      &:last-child {
        margin-bottom: 0;
      }
      &.active {
        background-color: #ecf1ff;
      }
    }
  }
}
</style>