AddPropertyCompany.vue
4.51 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
<template>
<el-dialog :title="$t('propertyCompanyManage.add')" :visible="visible" width="70%" @close="handleClose">
<el-form ref="form" :model="formData" label-width="120px">
<el-form-item :label="$t('propertyCompanyManage.name')" prop="name" required>
<el-input v-model="formData.name" />
</el-form-item>
<el-form-item :label="$t('propertyCompanyManage.address')" prop="address" required>
<el-input v-model="formData.address" />
</el-form-item>
<el-form-item :label="$t('propertyCompanyManage.tel')" prop="tel" required>
<el-input v-model="formData.tel" />
</el-form-item>
<el-form-item :label="$t('propertyCompanyManage.corporation')" prop="corporation" required>
<el-input v-model="formData.corporation" />
</el-form-item>
<el-form-item :label="$t('propertyCompanyManage.foundingTime')" prop="foundingTime" required>
<el-date-picker v-model="formData.foundingTime" type="date" value-format="yyyy-MM-dd" style="width: 100%" />
</el-form-item>
<el-form-item :label="$t('propertyCompanyManage.landmark')" prop="nearbyLandmarks" required>
<el-input v-model="formData.nearbyLandmarks" />
</el-form-item>
<el-form-item :label="$t('propertyCompanyManage.communities')">
<el-select v-model="formData.communityIds" multiple filterable style="width: 100%"
:placeholder="$t('propertyCompanyManage.selectCommunities')">
<el-option v-for="item in communities" :key="item.communityId" :label="item.name" :value="item.communityId" />
</el-select>
</el-form-item>
<el-form-item v-if="formData.communityIds && formData.communityIds.length > 0"
:label="$t('propertyCompanyManage.functions')">
<el-checkbox v-model="formData.isAll" @change="handleCheckAll">
{{ $t('propertyCompanyManage.all') }}
</el-checkbox>
<el-checkbox-group v-model="formData.groupIds" @change="handleCheckGroup">
<el-checkbox v-for="group in menuGroups" :key="group.gId" :label="group.gId">
{{ group.name }}
</el-checkbox>
</el-checkbox-group>
</el-form-item>
</el-form>
<div slot="footer">
<el-button @click="handleClose">{{ $t('common.cancel') }}</el-button>
<el-button type="primary" @click="handleSubmit">{{ $t('common.save') }}</el-button>
</div>
</el-dialog>
</template>
<script>
import { saveProperty, listMenuGroup, listNoEnterCommunity } from '@/api/store/propertyCompanyManageApi'
export default {
name: 'AddPropertyCompany',
data() {
return {
visible: false,
formData: {
name: '',
address: '',
tel: '',
corporation: '',
foundingTime: '',
nearbyLandmarks: '',
communityIds: [],
menuGroups: [],
groupIds: [],
isAll: true
},
communities: [],
menuGroups: []
}
},
methods: {
open() {
this.visible = true
this.fetchMenuGroups()
this.fetchCommunities()
},
async fetchMenuGroups() {
try {
const { data } = await listMenuGroup({
page: 1,
row: 100,
storeType: '800900000003'
})
this.menuGroups = data
this.formData.groupIds = data.map(item => item.gId)
} catch (error) {
this.$message.error(this.$t('propertyCompanyManage.fetchMenuError'))
}
},
async fetchCommunities() {
try {
const data = await listNoEnterCommunity({
communityName: ''
})
this.communities = data
} catch (error) {
this.$message.error(this.$t('propertyCompanyManage.fetchCommunityError'))
}
},
handleCheckAll(val) {
this.formData.groupIds = val ? this.menuGroups.map(item => item.gId) : []
},
handleCheckGroup() {
this.formData.isAll = this.formData.groupIds.length === this.menuGroups.length
},
async handleSubmit() {
try {
await saveProperty(this.formData)
this.$message.success(this.$t('propertyCompanyManage.addSuccess'))
this.$emit('success')
this.handleClose()
} catch (error) {
this.$message.error(error.message)
}
},
handleClose() {
this.visible = false
this.$refs.form.resetFields()
this.formData = {
name: '',
address: '',
tel: '',
corporation: '',
foundingTime: '',
nearbyLandmarks: '',
communityIds: [],
menuGroups: [],
groupIds: [],
isAll: true
}
}
}
}
</script>