<template>
  <el-select
    v-model="selected"
    v-bind="$attrs"
    :loading="loading"
    :disabled="disabled"
    @change="change"
  >
    <el-option
      v-for="item in options"
      :key="item.id"
      :label="item.name"
      :value="item.code"
    >
      <el-row :gutter="20">
        <el-col :span="12">{{ item.code }}</el-col>
        <el-col :span="12" class="text-right">{{ item.name }}</el-col>
      </el-row>
    </el-option>
  </el-select>

</template>

<script>
import { getDictDate } from '@/api/bpm/processModel'

export default {
  props: {
    value: {
      type: [String, Number],
      default: ''
    },
    disabled: {
      type: [String, Boolean, Number],
      default: false
    },
    dictTable: {
      type: [String, Boolean, Number],
      default: ''
    },
    dictTableColumnCode: {
      type: [String, Boolean, Number],
      default: ''
    },
    dictTableColumnName: {
      type: [String, Boolean, Number],
      default: ''
    }

  },
  data() {
    return {
      options: [],
      loading: false
    }
  },
  computed: {
    selected: {
      get() {
        return this.value
      },
      set(v) {
        this.$emit('input', v)
      }
    }
  },
  created() {
    this.fetchFormList()
  },
  methods: {
    fetchFormList() {
      this.loading = true
      const params = {
        pageNo: 1,
        pageSize: 200,
        dictTable: this.dictTable,
        dictTableColumnCode: this.dictTableColumnCode,
        dictTableColumnName: this.dictTableColumnName
      }
      getDictDate(params).then(res => {
        this.options = res.data
        console.log(this.options)
      }).finally(() => {
        this.loading = false
      })
    },
    change(value) {
      const item = this.options.find(item => item.code === value)
      this.$emit('change', item)
    }
  }
}
</script>

    <style>

    </style>

