batchAddParkingSpace.vue
4.83 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
138
139
140
141
142
143
<template>
<el-dialog :title="$t('batchAddParkingSpace.title')" :visible.sync="visible" width="50%" @close="closeDialog">
<el-form :model="form" ref="form" label-width="120px">
<el-form-item :label="$t('batchAddParkingSpace.prefixNum')" prop="preNum">
<el-input v-model="form.preNum" :placeholder="$t('batchAddParkingSpace.prefixNumPlaceholder')"></el-input>
</el-form-item>
<el-form-item :label="$t('batchAddParkingSpace.startNum')" prop="startNum"
:rules="[{ required: true, message: $t('batchAddParkingSpace.startNumPlaceholder'), trigger: 'blur' }]">
<el-input v-model="form.startNum" type="number"
:placeholder="$t('batchAddParkingSpace.startNumPlaceholder')"></el-input>
</el-form-item>
<el-form-item :label="$t('batchAddParkingSpace.endNum')" prop="endNum"
:rules="[{ required: true, message: $t('batchAddParkingSpace.endNumPlaceholder'), trigger: 'blur' }]">
<el-input v-model="form.endNum" type="number"
:placeholder="$t('batchAddParkingSpace.endNumPlaceholder')"></el-input>
</el-form-item>
<el-form-item :label="$t('batchAddParkingSpace.parkingLot')" prop="paId"
:rules="[{ required: true, message: $t('batchAddParkingSpace.parkingLotPlaceholder'), trigger: 'change' }]">
<el-select v-model="form.paId" :placeholder="$t('batchAddParkingSpace.parkingLotPlaceholder')" style="width:100%">
<el-option v-for="item in parkingAreas" :key="item.paId" :label="item.num" :value="item.paId"></el-option>
</el-select>
</el-form-item>
<el-form-item :label="$t('batchAddParkingSpace.parkingSpaceType')" prop="parkingType"
:rules="[{ required: true, message: $t('batchAddParkingSpace.parkingSpaceTypePlaceholder'), trigger: 'change' }]">
<el-select v-model="form.parkingType" :placeholder="$t('batchAddParkingSpace.parkingSpaceTypePlaceholder')"
style="width:100%">
<template v-for="(item,index) in parkingTypes" >
<el-option :label="item.name" :key="index" :value="item.statusCd" v-if="item.statusCd != '2'"></el-option>
</template>
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="visible = false">{{ $t('batchAddParkingSpace.cancel') }}</el-button>
<el-button type="primary" @click="batchSaveParkingSpace" :loading="saving">
{{ $t('batchAddParkingSpace.save') }}
</el-button>
</div>
</el-dialog>
</template>
<script>
import { batchSaveParkingSpace } from '@/api/car/listParkingSpaceApi'
import { listParkingAreas } from '@/api/car/listParkingSpaceApi'
import { getDict } from '@/api/community/communityApi'
import { getCommunityId } from '@/api/community/communityApi'
export default {
name: 'BatchAddParkingSpace',
data() {
return {
visible: false,
saving: false,
form: {
preNum: '',
startNum: '',
endNum: '',
paId: '',
parkingType: '1',
area: '1',
communityId: getCommunityId()
},
parkingTypes: [],
parkingAreas: []
}
},
methods: {
open() {
this.visible = true
this.loadParkingTypes()
this.loadParkingAreas()
},
async loadParkingTypes() {
try {
const data = await getDict('parking_space', 'parking_type')
this.parkingTypes = data
} catch (error) {
this.$message.error(this.$t('common.loadDictError'))
}
},
async loadParkingAreas() {
try {
const params = {
page: 1,
row: 50,
communityId: getCommunityId()
}
const res = await listParkingAreas(params)
this.parkingAreas = res.parkingAreas
} catch (error) {
this.$message.error(this.$t('common.loadError'))
}
},
async batchSaveParkingSpace() {
try {
this.saving = true
await this.$refs.form.validate()
// 验证结束编号大于开始编号
if (parseInt(this.form.endNum) < parseInt(this.form.startNum)) {
this.$message.error(this.$t('batchAddParkingSpace.endNumPlaceholder'))
return
}
const res = await batchSaveParkingSpace(this.form)
if (res.code === 0) {
this.$message.success(this.$t('common.operationSuccess'))
this.$emit('success')
this.visible = false
} else {
this.$message.error(res.msg || this.$t('common.saveError'))
}
} catch (error) {
console.error('Validation failed:', error)
} finally {
this.saving = false
}
},
closeDialog() {
this.$refs.form.resetFields()
this.form = {
preNum: '',
startNum: '',
endNum: '',
paId: '',
parkingType: '1',
area: '1',
communityId: getCommunityId()
}
}
}
}
</script>