<template>
  <div>
    
<el-dialog title="详情" :visible.sync="dialogTableVisible" width="1280px">
    <detailDatatable
      :newTime="newTime"
      v-if="newTime !== '' && sitem"
      :sitem="sitem"
      :columns="columns"
    >
      <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="order_type">
        <el-tag
          :size="'mini'"
          v-text="
            (
              cg_order_type_options.find(
                (item) => item.id === sitem.order_type
              ) || {}
            ).label || '--'
          "
        ></el-tag>
      </template>
      <template slot="diff_is_act">
        <el-tag
          :size="'mini'"
          v-text="
            (
              is_act_options.find((item) => item.value === sitem.diff_is_act) ||
              {}
            ).label || '--'
          "
        ></el-tag>
      </template>
      <template slot="diff_customer_remark">
        <el-tag
          :size="'mini'"
          v-if="sitem.diff_is_act === '1'"
          v-text="
            (
              customer_remark_options.find(
                (item) => item.value === sitem.diff_customer_remark
              ) || {}
            ).label || '--'
          "
        ></el-tag>
        <el-tag :size="'mini'" v-else v-text="'--'"></el-tag>
      </template>
      <template slot="diff_price">
        <span
          v-if="
            newTime !== '' &&
            private_field &&
            private_field.length > 0 &&
            private_field.some((item) => item == '1')
          "
          >{{ sitem.diff_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>
</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="
              (statusOptions.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, statusOptions ,listColumns} 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/purchaseIn/purchaseDiffOrder";
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() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "standingBookDetail"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  props: ["queryId"],
  data() {
    return {

      parmValue: {
        name: "", // 业务员名字
        username: "", // 账号
        apply_name: "", //申请人
        cgdNo: "", //采购单编号
        status: "", //工差单状态
        start: "", //
        end: "",
        company_name:"", //部门
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        // _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      loading: true,
      dialogTableVisible:false,
      listColumns,




      cg_order_type_options,
      statusOptions,
      status: "",
      orderCode:"",
      customer_remark_options: [
        {
          value: "1",
          label: "竞价订单减工差",
        },
        {
          value: "2",
          label: "竞价订单不减工差",
        },
      ],
      is_act_options: [
        {
          value: "1",
          label: "接受工差",
        },
        {
          value: "2",
          label: "不接受工差-退回重做",
        },
      ],
      //——————————————————————
      columns,
      newTime: "",
      sitem: null,
      loading: false,
    };
  },
  mounted() {
    this.searchList();
  },
  methods: {
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
    async initData(id) {
      this.loading = true;
      const res = await asyncRequest.detail({ id});
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;

        const { can, status, cgdNo } = this.sitem;
        this.status = status;
        this.orderCode = cgdNo;
        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);
      }
      this.loading = false;
    },

    async searchList() {
        //通过采购编号去查询所有列表、当采购编号为空时，所有涉及字段不展示
      this.parmValue.cgdNo = 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.forEach((v) => {
          v.class_cat = "";
          if (v.can && v.can.length > 0) {
            v.class_cat = "";
            v.can.forEach((x, i) => {
              v.class_cat += i === 0 ? x.name : "/" + x.name;
            });
          }
        });
        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>