<template> 
 | 
  <div v-loading="loading" class="fa-card-a" shadow="never"> 
 | 
    <el-row :gutter="24"> 
 | 
      <el-col :span="12"> 
 | 
        <dataExportRecord ref="child"/> 
 | 
      </el-col> 
 | 
      <el-col :span="12"> 
 | 
        <el-form ref="ruleForm" :model="dataForm" :rules="rules" 
 | 
                 @keyup.enter.native="table.query()"> 
 | 
          <el-form-item> 
 | 
            <el-button class="form-title" type="text">本次导出信息</el-button> 
 | 
          </el-form-item> 
 | 
          <el-form-item label="导出时间范围" required label-width="150px"> 
 | 
            <el-col :span="12"> 
 | 
              <el-date-picker v-model="dateVals" :clearable="false" :editable="false" end-placeholder="结束日期" 
 | 
                              range-separator="至" start-placeholder="开始日期" 
 | 
                              type="daterange" value-format="yyyy-MM-dd" @change="pickerChange"> 
 | 
              </el-date-picker> 
 | 
            </el-col> 
 | 
          </el-form-item> 
 | 
          <el-form-item label="是否导出附件" required label-width="150px"> 
 | 
            <el-col :span="12"> 
 | 
              <el-checkbox v-model="dataForm.exportFile"></el-checkbox> 
 | 
            </el-col> 
 | 
            <el-col :span="12"> 
 | 
              <!-- <zt-button type="export" :disabled="dis" @click="exportData">增量数据包</zt-button> --> 
 | 
              <el-button :disabled="dis" icon="el-icon-download" type="primary" @click="exportData">增量数据包 
 | 
              </el-button> 
 | 
              <el-link id="d" :href="filePath" style="visibility:hidden" target="_blank" type="primary">下载 
 | 
              </el-link> 
 | 
            </el-col> 
 | 
          </el-form-item> 
 | 
  
 | 
          <!-- <el-form-item label="导出时间范围" required> 
 | 
            <el-col :span="11"> 
 | 
              <el-form-item prop="gmtStart"> 
 | 
                <el-date-picker type="date" placeholder="选择日期" format="yyyy-MM-dd" v-model="dataForm.gmtStart" style="width: 100%;"></el-date-picker> 
 | 
              </el-form-item> 
 | 
            </el-col> 
 | 
            <el-col class="line" :span="2">至</el-col> 
 | 
            <el-col :span="11"> 
 | 
              <el-form-item prop="gmtEnd"> 
 | 
                <el-date-picker type="date" placeholder="选择日期" format="yyyy-MM-dd" v-model="dataForm.gmtEnd" style="width: 100%;"></el-date-picker> 
 | 
              </el-form-item> 
 | 
            </el-col> 
 | 
          </el-form-item> --> 
 | 
          <!-- 
 | 
                          <el-form-item label="导出目标区域" prop="target" label-width="150px"> 
 | 
                            <el-col :span="12"> 
 | 
                              <zt-select v-model="dataForm.target" :datas="cmplist" placeholder="请选择目标区域"></zt-select> 
 | 
                            </el-col> 
 | 
                          </el-form-item> 
 | 
          --> 
 | 
        </el-form> 
 | 
        <el-progress style="padding: 20px" :percentage="dataForm.speed" :stroke-width="30" 
 | 
                     :text-inside="true"></el-progress> 
 | 
        <el-input v-model="dataForm.text" :autosize="{ minRows: 25, maxRows: 25}" readonly type="textarea"> 
 | 
        </el-input> 
 | 
      </el-col> 
 | 
    </el-row> 
 | 
  </div> 
 | 
</template> 
 | 
