<template>
  <div class="tenant">
    <!-- <Banner /> -->
    <div class="content">
      <byTable
        :source="sourceList.data"
        :pagination="sourceList.pagination"
        :config="config"
        :loading="loading"
        highlight-current-row
        :selectConfig="selectConfig"
        :table-events="{
          //element talbe事件都能传
        }"
        @get-list="getList"
        ref="table"
      >
        <template #slotName="{ item }">
          {{ item.createTime }}
        </template>
      </byTable>
    </div>
  </div>
</template>
    
<script setup name="DealWith">
import byTable from "@/components/byTable/index";
import { computed, defineComponent, ref } from "vue";
const loading = ref(false);
const sourceList = ref({
  data: [],
  pagination: {
    total: 3,
    pageNum: 1,
    pageSize: 10,
    status: 1,
  },
});

const { proxy } = getCurrentInstance();
const selectConfig = computed(() => {
  return [
    {
      label: "流程类型",
      prop: "flowInfoId",
      data: [],
    },
    {
      label: "流程状态",
      prop: "status",
      isShowAll: false,
      data: [
        {
          label: "已发起（未结束）",
          value: "1",
        },
        {
          label: "已发起（已结束）",
          value: "2",
        },
        {
          label: "已办理",
          value: "3",
        },
      ],
    },
  ];
});
const config = computed(() => {
  return [
    {
      attrs: {
        label: "流程类型",
        prop: "flowName",
      },
    },
    {
      attrs: {
        label: "流程标题",
        prop: "title",
      },
    },

    {
      attrs: {
        label: "流程状态",
        width: 100,
        prop: "status",
      },
      render(status) {
        return status == 0 || status == 1
          ? "待办理"
          : status == 2
          ? "已通过"
          : "已驳回";
      },
    },
    {
      attrs: {
        label: "发起人",
        prop: "createUserName",
      },
    },
    {
      attrs: {
        label: "发起时间",
        prop: "createTime",
      },
    },
    {
      attrs: {
        label: "操作",
        width: "200",
        align: "right",
      },
      // 渲染 el-button，一般用在最后一列。
      renderHTML(row) {
        return [
          {
            attrs: {
              label: "查看",
              type: "primary",
              text: true,
              bg: true,
              disabled: false,
            },
            el: "button",
            click() {
              proxy.$router.push({
                path: "/platform_manage/process/processApproval",
                query: {
                  flowKey: row.flowKey,
                  id: row.id,
                  processType: 20,
                  version: row.version,
                  businessId: row.businessId,
                  submitType: "10",
                },
              });
            },
          },
        ];
      },
    },
  ];
});

const getFlowType = () => {
  proxy.post("/flowExample/getFlowType").then((message) => {
    selectConfig.value[0].data = message.map((item) => {
      return {
        label: item.flowName,
        value: item.id,
      };
    });
  });
};
getFlowType();

const getUrlObj = {
  1: "/flowExample/getHaveInitiatedPage",
  2: "/flowExample/getHaveInitiatedPage",
  3: "/flowExample/getProcessedPage",
};
const getList = async (req) => {
  sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  loading.value = true;
  proxy
    .post(
      getUrlObj[sourceList.value.pagination.status] ||
        "/flowExample/getHaveInitiatedPage",
      sourceList.value.pagination
    )
    .then((message) => {
      sourceList.value.data = message.rows;
      sourceList.value.pagination.total = message.total;
      setTimeout(() => {
        loading.value = false;
      }, 200);
    });
};
const table = ref(null);
const searchItemSelct = () => {
  // 默认选中的方法
  table.value.searchItemSelct(
    selectConfig.value[1].data[2],
    selectConfig.value[1]
  );
};
onMounted(() => {
  const route = useRoute();
  if (route.query && route.query.type) {
    table.value.searchItemSelct(
      selectConfig.value[1].data[0],
      selectConfig.value[1]
    );
  } else {
    searchItemSelct();
  }
});
</script>
    
  <style lang="scss" scoped>
.tenant {
  padding: 20px;
}
</style>