addFloor.vue
4.13 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
133
134
135
136
<template>
<el-dialog
:title="$t('room.addFloor.title')"
:visible.sync="visible"
width="50%"
:before-close="handleClose"
>
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-form-item :label="$t('room.addFloor.floorNum')" prop="floorNum">
<el-input v-model="form.floorNum" :placeholder="$t('room.addFloor.floorNumPlaceholder')" />
</el-form-item>
<el-form-item :label="$t('room.addFloor.name')" prop="name">
<el-input v-model="form.name" :placeholder="$t('room.addFloor.namePlaceholder')" />
</el-form-item>
<el-form-item :label="$t('room.addFloor.floorArea')" prop="floorArea">
<el-input v-model="form.floorArea" :placeholder="$t('room.addFloor.floorAreaPlaceholder')">
<template slot="append">m²</template>
</el-input>
</el-form-item>
<el-form-item :label="$t('room.addFloor.seq')" class="text-left" prop="seq">
<el-input-number v-model="form.seq" :min="1" />
</el-form-item>
<el-form-item :label="$t('room.addFloor.remark')" prop="remark">
<el-input v-model="form.remark" type="textarea" :placeholder="$t('room.addFloor.remarkPlaceholder')" />
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="handleClose">{{ $t('common.cancel') }}</el-button>
<el-button type="primary" @click="handleSave">{{ $t('common.save') }}</el-button>
</span>
</el-dialog>
</template>
<script>
import { addFloor } from '@/api/room/addFloorApi'
export default {
name: 'AddFloor',
props: {
callBackListener: String,
callBackFunction: String
},
data() {
return {
visible: false,
form: {
communityId: this.getCommunityId(),
floorNum: '',
name: '',
floorArea: '',
seq: 1,
remark: ''
},
errorInfo: '',
rules: {
floorNum: [
{ required: true, message: this.$t('room.addFloor.floorNumRequired'), trigger: 'blur' },
{ min: 1, max: 64, message: this.$t('room.addFloor.floorNumLength'), trigger: 'blur' }
],
name: [
{ required: true, message: this.$t('room.addFloor.nameRequired'), trigger: 'blur' },
{ min: 2, max: 64, message: this.$t('room.addFloor.nameLength'), trigger: 'blur' }
],
floorArea: [
{ required: true, message: this.$t('room.addFloor.floorAreaRequired'), trigger: 'blur' },
{ pattern: /^\d+(\.\d{1,2})?$/, message: this.$t('room.addFloor.floorAreaFormat'), trigger: 'blur' }
],
seq: [
{ required: true, message: this.$t('room.addFloor.seqRequired'), trigger: 'blur' },
{ type: 'number', message: this.$t('room.addFloor.seqNumber'), trigger: 'blur' }
],
remark: [
{ max: 200, message: this.$t('room.addFloor.remarkMaxLength'), trigger: 'blur' }
]
}
}
},
watch: {
'form.floorNum': function(newVal) {
if (newVal) {
this.form.name = `${newVal}${this.$t('room.addFloor.buildingSuffix')}`
} else {
this.form.name = ''
}
}
},
methods: {
open() {
this.visible = true
this.resetForm()
},
handleClose() {
this.visible = false
this.resetForm()
},
resetForm() {
this.form = {
communityId: this.getCommunityId(),
floorNum: '',
name: '',
floorArea: '',
seq: 1,
remark: ''
}
this.errorInfo = ''
this.$refs.form.resetFields()
},
async handleSave() {
this.$refs.form.validate(async (valid) => {
if (!valid) return
try {
const response = await addFloor(this.form)
if (response.code == 0) {
this.$message.success(this.$t('room.addFloor.saveSuccess'))
this.handleClose()
this.$emit('handleRefreshTree', {})
} else {
this.errorInfo = response.msg || this.$t('room.addFloor.saveFailed')
}
} catch (error) {
this.errorInfo = this.$t('room.addFloor.saveError')
}
})
},
}
}
</script>