<!--业务用户管理界面-->
<template>
    <div class="default-main">
        <TableHeader>
            <template v-slot:select>
                <el-form-item label='流程名称'>
                    <el-input v-model='tableStore.table.params.name' clearable placeholder='流程名称' />
                </el-form-item>
                <el-form-item label='流程分类'>
                    <el-select v-model="tableStore.table.params.searchState" clearable placeholder="请选择流程分类">
                        <el-option v-for="item in categoryList" :key="item.id" :label="item.name" :value="item.id" />
                    </el-select>
                </el-form-item>
            </template>
        </TableHeader>
        <!--表格-->
        <Table ref="tableRef"></Table>
        <!-- 详情 -->
        <Detail ref="detailRef" />
    </div>
</template>

<script setup lang='ts'>
import { ElMessage } from 'element-plus'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import { onMounted, provide, ref } from 'vue'
import { useDictData } from '@/stores/dictData'
import { pageTable } from '@/api/harmonic-boot/luckyexcel'
import Detail from './components/detail.vue'

defineOptions({
    name: '/flowTask/mytask'
})
const dictData = useDictData()
const tableRef = ref()
const detailRef = ref()

const tableStore = new TableStore({
    url: '/process-boot/flowable/task/myProcess',
    method: 'GET',
    column: [
    { title: '序号',  width: 80,formatter: (row: any) => {
        return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
      } },
        { title: '流程名称', field: 'procDefName', width: 200 },
        { title: '流程类别', field: 'category', width: 200 },
        { title: '流程版本', field: 'procDefVersion' },
        { title: '提交时间', field: 'createTime' },
        {
            title: '流程状态', field: 'finishTime',
            render: 'tag',
            custom: {
                0: 'warning',
                1: 'success'
            },
            formatter(row: any) {
                return row.finishTime == null ? 0 : 1
            }
        },
        { title: '流程名称', field: 'procDefName', width: 200 },
        { title: '流程类别', field: 'category' },
        {
            title: '流程版本',
            field: 'procDefVersion'
        },
        {
            title: '提交时间',
            field: 'createTime'
        },
        {
            title: '流程状态',
            field: 'finishTime',
            render: 'tag',
            custom: {
                0: 'warning',
                1: 'success'
            },
            replaceValue: {
                0: '进行中',
                1: '已完成'
            }
        },
        { title: '耗时', field: 'duration' },
        {
            title: '当前节点',
            field: 'taskName'
        },
        {
            title: '办理人',
            field: 'assigneeName'
        },

        {
             title: '操作',fixed: 'right',
            width: '180',
            render: 'buttons',
            buttons: [
                {
                    name: 'edit',
                    title: '详情',
                    type: 'primary',
                    icon: 'el-icon-Plus',
                    render: 'basicButton',
                    click: row => {
                        detailRef.value.open(row)
                    }
                },
                {
                    name: 'del',
                    text: '删除',
                    type: 'danger',
                    icon: 'el-icon-Delete',
                    render: 'confirmButton',
                    popconfirm: {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        confirmButtonType: 'danger',
                        title: '确定删除？'
                    },
                    click: row => {}
                }
            ]
        }
    ],
    beforeSearchFun: () => {
        tableStore.table.params.beginTime = tableStore.table.params.startTime
        tableStore.table.params.deptId = tableStore.table.params.deptIndex
    },
    loadCallback: () => {
        tableStore.table.data.forEach((item: any) => {
            item.finishTime = item.finishTime == null ? '0' : '1'
        })
    }
})

onMounted(() => {
    tableStore.index()
})
tableStore.table.params.name = ''
provide('tableStore', tableStore)
</script>
