zhangwei
4 天以前 019b6cf4ccaa06fc5ca8f5dc5663975eb027d360
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<template>
    <div class="labApprovalFlow-container">
        <el-dialog v-model="state.isShowDialog" :width="800" draggable>
            <template #header>
                <div style="color: #fff">
                    <el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>
                    <span>{{ props.title }}</span>
                </div>
            </template>
            <el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto" :rules="rules">
                <el-tabs>
                    <el-tab-pane label="基本信息">
                        <el-row :gutter="35">
                            <el-form-item v-show="false">
                                <el-input v-model="state.ruleForm.id" />
                            </el-form-item>
                            <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                                <el-form-item label="编号" prop="code">
                                    <el-input v-model="state.ruleForm.code" placeholder="请输入编号" maxlength="32" show-word-limit clearable />
                                </el-form-item>
                            </el-col>
                            <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                                <el-form-item label="名称" prop="name" :rules="[{ required: true, message: '名称不能为空', trigger: 'blur' }]">
                                    <el-input v-model="state.ruleForm.name" placeholder="请输入名称" maxlength="32" show-word-limit clearable />
                                </el-form-item>
                            </el-col>
                            <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                                <el-form-item label="状态" prop="status" :rules="[{ required: true, message: '状态不能为空', trigger: 'blur' }]">
                                    <g-sys-dict code="LabStatusEnum" v-model="state.ruleForm.status" render-as="select" />
                                </el-form-item>
                            </el-col>
                            <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                                <el-form-item label="备注" prop="remark">
                                    <el-input v-model="state.ruleForm.remark" placeholder="请输入备注" type="textarea" maxlength="255" show-word-limit clearable />
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-tab-pane>
                    <el-tab-pane label="扩展信息">
                        <el-row :gutter="35">
                            <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                                <el-form-item label="表单" prop="formJson">
                                    <el-input v-model="state.ruleForm.formJson" placeholder="请输入表单" type="textarea" maxlength="4096" show-word-limit clearable />
                                </el-form-item>
                            </el-col>
                            <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                                <el-form-item label="流程" prop="flowJson">
                                    <el-input v-model="state.ruleForm.flowJson" placeholder="请输入流程" type="textarea" maxlength="4096" show-word-limit clearable />
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-tab-pane>
                </el-tabs>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="cancel">取 消</el-button>
                    <el-button type="primary" @click="submit">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
 
<script setup lang="ts">
import { reactive, ref } from 'vue';
import { ElMessage } from 'element-plus';
import type { FormRules } from 'element-plus';
import { getAPI } from '/@/utils/axios-utils';
import { ApprovalFlowApi } from '/@/api-plugins/approvalFlow/api';
 
// 父级传递来的参数
var props = defineProps({
    title: {
        type: String,
        default: '',
    },
    labStatus: {
        type: Array,
        default: () => [],
    },
});
// 父级传递来的函数,用于回调
const emit = defineEmits(['reloadTable']);
 
// 定义变量内容
const ruleFormRef = ref();
const state = reactive({
    loading: false,
    isShowDialog: false,
    ruleForm: {} as any,
});
 
// 自行添加其他规则
const rules = ref<FormRules>({
    name: [
        {
            pattern: /^(?!^[0-9].*$).*/,
            message: '不能以数字开头',
            trigger: 'blur',
        },
    ],
});
 
// 打开弹窗
const openDialog = async (row: any) => {
    let rowData = JSON.parse(JSON.stringify(row));
    state.ruleForm = rowData.id ? (await getAPI(ApprovalFlowApi).apiApprovalFlowDetailGet(rowData.id)).data.result : rowData;
    state.isShowDialog = true;
};
 
// 关闭弹窗
const closeDialog = () => {
    emit('reloadTable');
    state.isShowDialog = false;
};
 
// 取消
const cancel = () => {
    state.isShowDialog = false;
};
 
// 提交
const submit = async () => {
    ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
        if (isValid) {
            if (state.ruleForm.id == undefined || state.ruleForm.id == null || state.ruleForm.id == 0) {
                await getAPI(ApprovalFlowApi).apiApprovalFlowAddPost(state.ruleForm);
            } else {
                await getAPI(ApprovalFlowApi).apiApprovalFlowUpdatePost(state.ruleForm);
            }
            closeDialog();
        } else {
            ElMessage({
                message: `表单有${Object.keys(fields).length}处验证失败,请修改后再提交`,
                type: 'error',
            });
        }
    });
};
 
// 将属性或者函数暴露给父组件
defineExpose({ openDialog });
</script>
 
<style scoped lang="scss">
:deep(.el-select),
:deep(.el-input-number) {
    width: 100%;
}
</style>