<template>
  <div class="app-container" style="width: 50%">
    <el-form v-loading="loading">
      <el-form-item label="转单号" label-width="100px">
        <el-input
          v-model="SysmteNos"
          type="textarea"
          :rows="25"
          placeholder="请输入转单号,每行一个"
        />
      </el-form-item>
    </el-form>
    <div class="text-center">
      <el-button type="success" @click="submit" v-loading="loading">确认推送</el-button>
    </div>
  </div>
</template>
<script>
import axios from "axios";
import { getToken } from "@/utils/auth";
export default {
  name: "ManualPush",
  data: function () {
    return {
      loading: false,
      SysmteNos: "",
      submitLoading: false,
      errorTip: "",
    };
  },
  methods: {
    submit() {
      if (!this.SysmteNos) {
        this.$message({ message: "请填写转单号单号", type: "error" });
        return;
      }
      const SysmteNos = this.SysmteNos.split(/[\n,]/);
      if (this.loading) {
        return false;
      }
      this.loading = true;
      const url = process.env.VUE_APP_BASE_API + "/Tracking/OnlineOrderPush";
      axios({
        method: "post",
        url: url,
        data: SysmteNos,
        responseType: "blob",
        headers: { token: getToken() },
      })
        .then((res) => {
          const _res = res.data;
          const blob = new Blob([res.data], { type: res.data.type });

          var url = window.URL.createObjectURL(blob);
          var a = document.createElement("a");
          a.href = url;
          a.download = `推送结果.xlsx`;
          a.click();
        })
        .catch((err) => {
          this.$message({ type: "error", message: "获取推送将结果出错" });
          this.loading = false;
        })
        .finally(() => {
          this.loading = false;
        });
    },
  },
};
</script>