<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.materialNo"
      :value="item.materialNo"
    >
      <el-row :gutter="20">
        <el-col :span="12">{{ item.materialNo }}</el-col>
        <el-col :span="12" class="text-right">{{ item.materialName }}</el-col>
      </el-row>
    </el-option>
  </el-select>

</template>

<script>
import { getMaterialDropDownList } from '@/api/wms/base/material'
import { getSameMaterialNo } from '@/api/wms/inLibrary/slittingOrder'

export default {
  props: {
    value: {
      type: [String, Number],
      default: ''
    },
    inspectionType: {
      type: Number,
      default: 0
    }
    // currentRows: {
    //   type: Array,
    //   default: () => []
    // }
  },
  data() {
    return {
      options: [],
      loading: false,
      currentRows: [],
      summaryOrderNo: null
    }
  },
  computed: {
    selected: {
      get() {
        return this.value
      },
      set(v) {
        this.$emit('input', v)
      }
    }
  },
  created() {
    // this.fetchslitMaterialList()
  },
  methods: {
    fetchslitMaterialList() {
      this.loading = true
      const params = {
        pageNo: 1,
        pageSize: 100,
        summaryOrderNo: this.summaryOrderNo
      }
      getMaterialDropDownList(params).then(res => {
        this.options = res.data
      }).finally(() => {
        this.loading = false
      })
    },
    fetchSameMaterialList() {
      this.loading = true
      if (this.currentRows.length > 0) {
        const workOrderNos = this.currentRows.map(item => {
          const { workOrderBomNo } = item
          return workOrderBomNo
        })
        const params = {
          workOrderBomNos: workOrderNos.join(',')
        }
        getSameMaterialNo(params).then(res => {
          this.options = res.data
        }).finally(() => {
          this.loading = false
        })
      }
    },
    change(value) {
      const item = this.options.find(item => item.materialNo === value)
      this.$emit('change', item)
    }
  }
}
</script>

    <style>

    </style>

