<template>
  <div class="sellReturnDetail pagePadding">
    <div style="display:flex;justify-content:flex-end;align-items:center">
        <el-button type="primary" plain size="mini" @click="visible = true">退货工单标记</el-button>
    </div>

    <div style="width: 100%" v-if="powers.some((i) => i == '007')">
      <el-tabs v-model="activeTabs">
        <el-tab-pane label="业务详情" name="1">
          <el-collapse v-model="activeNames" style="margin: -18px 0 0 0">
            <el-collapse-item title="退货工单详情" name="0">
              <show-data-table
                style="margin: 0; padding: 0"
                :sitem="sitem"
                v-if="status"
                :columns="showColumns"
              >
                <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="stock_type">
                  <el-tag size="mini">{{sitem.type === '1' ? '销售仓' : '次品仓'}}</el-tag>
                </template>

                <template slot="record">
                  <div class="ql-editor"  v-html="sitem.record"></div>
                </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>f=
                    <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="360" 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="returnWsm">
                  <span>{{ sitem.return_wsm_name }}</span>
                  <el-popover placement="top" width="360" trigger="hover">
                    <ul>
                      <li><h3>退货仓库</h3></li>
                      <li>
                        <span>编号:</span
                        ><span>{{ sitem.return_wsm_code }}</span>
                      </li>
                      <li>
                        <span>名称:</span
                        ><span>{{ sitem.return_wsm_name}}</span>
                      </li>
                      <li>
                        <span>负责人:</span
                        ><span>xx</span>
                      </li>
                      <li>
                        <span>供应商编码:</span
                        ><span>{{ sitem.return_supplierNo }}</span>
                      </li>
                      <li>
                        <span>供应商名称:</span
                        ><span>{{ sitem.return_supplierName }}</span>
                      </li>
                    </ul>
                    <i class="el-icon-warning-outline fr" slot="reference" />
                  </el-popover>
                </template>

                <template slot="sendWsm">
                  <span>{{ sitem.send_wsm_name }}</span>
                  <el-popover placement="top" width="360" trigger="hover">
                    <ul>
                      <li><h3>发货仓库</h3></li>
                      <li>
                        <span>编号:</span
                        ><span>{{ sitem.send_wsm_code }}</span>
                      </li>
                      <li>
                        <span>名称:</span
                        ><span>{{ sitem.send_wsm_name }}</span>
                      </li>
                      <li>
                        <span>负责人:</span
                        ><span>xx</span>
                      </li>
                      <li>
                        <span>供应商编码:</span
                        ><span>{{ sitem.send_supplierNo }}</span>
                      </li>
                      <li>
                        <span>供应商名称:</span
                        ><span>{{ sitem.send_supplierName }}</span>
                      </li>
                    </ul>
                    <i class="el-icon-warning-outline fr" slot="reference"></i>
                  </el-popover>
                </template>

                <template slot="customer">
                  <span>{{ sitem.customer_name }}</span>
                  <el-popover placement="top" width="360" trigger="hover">
                    <ul>
                      <li>
                        <span>客户公司编号:</span
                        ><span>{{ sitem.customer_code }}</span>
                      </li>
                    </ul>
                    <i class="el-icon-warning-outline fr" slot="reference"></i>
                  </el-popover>
                </template>
              </show-data-table>
            </el-collapse-item>

            <el-collapse-item title="商品信息" name="2">
              <show-goods-data-table :type="order_type" :spucode="spuCode" iscgd :newTime="newTime"  />
           </el-collapse-item>
          </el-collapse>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div v-else>
      <no-auth></no-auth>
    </div>

    <mark-modal :visible.sync="visible" :sitem="sitem" @reload="() => initData()" />
  </div>
</template>

<script>
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import asyncRequest from "@/apis/service/sellOut/returnGoodWorkOrder";
import { showColumns } from "./components/ShowDataTableColumns";
import { xs_order_type_options } from "@/assets/js/statusList";
import WorkOrderMark from "./components/work-order-mark.vue"
import MarkModal from "./components/mark-modal.vue";
import { mapGetters } from "vuex";

export default {
  name: "deliveryWorkOrderDetail",
  mixins: [mixinPage, resToken],
  components: { WorkOrderMark , MarkModal},
  computed: {
    ...mapGetters(['isSupertube']),
    powers() {
      const {btnList} = this.$store.getters;
      const tran = btnList.find((item) => item.menu_route == "supplierReturnWorkOrderDetail" ) || {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },
  data() {
    return {
      activeTabs: "1",
      visible: false,
      spuCode:"",
      order_type:"",
      showColumns: showColumns,
      statusOptions: [
        { value: "1", label: "待主流程收货" },
        { value: "2", label: "主流程已收货" }
      ],
      xs_order_type_options,
      sitem: null, //传给组件
      activeNames: ["0", "1", "2", "3", "4", "5", "6"],
      status: "", //存储详情接口状态
      statusList: [
        { value: "1", label: "待收货" },
        { value: "2", label: "已收货" }
      ],
      newTime: "",
      loading: false,
      is_stock: "",
      queryId: "",
    };
  },
  mounted() {
    this.queryId = this.$route.query.id;
    this.initData();
  },
  methods: {
    async initData() {
      const { code, data, message } = await asyncRequest.detail({
        id: this.queryId,
      });
      if (code === 0) {
        const { is_stock, status ,spuCode,order_type } = data;
        this.spuCode = spuCode
        this.order_type = order_type
        this.is_stock = is_stock;
        this.status = status;
        this.sitem = data;
        this.getNewTime();
      } else if (code >= 100 && code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(message);
      }
    },
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
  },
};
</script>
