<template>
  <search-item
    label="服务类型"
    :size="size"
  >
    <el-select
      clearable
      filterable
      :value="value"
      @change="changeHandle"
    >
      <el-option
        v-for="(item, index) in serviceTypeList"
        :key="index"
        :value="item.value"
        :label="item.name"
      ></el-option>
    </el-select>
  </search-item>
</template>

<script>
import { mapGetters, mapActions } from 'vuex';

export default {
  name: 'service-select',
  props: {
    size: {
      type: String,
      default: '',
    },
    value: {
      type: Number,
      default: null,
    },
  },
  mounted() {
    if (!this.serviceTypeList.length) {
      this.fetchServiceTypeList();
    }
  },
  computed: {
    ...mapGetters(['serviceTypeList']),
  },
  methods: {
    ...mapActions(['fetchServiceTypeList']),
    changeHandle(val) {
      if(!val){
        this.$emit('input', null);
      }else{
        this.$emit('input', val);
      }
     
    },
  },
};
</script>

