<template>
  <div style="display: flex; justify-content:center;">
    <button style="height: 20px"><a target="_blank"  :href=File>查看</a></button>
    <el-upload
      class="upload-demo"
      :action="uploadImgUrl"
      list-type="picture-card"
      :on-success="handleUploadSuccess"
      :before-upload="handleBeforeUpload"
      :on-error="handleUploadError"
      name="file"
      :show-file-list="false"
      :headers="headers"
    >
      <!-- <img v-if="value" :src="value" class="avatar" />
      <i v-else class="el-icon-plus avatar-uploader-icon"></i> -->
      <button>上传</button>
    </el-upload>
    <button @click="Delete" style="height: 20px; margin-left:10px;">删除</button>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";

export default {
  components: {},
  data() {
    return {
      File: '',
      uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
      headers: {
        Authorization: "Bearer " + getToken(),
      },
    };
  },
  // props: {
  //   value: {
  //     type: String,
  //     default: "",
  //   },
  // },
  methods: {
    handleUploadSuccess(res) {
      console.log(res)
      this.$emit("input", res);
      // this.$emit("fileName", res.fileName);
      
      this.File = res.url;
      console.log(res.url)
      this.loading.close();
    },
    handleBeforeUpload() {
      this.loading = this.$loading({
        lock: true,
        text: "上传中",
        background: "rgba(0, 0, 0, 0.7)",
      });
    },
    // 删除
    Delete() {
     this.File = '';
     this.$message('已删除')
    },
    handleUploadError() {
      this.$message({
        type: "error",
        message: "上传失败",
      });
      this.loading.close();
    },
  },
  watch: {},
};
</script>

<style scoped lang="scss">
.avatar {
  width: 100%;
  height: 100%;
}

.upload-demo /deep/ .el-upload--picture-card {
  height: 18px;
  width: 45px;
  line-height: 18px;
  border: none;
  margin-left:10px!important;
}
.upload-demo {
  line-height: 30px;
   margin-left:0px!important;
}
</style>