<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      :rules="rules"
      label-width="68px"
    >
      <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="Search"
          @click="handleExport('changchun')"
          >导出长春</el-button
        >
        <el-button type="primary" icon="Search" @click="handleExport('foshan')"
          >导出佛山青岛</el-button
        >
        <el-button type="primary" icon="Search" @click="handleExport('guowai')"
          >导出国外</el-button
        >
        <el-button type="info" plain icon="Refresh" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup name="Excel">
import { exportOut } from "@/api/excel";
const uploadImgUrl = ref(import.meta.env.VITE_APP_BASE_API + "/profile/upload");

const { proxy } = getCurrentInstance();

const linuxAccessList = ref([]);
const loading = ref(true);

const data = reactive({
  queryParams: {
    orderNo: null,
    type: "changchun",
  },
  rules: {
    orderNo: [
      {
        required: true,
        message: "订单号不能为空",
        trigger: "blur",
      },
      {
        max: 50,
        message: "字符长度不得超于50",
        trigger: "blur",
      }
    ]
  }
});

const { queryParams, rules } = toRefs(data);

/** 搜索按钮操作 */
function handleQuery() {
  handleExport();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
}

/** 导出按钮操作 */
function handleExport(type) {
  proxy.$refs["queryRef"].validate((valid) => {
    if (valid) {
      loading.value = true;
      queryParams.value.type = type;
      exportOut(queryParams.value).then((response) => {
        response.data.forEach((item) => {
          window.open(uploadImgUrl.value + "/" + item, "_blank");
        });
        loading.value = false;
      });
    }
  });
}
</script>
