<template>
  <el-dialog
    :title="refList.title"
    :visible.sync="dialogVisible"
    width="33%"
    :before-close="handleClose"
  >
    <el-form :model="form" label-width="100px">
      <el-form-item label="分类名称：" required>
        <el-input placeholder="请输入" v-model.trim="form.name"></el-input>
      </el-form-item>
      <el-form-item label="文件名称：" required>
        <el-input placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="上传文件：" required>
        <div>
          <el-upload
            class="upload-demo"
            action
            :http-request="api_import"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            multiple
            :limit="3"
            :on-exceed="handleExceed"
            :file-list="fileList"
            :before-upload="beforeAvatarUpload"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">仅支持pdf文件</div>
          </el-upload>
        </div>
      </el-form-item>
      <el-form-item required>
        <template slot="label" class="status"
          ><span>状&#8195;&emsp;态</span>：</template
        >
        <el-radio-group v-model="form.status">
          <el-radio :label="1">启用</el-radio>
          <el-radio :label="0">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="dialogVisible = false">取 消</el-button>
      <el-button
        size="small"
        style="margin-left: 60px"
        type="primary"
        @click="addList"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
import * as api from '@/api/api'
export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        docUrl: '',
        id: '',
        linkUrl: '',
        name: '',
        status: '',
        typeId: ''
      },
      refList: {},
      fileList:[]
    }
  },
  methods: {
    handleClose() {
      this.dialogVisible = false
    },
    openClose(val) {
      if (val) {
        this.refList = val
      }
      this.dialogVisible = true
    },
    /**
     * @method 上传
     * **/ 
    api_import(file){
       const files = {
        file: file.file
      }
      api.IMPORT('/api/file/local/upload',files).then(data=>{
        console.log(data)
      })
    },
    /**
     * @method 
     * **/ 
    handleExceed(){},
    handlePreview(){},
    handleRemove(){},
    beforeRemove(){},
    /**
     * @method 上传限制
     * **/ 
     beforeAvatarUpload(file) {
        const ispaf = file.type === 'application/pdf';

        if (!ispaf) {
          this.$message.error('上传文件只能是 PDF 格式!');
        }
        return ispaf
      },
    /**
     * @method 提交确定
     * **/ 
    addList(){}
  }
}
</script>
<style lang="less" scoped>

</style>