<template>
  <div class="done pagePadding">
    <ex-table
      v-loading="loading"
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
      :table="table"
      :data="tableData"
      :columns="columns"
      :page="pageInfo"
      :size="size"
      @page-curr-change="handlePageChange"
      @page-size-change="handleSizeChange"
      @screen-reset="
        pageInfo.curr = 1;
        searchList();
      "
      @screen-submit="
        pageInfo.curr = 1;
        searchList();
      "
    >
      <template #table-header="{}">
        <div style="width: 100%; height: 30px">
          <el-row>
            <el-col :span="24">
              <el-col :span="3" style="width: 66px; float: right">
                <el-button
                  type="primary"
                  :size="searchSize"
                  style="float: right"
                  @click="searchList"
                >
                  刷新
                </el-button>
              </el-col>
              <el-col
                :span="3"
                style="width: 66px; float: right"
                v-if="powers.some((item) => item == '003')"
              >
                <el-button
                  :size="searchSize"
                  type="success"
                  style="float: right"
                  @click="openModal('add', false)"
                >
                  添加
                </el-button>
              </el-col>
            </el-col>
          </el-row>
        </div>
      </template>
      <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
          v-if="powers.some((item) => item == '007')"
          effect="dark"
          content="详情"
          placement="top"
        >
          <i
            class="el-icon-view tb-icon"
            @click="getRouter(scope.row.toRouter, scope.row.queryId)"
          ></i>
        </el-tooltip>
      </template>
    </ex-table>
    <no-auth v-else></no-auth>
  </div>
</template>
<script>
import asyncRequest from "@/apis/service/process/done";
import mixinPage from "@/mixins/elPaginationHandle";
import { mapGetters } from "vuex";
import resToken from "@/mixins/resToken";
import routerList from "@/views/process/columns";
export default {
  name: "done",
  mixins: [mixinPage, resToken],
  computed: {
    //组件SIZE设置
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      let tran =
        this.$store.getters.btnList.find((item) => item.menu_route == "done") ||
        {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      loading: true,
      showModel: false,
      isDetail: false,
      modelId: 0,
      process_router_list: JSON.parse(JSON.stringify(routerList)),
      parmValue: {
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      // 状态
      statusOptions: [
        { id: 0, label: "禁用" },
        { id: 1, label: "启用" },
      ],
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: [
        {
          prop: "order_code",
          label: "业务编号",
        },
          {
          prop: "process_name",
          label: "流程名称",
          // sortable: true,
        },
        // {
        //   prop: "order_type",
        //   label: "订单类型",
        // },

        {
          prop: "apply_name",
          label: "申请人",
        },
        {
          prop: "action_name",
          label: "操作人",
        },
        // {
        //   prop: "order_process",
        //   label: "状态",
        // },
        {
          prop: "addtime",
          label: "创建时间",
          // width: "150",
        },
        {
          prop: "",
          label: "操作",
          fixed: "right",
          _noset_: true,
          _slot_: "operation",
          width: "50",
        },
      ],
    };
  },
  mounted() {
    this.searchList();
  },
  methods: {
    getRouter(toRouter, queryId) {
      if (toRouter && queryId) {
        this.routeGoto(toRouter, { id: queryId });
      } else {
        this.$message.warning("暂未找到相关流程！");
      }
    },
    restSearch() {
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0,
      };
      this.parmValue = {
        page: 1, // 页码
        size: 15, // 每页显示条数
      };
      this.searchList();
    },
   
  

    // 刷新表格
    async searchList() {
      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, i) => {
          let index = this.process_router_list.findIndex(
            (y) => y.type === v.order_type
          );
          if (index !== -1) {
            const { name, toRouter, to } = this.process_router_list[index];
            this.tableData[i].process_name = name;
            this.tableData[i].toRouter = toRouter;
            this.tableData[i].queryId =
              to == "code" ? v.order_code : v.order_id;
          } else {
            this.tableData[i].process_name = "";
            this.tableData[i].toRouter = "";
            this.tableData[i].queryId = "";
          }
        });
        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;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>