<script> 
 | 
  import Cookies from 'js-cookie' 
 | 
  import qs from 'qs' 
 | 
  import dataExportRecord from './data-export-record' 
 | 
  import {guid} from '@/commonJS/common'; 
 | 
  
 | 
  export default { 
 | 
    data() { 
 | 
      return { 
 | 
        localShip: 0, 
 | 
        dataForm: { 
 | 
          progressId: 0, 
 | 
          exportFile: true, 
 | 
          id: '', 
 | 
          speed: 0, 
 | 
          text: '', 
 | 
          gmtStart: '', 
 | 
          gmtEnd: '', 
 | 
          target: 'jd', 
 | 
          targetPid: '' 
 | 
        }, 
 | 
        dateVals: [], 
 | 
        start: 0, 
 | 
        filePath: '', 
 | 
        cmplist: [], 
 | 
        dis: false, 
 | 
        rules: { 
 | 
          gmtStart: [ 
 | 
            { 
 | 
              type: 'date', 
 | 
              required: true, 
 | 
              message: '请选择日期', 
 | 
              trigger: 'change' 
 | 
            } 
 | 
          ], 
 | 
          gmtEnd: [ 
 | 
            { 
 | 
              type: 'date', 
 | 
              required: true, 
 | 
              message: '请选择日期', 
 | 
              trigger: 'change' 
 | 
            } 
 | 
          ], 
 | 
          target: [ 
 | 
            { 
 | 
              required: true, 
 | 
              message: '请选择导出目标区域', 
 | 
              trigger: 'change' 
 | 
            } 
 | 
          ] 
 | 
        }, 
 | 
        tarlist: [], 
 | 
        loading: false 
 | 
      } 
 | 
    }, 
 | 
    components: { 
 | 
      dataExportRecord 
 | 
    }, 
 | 
    mounted() { 
 | 
      // this.gettarget() 
 | 
      this.defaultDate() 
 | 
    }, 
 | 
    methods: { 
 | 
      async exportData() { 
 | 
  
 | 
        // this.loading = true 
 | 
        /*        let sub = false 
 | 
                this.$refs['ruleForm'].validate((valid) => { 
 | 
                  if (valid) { 
 | 
                    sub = true 
 | 
                  } else { 
 | 
                    return false 
 | 
                  } 
 | 
                })*/ 
 | 
        let sub = true 
 | 
        if (sub) { 
 | 
          this.dataForm.progressId = guid() 
 | 
          this.dis = true 
 | 
          this.dataForm.speed = 0 
 | 
          this.start = 1 
 | 
          this.timer = setInterval(this.getStroke, 1000) 
 | 
          window.console.log(this.dataForm) 
 | 
          let res = await this.$http.post( 
 | 
            '/sys/data/export/record/exportData', 
 | 
            this.dataForm 
 | 
          ) 
 | 
          if (res.success) { 
 | 
            clearInterval(this.timer) 
 | 
            this.dataForm.speed = 100 
 | 
            this.$refs.child.$refs.tableObj.query() 
 | 
            this.loading = false 
 | 
            this.dis = false 
 | 
            window.console.log(res) 
 | 
            if (res.data.fileName) { 
 | 
              this.filePath = res.data.path + res.data.fileName 
 | 
              this.download(res.data.fileName) 
 | 
            } else { 
 | 
              this.$tip.error('当前条件下没有可导出数据') 
 | 
            } 
 | 
          } else { 
 | 
            clearInterval(this.timer) 
 | 
            this.loading = false 
 | 
            window.console.log(res.data) 
 | 
            this.dis = false 
 | 
          } 
 | 
        } 
 | 
      }, 
 | 
      async download(name) { 
 | 
        var params = qs.stringify({ 
 | 
          token: Cookies.get('token'), 
 | 
          resourcePath: this.filePath, 
 | 
          fileName: name 
 | 
        }) 
 | 
        let apiURL = `/sys/data/export/record/download` 
 | 
        window.location.href = `${window.SITE_CONFIG['apiURL']}${apiURL}?${params}` 
 | 
      }, 
 | 
      async gettarget() { 
 | 
        let res = await this.$http.get('/sys/data/export/record/dict') 
 | 
        if (res.success) { 
 | 
          console.log(res.data, 'res.data gettarget') 
 | 
          this.cmplist = res.data 
 | 
        } 
 | 
      }, 
 | 
      async getStroke() { 
 | 
        if (this.start === 1 && this.dataForm.speed < 100) { 
 | 
          let res = await this.$http.get(`/sys/common/stroke?progressId=${this.dataForm.progressId}`) 
 | 
          if (res.success) { 
 | 
            this.dataForm.speed = parseFloat(res.data.speed) 
 | 
            this.dataForm.text = res.data.text 
 | 
          } else { 
 | 
            clearInterval(this.timer) 
 | 
          } 
 | 
        } 
 | 
      }, 
 | 
      handleChange(value) { 
 | 
        if (this.tarlist.length < 2) { 
 | 
          this.dataForm.target = this.tarlist[0] 
 | 
          this.dataForm.targetPid = this.tarlist[0] 
 | 
        } else { 
 | 
          this.dataForm.target = this.tarlist[1] 
 | 
          this.dataForm.targetPid = this.tarlist[0] 
 | 
        } 
 | 
      }, // 设置默认日期 
 | 
      defaultDate() { 
 | 
        // 获取新的时间(2019.4.12) 
 | 
        let date = new Date() 
 | 
        // 字符串拼接,开始时间,结束时间 
 | 
        let end = date.getFullYear().toString() + '-' + (date.getMonth() + 1).toString() + '-' + date.getDate().toString() 
 | 
        // let beg = date.getFullYear().toString() + '-' + (date.getMonth() + 1).toString() + '-' + date.getDate().toString() 
 | 
        // 获取7天前的日期 
 | 
        date.setDate(date.getDate() - 7); 
 | 
        // 格式化日期为字符串 
 | 
        let beg = date.toISOString().split('T')[0]; 
 | 
        console.log(beg, '开始时间') 
 | 
        this.dataForm.gmtStart = beg 
 | 
        this.dataForm.gmtEnd = end 
 | 
        this.dateVals = [beg, end] // 将值设置给插件绑定的数据 
 | 
      }, 
 | 
      pickerChange() { 
 | 
        this.dataForm.gmtStart = this.dateVals[0] 
 | 
        this.dataForm.gmtEnd = this.dateVals[1] 
 | 
      } 
 | 
    }, 
 | 
    beforeDestroy() { 
 | 
      clearInterval(this.timer) 
 | 
    } 
 | 
  } 
 | 
</script> 
 |