addCommunity.vue
5.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<template>
<el-dialog :title="$t('addCommunity.title')" :visible.sync="visible" width="60%" @close="clearAddCommunityInfo">
<el-form ref="form" :model="addCommunityInfo" label-width="120px">
<el-form-item :label="$t('addCommunity.name')" prop="name" required>
<el-input v-model="addCommunityInfo.name" :placeholder="$t('addCommunity.namePlaceholder')" />
</el-form-item>
<el-form-item :label="$t('addCommunity.area')" prop="area">
<area-select @selectArea="selectArea" />
</el-form-item>
<el-form-item :label="$t('addCommunity.address')" prop="tmpAddress" required>
<el-input v-model="addCommunityInfo.tmpAddress" :placeholder="$t('addCommunity.addressPlaceholder')" />
</el-form-item>
<el-form-item :label="$t('addCommunity.nearbyLandmarks')" prop="nearbyLandmarks" required>
<el-input v-model="addCommunityInfo.nearbyLandmarks"
:placeholder="$t('addCommunity.nearbyLandmarksPlaceholder')" />
</el-form-item>
<el-form-item :label="$t('addCommunity.tel')" prop="tel" required>
<el-input v-model="addCommunityInfo.tel" :placeholder="$t('addCommunity.telPlaceholder')" />
</el-form-item>
<el-form-item :label="$t('addCommunity.payFeeMonth')" prop="payFeeMonth" required>
<el-input v-model="addCommunityInfo.payFeeMonth" :placeholder="$t('addCommunity.payFeeMonthPlaceholder')" />
</el-form-item>
<el-form-item :label="$t('addCommunity.feePrice')" prop="feePrice" required>
<el-input v-model="addCommunityInfo.feePrice" :placeholder="$t('addCommunity.feePricePlaceholder')" />
</el-form-item>
<el-form-item v-for="(item, index) in addCommunityInfo.attrs" :key="index" :label="item.specName"
:prop="'attrs.' + index + '.value'">
<el-input v-if="item.specType === '2233'" v-model="item.value" :placeholder="item.specHoldplace" />
<el-select v-else-if="item.specType === '3344'" v-model="item.value" :placeholder="item.specHoldplace"
style="width: 100%">
<el-option v-for="value in item.values" :key="value.value" :label="value.valueName" :value="value.value" />
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="visible = false">{{ $t('common.cancel') }}</el-button>
<el-button type="primary" @click="saveCommunityInfo">{{ $t('common.save') }}</el-button>
</div>
</el-dialog>
</template>
<script>
import { saveCommunity } from '@/api/community/communityManageApi'
import { getAttrSpecList } from '@/api/dev/attrSpecApi'
import { getAttrValueList } from '@/api/dev/attrValueApi'
import AreaSelect from '@/components/community/areaSelect'
export default {
name: 'AddCommunity',
data() {
return {
visible: false,
addCommunityInfo: {
name: '',
address: '',
tmpAddress: '',
areaAddress: '',
nearbyLandmarks: '',
tel: '',
cityCode: '',
mapX: '101.33',
mapY: '101.33',
attrs: [],
payFeeMonth: 12,
feePrice: 0
}
}
},
components: { AreaSelect },
methods: {
openModal() {
this._loadCommunityAttrSpec()
this.visible = true
},
selectArea(area) {
this.addCommunityInfo.cityCode = area.selectArea
},
saveCommunityInfo() {
this.addCommunityInfo.address = this.addCommunityInfo.areaAddress + this.addCommunityInfo.tmpAddress
if (!this.validateForm()) {
return
}
saveCommunity(this.addCommunityInfo).then(res => {
console.log(res)
this.$message.success(this.$t('addCommunity.saveSuccess'))
this.visible = false
this.$emit('listData')
}).catch(error => {
this.$message.error(error.message)
})
},
validateForm() {
if (!this.addCommunityInfo.name) {
this.$message.error(this.$t('addCommunity.validate.name'))
return false
}
if (!this.addCommunityInfo.cityCode) {
this.$message.error(this.$t('addCommunity.validate.cityCode'))
return false
}
if (!this.addCommunityInfo.address) {
this.$message.error(this.$t('addCommunity.validate.address'))
return false
}
if (!this.addCommunityInfo.nearbyLandmarks) {
this.$message.error(this.$t('addCommunity.validate.nearbyLandmarks'))
return false
}
if (!this.addCommunityInfo.tel) {
this.$message.error(this.$t('addCommunity.validate.tel'))
return false
}
return true
},
clearAddCommunityInfo() {
this.addCommunityInfo = {
name: '',
address: '',
tmpAddress: '',
areaAddress: '',
nearbyLandmarks: '',
cityCode: '',
mapX: '101.33',
mapY: '101.33',
attrs: [],
payFeeMonth: 12,
feePrice: 0
}
},
async _loadCommunityAttrSpec() {
this.addCommunityInfo.attrs = []
const { data } = await getAttrSpecList({
page: 1,
row: 100,
tableName: 'building_community_attr'
})
data.forEach(item => {
item.value = ''
if (item.specShow === 'Y') {
item.values = []
this._loadAttrValue(item.specCd, item.values)
this.addCommunityInfo.attrs.push(item)
}
})
},
async _loadAttrValue(specCd, values) {
const { data } = await getAttrValueList({ specCd, page: 1, row: 100 })
data.forEach(item => {
if (item.valueShow === 'Y') {
values.push(item)
}
})
}
}
}
</script>