马宇豪
2025-03-04 1b9fea7d4af68d8f933b2dc42bf6084b9646f64c
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<template>
    <div class="system-add-user-container">
        <el-dialog :title="title" v-model="isShowVideoDialog" width="50%">
            <el-form :model="videoForm" size="default" ref="userRef" :rules="videoFormRules" label-width="120px">
                <el-row :gutter="35">
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="视频设备名称" prop="name">
                            <el-input v-model.trim="videoForm.name" placeholder="请输入设备名称" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="设备简称" prop="shortName">
                            <el-input v-model.trim="videoForm.shortName" placeholder="请输入设备简称" clearable></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="所属部门" prop="bizDepId">
                            <el-cascader v-model="videoForm.bizDepId" :options="departmentData" :props="addProps" placeholder="请选择部门" :show-all-levels="false" clearable class="w100"> </el-cascader>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                      <el-form-item label="设备号" prop="deviceNo">
                        <el-input v-model.trim="videoForm.deviceNo" placeholder="请输入设备号" clearable></el-input>
                      </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="isShowVideoDialog = !isShowVideoDialog" size="default">取 消</el-button>
                    <el-button type="primary" v-throttle @click="onSubmit" size="default">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
 
<script lang="ts">
import { reactive, toRefs, onMounted, defineComponent, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { videoApi } from '/@/api/systemManage/video';
 
// 定义接口来定义对象的类型
interface DeptData {}
interface sexData {}
interface UserState {
    title: string;
    isShowVideoDialog: boolean;
    videoForm: {
        name: string | null;
        shortName: string | null;
        deviceNo: string | null;
        bizDepId: number | null;
    };
    videoFormRules:{
 
    },
    departmentData: Array<DeptData>;
    addProps:{}
}
 
export default defineComponent({
    name: 'videoDialog',
    setup(props, context) {
        const userRef = ref()
        const state = reactive<UserState>({
            title: '',
            isShowVideoDialog: false,
            videoForm: {
                name: '', // 账户名称
                shortName: '', // 用户昵称
                deviceNo: '', // 关联角色
                bizDepId: null
            },
            videoFormRules:{
                name: [{ required: true, message: '请填写设备名称', trigger: 'blur' }],
                shortName: [{ required: true, message: '请填写设备简称', trigger: 'blur' }],
                deviceNo: [{ required: true, message: '请输入设备编号', trigger: 'change' }],
                bizDepId: [{ required: true, message: '请选择部门', trigger: 'change' }]
            },
            departmentData: [], // 部门数据
            addProps:{
              expandTrigger: 'hover',
              emitPath: false,
              value: 'depId',
              label: 'depName',
              checkStrictly: true
            }
        });
        // 打开弹窗
        const openDialog = (type: string, value: any, departmentList: [], roleList: [], dutyList:[]) => {
            state.isShowVideoDialog = true;
            state.departmentData = departmentList;
            if (type === '新增') {
                state.title = '新增视频设备';
                state.videoForm = {
                    name: '',
                    shortName: '',
                    deviceNo: '',
                    bizDepId: null
                };
            } else {
                state.title = '修改视频设备';
                state.videoForm = JSON.parse(JSON.stringify(value));
            }
        };
 
        // 新增修改
        const onSubmit = async () => {
            userRef.value.validate(async (valid:Boolean) => {
              console.log(state.videoForm,'state.videoForm')
                if(valid){
                    if (state.title === '新增视频设备') {
                        let res = await videoApi().addVideo(state.videoForm);
                        if (res.data.code === '200') {
                            ElMessage({
                                type: 'success',
                                message: '视频设备新增成功',
                                duration: 2000
                            });
                            state.isShowVideoDialog = false;
                            context.emit('getVideoList');
                        } else {
                            ElMessage({
                                type: 'warning',
                                message: res.data.msg
                            });
                        }
                    } else {
                        let res = await videoApi().modVideo(state.videoForm);
                        if (res.data.code === '200') {
                            ElMessage({
                                type: 'success',
                                message: '设备修改成功',
                                duration: 2000
                            });
                            state.isShowVideoDialog = false;
                            context.emit('getVideoList');
                        } else {
                            ElMessage({
                                type: 'warning',
                                message: res.data.msg
                            });
                        }
                    }
                }else{
                    ElMessage({
                        type:'warning',
                        message:'请完善基本信息'
                    })
                }
            })
 
        };
 
        // 页面加载时
        onMounted(() => {});
        return {
            userRef,
            openDialog,
            onSubmit,
            ...toRefs(state)
        };
    }
});
</script>