<!--
  @description: 导入邮寄信息/倒入开票信息
  @Modifier: haofengxian/肖文龙
  @routerPath:
  @date: 2021-01-21
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialog"
    :close-on-click-modal="false"
    :title="title"
    width="840px"
    custom-class="el-dialog__body-p0"
  >
    <div class="main" style="height: 400px">
      <table class="tableData">
        <tr>
          <td>
            <span class="red-star">*</span>
            {{ title }}
          </td>
          <td colspan="3">
            <el-upload
              ref="upload"
              :on-success="handleAvatarSuccess"
              :headers="headers"
              :accept="accept"
              :action="mailAddressIUpload"
              multiple
              :limit="10"
              :file-list="fileList"
            >
              <el-button size="small" type="primary">
                点击上传
              </el-button>
              <el-button type="text">
                上传类型为（{{ accept }}）
              </el-button>
            </el-upload>
          </td>
        </tr>
      </table>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialog = false">
        关 闭
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
/* api */
import { saveMailAddressInfoByExcel } from '@/api/fee/servicefee'
import { getToken } from '@/assets/js/utils/auth'
export default {
  name: 'ImportServiceCollectFee',
  data() {
    return {
      fileList: [],
      accept: '.xlsx,.xls', // 上传类型
      title: '', // 标题 标书费开票上传 标书费开票邮寄信息上传
      mailAddressIUpload: '',
      dialog: false,
      headers: {
        'X-AUTH-TOKEN': getToken()
      }
    }
  },
  methods: {
    /*
     *打开弹框
     * @params upType 00 开票上传 01 开票邮寄信息
    */
    openDialog(upType) {
      this.dialog = true
      this.mailAddressIUpload = saveMailAddressInfoByExcel + '?upType=' + upType
      if (upType === '00') {
        this.title = '服务费开票上传'
      } else if (upType === '01') {
        this.title = '服务费开票邮寄信息上传'
      } else {
        this.title = '上传'
      }
    },
    // 上传
    handleAvatarSuccess(res) {
      if (res.header.ret === '0') {
        this.$message.success(res.header.msg)
      } else {
        this.$message.error(res.header.msg)
        this.$refs.upload.clearFiles()
      }
    }
  }
}
</script>

<style scoped lang="less">
    /deep/.tableData{
        .file-list{
            .fileBtn{
                margin-bottom: 0;
            }
        }
    }
</style>
