importPost.vue 2.51 KB
Newer Older
wangdanlei's avatar
wangdanlei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
/**
* @Description:岗位导入
* @author wx
* @date 2021/12/30
*/
<template>
  <dee-dialog
    :dialog-visible="dialogVisible"
    title="导入岗位"
    width="60%"
    @handleClose="handleClose"
  >
    <div class="importTemp-com">
      <el-upload
        ref="upload"
        :action="action"
        :headers="headers"
        :multiple="false"
        :on-change="onFileChange"
        :accept="accept"
        :http-request="submitUploadFile"
      >
        <el-button class="border-none">选择文件:
          <img
            src="/icons/settledlcons/upLoad.png"
          >
        </el-button>
      </el-upload>
      <div class="info">
        <p style="color:rgb(153 152 152);">说明:导入格式要求xlsx</p>
      </div>
      <div class="flex-c">
        <el-button
          type="primary"
          class="searchBtn"
          @click="submitUpload"
        >确定</el-button>
        <el-button
          class="searchBtn"
          @click="handleClose"
        >取消</el-button>
      </div>
    </div>
  </dee-dialog>
</template>

<script>
import { post } from '@/utils/http'
export default {
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      accept: '.xlsx',
      uploadInput: '',
      headers: {},
      action: '/Post/import?generateOperator='
    }
  },
  computed: {

  },
  watch: {

  },
  created() {
  },
  mounted() {

  },
  methods: {
    onFileChange(file, fileList) {
      if (fileList.length > 1) {
        fileList.splice(0, 1)
      }
      this.uploadInput = file.name
    },
    submitUploadFile(file) {
      this.ePartFile = file
    },
    submitUpload(file) {
      const formData = new FormData()
      if (!this.ePartFile || !this.ePartFile.file) return this.$utils.showMessageWarning('请选择文件')
      if (this.ePartFile !== '') {
        formData.append('file', this.ePartFile.file)
        const action = `${this.action}${this.ePartFile.file.name.indexOf('.zip') > -1 ? 'XMLTOVO' : 'EXCELTOVO'}`
        post(action, formData).then(res => {
          this.handleClose()
          this.$emit('getList')
        })
      }
    },
    handleClose() {
      this.$emit('handleClose')
    }
  }
}

</script>
<style lang='scss'>
.importTemp-com{
  .border-none{
    border: none;
    color: #2678cb;
    img{
      padding-left: 15px;
      width: 18px;
      height: 16px;
    }
  }
  .info{
    background: #eee;
    padding: 10px 15px;
    margin-bottom: 20px;
  }
  .flex-c{
    display:flex;
    justify-content: center;
  }
}
</style>