<template>
  <div class="customer-css">
    <el-dialog :title="pageData.titleCon" :close-on-click-modal="false" :visible.sync="visible" width="390px" style="height: 520px;" class="customer-dialog">
      <el-form :inline="true" label-position="top" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item class="customer-item" label="编码" >
              <el-input v-model="pageData.dataNo" readonly style="width: 120px"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-upload class="customer-upload" drag
                       action="javascript:void(0);" ref="uploadFile" :limit="3" multiple :on-remove="onRemove"
                       :before-upload="beforeUploadHandle" :on-change="onChange"
                       accept="*" :auto-upload="false"
                       style="text-align: left;">
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            </el-upload>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24" style="margin-bottom: 30px;">
            <el-form-item class="customer-item" label="备注:" >
              <el-input type="textarea" style="width: 360px;" placeholder="请输入内容" v-model="pageData.fileRemark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="saveUploadFile">保存</el-button>
        <el-button type="primary" @click="closeDialog">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  uploadFile // 文件上传
} from '@/api/oss/oss.js'
export default {
  data () {
    return {
      visible: false,
      fileList: [],
      pageData: {
        titleCon: '',
        site: '',
        createBy: '',
        dataNo: '',
        fileRemark: '',
        folder: '',
        file: ''
      },

    }
  },
  methods: {

    // 初始化组件的参数
    init (currentRow) {
      // 初始化参数
      this.pageData = JSON.parse(JSON.stringify(currentRow))
      // 打开页面
      this.visible = true
    },

    // 上传之前
    beforeUploadHandle (file) {},

    // 选择上传文件时
    onChange (file) {
      this.fileList.push(file)
    },

    onRemove (file,fileList) {
      this.fileList = fileList
    },

    // 关闭modal
    closeDialog () {
      this.fileList = []
      this.$refs.uploadFile.clearFiles()
      // 关闭当前的页面
      this.visible = false
    },

    // 保修当前的数据
    saveUploadFile () {
      if (this.pageData.fileRemark == null) {
        this.pageData.fileRemark = ''
      }
      // 判断文件是否上传
      if (this.fileList == null || this.fileList.length === 0) {
        this.$message.error("请先上传文件!")
        return false
      }
      for (let i = 0; i < this.fileList.length; i++) {
        this.pageData.file[i] = this.fileList[i].raw
      }
      //this.pageData.file = this.fileList
      this.$emit('refreshPageTables', this.pageData)
      this.$message.success('操作成功!')
      this.closeDialog()

      // uploadFile(formData).then(({data}) => {
      //   if (data.code === 0) {
      //     this.$message.success(data.msg)
      //     // 清空文件上传记录
      //     this.$refs.uploadFile.clearFiles()
      //     this.pageData.fileRemark = ''
      //     this.fileList = []
      //   }else {
      //     this.$message.warning(data.msg)
      //   }
      // })
    }

  }
}
</script>
<style scoped lang="scss">

</style>
