<template>
  <div class="page-box">
    <div class="print-box">
      <el-button type="primary" icon="el-icon-printer" @click="print"
        >打印</el-button
      >
    </div>
    <div class="card-box" id="print">
      <div class="title">
        <h5>Result Details</h5>
      </div>
      <div class="content-box">
        <div class="base-info">
          <div>任务ID：{{ jobId }}</div>
          <div>
            Status:
            <el-tag type="info">{{ getStatus(detail.status) }}</el-tag>
          </div>
        </div>
      </div>
      <div>
        <el-row>
          <el-col :span="12"
            ><img v-if="detail.SC_GRS" :src="detail.SC_GRS" alt=""
          /></el-col>
          <el-col :span="12"
            ><img
              v-if="detail.SC_GRS_prob_pre"
              :src="detail.SC_GRS_prob_pre"
              alt=""
          /></el-col>
        </el-row>
        <el-row>
          <el-col :span="24" class="txt_box">
            <div>title: SC_GRS 超过0.5的数据下标</div>
            <br />
            <div>
              <p v-if="detail.SC_GRS_list.length">
                {{ detail.SC_GRS_list.toString().replace(/,/g, "，") }}
              </p>
              <span v-else>暂无预测数据</span>
            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12"
            ><img v-if="detail.OR_GRS" :src="detail.OR_GRS" alt=""
          /></el-col>
          <el-col :span="12"
            ><img
              v-if="detail.OR_GRS_prob_pre"
              :src="detail.OR_GRS_prob_pre"
              alt=""
          /></el-col>
        </el-row>
        <el-row>
          <el-col :span="24" class="txt_box">
            <div>title: OR_GRS 超过0.5的数据下标</div>
            <br />
            <div>
              <p v-if="detail.OR_GRS_list.length">
                {{ detail.OR_GRS_list.toString().replace(/,/g, "，") }}
              </p>
              <span v-else>暂无预测数据</span>
            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12"
            ><img v-if="detail.DL_GRS" :src="detail.DL_GRS" alt=""
          /></el-col>
          <el-col :span="12"
            ><img
              v-if="detail.DL_GRS_prob_pre"
              :src="detail.DL_GRS_prob_pre"
              alt=""
          /></el-col>
        </el-row>
        <el-row>
          <el-col :span="24" class="txt_box">
            <div>title: DL_GRS 超过0.5的数据下标</div>
            <br />
            <div>
              <p v-if="detail.DL_GRS_list.length">
                {{ detail.DL_GRS_list.toString().replace(/,/g, "，") }}
              </p>
              <span v-else>暂无预测数据</span>
            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12"
            ><img v-if="detail.t_alt_count" :src="detail.t_alt_count" alt=""
          /></el-col>
          <el-col :span="12"
            ><img v-if="detail.t_depth" :src="detail.t_depth" alt=""
          /></el-col>
        </el-row>

        <el-row>
          <el-col :span="12"
            ><img v-if="detail.t_ref_count" :src="detail.t_ref_count" alt=""
          /></el-col>
          <el-col :span="12"
            ><img v-if="detail.Variant_Type" :src="detail.Variant_Type" alt=""
          /></el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
import { createOrder, orderDetail } from "@/api";
export default {
  name: "result",
  data() {
    return {
      jobId: "",
      detail: {},
    };
  },
  mounted() {
    this.jobId = this.$route.query.jobId;
    this.getDetailFn();
  },
  methods: {
    async getDetailFn() {
      if (!this.jobId) return;
      const res = await orderDetail({
        id: this.jobId,
      });
      if (res.code === 200) {
        this.detail = res.data;
      }
    },
    getTag(row) {
      if (row.status === "success") {
        return "success";
      }
      if (row.status === "waiting") {
        return "info";
      }
      return "danger";
    },
    getStatus(status) {
      if (status === 0) {
        return "已创建";
      }
      if (status === 1) {
        return "已创建任务";
      }
      if (status === 2) {
        return "任务运行中";
      }
      if (status === 3) {
        return "已完成";
      }
      return "正在初始化中";
    },
    print() {
      console.log("82 print");
      // 缓存页面内容
      const bodyHtml = window.document.body.innerHTML;
      // 获取要打印的dom
      const printContentHtml = document.getElementById("print").innerHTML;
      // 替换页面内容
      window.document.body.innerHTML = printContentHtml;
      // 全局打印
      window.print();
      // 还原页面内容
      window.document.body.innerHTML = bodyHtml;
    },
  },
};
</script>
<style lang="less" scoped>
.page-box {
  padding: 24px;
  position: relative;

  .print-box {
    position: absolute;
    right: 50px;
    top: 100px;
  }

  .card-box {
    background-color: rgb(255, 255, 255);
    color: rgba(0, 0, 0, 0.87);
    transition: box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
    border-radius: 4px;
    box-shadow: rgba(0, 0, 0, 0.2) 0px 3px 3px -2px,
      rgba(0, 0, 0, 0.14) 0px 3px 4px 0px, rgba(0, 0, 0, 0.12) 0px 1px 8px 0px;
    min-width: 300px;
    margin-top: 16px;
    margin-bottom: 16px;
    overflow: hidden;
    padding-right: 15px;
    padding-top: 15px;
    padding-bottom: 15px;

    .txt_box {
      padding: 40px;
      p {
        white-space: pre-wrap;
      }
    }

    .title {
      border-left: 6px solid rgb(246, 144, 61);
      border-top-color: rgb(246, 144, 61);
      border-right-color: rgb(246, 144, 61);
      border-bottom-color: rgb(246, 144, 61);
      background-color: rgb(16, 126, 100);
      color: rgb(255, 255, 255);
      padding: 8px 8px 8px 16px;

      h5 {
        font-size: 24px;
        margin: 0px;
        font-family: Roboto, Helvetica, Arial, sans-serif;
        font-weight: 400;
        font-size: 1.5rem;
        line-height: 1.334;
        letter-spacing: 0em;
        display: flex;
        -webkit-box-align: center;
        align-items: center;
      }
    }

    .content-box {
      display: flex;

      .base-info {
        width: 150px;
        padding: 15px;
      }
    }
  }
}
</style>
