<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="visible"
    title="文件上传"
    append-to-body
    width="800px"
    @open="onOpen"
  >
    <FileUpload ref="fileUpload" />
    <div slot="footer">
      <el-button @click="close">取消</el-button>
      <el-button
        type="primary"
        :loading="ensureLoading"
        @click="handelConfirm"
      >确定</el-button>
    </div>

  </el-dialog>
</template>

<script>
import FileUpload from '@/components/FileUpload/index.vue'
import { saveSupplierFile } from '@/api/wms/orders/deliveryNotice'

export default {
  components: {
    FileUpload
  },
  data() {
    return {
      ensureLoading: false,
      fileList: [],
      deliveryId: null,
      form: {
      },
      isUploadShow: '',
      selectRows: [],
      rules: {
      },
      visible: false
    }
  },
  methods: {
    onOpen() {
      this.$nextTick(() => {
        this.$refs.fileUpload.isUploadShow = -1
        this.$refs.fileUpload.fileList = this.fileList
      })
    },
    close() {
      this.reset()
      this.visible = false
    },
    reset() {
      this.form = {
        id: undefined,
        inspectionItemId: undefined,
        inspectionNo: undefined
      }
      this.resetForm('form')
    },
    handelConfirm() {
      this.fileList = this.$refs.fileUpload.fileList
      const idList = this.fileList.map(item => {
        const { url, id } = item
        return url.fileId === undefined ? id : url.fileId
      })
      const params = {
        fileIds: idList,
        id: this.deliveryId
      }
      saveSupplierFile(params).then(res => {
        this.$modal.msgSuccess('上传成功!')
        this.visible = false
        this.fileList = []
        this.$refs.fileUpload.fileList = res.data
        this.$emit('uploadComplete')
      })
    },
    queryDetails() {

    },
    badCodeChange(v) {
      console.log(v)
    }
  }
}

</script>
  <style>
  </style>
