<template>
  <div>
    <detailDatatable
      style="padding: 10px 0 5px 0"
      :newTime="newTime"
      v-if="sitem"
      :sitem="sitem"
      :columns="columns"
      :border="true"
    >
      <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="ocr_status">
        <el-tag
          :size="'mini'"
          :type="
            sitem.ocr_status == '0'
              ? 'info'
              : sitem.ocr_status == '1'
              ? 'primary'
              : sitem.ocr_status == '2'
              ? 'danger'
              : ''
          "
          v-text="
            (ocr_status.find((item) => item.id == sitem.ocr_status) || {}).label || '--'
          "
        ></el-tag>
      </template>

      <template slot="coop_state">
        <span>{{ sitem.coop_state }}</span>
        <!-- <span
          v-text="
            (
              coop_stateoptions.find(
                (item) => item.value == sitem.coop_state
              ) || {}
            ).label || '--'
          "
        ></span> -->
      </template>

      <template slot="source">
        <span>{{ sitem.source }}</span>

        <!-- <span
          v-text="
            (
              sourceoptions.find(
                (item) => item.value == sitem.source
              ) || {}
            ).label || '--'
          "
        ></span> -->
      </template>
      <template slot="type">
        <span>{{ sitem.type }}</span>

        <!-- <span
          v-text="
            (
              typeoptions.find(
                (item) => item.value == sitem.type
              ) || {}
            ).label || '--'
          "
        ></span> -->
      </template>
      <template slot="category">
        <span>{{ sitem.category }}</span>

        <!-- <span
          v-text="
            (
              categoryoptions.find(
                (item) => item.value == sitem.category
              ) || {}
            ).label || '--'
          "
        ></span> -->
      </template>
      <template slot="delivery_way">
        <span>{{ sitem.delivery_way }}</span>
        <!-- <span
          v-text="
            (
              delivery_wayoptions.find(
                (item) => item.value == sitem.delivery_way
              ) || {}
            ).label || '--'
          "
        ></span> -->
      </template>
      <template slot="supplier_type">
        <span>{{ sitem.supplier_type }}</span>
        <!-- <span
          v-text="
            (
              supplier_typeoptions.find(
                (item) => item.value == sitem.supplier_type
              ) || {}
            ).label || '--'
          "
        ></span> -->
      </template>
      <template slot="level">
        <span>{{ sitem.level }}</span>
        <!-- <span
          v-text="
            (
              leveloptions.find(
                (item) => item.value == sitem.level
              ) || {}
            ).label || '--'
          "
        ></span> -->
      </template>
      <template slot="pay_type">
        <span>{{ sitem.pay_type }}</span>
        <!-- <span
          v-text="
            (
              pay_typeoptions.find(
                (item) => item.value == sitem.pay_type
              ) || {}
            ).label || '--'
          "
        ></span> -->
      </template>

      <template slot="supplier_img">
        <img
          :src="sitem.supplier_img"
          class="avatar hover fl"
          v-viewer
          style="height: 23px; display: block"
        />
      </template>
      <template slot="prove_img">
        <img
          v-for="img in sitem.prove_img"
          v-if="img != ''"
          :key="img"
          :src="img"
          class="avatar hover fl"
          v-viewer
          style="height: 23px; display: block"
        />
      </template>
    </detailDatatable>
  </div>
</template>

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

//————————————————
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import asyncRequest from "@/apis/service/serviceParam/supplier";
import { mapGetters } from "vuex";
import detailDatatable from "../detail-data-table";

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 {
      xs_order_type_options,
      // 状态
      statusOptions: [
        { id: "0", label: "禁用" },
        { id: "1", label: "启用" },
      ],
      ocr_status: [
        { id: "0", label: "未上传" },
        { id: "1", label: "识别成功" },
        { id: "2", label: "识别失败" },
      ],

      coop_stateoptions: [
        { value: "0", label: "白名单" },
        { value: "1", label: "黑名单" },
      ],
      sourceoptions: [
        { value: "0", label: "客户提供" },
        { value: "1", label: "供应商" },
        { value: "2", label: "公司开发" },
      ],
      typeoptions: [
        { value: "0", label: "正式供应商" },
        { value: "1", label: "临时供应商" },
      ],
      categoryoptions: [
        { value: "0", label: "单品类供应商" },
        { value: "1", label: "多品类供应商" },
      ],
      delivery_wayoptions: [
        { value: "0", label: "供应商发货" },
        { value: "1", label: "公司自提" },
      ],
      supplier_typeoptions: [
        { value: "0", label: "生产厂家" },
        { value: "1", label: "代理商" },
        { value: "2", label: "经销商" },
        { value: "3", label: "分销商" },
        { value: "4", label: "电商平台" },
      ],
      leveloptions: [
        { value: "2", label: "生产厂家" },
        { value: "0", label: "一级代理商" },
        { value: "1", label: "二级代理商" },
      ],
      pay_typeoptions: [
        { value: "0", label: "现结" },
        { value: "1", label: "月清" },
        { value: "2", label: "双月清" },
      ],
      ocr_status: [
        { id: "0", label: "未上传" },
        { id: "1", label: "识别成功" },
        { id: "2", label: "识别失败" },
      ],

      //——————————————————————
      columns,
      newTime: "",
      status: "",
      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({
        code: this.queryId,
      });
      this.loading = false;
      if (code === 0) {
        this.sitem = JSON.parse(JSON.stringify(data));

        const { status } = this.sitem;

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

<style lang="scss" scoped>
/deep/ .label {
  // width: 120px !important;
}
</style>
