<!--业务用户管理界面-->
<template>
    <div class="default-main">
        <div v-show="addedShow">
            <TableHeader showCustomColumn>
                <template v-slot:select>
                    <el-form-item label="筛选数据">
                        <el-input v-model="tableStore.table.params.name" clearable placeholder="筛选数据" />
                    </el-form-item>
                </template>

                <template v-slot:operation>
                    <el-button type="primary" @click="add" class="ml10" icon="el-icon-Plus">新增</el-button>
                </template>
            </TableHeader>
            <!--表格-->
            <Table ref="tableRef"></Table>
        </div>
        <!-- 设计流程 -->
        <editor v-if="!addedShow" :model="model" @quit="quit" />
        <!-- 配置表单 -->
        <Allocation ref="allocationRef" @quit="tableStore.index()" />
    </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 Allocation from './allocation.vue'
import { deleteDeploy } from '@/api/process-boot/bpm'
import { onMounted, provide, ref } from 'vue'
import { ElMessage } from 'element-plus'
import editor from './editor/index.vue'

defineOptions({
    name: '/flowable/definition/index'
})

const tableRef = ref()
const allocationRef = ref()
const model = ref({})
const addedShow = ref(true)

const tableStore = new TableStore({
    url: '/process-boot/flowable/definition/list',
    method: 'GET',
    column: [
        {
            title: '序号',
            width: 80,
            formatter: (row: any) => {
                return (tableStore.table.params.pageNum - 1) * tableStore.table.params.pageSize + row.rowIndex + 1
            }
        },
        { title: '流程标识', field: 'flowKey' },
        { title: '流程分类', field: 'category' },
        { title: '流程名称', field: 'name' },

        {
            title: '业务功能',
            field: 'formId',
            formatter: (row: any) => {
                return row.cellValue == 1 ? '谐波普测计划' : row.cellValue == 2 ? '干扰源用户管理' : '暂无表单'
            }
        },
        { title: '流程版本（V）', field: 'version' },

    
        { title: '部署时间', field: 'deploymentTime' },
        {
             title: '操作',fixed: 'right',
            width: '180',
            render: 'buttons',
            buttons: [
                {
                    name: 'edit',
                    title: '设计',
                    type: 'primary',
                    icon: 'el-icon-Plus',
                    render: 'basicButton',
                    click: row => {
                        model.value = row
                        addedShow.value = false
                    }
                },
                {
                    name: 'edit',
                    title: '配置主表单',
                    type: 'primary',
                    icon: 'el-icon-Plus',
                    render: 'basicButton',
                    click: async row => {
                        allocationRef.value.open(row)
                    }
                },
             
                {
                    name: 'del',
                    title: '删除',
                    type: 'danger',
                    icon: 'el-icon-Delete',
                    render: 'confirmButton',
                    popconfirm: {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        confirmButtonType: 'danger',
                        title: '确定删除吗？'
                    },
                    click: row => {
                        deleteDeploy([row.id]).then(() => {
                            ElMessage.success('删除成功')
                            tableStore.index()
                        })
                    }
                }
            ]
        }
    ],
    beforeSearchFun: () => {
        tableStore.table.params.beginTime = tableStore.table.params.startTime
        tableStore.table.params.deptId = tableStore.table.params.deptIndex
    }
})
// 新增
const add = () => {
    model.value = {}
    addedShow.value = false
}

onMounted(() => {
    // 加载数据
    tableStore.index()
})
const quit = () => {
    addedShow.value = true
    tableStore.index()
}
tableStore.table.params.name = ''
provide('tableStore', tableStore)
</script>
