<template>
  <div>
    <detailDatatable
      style="padding: 10px 0 5px 0"
      :newTime="newTime"
      v-if="newTime !== '' && sitem"
      :sitem="sitem"
      :columns="columns"
      :border="true"
    >
      <template slot="status">
        <el-tag
          :size="tablebtnSize"
          v-text="(options.find((item) => item.id == sitem.status) || {}).label || '--'"
        ></el-tag>
      </template>

      <template slot="departinfo">
        <span>{{ sitem.salesman }}--</span>
        <span v-for="(si, sii) in sitem.departinfo" :key="si + sii"
          ><span v-if="sii !== 0">/</span>{{ si.name }}</span
        >
      </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="khName">
        <span>{{ sitem.khname }}</span>
        <el-popover placement="top" width="300" trigger="hover">
          <ul>
            <li>
              <span>购买方公司编号：</span><span>{{ sitem.khNo }}</span>
            </li>
          </ul>
          <i class="el-icon-warning-outline fr" slot="reference"></i>
        </el-popover>
      </template>
      <template slot="is_project">
        <span
          v-text="is_project_options.find((item) => item.value == sitem.is_project).label"
        ></span>
      </template>

      <template slot="is_custom">
        <span
          v-text="is_custom_options.find((item) => item.value == sitem.is_custom).label"
        ></span>
      </template>

      <template slot="cat_id">
        <span v-for="(item, index) in sitem.can" :key="item.id + item.name">
          {{ item.name }} <span v-if="index + 1 < sitem.can.length">_</span>
        </span>
      </template>

      <template slot="is_gold_price">
        <span
          v-text="
            is_gold_price_options.find((item) => item.value == sitem.is_custom).label
          "
        ></span>
      </template>

      <template slot="good_img">
        <div class="btnupload">
          <img
            v-if="sitem.good_img"
            :src="sitem.good_img"
            style="height: 23px; display: block"
            v-viewer
            class="hover"
          />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </div>
      </template>

      <template slot="specinfo">
        <el-table
          :data="sitem.specinfo"
          :size="'mini'"
          border
          style="width: 90%; margin: auto"
          height="130px"
        >
          <el-table-column prop="spec_name" label="规格类型" />
          <el-table-column prop="spec_value_name" label="规格值" />
        </el-table>
      </template>

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

<script>
import { columns } 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/zixunOrder";
import { mapGetters } from "vuex";
import detailDatatable from "../detail-data-table";

export default {
  mixins: [mixinPage, resToken],
  components: {
    detailDatatable,
  },
  props: ["queryId"],
  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 ?? [];
    },
  },
  data() {
    return {
      options: [
        { id: "0", label: "待发布竞标" },
        { id: "1", label: "招标进行中" },
        { id: "2", label: "招标已结束" },
        { id: "3", label: "待选择商品" },
        { id: "4", label: "已选商品待下单" },
        { id: "5", label: "已成功转单" },
        { id: "6", label: "已取消转单" },
        { id: "7", label: "招标已暂停" },
      ],
      is_project_options: [
        { value: "0", label: "非项目" },
        { value: "1", label: "项目" },
      ],
      is_addrs_options: [
        { value: "0", label: "一地" },
        { value: "1", label: "多地" },
      ],
      is_custom_options: [
        { value: "0", label: "非定制" },
        { value: "1", label: "定制" },
      ],
      is_gold_price_options: [
        { value: "0", label: "不启用" },
        { value: "1", label: "启用" },
      ],

      //——————————————————————
      status: "",
      columns,
      newTime: "",
      sitem: null,
      loading: false,
    };
  },
  mounted() {
    this.initData();
  },
  methods: {
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
    async initData() {
      this.loading = true;
      const { code, message, data } = await asyncRequest.detail({
        infoNo: this.queryId,
      });
      this.loading = false;
      console.log(data);
      if (code === 0) {
        this.sitem = JSON.parse(JSON.stringify(data));
        const { status, can } = this.sitem;
        if (can && can.length > 0) {
          let cat_id = [];
          can.forEach((e) => {
            cat_id.push(e.id);
          });
          this.sitem.cat_id = cat_id;
        } else {
          this.sitem.cat_id = [];
        }

        this.status = status;
        this.getNewTime();
      } else if (code >= 100 && code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(message);
      }
    },
  },
};
</script>

<style></style>
