<template>
  <el-dialog v-model="dialog" title="自动上传信息" @closed="emit('close')">
    <el-form label-width="120px">
      <el-form-item label="日期">
        <el-date-picker
            v-model="dateRange"
            type="daterange"
            format="YYYY-MM-DD"
            placeholder="开始日期"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :shortcuts="shortcuts"
            style="width: 120px"
            value-format="YYYY-MM-DD"
        />
      </el-form-item>
    </el-form>

    <template #footer>
      <el-button type="primary" @click="ExportToExcel">导出Excel</el-button>
    </template>
  </el-dialog>
</template>

<script setup name='ExportAutoUploadInfo'>
import {shortcuts} from '@/data/shortcuts'
import {onMounted} from "vue";
import {getServerDateApi} from "@/api/public-api";
import moment from "moment";
import {getFormatDatetime} from "@/utils/date";
import {downloadExcel} from "@/utils/excel";

const emit = defineEmits(['close'])

const dialog = ref(true)
let dateRange = $ref([])

const ExportToExcel = async () => {
  if (!dateRange) return
  const data = {
    param: {startTime: dateRange[0], endTime: dateRange[1]},
    url: '/setlListUpld/exportAutoUploadInfo',
    fileName: `${dateRange[0]}至${dateRange[1]}.xlsx`,
  }
  setTimeout(() => {
    downloadExcel(data)
  }, 500)
}

onMounted(async () => {
  let res = await getServerDateApi()
  let date = getFormatDatetime(res, 'YYYY-MM-DD')
  let date1 = getFormatDatetime(moment(date).subtract(1, 'days')._d, 'YYYY-MM-DD')
  dateRange[0] = date1
  dateRange[1] = date1
})

</script>

<style scoped>

</style>
