<template>
  <div class="child-container">
    <el-dialog :visible.sync="dialogExportVisible" width="770px" append-to-body class="dialogExport" :close-on-click-modal="false" :show-close='false'>
      <template slot="title">
        <!--<img class="tip-img" src="@/assets/images/icon.png" />-->
        数据导出
      </template>
      <div class="exportTitle"><span>文件名称</span><el-input style="width: 645px;display: inline-block;" v-model="title"></el-input></div>
      <img class="exportImg" src="@/assets/images/export.png" />
      <div class="table-item">
        <el-table :data="exportTableData">
          <el-table-column
            v-for="(item,index) in forData"
            :key="index"
            :label="item.label"
            :prop="item.prop"
            :width="item.width"
            :min-width="item.minWidth"></el-table-column>
        </el-table>
      </div>
      <div class="input">
        <div>
          导出数量：
          <el-input placeholder="" v-model="value" oninput="value=value.replace(/[^\d]/g,'')">
            <template slot="append">条</template>
          </el-input>
          <p class="tips1"><span>导出文件格式为Excel表格</span><span>最多导出2000条数据，若需导出更多数据，请联系大司空工作人员。</span></p>
        </div>
        <p class="tips2" v-if="value > 2000">导出数据最多支持导出2000条数据</p>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel()">取消</el-button>
        <el-button type="primary" :loading="loading" @click="handleEXCEL">确认导出</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="dialogExportVisible1" width="348px" append-to-body class="dialogExport1" @close="handleCancel2">
      <template slot="title">
        <img class="tip-img" src="@/assets/images/success.png" />
        提交成功
      </template>
      <div class="content">
        <p class="p2">
          可前往个人中心查看导出的全部表格
          <!--<span @click="toUrl">前往个人中心</span>-->
        </p>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel2()">取消</el-button>
        <!--<el-button type="primary" @click="downloadFile(exportData.url,exportData.originalName)">下载表格</el-button>-->
        <el-button type="primary" @click="toUrl">前往个人中心</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: false,
      exportTableData:[],
      forData:[],
      value:'',
      title:this.data.title,
      loading:false,
    }
  },
  watch: {
    'data.exportEXCEL':{
      handler(newValue, oldValue) {
        if(newValue === true){
          this.loading = false;
          this.dialogExportVisible=false;
          this.dialogExportVisible1=true;
        }
      },
      immediate: true
    },
  },
  created() {
    this.exportTableData=this.data.exportTableData
    this.forData=this.data.forData;
  },
  computed: {

  },
  methods: {
    handleEXCEL(){
      this.loading = true;
      this.$nextTick(() => {
        this.$emit('clickEXCEL',this.value,this.title)
      })
    },
    handleCancel(){
      this.dialogExportVisible=false;
      this.$parent.cancel();
    },
    handleCancel2(){
      this.dialogExportVisible1=false;
      this.$parent.cancel();
    },
    downloadFile() {
      const x = new XMLHttpRequest()
      x.open("GET", this.exportEXCEL.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 = this.exportEXCEL.fileName
        a.click()
        a.remove()
      }
      x.send()
    },
    toUrl(){
      this.$parent.cancel();
      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;
          }
        }
      }

      .exportTitle{
        height: 34px;
        margin-bottom: 20px;
        span{
          color: rgba(35,35,35,0.8);
          font-size: 14px;
          margin-right: 12px;
        }
        p{
          display: inline-block;
          width: 669px;
          border: 1px solid #D9D9D9;
          border-radius: 2px;
          height: 32px;
          line-height: 32px;
          color: #232323;
          margin: 0;
          padding-left: 12px;
        }
      }
      .exportImg{
        width: 84px;
        height: 24px;
        display: block;
      }

      .el-dialog__body{
        padding: 16px 16px 24px 16px;
        border-bottom: 1px solid #E5E6EB;
        .input{
          margin-top: 16px;
          position: relative;
          .el-input{
            width: 120px;
            border-radius: 2px;
            height: 32px;
            .el-input__inner{
              height: 32px;
              line-height: 32px;
            }
          }
          .el-input-group__append{
            padding: 0 14px;
          }
          .el-input-group__append:hover{
            background: #F5F7FA !important;
          }
          .tips1{
            color: rgba(35,35,35,0.4);
            font-size: 12px;
            display: inline-block;
            position: absolute;
            left: 220px;
            top: 0;
            span{
              display: block;
            }
          }
          .tips2{
            color: #FF3C3C;
            font-size: 12px;
            margin-top: 8px;
            line-height: 20px;
            margin-left: 75px;
          }
        }
        .content{
          /*text-align: center;*/
          margin-top: 36px;
          .success{
            width: 64px;
            height: 64px;
            margin-bottom: 16px;
          }
          p{
            padding: 0;
            margin: 0;
          }

        }
      }
      .el-dialog__footer{
        text-align: right;
        padding: 16px 20px;
      }
    }
  }
  .dialogExport1{
    ::v-deep .el-dialog{
      .el-dialog__header{
        height: 48px;
        line-height: 48px;
        padding: 0 16px;
        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: 0 16px;
        .content{
          text-align: center;
          .p2{
            color: rgba(35,35,35,0.4);
            font-size: 14px;
            margin: 6px;
            span{
              color:#0081FF;
              cursor: pointer;
            }
          }
        }
      }
      .el-dialog__footer{
        text-align: right;
        padding: 16px 20px;
      }
    }
  }
</style>
