AddInspectionRoute.vue
3.43 KB
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
<template>
<el-dialog
:title="$t('inspectionRoute.addRouteTitle')"
:visible.sync="visible"
width="50%"
@close="handleClose"
>
<el-form
ref="form"
:model="addInspectionRouteInfo"
:rules="rules"
label-width="120px"
>
<el-form-item
:label="$t('inspectionRoute.routeName')"
prop="routeName"
>
<el-input
v-model.trim="addInspectionRouteInfo.routeName"
:placeholder="$t('inspectionRoute.routeNamePlaceholder')"
clearable
/>
</el-form-item>
<el-form-item
:label="$t('inspectionRoute.sequence')"
prop="seq"
>
<el-input
v-model.number="addInspectionRouteInfo.seq"
:placeholder="$t('inspectionRoute.sequencePlaceholder')"
clearable
/>
</el-form-item>
<el-form-item
:label="$t('inspectionRoute.remark')"
prop="remark"
>
<el-input
v-model.trim="addInspectionRouteInfo.remark"
:placeholder="$t('inspectionRoute.remarkPlaceholder')"
type="textarea"
:rows="3"
clearable
/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="handleClose">
{{ $t('common.cancel') }}
</el-button>
<el-button
type="primary"
@click="saveInspectionRouteInfo"
>
{{ $t('common.save') }}
</el-button>
</div>
</el-dialog>
</template>
<script>
import { getCommunityId } from '@/api/community/communityApi'
import { saveInspectionRoute } from '@/api/inspection/inspectionRouteApi'
export default {
name: 'AddInspectionRoute',
data() {
return {
visible: false,
addInspectionRouteInfo: {
routeName: '',
seq: 1,
remark: ''
},
communityId: '',
rules: {
routeName: [
{ required: true, message: this.$t('inspectionRoute.routeNameRequired'), trigger: 'blur' },
{ max: 100, message: this.$t('inspectionRoute.routeNameMaxLength'), trigger: 'blur' }
],
seq: [
{ required: true, message: this.$t('inspectionRoute.sequenceRequired'), trigger: 'blur' },
{ type: 'number', message: this.$t('inspectionRoute.sequenceMustBeNumber'), trigger: 'blur' }
],
remark: [
{ max: 200, message: this.$t('inspectionRoute.remarkMaxLength'), trigger: 'blur' }
]
}
}
},
created() {
this.communityId = getCommunityId()
},
methods: {
open() {
this.visible = true
this.$nextTick(() => {
this.$refs.form.clearValidate()
})
},
async saveInspectionRouteInfo() {
try {
await this.$refs.form.validate()
const params = {
...this.addInspectionRouteInfo,
communityId: this.communityId
}
await saveInspectionRoute(params)
this.$message.success(this.$t('common.operationSuccess'))
this.$emit('success')
this.handleClose()
} catch (error) {
if (error !== 'validate') {
console.error('添加巡检路线失败:', error)
this.$message.error(this.$t('inspectionRoute.addFailed'))
}
}
},
handleClose() {
this.visible = false
this.addInspectionRouteInfo = {
routeName: '',
seq: 1,
remark: ''
}
this.$refs.form.clearValidate()
}
}
}
</script>