<!--
 * @Descripttion: 
 * @version: 
 * @Author: 王三华
 * @Date: 2023-10-12 15:10:59
-->
<template>
  <view class="qiu" @click="toExport">
    <img src="@/assets/images/export.png"
         alt="">
    <view>导出</view>
  </view>
</template>

<script>
import { getToken } from '@/config/auth.js'
let Qs = require("qs")
export default {
  methods:{
    toExport(){
      this.$emit('handleExport')
    },
    // 导出地址，参数，名称
    handleExport(url,obj,name){
      let urlObj = Qs.stringify(obj)
      uni.request({
        url:
          uni.$u.http.config.baseURL +"/"+ url,
        responseType: 'arraybuffer',//接收格式
        method: 'POST',
        data: urlObj,
        header: {
          'Content-Type': 'application/x-www-form-urlencoded',
          Authorization: getToken(),
        },
        success: async (data) => {
          const blob = new Blob([data.data])
          let a = document.createElement('a')
          let href = window.URL.createObjectURL(blob) //创建下载的链接
          a.href = href
          a.download = `${name}${new Date().getTime()}.xlsx` //下载后文件名
          document.body.appendChild(a)
          a.click() //点击下载
          document.body.removeChild(a) //下载完成移除元素
          window.URL.revokeObjectURL(href) //释放掉blob对象
        },
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.qiu {
  position: fixed;
  bottom: 200px;
  right: 20px;
  width: 58px;
  height: 58px;
  background: #ffffff;
  box-shadow: 0px 2px 20px 0px rgba(204, 204, 204, 0.5);
  border-radius: 50%;
  opacity: 1;
  text-align: center;

  font-size: 10px;
  font-family: PingFang HK-Medium, PingFang HK;
  font-weight: 500;
  color: #333333;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  img {
    width: 22px;
    height: 22px;
    margin-bottom: 10rpx;
  }
}
</style>