<template>
  <div>
    <el-dialog title="详情" :visible.sync="dialogTableVisible" width="1280px">
      <detailDatatable
        style="margin: 0; padding: 0"
        v-if="sitem"
        :newTime="newTime"
        :sitem="sitem"
        :columns="columns"
        :border="true"
      >
        <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="is_act">
          <el-tag
            :size="'mini'"
            v-text="
              (is_act_options.find((item) => item.value == sitem.is_act) || {}).label ||
              '--'
            "
          ></el-tag>
        </template>
        <template slot="customer_remark">
          <el-tag
            :size="'mini'"
            v-if="sitem.is_act === '1'"
            v-text="
              (
                customer_remark_options.find(
                  (item) => item.value == sitem.customer_remark
                ) || {}
              ).label || '--'
            "
          ></el-tag>
          <el-tag :size="'mini'" v-else v-text="'--'"></el-tag>
        </template>
      </detailDatatable>
    </el-dialog>

    <ex-table
      v-loading="loading"
      :table="table"
      :data="tableData"
      :columns="listColumns"
      :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="
            (listStatusOptions.find((item) => item.id == 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.id)"></i>
        </el-tooltip>
      </template>
    </ex-table>
  </div>
</template>

<script>
import { columns, listColumns } 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/sellOut/zxDiffOrder";
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 {
      parmValue: {
        zxNo: "", // 竞价单编码
        khNo: "", // 客户编码
        cpName: "", //商品名称
        status: "", //竞价类型
        salesman: "", //申请人
        start: "",
        end: "",
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        // _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      listColumns,
      loading: true,
      dialogTableVisible: false,

      xs_order_type_options,
      // statusOptions,
      activeTabs: "1",
      activeNames: ["-1", "0", "1", "2", "3", "4", "5", "10"],
      statusOptions: [
        { value: "1", label: "待业务部门审核" },
        { value: "2", label: "审批已完成" },
      ],
      listStatusOptions: [
        { id: "1", label: "待业务部门审核" },
        { id: "2", label: "工差单审核完成" },
      ],
      xs_order_type_options,
      customer_remark_options: [
        {
          value: "1",
          label: "竞价订单减工差",
        },
        {
          value: "2",
          label: "竞价订单不减工差",
        },
      ],
      is_act_options: [
        {
          value: "1",
          label: "接受工差",
        },
        {
          value: "2",
          label: "不接受工差-退回重做",
        },
      ],
      // cost_detailArr: [],

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

      const res = await asyncRequest.list(this.parmValue);
      if (res && res.code === 0 && res.data) {
        this.tableData = res.data.list;
        this.tableData.map((v) => {
          v.sale_price = this.setNum(v.sale_price);
          v.sale_fee = this.setNum(v.sale_fee);
          v.class_cat = "";
          if (v.can && v.can.length > 0) {
            v.can.forEach((x, i) => {
              v.class_cat += i === 0 ? x.name : "/" + x.name;
            });
          }
          return v;
        });
        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(id) {
      this.dialogTableVisible = true;
      this.initData(id);
    },
  },
};
</script>

<style></style>
