<template>
  <div>
    <detailDatatable
      style="margin: 0; padding: 0"
      :sitem="sitem"
      :columns="columns"
      v-if="sitem"
      :border="true"
    >
      <template slot="status">
        <el-tag
          :size="'mini'"
          v-text="
            (statusOptions.find((item) => item.value == 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="supplierName">
        <span>{{ sitem.supplierName }}</span>
        <el-popover placement="top" width="300" trigger="hover">
          <ul>
            <li>
              <span>销售方公司编号：</span><span>{{ sitem.supplierNo }}</span>
            </li>
          </ul>
          <i class="el-icon-warning-outline fr" slot="reference"></i>
        </el-popover>
      </template>
      <template slot="companyName">
        <span>{{ sitem.companyName }}</span>
        <el-popover placement="top" width="300" trigger="hover">
          <ul>
            <li>
              <span>购买方公司编号：</span><span>{{ sitem.companyNo }}</span>
            </li>
          </ul>
          <i class="el-icon-warning-outline fr" slot="reference"></i>
        </el-popover>
      </template>
      <template slot="is_active">
        <span v-if="sitem.order_type === '1' || sitem.order_type === '2'"
          ><span
            >{{ sitem.is_activity === "1" ? "参与活动" : "不参与活动" }}/{{
              (goodtype_options.find((item) => item.value == sitem.good_type) || {})
                .label || "--"
            }}</span
          ></span
        >
        <span v-else>--</span>
      </template>
      <template slot="proof_id">
        <el-popover
          placement="top"
          width="300"
          trigger="hover"
          v-if="sitem.proof_type === '1'"
        >
          <video width="275" controls class="fl">
            <source :src="sitem.proof_url" type="video/mp4" />
            <source :src="sitem.proof_url" type="video/avi" />
            您的浏览器不支持Video标签。
          </video>
          <i
            class="el-icon-video-camera-solid hover"
            style="font-size: 18px"
            slot="reference"
          ></i>
        </el-popover>

        <img
          v-else-if="sitem.proof_type === '2'"
          style="width: 28px; height: 28px"
          :src="sitem.proof_url"
          class="avatar fl hover"
          v-viewer
        />

        <a
          v-else-if="sitem.proof_type === '3'"
          :href="sitem.proof_url"
          download="凭证文件"
          >点击下载</a
        >
        <span v-else>暂无凭证</span>
      </template>
      <template slot="send_type">
        <el-tag :size="'mini'">{{
          sitem.send_type === "1"
            ? "直接发货"
            : sitem.send_type === "2"
            ? "延迟发货"
            : "--"
        }}</el-tag>
      </template>

      <template slot="sale_price">
        <span
          v-if="
            newTime !== '' &&
            private_field &&
            private_field.length > 0 &&
            private_field.some((item) => item == '2')
          "
          >{{ sitem.sale_price }}元</span
        >
        <span v-else>******</span>
      </template>
      <template slot="total_price">
        <span
          v-if="
            newTime !== '' &&
            private_field &&
            private_field.length > 0 &&
            private_field.some((item) => item == '2')
          "
          >{{ sitem.total_price }}元</span
        >
        <span v-else>******</span>
      </template>
    </detailDatatable>
  </div>
</template>

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

//————————————————
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import asyncRequest from "@/apis/service/sellOut/salesOrder/detail";
import detailDatatable from "../detail-data-table";

import { mapGetters } from "vuex";

export default {
  mixins: [mixinPage, resToken],
  components: {
    detailDatatable,
  },
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size", "private_field"]),
    powers() {
      const tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "standingBookDetail"
        ) || {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },
  props: ["queryId"],
  data() {
    return {
      // cg_order_type_options,
      statusOptions,
      orderCode: "",
      xs_order_type_options,
      goodtype_options: [
        {
          value: "1",
          label: "常规商品",
        },
        {
          value: "2",
          label: "赠品",
        },
        {
          value: "3",
          label: "样品",
        },
      ],
      // cost_detailArr: [],

      //——————————————————————
      columns,
      newTime: "",
      status: "",
      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;
        this.status = this.sitem.status;
        this.orderCode = this.sitem.orderCode;
        this.getNewTime();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
      this.loading = false;
    },
  },
};
</script>

<style></style>
