addUnit.vue
3.87 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
<template>
<el-dialog :title="$t('addUnit.title')" :visible.sync="visible" width="50%" :before-close="handleClose">
<el-form ref="form" :model="addUnitInfo" :rules="rules" label-width="120px">
<el-form-item :label="$t('addUnit.unitNum')" prop="unitNum">
<el-input v-model="addUnitInfo.unitNum" :placeholder="$t('addUnit.unitNumPlaceholder')"></el-input>
</el-form-item>
<el-form-item :label="$t('addUnit.layerCount')" prop="layerCount">
<el-input v-model.number="addUnitInfo.layerCount" type="number"
:placeholder="$t('addUnit.layerCountPlaceholder')"></el-input>
</el-form-item>
<el-form-item :label="$t('addUnit.unitArea')" prop="unitArea">
<el-input v-model="addUnitInfo.unitArea" :placeholder="$t('addUnit.unitAreaPlaceholder')"></el-input>
</el-form-item>
<el-form-item :label="$t('addUnit.lift')" prop="lift">
<el-select v-model="addUnitInfo.lift" :placeholder="$t('addUnit.liftPlaceholder')" style="width: 100%">
<el-option :label="$t('addUnit.liftOption1')" value="1010"></el-option>
<el-option :label="$t('addUnit.liftOption2')" value="2020"></el-option>
</el-select>
</el-form-item>
<el-form-item :label="$t('addUnit.remark')">
<el-input v-model="addUnitInfo.remark" type="textarea" :rows="3"
:placeholder="$t('addUnit.remarkPlaceholder')"></el-input>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="handleClose">{{ $t('addUnit.cancel') }}</el-button>
<el-button type="primary" @click="addUnit">{{ $t('addUnit.save') }}</el-button>
</span>
</el-dialog>
</template>
<script>
import { saveUnit } from '@/api/room/addUnitApi'
export default {
name: 'AddUnit',
data() {
return {
visible: false,
addUnitInfo: {
floorId: '',
unitNum: '',
layerCount: '',
lift: '',
remark: '',
communityId: '',
unitArea: ''
},
rules: {
unitNum: [
{ required: true, message: this.$t('addUnit.unitNumRequired'), trigger: 'blur' }
],
layerCount: [
{ required: true, message: this.$t('addUnit.layerCountRequired'), trigger: 'blur' }
],
unitArea: [
{ required: true, message: this.$t('addUnit.unitAreaRequired'), trigger: 'blur' }
],
lift: [
{ required: true, message: this.$t('addUnit.liftRequired'), trigger: 'change' }
]
}
}
},
methods: {
open(params) {
this.refreshAddUnitInfo()
if (params && params.floorId) {
this.addUnitInfo.floorId = params.floorId
}
this.addUnitInfo.communityId = this.getCommunityId()
this.visible = true
},
handleClose() {
this.visible = false
},
refreshAddUnitInfo() {
this.addUnitInfo = {
floorId: '',
unitNum: '',
layerCount: '',
lift: '',
remark: '',
communityId: '',
unitArea: ''
}
this.$nextTick(() => {
if (this.$refs.form) {
this.$refs.form.clearValidate()
}
})
},
validateForm() {
return new Promise((resolve) => {
this.$refs.form.validate((valid) => {
resolve(valid)
})
})
},
async addUnit() {
const isValid = await this.validateForm()
if (!isValid) return
if (this.addUnitInfo.unitNum === '0') {
this.$message.warning(this.$t('addUnit.zeroUnitWarning'))
return
}
try {
await saveUnit(this.addUnitInfo)
this.$message.success(this.$t('common.operationSuccess'))
this.$emit('handleRefreshTree', {})
this.handleClose()
} catch (error) {
console.error('添加单元失败:', error)
this.$message.error(error.message || this.$t('addUnit.errorMessage'))
}
}
}
}
</script>