<!--流程分类页面-->
<template>
    <div class="default-main">
        <TableHeader showCustomColumn>
            <template v-slot:select>
                <el-form-item label="标识名称">
                    <el-input v-model="tableStore.table.params.name" clearable placeholder="请输入名称" maxlength="32" show-word-limit/>
                </el-form-item>
                <el-form-item label="标识key">
                    <el-input v-model="tableStore.table.params.signKey" clearable placeholder="请输入key" maxlength="32" show-word-limit/>
                </el-form-item>
            </template>
            <template v-slot:operation>
                <el-button type="primary" class="ml10" @click="add" :icon="Plus">新增</el-button>
            </template>
        </TableHeader>
        <!--表格-->
        <Table ref="tableRef"></Table>
        <!--弹出框-->
        <sign-popup ref="signPopup" />
    </div>
</template>

<script setup lang="ts">
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 { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
import SignPopup from '@/views/system/bpm/sign/signPopup.vue'
import { deleteSign } from '@/api/bpm-boot/sign'

defineOptions({
    name: 'bpmSign'
})

const { push } = useRouter()
const signPopup = ref()

const tableStore = new TableStore({
    url: '/bpm-boot/bpmSign/list',
    method: 'POST',
    column: [
    { title: '序号',  width: 80,formatter: (row: any) => {
        return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
      } },
        { title: '标识名称', field: 'name', minWidth: 130 },
        { title: '标识key', field: 'signKey', minWidth: 130 },
        { title: '表单查看地址', field: 'viewPath', minWidth: 200 },
        { title: '创建时间', field: 'createTime', minWidth: 170 },
        { title: '排序', field: 'sort', width: 80 },
        {
             title: '操作',fixed: 'right',
            align: 'center',
            minWidth: '150',
         
            render: 'buttons',
            buttons: [
                {
                    name: 'update',
                    title: '编辑',
                    type: 'primary',
                    icon: 'el-icon-EditPen',
                    render: 'basicButton',
                    click: row => {
                        signPopup.value.open('修改流程标识', row)
                    }
                },
                {
                    name: 'update',
                    title: '删除',
                    type: 'danger',
                    icon: 'el-icon-Delete',
                    render: 'confirmButton',
                    popconfirm: {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        confirmButtonType: 'danger',
                        title: '确定删除吗？'
                    },
                    click: row => {
                        deleteSign(row.id).then(res => {
                            ElMessage.success('删除成功')
                            tableStore.index()
                        })
                    }
                }
            ]
        }
    ],
    beforeSearchFun: () => {
        for (let key in tableStore.table.params) {
            if (tableStore.table.params[key] === '') {
                delete tableStore.table.params[key]
            }
        }
    },
    resetCallback: () => {
        tableStore.table.params.name = ''
        tableStore.table.params.signKey = ''
    }
})

onMounted(() => {
    // 加载数据
    tableStore.index()
})
tableStore.table.params.name = ''
tableStore.table.params.signKey = ''
provide('tableStore', tableStore)

const add = () => {
    signPopup.value.open('新增流程标识')
}
</script>
