import.vue 4.15 KB
<template>
  <div class="imort_page">

    <div class="choose_box">
      <div class="upload_wrap">
        <el-input placeholder="请选择需要导入的车辆表格" v-model="uploadFile.name" readonly>
          <el-button slot="append" @click="chooseFiles">选择文件</el-button>
        </el-input>
        <!-- 隐藏上传文件按钮 开始 -->
        <el-upload ref="uploadBox" class="upload_box" :auto-upload="false" :headers="uploadHead" :data="uploadParams" :action="uploadPath" multiple :limit="1" :show-file-list="false" :on-change="onChange">
          <el-button type="primary">点击上传</el-button>
        </el-upload>
        <!-- 隐藏上传文件按钮 end -->
      </div>
      <el-link type="primary" class="el_link">下载模版</el-link>
    </div>

    <div class="btn_group">
      <el-button type="default" size="small">取消</el-button>
      <el-button type="primary" size="small">确定</el-button>
    </div>

    <!-- 导入结果 开始 -->
    <div class="upload_result">
      <h2 class="title">导入结果</h2>
      <div class="result_box">
        <div class="cell">
          <div class="name">
            <span>成功记录</span>
          </div>
          <span class="txt">11071</span>
        </div>
        <div class="cell">
          <div class="name">
            <span>失败记录</span>
            <span class="btn">导出记录</span>
          </div>
          <span class="txt">29</span>
        </div>
      </div>
    </div>
    <!-- 导入结果 end -->

  </div>
</template>
<script>
import { IMPORT_VEHICLE_TEMPLATE } from "@/services/user";
export default {
  name: "ImportVehicle",
  props: {
    id: {
      type: [String, Number],
      default: "",
    },
  },
  data() {
    return {
      fileInfo: "",
      uploadPath: "",
      uploadHead: {},
      uploadFile:{}
    };
  },
  mounted() {
    let id = this.id;
    let token = localStorage.getItem("token");
    this.uploadPath =
      this.$root.parentVuex.getters.baseURL + IMPORT_VEHICLE_TEMPLATE;
    this.uploadHead = { Authorization: token };
    this.uploadParams = { receiverId: id };
  },
  methods: {
    // 选择文件
    chooseFiles() {
      console.log(this.$refs.uploadBox.$el);
      this.$refs.uploadBox.$el.click();
    },

    // 监听文件选择
    onChange(file) {
      console.log(file);
      this.uploadFile = file;
    },
  },
};
</script>
<style lang="scss" scoped>
.choose_box {
  display: flex;
  align-items: center;
  padding: 10px 72px;
  .el_link {
    flex-shrink: 0;
    text-align: left;
    margin: 0 10px;
  }
  .upload_wrap {
    flex: 1;
    position: relative;
    .upload_box {
      position: absolute;
      right: 0;
      bottom: 0;
      top: 0;
      opacity: 0;
    }
  }
}
.btn_group {
  padding: 20px 0 10px 0;
  text-align: center;
}
.upload_result {
  border-top: 1px solid #eee;
  margin-top: 30px;
  .title {
    font-family: PingFangSC-Medium;
    font-size: 20px;
    color: #333333;
    font-weight: 500;
  }
  .result_box {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: 30px;
    .cell {
      width: 248px;
      height: 108px;
      background: #fbfbfb;
      border: 1px solid rgba(215, 215, 215, 1);
      border-radius: 4px;
      margin: 0 20px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      padding: 20px;
      box-sizing: border-box;
      .name {
        font-family: PingFangSC-Medium;
        font-size: 14px;
        color: #666666;
        font-weight: 500;
        display: flex;
        align-items: center;
        .btn {
          width: 76px;
          height: 30px;
          border: 1px solid rgba(33, 150, 243, 1);
          border-radius: 4px;
          text-align: center;
          line-height: 28px;
          font-family: PingFangSC-Regular;
          font-size: 14px;
          color: #409eff;
          font-weight: 400;
          cursor: pointer;
          margin-left: 10px;
        }
        .btn:hover {
          opacity: 0.8;
        }
      }
      .txt {
        font-family: PingFangSC-Medium;
        font-size: 30px;
        color: #333333;
        font-weight: 500;
        line-height: 1.5;
      }
    }
  }
}
</style>