<template>

  <!-- 修改的 -->
  <el-select
    v-model="selected"
    v-bind="$attrs"
    :loading="loading"
    @change="change"
    @visible-change="handleCaseVisibleChange"
  >
    <el-option
      v-for="item in options"
      :key="item.id"
      :label="item.inspectionNo"
      :value="item.inspectionNo"
    >
      <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 { getPageLike } from '@/api/wms/quality/inspectionCase'
export default {
  props: {
    value: {
      type: [String, Number, Array],
      default: ''
    },
    list: {
      type: Array,
      default: () => []
    },
    type: {
      type: [String, Number, Array],
      default: ''
    }
  },
  data() {
    return {
      loading: false,
      options: [],
      copiedOptions: [],
      codeList: [],
      selectFlag: false
    }
  },
  computed: {
    selected: {
      get() {
        return this.value
      },
      set(v) {
        this.$emit('input', v)
      }
    }
  },
  methods: {
    fetchCaseList(valueLike) {
      const _list = []
      // 过滤page列表的wmsInspectionItemId，替换为inspectionItemId字段
      this.list.forEach(item => {
        if (item.inspectionNo !== '') {
          const _item = JSON.parse(JSON.stringify(item))
          Reflect.deleteProperty(_item, 'wmsInspectionItemId')
          _list.push({
            ..._item,
            inspectionItemId: item.inspectionItemId ? item.inspectionItemId : item.wmsInspectionItemId
          })
        }
      })
      this.loading = true
      const params = {
        valueLike: valueLike === undefined ? '' : valueLike,
        likeRespVOList: _list,
        inspectionType: this.type
      }
      getPageLike(params).then(response => {
        this.options = response.data || []
      }).finally(() => {
        this.loading = false
      })
    },
    change(v) {
      const items = this.options.find(item => item.inspectionNo === v)
      this.$emit('change', items)
    },
    // 下拉框显示/隐藏
    handleCaseVisibleChange(visible) {
      if (visible) {
        this.fetchCaseList()
      }
    }
  }

}
</script>

  <style>

  </style>

