selectCpn.vue 2.67 KB
<template>
  <div class='select'>
    <span v-show='selectName'>{{ selectName }}</span>
    <select v-if='selectArr' class='sel' id='sel' v-model='selStr' :style='widthHeight' @change='selectBtn(selectType)'>
      <option v-for='(item,index) in selectArr' :key='index' :value='item[valName]'>
        {{ item[labelName] }}
      </option>
    </select>
  </div>
</template>

<script>
export default {
  name: 'SelectOptions',
  props: {
    valName: {
      type: String,
      default: 'value'
    },
    labelName: {
      type: String,
      default: 'label'
    },
    selectType: {
      type: String,
      default: ''
    },
    selectName: {
      type: String,
      default: ''
    },
    // showSelect: {
    //   type: Boolean,
    //   default: false
    // },
    selectArr: {
      type: Array,
      default: () => []
    },
    widthHeight: {
      type: Object,
      default: () => {
      }
    },
    getQuery: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      selStr: '',
    }
  },
  watch: {
    selectArr: {
      handler(newval, oldval) {
        this.selStr = this.selectArr[0][this.valName]
        // if (newval == true && this.showSelect == true) {
        //   this.selStr = this.selectArr[0][this.valName]
        //   console.log(this.selStr)
        // }
        // if (newval == false && this.showSelect == true) {
        //   this.selStr = ''
        // }
      }
    }
  },
  mounted() {
    if (this.selectArr.length) {
      this.selStr = this.selectArr[0][this.valName]
    }
    // this.$bus.$on('changeBussiness', data => {
    //   const { bussinessType } = data
    //   this.showFirstSelStaus = bussinessType == 'expandedGold' || bussinessType == 'crowdFunding'
    // })
  },

  methods: {
    selectBtn(type) {
      switch (type) {
        case 'business':
          // eslint-disable-next-line no-case-declarations
          let title
          this.selectArr.forEach(item => {
            if (item.value == this.selStr) {
              title = item.label
            }
          })
          this.$bus.$emit('changeBussiness', { bussinessTitle: title + '业务', bussinessType: this.selStr })
          break
        // case 'system':
        //   this.$bus.$emit('changeSystem', { systemType: this.selStr })
        //   break
        case 'months':
          this.$bus.$emit('changeMonths', { month: this.selStr })
          break
        case 'springbudAtion':
          this.$bus.$emit('changeSpringbudAtion', { action: this.selStr })
          break
      }
    }
  }
}
</script>

<style scoped lang='scss'>
.select {
  margin: 1vh;

  .sel {
    background: #2436b7;
    border: none;
    color: #ffffff;
    border-radius: 5px;
  }
}
</style>