<template>
  <div class="app-container">
    <el-form ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" prop="daterangeTime">
        <el-date-picker clearable
                        v-model="dt"
                        type="daterange"
                        value-format="YYYY-MM-DD"
                        start-placeholder="开始时间"
                        end-placeholder="结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
          <el-input-number v-model="days" :min="1" :max="30" />
      </el-form-item>
      <el-form-item>
        <el-button type="'warning" icon="Download" @click="impdata">导出</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script setup name="baipi">
import {ref} from "vue";

const {proxy} = getCurrentInstance();
const dt = ref([]);
const days = ref(10);
const showSearch = ref(true);

// 初始化日期
const initDate = () => {
  let day = new Date();
  day.setHours(day.getHours() - 7);
  day.setDate(day.getDate() - 1);
  let end = new Date(day).Format('yyyy-MM-dd');
  day.setDate(day.getDate() - 7);
  let start = new Date(day).Format('yyyy-MM-dd');
  dt.value = [start, end]
}

function impdata() {
  let uri = "api/export/order?start=" + dt.value[0] + "&end=" + dt.value[1] + "&days=" + days.value;
  proxy.download(uri, {}, `白坯布靶向智能生产预测${dt.value[0]}至${dt.value[1]}.zip`)
}

// 初始化
initDate();
</script>
