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

</template>

<script>
import { getInspectionItemPage } from '@/api/wms/quality/inspectionItems'

export default {
  props: {
    value: {
      type: [String, Number],
      default: ''
    },
    inspectionType: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      options: [],
      loading: false
    }
  },
  computed: {
    selected: {
      get() {
        return this.value
      },
      set(v) {
        this.$emit('input', v)
      }
    }
  },
  created() {
    this.fetchInspectionList()
  },
  methods: {
    fetchInspectionList() {
      this.loading = true
      const params = {
        pageNo: 1,
        pageSize: 100,
        inspectionType: this.inspectionType
      }
      getInspectionItemPage(params).then(res => {
        const { list = [] } = res.data || {}
        // list.forEach(i => {
        //   i.iNo = i.inspectionNo
        // })
        this.options = list
      }).finally(() => {
        this.loading = false
      })
    },
    change(value) {
      const item = this.options.find(item => item.id === value)
      this.$emit('change', item)
    }
  }
}
</script>

    <style>

    </style>

