<template>
  <el-select v-model="orgCatId" value-key="orgCatId" style="width: 100%" filterable placeholder="请选择措施类型">
    <el-option-group>
      <el-option
        v-for="item in orgCatList"
        :key="item.orgCatId"
        :label="item.orgCatTitle"
        :value="item.orgCatId"
      />
    </el-option-group>
  </el-select>
</template>
<script>
import { getOrgCatByList } from '@/api/system/orgCatApi'

export default {
  name: 'OrgCatSelector',
  components: { },
  props: {
    value: {
      type: Number,
      default: undefined
    }
  },
  data() {
    return {
      orgCatId: undefined,
      orgCatList: []
    }
  },
  watch: {
    value(val) {
      this.orgCatId = val
    },
    orgCatId(val) {
      this.$emit('input', val)
    }
  },
  created() {
    this.initOrgCatList()
  },
  mounted() {},
  methods: {
    initOrgCatList() {
      getOrgCatByList().then((resp) => {
        const { code, data, msg } = resp
        if (code === 200) {
          this.orgCatList = data
        } else {
          this.$message.error(msg)
        }
      }).catch((error) => {
        console.log(error)
      })
    }
  }
}
</script>
