wujingjing
2024-10-30 111a9f347755ae791d3d88373a18a5dfeff4c53c
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
<template>
    <ywDialog
        v-model="dialogIsShow"
        :headerIcon="dialogHeaderIcon"
        :title="dialogTitle"
        width="470"
        @dlgClosed="closeDialog"
        @submit="submitFormValue"
    >
        <el-form :model="dialogFormValue" ref="dialogFormRef" :rules="dialogFormRules" label-width="76">
            <el-form-item label="名称" prop="group_name">
                <el-input v-model="dialogFormValue.group_name"></el-input>
            </el-form-item>
 
            <el-form-item label="说明" prop="group_title">
                <el-input v-model="dialogFormValue.group_title" type="textarea" :rows="3"></el-input>
            </el-form-item>
        </el-form>
    </ywDialog>
</template>
 
<script setup lang="ts">
import ywDialog from '/@/components/dialog/yw-dialog.vue';
 
import type { FormInstance, FormRules } from 'element-plus';
import { ElMessage } from 'element-plus';
 
import { computed, ref, watch } from 'vue';
// import { useTableSort } from '/@/hooks/useTableSort';
// import { useValidateUniqueness } from '/@/hooks/useValidateUniqueness';
import { deepClone } from '/@/utils/other';
 
import { storeToRefs } from 'pinia';
import * as agentGroupApi from '/@/api/ai/agentGroup';
import { useUserInfo } from '/@/stores/userInfo';
import { formatDate } from '/@/utils/formatTime';
 
const props = defineProps(['item']);
const emit = defineEmits(['update', 'insert']);
//#region ====================== 增加、修改记录操作, dialog init======================
const isEditDialog = ref(false);
const dialogTitle = computed(() => {
    return isEditDialog.value ? '修改分组' : '添加分组';
});
const dialogHeaderIcon = computed(() => {
    return isEditDialog.value ? 'ele-Edit' : 'ele-Plus';
});
const dialogFormValue = ref(null);
const dialogIsShow = defineModel({
    type: Boolean,
});
const dialogFormRef = ref<FormInstance>(null);
 
const dialogFormRules = ref<FormRules>({
    group_name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    group_title: [{ required: true, message: '请输入说明', trigger: 'blur' }],
});
const openOperateDialog = (row?) => {
    if (row) {
        isEditDialog.value = true;
        const { group_id, group_name, group_title } = row;
        dialogFormValue.value = deepClone({ group_id, group_name, group_title });
    } else {
        isEditDialog.value = false;
 
        dialogFormValue.value = { group_name: null, group_title: null };
    }
};
const closeDialog = () => {
    dialogIsShow.value = false;
    dialogFormRef.value.clearValidate();
};
const stores = useUserInfo();
const { userInfos } = storeToRefs(stores);
 
const submitFormValue = async () => {
    const valid = await dialogFormRef.value.validate().catch(() => {});
    if (!valid) return;
 
    const sendForm = { ...dialogFormValue.value };
    const updateTime = formatDate(new Date());
    if (isEditDialog.value) {
        const res = await agentGroupApi.updateSceneGroupInfoByPost(sendForm);
        emit('update', { ...dialogFormValue.value });
 
        closeDialog();
        ElMessage.success('修改分组成功');
    } else {
        const res = await agentGroupApi.addSupervisor(sendForm);
        const newData = {
            ...dialogFormValue.value,
        };
        emit('insert', newData);
        // tableData.value.push(newData);
        closeDialog();
        ElMessage.success('添加分组成功');
    }
};
 
//#endregion
 
watch(
    () => dialogIsShow.value,
    (val) => {
        if (!val) return;
        openOperateDialog(props.item);
    }
);
</script>
<style scoped lang="scss"></style>