<template>
  <div>
    <el-dialog title="详情" :visible.sync="dialogTableVisible" width="1280px">
      <detailDatatable
        :newTime="newTime"
        v-if="newTime !== ''"
        :sitem="sitem"
        :columns="columns"
        :border="true"
      >
        <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>
      </detailDatatable>
    </el-dialog>

    <ex-table
      v-loading="loading"
      :table="table"
      :data="tableData"
      :columns="listColumens"
      :page="pageInfo"
      :size="size"
      @page-curr-change="handlePageChange"
      @page-size-change="handleSizeChange"
      @screen-reset="
        pageInfo.curr = 1;
        parmValue.page = 1;
        searchList();
      "
      @screen-submit="
        pageInfo.curr = 1;
        parmValue.page = 1;
        searchList();
      "
    >
      <template #status="{ scope }">
        <el-tag
          :size="tablebtnSize"
          :type="scope.row.status == '0' ? 'warning' : ''"
          v-text="
            (statusList.find((item) => item.value == scope.row.status) || {}).label ||
            '--'
          "
        ></el-tag>
      </template>
      <template #operation="{ scope }">
        <el-tooltip effect="dark" content="详情" placement="top">
          <i class="el-icon-view tb-icon" @click="dilog(scope.row.thNo)"></i>
        </el-tooltip>
      </template>
    </ex-table>
  </div>
</template>

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

export default {
  components: {
    detailDatatable,
  },
  mixins: [mixinPage, resToken],
  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 {
      loading: true,
      dialogTableVisible: false,
      parmValue: {
        order_type: "",
        order_code: "", //销售订单编号
        thNo: "", //退货编号
        out_code: "", //销售出库编号
        return_code: "", //售后退货编号
        post_compay: "", //物流公司
        post_code: "", //物流单号
        start: "", //
        end: "", //
        status: "", //状态节点
        customer_code: "", //退货客户编号
        supplierName: "",
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        // _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      listColumens,
      statusList: [
        { value: "0", label: "待申请" },
        { value: "1", label: "待验收" },
        { value: "2", label: "待验收审核" },
        { value: "3", label: "待业务审核" },
        { value: "4", label: "完成退货" },
      ],
      // cg_order_type_options,
      orderCode: "",
      statusOptions,
      // cost_detailArr: [],

      //——————————————————————
      columns,
      newTime: "",
      status: "",
      sitem: null,
      loading: false,
    };
  },
  mounted() {
    this.searchList();
  },
  methods: {
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
    async initData(code) {
      this.newTime = "";
      let model = {
        thNo: code,
      };
      const res = await asyncRequest.detail(model);
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;
        const { status, orderCode, can } = this.sitem;
        this.status = status;
        this.orderCode = orderCode;
        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);
      }
    },

    async searchList() {
      //通过订单编号去查询所有列表、当订单编号为空时，所有涉及字段不展示
      this.parmValue.order_code = this.queryId;
      this.loading = true;

      let model = JSON.parse(JSON.stringify(this.parmValue));
      model.post_compay = model.post_compay.toString();
      const res = await asyncRequest.list(model);
      if (res && res.code === 0 && res.data) {
        this.tableData = res.data.list;
        this.pageInfo.total = Number(res.data.count);
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.tableData = [];
        this.pageInfo.total = 0;
      }
      this.loading = false;
    },
    dilog(thNo) {
      this.dialogTableVisible = true;
      this.initData(thNo);
    },
  },
};
</script>

<style></style>
