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