<template>
  <div v-loading="downloading" class="app-container">
    <el-input v-model="boxNumbers" type="textarea" :rows="30" placeholder="请输入箱号,每行一个" />
    <br><br>
    <div class="text-center">
      <el-button type="success" size="large" @click="downLoad">下载PDF</el-button>
      <el-button type="success" size="large" @click="downLoadCsv">下载卢邮箱号</el-button>
    </div>
  </div>
</template>
<script>
import { format } from '@/utils/multiInput'
import { downLoadPackLabel } from '@/api/luxPackLabel'
import { getToken } from '@/utils/auth'

export default {
  name: 'DownLuxPackLabel',
  data() {
    return {
      boxNumbers: null,
      downloading: false
    }
  },
  methods: {
    downLoad() {
      const boxNumbers = format(this.boxNumbers)
      const param = { boxNumbers }
      this.downloading = true
      var url = `${process.env.VUE_APP_BASE_API}/Pkg/BatchDown5UPackLabelPdf`
      var x = new XMLHttpRequest()
      x.open('POST', url, true)
      x.responseType = 'blob'
      x.setRequestHeader('content-type', 'application/json')
      x.setRequestHeader('token', getToken())

      x.onload = (e) => {
        this.downloading = false
        var url = window.URL.createObjectURL(x.response)
        var a = document.createElement('a')
        a.href = url
        a.download = `合并卢邮标签.pdf`
        a.click()
        this.downloadLoading = false
      }
      const data = JSON.stringify(param)

      x.send(data)
    },
    downLoadCsv() {
      const boxNumbers = format(this.boxNumbers)
      const param = { boxNumbers }
      this.downloading = true
      var url = `${process.env.VUE_APP_BASE_API}/Pkg/BatchDown5UPackNumber`
      var x = new XMLHttpRequest()
      x.open('POST', url, true)
      x.responseType = 'blob'
      x.setRequestHeader('content-type', 'application/json')
      x.setRequestHeader('token', getToken())

      x.onload = (e) => {
        this.downloading = false
        var url = window.URL.createObjectURL(x.response)
        var a = document.createElement('a')
        a.href = url
        a.download = `卢邮箱号对照.csv`
        a.click()
        this.downloadLoading = false
      }
      const data = JSON.stringify(param)

      x.send(data)
    }
  }
}
</script>
<style scoped></style>
