<template>
  <div>
    

    <show-data-table
      :newTime="newTime"
      v-if="newTime !== '' && sitem"
      :sitem="sitem"
      :columns="columns"
    >
      <template slot="status">
        <el-tag
          :size="'mini'"
          :type="sitem.status == '0' ? 'warning' : ''"
          v-text="
            (statusOptions.find((item) => item.id === sitem.status) || {})
              .label || '--'
          "
        ></el-tag>
      </template>
      <template slot="order_type">
        <el-tag
          :size="'mini'"
          v-text="
            (
              cg_order_type_options.find(
                (item) => item.id === sitem.order_type
              ) || {}
            ).label || '--'
          "
        ></el-tag>
      </template>
      <template slot="diff_is_act">
        <el-tag
          :size="'mini'"
          v-text="
            (
              is_act_options.find((item) => item.value === sitem.diff_is_act) ||
              {}
            ).label || '--'
          "
        ></el-tag>
      </template>
      <template slot="diff_customer_remark">
        <el-tag
          :size="'mini'"
          v-if="sitem.diff_is_act === '1'"
          v-text="
            (
              customer_remark_options.find(
                (item) => item.value === sitem.diff_customer_remark
              ) || {}
            ).label || '--'
          "
        ></el-tag>
        <el-tag :size="'mini'" v-else v-text="'--'"></el-tag>
      </template>
    </show-data-table>
  </div>
</template>

<script>
import { columns, statusOptions } from "./columns";
import { cg_order_type_options } from "@/assets/js/statusList";

//————————————————
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import asyncRequest from "@/apis/service/purchaseIn/purchaseDiffOrder";

export default {
  mixins: [mixinPage, resToken],
  props: ["queryId"],
  data() {
    return {
      cg_order_type_options,
      statusOptions,
      status: "",
      orderCode:"",
      customer_remark_options: [
        {
          value: "1",
          label: "竞价订单减工差",
        },
        {
          value: "2",
          label: "竞价订单不减工差",
        },
      ],
      is_act_options: [
        {
          value: "1",
          label: "接受工差",
        },
        {
          value: "2",
          label: "不接受工差-退回重做",
        },
      ],
      //——————————————————————
      columns,
      newTime: "",
      sitem: null,
      loading: false,
    };
  },
  mounted() {
    this.initData();
  },
  methods: {
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
    async initData() {
      this.loading = true;
      const res = await asyncRequest.detail({ id: this.queryId });
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;

        const { can, status, cgdNo } = this.sitem;
        this.status = status;
        this.orderCode = cgdNo;
        if (can && can.length > 0) {
          this.sitem.class_cat = "";
          can.forEach((x, i) => {
            this.sitem.class_cat += i === 0 ? x.name : "/" + x.name;
          });
        }

        this.getNewTime();
        // if (this.order_type === "2") {
        //   this.order_type = res.data.cgdNo;
        //   this.statusOptions.unshift({ value: "0", label: "竞价单" });
        // }
        // this.order_type === "1" ? "CGGCD" : "ZXGCD";
        // this.order_type = res.data.order_type;
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
      this.loading = false;
    },

  },
};
</script>

<style>
</style>