<template>
  <el-select v-model="msgCatId" value-key="msgCatId" style="width: 100%" filterable placeholder="请选择消息类型">
    <el-option-group>
      <el-option
        v-for="item in msgCatList"
        :key="item.msgCatId"
        :label="item.msgCatTitle"
        :value="item.msgCatId"
      />
    </el-option-group>
  </el-select>
</template>
<script>
import { getMsgCatByList } from '@/api/system/msgCatApi'

export default {
  name: 'MsgCatSelector',
  components: { },
  props: {
    value: {
      type: Number,
      default: undefined
    }
  },
  data() {
    return {
      msgCatId: undefined,
      msgCatList: []
    }
  },
  watch: {
    value(val) {
      this.msgCatId = val
    },
    msgCatId(val) {
      this.$emit('input', val)
    }
  },
  created() {
    this.initMsgCatListData()
  },
  mounted() {},
  methods: {
    // Init Measure Type List
    initMsgCatListData() {
      getMsgCatByList().then((resp) => {
        const { code, data, msg } = resp
        if (code === 200) {
          this.msgCatList = data
        } else {
          this.$message.error(msg)
        }
      }).catch((error) => {
        console.log(error)
      })
    }
  }
}
</script>
