<template>
  <div class="child-container">
    <el-dialog :visible.sync="dialogExportVisible" width="640px" append-to-body class="dialogExport">
      <template slot="title">
        <img class="tip-img" src="@/assets/images/icon.png" />数据导出
      </template>
      <div class="table-item">
        <el-table :data="exportTableData">
          <el-table-column prop="issueTime" label="招标发布时间" width="110"></el-table-column>
          <el-table-column prop="tenderee" label="招标成员" width="200"></el-table-column>
          <el-table-column prop="stockPercent" label="持股比例" min-width="100"></el-table-column>
          <el-table-column prop="projectName" label="项目名称" min-width="220"></el-table-column>
          <el-table-column prop="bidAmount" label="预算金额" min-width="100"></el-table-column>
          <el-table-column prop="address" label="项目地区" min-width="100"></el-table-column>
          <el-table-column prop="subjectMatter" label="招标采购分类" min-width="130"></el-table-column>
          <el-table-column prop="projectType" label="项目类型" min-width="100"></el-table-column>
          <el-table-column prop="agency" label="代理单位" min-width="160"></el-table-column>
        </el-table>
      </div>
      <div class="input">
        导出数量：
        <el-input placeholder="" v-model="value" oninput="value=value.replace(/[^\d]/g,'')">
          <template slot="append">条</template>
        </el-input>
        <p v-if="value > 2000"><i class="el-icon-error"></i>最多支持导出2000条，如需更多请联系销售人员</p>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="clickEXCEL">确认导出</el-button>
        <el-button @click="cancel(1)">取消</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogExportVisible1" width="640px" append-to-body class="dialogExport">
      <template slot="title">
        <img class="tip-img" src="@/assets/images/icon.png" />
        数据导出
      </template>
      <div class="content">
        <img class="success" src="@/assets/images/success.png" />
        <p class="p1">导出成功</p>
        <p class="p2">
          可在个人中心查看导出表格
          <span @click="toUrl">前往个人中心</span>
        </p>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="downloadFile(exportData.url,exportData.originalName)">下载表格</el-button>
        <el-button @click="cancel(2)">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { getNationalDetails } from '@/api/macro/macro'
export default {
  name: '',
  components: {},
  props: {
    data: {}
  },
  data() {
    return {
      dialogExportVisible: this.data.dialogExportVisible,
      dialogExportVisible1: this.data.dialogExportVisible1,
      exportTableData:[],
      value:'',
    }
  },
  created() {
    this.exportTableData=this.data.exportTableData
  },
  computed: {

  },
  methods: {
    clickEXCEL(){
      this.$emit('clickEXCEL',this.value)
    },
    cancel(key){
      this.$emit('cancel',key)
    },
    downloadFile(url, fileName) {
      const x = new XMLHttpRequest()
      x.open("GET", url, true)
      x.responseType = 'blob'
      x.onload=function(e) {
        const url = window.URL.createObjectURL(x.response)
        const a = document.createElement('a')
        a.href = url
        a.download = fileName
        a.click()
        a.remove()
      }
      x.send()
    },
    toUrl(){
      this.dialogExportVisible1=false;
      this.$router.push({
        path: '/user/profile',
      })
    },
  }
}
</script>

<style lang="scss" scoped>
  .dialogExport{
    ::v-deep .el-dialog{
      .el-dialog__header{
        height: 48px;
        line-height: 48px;
        padding: 0 16px;
        border-bottom: 1px solid #E1E1E1;
        font-weight: bold;
        color: #1D2129;
        font-size: 16px;
        .tip-img{
          width: 18px;
          height: 18px;
          margin-right: 7px;
          margin-bottom: -3px;
        }
        .el-dialog__headerbtn{
          font-size: 20px;
          font-weight: bold;
          top: 15px;
          .el-dialog__close{
            color:#999999;
          }
        }
      }
      .el-dialog__body{
        padding: 16px;
        .input{
          margin-top: 16px;
          .el-input{
            width: 160px;
            border-radius: 2px;
            height: 32px;
            .el-input__inner{
              height: 32px;
              line-height: 32px;
            }
          }
          .el-input-group__append{
            padding: 0 14px;
          }
          p{
            color: #FF3C3C;
            font-size: 12px;
            margin-left: 12px;
            display: inline-block;
            i{
              font-size: 14px;
              margin-right: 4px;
            }
          }
        }
        .content{
          text-align: center;
          margin-top: 36px;
          .success{
            width: 64px;
            height: 64px;
            margin-bottom: 16px;
          }
          p{
            padding: 0;
            margin: 0;
          }
          .p1{
            color: #232323;
            font-size: 16px;
            margin-bottom: 8px;
          }
          .p2{
            color: rgba(35,35,35,0.4);
            font-size: 14px;
            span{
              color:#0081FF;
              cursor: pointer;
            }
          }
        }
      }
      .el-dialog__footer{
        text-align: center;
        padding-bottom: 24px;
      }
    }
  }
</style>
