<template>
  <div>
    <detailDatatable
      :newTime="newTime"
      v-if="newTime !== '' && sitem"
      :sitem="sitem"
      :columns="columns"
      :border="true"
    >
      <template slot="supplier_name">
        <span>{{ sitem.supplier_name }}</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="company">
        <span>{{ sitem.company }}</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="status">
        <el-tag
          :size="'mini'"
          :type="sitem.status == '0' ? 'warning' : ''"
          v-text="
            (statusOptions.find((item) => item.value == 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>
        <el-popover
          placement="top"
          width="300"
          v-if="sitem.order_type === '1'"
          trigger="hover"
        >
          <ul>
            <li>
              <span>备库单编号：</span><span>{{ sitem.bkcode }}</span>
            </li>
          </ul>
          <i class="el-icon-warning-outline fr" slot="reference"></i>
        </el-popover>
        <el-popover
          placement="top"
          width="300"
          v-if="sitem.order_type !== '1'"
          trigger="hover"
        >
          <ul>
            <li>
              <span>订单编号：</span><span>{{ sitem.orderCode }}</span>
            </li>
          </ul>
          <i class="el-icon-warning-outline fr" slot="reference"></i>
        </el-popover>
      </template>

      <template slot="wsm">
        <span>{{ sitem.wsm_supplier }}/{{ sitem.wsm_name }}</span>
        <el-popover placement="top" width="300" trigger="hover">
          <ul>
            <li>
              <span>仓库公司编号：</span><span>{{ sitem.wsm_supplierNo }}</span>
            </li>
            <li>
              <span>仓库名称编号：</span><span>{{ sitem.wsm_code }}</span>
            </li>
          </ul>
          <i class="el-icon-warning-outline fr" slot="reference"></i>
        </el-popover>
      </template>

      <template slot="gold_price">
        <div
          v-if="
            sitem.status == '0' &&
            sitem.can[0].id == '6' &&
            cost_detailArr.is_gold_price == '1' &&
            private_field &&
            private_field.length > 0 &&
            private_field.some((item) => item == '1')
          "
        >
          {{ sitem.gold_price }}
        </div>
        <div v-else>----</div>
      </template>
      <template slot="customer">
        <span>{{ sitem.customer.companyName }}</span>
        <el-popover
          placement="top"
          width="300"
          trigger="hover"
          v-if="sitem.order_type != 1"
        >
          <ul>
            <li>
              <span>客户编号：</span><span>{{ sitem.customer.companyNo }}</span>
            </li>
          </ul>
          <i class="el-icon-warning-outline fr" slot="reference"></i>
        </el-popover>
      </template>

      <!-- <template slot="addr_info">
        <el-table
          :data="sitem.addr_info"
          :size="'mini'"
          border
          stripe
          style="width: 100%"
        >
        <el-table-column
            prop="receipt_quantity"
            label="发货数量"
            show-overflow-tooltip
            min-width="180px"
          >
          </el-table-column>
          <el-table-column
            prop="contactor"
            label="收货人"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column prop="mobile" label="联系电话" show-overflow-tooltip>
          </el-table-column>


          
        </el-table>
      </template> -->

      <template slot="total_fee">
        <span
          v-if="
            newTime !== '' &&
            private_field &&
            private_field.length > 0 &&
            private_field.some((item) => item == '1')
          "
          >{{ sitem.total_fee }}</span
        >
        <span v-else>******</span>
      </template>
      <template slot="good_price">
        <span
          v-if="
            newTime !== '' &&
            private_field &&
            private_field.length > 0 &&
            private_field.some((item) => item == '1')
          "
          >{{ sitem.good_price }}</span
        >
        <span v-else>******</span>
      </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/purchaseIn/purchaseOrder";
import { mapGetters } from "vuex";
import detailDatatable from "../detail-data-table";

export default {
  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 ?? [];
    },
  },
  components: {
    detailDatatable,
  },
  mixins: [mixinPage, resToken],
  props: ["queryId"],
  data() {
    return {
      cg_order_type_options,
      statusOptions,
      cost_detailArr: [],

      //——————————————————————
      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({ cgdNo: this.queryId });
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;
        // console.log("11111111111111111", this.sitem);
        this.goldPrice();
        const { status, can, cgdNo } = this.sitem;
        this.status = status;
        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();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
      this.loading = false;
    },
    async goldPrice() {
      let res = {};
      let { order_type } = this.sitem;
      if (order_type == "1" || order_type == "2") {
        res = await asyncRequest.cost_detail({ spuCode: this.sitem.spuCode });
      } else {
        res = await asyncRequest.cove_detail({ spuCode: this.sitem.spuCode });
      }
      if (res && res.code === 0 && res.data) {
        this.cost_detailArr = res.data;
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },
  },
};
</script>

<style></style>
