<template>
  <div>
    <detailDatatable
      :newTime="newTime"
      v-if="sitem"
      :sitem="sitem"
      :columns="columns"
    >
      <template slot="status">
        <el-tag
          :size="'mini'"
          :type="sitem.status == '0' ? 'warning' : ''"
          v-text="
            (
              (sitem.is_receive === '0' ? status2Options : status1Options).find(
                (item) => item.id === sitem.status
              ) || {}
            ).label || '--'
          "
        ></el-tag>
      </template>
      <template slot="order_type">
        <el-tag
          :size="'mini'"
          v-text="
            (
              xs_order_type_options.find(
                (item) => item.id == sitem.order_type
              ) || {}
            ).label || '--'
          "
        ></el-tag>
      </template>
      <template slot="is_receive">
        <el-tag :size="'mini'" :type="''">{{
          sitem.is_receive === "1"
            ? "已收到货"
            : sitem.is_receive === "0"
            ? "未收到"
            : "--"
        }}</el-tag>
      </template>
      <template slot="except_code">
        <el-tag
          :size="'mini'"
          v-text="
            (
              expect_options.find((item) => item.value == sitem.except_code) ||
              {}
            ).label || '--'
          "
        ></el-tag>
      </template>

      <template slot="error_img">
        <img
          class="fl hover"
          style="width: 23px; height: 23px; margin: 0 5px 0 0"
          v-viewer
          v-for="(si, i) in sitem.error_img"
          :src="si"
          :key="si + i"
        />
      </template>
    </detailDatatable>
  </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/sellOut/sellAfterApply";
import { xs_order_type_options } from "@/assets/js/statusList";
import { mapGetters } from "vuex";
import detailDatatable from "../detail-data-table";

export default {
  mixins: [mixinPage, resToken],
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size", "private_field"]),
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "standingBookDetail"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  components:{
    detailDatatable
  },
  props: ["queryId"],
  data() {
    return {
      // cg_order_type_options,
      xs_order_type_options,
      activeTabs: "1",
      expect_options: [],
      expect_options1: [
        {
          value: "1",
          label: "退货",
        },
        {
          value: "2",
          label: "换货",
        },
      ],
      expect_options0: [
        {
          value: "1",
          label: "退货",
        },
        {
          value: "2",
          label: "补发",
        },
      ],
      activeNames: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
      status: "", //存储详情接口状态
      statusList: [],
      sitem: null,
      newTime: "",
      loading: false,
      // 收到货状态
      status1Options: [
        { id: "1", label: "待业务审核" },
        { id: "2", label: "待采购审核" },
        { id: "3", label: "待设置仓库" },
        { id: "4", label: "待客户退货" },
        { id: "5", label: "售后已完成" },
        { id: "6", label: "业务已驳回" },
        { id: "7", label: "采购已驳回" },
        { id: "8", label: "申请已取消" },
      ],
      // 未收到货状态
      status2Options: [
        { id: "1", label: "待业务审核" },
        { id: "2", label: "待采购审核" },
        { id: "3", label: "待同意退货" },
        { id: "5", label: "售后已完成" },
        { id: "6", label: "业务已驳回" },
        { id: "7", label: "采购已驳回" },
        { id: "8", label: "申请已取消" },
      ],
      orderCode: "",
      return_code: "",
      code: "",
      // cost_detailArr: [],

      //——————————————————————
      columns,
      
    };
  },
  mounted() {
    this.initData();
  },
  methods: {
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
    async initData() {
      let model = {
        returnCode: this.queryId,
      };
      const res = await asyncRequest.detail(model);
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;
        const { status, can, returnCode } = this.sitem;
        this.status = status;
        this.orderCode = returnCode;
        this.sitem.error_img = this.sitem.error_img.split(",");
        this.expect_options = JSON.parse(
          JSON.stringify(
            this.sitem.is_receive === "1"
              ? this.expect_options1
              : this.expect_options0
          )
        );
        this.getNewTime();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },
  },
};
</script>

<style>
</style>