floorSelect2.vue
1.38 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
<template>
<el-select
v-model="selectedFloor"
:placeholder="$t('meterWater.selectBuilding')"
filterable
clearable
style="width: 100%"
@change="handleChange"
>
<el-option
v-for="item in floors"
:key="item.floorId"
:label="`${item.floorNum}栋`"
:value="item.floorId"
/>
</el-select>
</template>
<script>
import { queryFloors } from '@/api/fee/meterWaterManageApi'
import { getCommunityId } from '@/api/community/communityApi'
export default {
name: 'FloorSelect2',
props: {
value: {
type: [String, Number],
default: ''
}
},
data() {
return {
floors: [],
selectedFloor: this.value,
communityId: ''
}
},
created() {
this.communityId = getCommunityId()
this.loadFloors()
},
methods: {
async loadFloors() {
try {
const { data } = await queryFloors({
communityId: this.communityId,
page: 1,
row: 500
})
this.floors = data
} catch (error) {
console.error('Failed to load floors:', error)
}
},
handleChange(value) {
const floor = this.floors.find(item => item.floorId === value)
this.$emit('change', {
floorId: value,
floorNum: floor ? floor.floorNum : ''
})
}
},
watch: {
value(newVal) {
this.selectedFloor = newVal
}
}
}
</script>