add.vue
9.97 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<template>
<div class="add-wrap">
<div class="container edit-container" style="min-height: 520px !important">
<p class="edit-title" id="basic">{{merchantId?'编辑门店':'新增门店'}}</p>
<glsx-combi-form class="edit-form-container" ref="editFormRef" :isEdit="true" :isBlock="true" :formRef="editChildRef" :formObj="editForm" :formData="editFormData" :formRules="editRule">
<div slot="merchantHtml">
<el-button type="default" class="el-icon-plus" v-if="!isDisabled" @click="handleRelateStoreClose">选择门店</el-button>
<div class="merchantNameLabel" v-if="editForm.merchantName">
<p>所属门店</p>
<div class="merchantName ellipsis-1">{{ editForm.merchantName }}</div>
</div>
<!-- <div class="el-form-item__error mrt5" v-if="merchantFlag">请选择门店</div> -->
</div>
<div slot="channelHtml">
<el-checkbox-group v-model="editForm.channelIds" @change="handleCheckedChannelChange">
<el-checkbox v-for="channel in channelList" :label="channel.channelType" :key="channel.channelType">{{ channel.channelName }}</el-checkbox>
</el-checkbox-group>
</div>
<div slot="carSeriesHtml">
<el-button type="default" class="el-icon-plus" v-if="!isDisabled" @click="handleCarSeriesClose">选择车系</el-button>
<div class="car-series-wrap" v-if="editForm.vehicleSeriesRequests && editForm.vehicleSeriesRequests.length">
<div class="car-series-item" v-for="item in editForm.vehicleSeriesRequests" :key="item.vehicleSeriesId">{{ item.vehicleSeriesName }}</div>
</div>
</div>
</glsx-combi-form>
</div>
<select-store v-if="relateStoreVisible" ref="relateStore" :dialogVisible="relateStoreVisible" :storeSelected="selectedList" :merchantInfo="editForm.merchantId" @handleRelateStoreConfirm="handleRelateStoreConfirm" @handleRelateStoreClose="handleRelateStoreClose"></select-store>
<selectCarDialog v-if="carDialogVisible" singleChoice @handleClose="handleClose" :echoData="editForm.vehicleSeriesRequests" @handleConfirm="handleConfirm" :dialogVisible="carDialogVisible"></selectCarDialog>
<GLFooter>
<el-button @click="handleCancel">取消</el-button>
<el-button type="primary" @click="handleSave">确定</el-button>
</GLFooter>
</div>
</template>
<script>
import selectStore from './components/selectStore'
import selectCarDialog from './components/selectCarDialog'
export default {
components: {
selectStore,
selectCarDialog
},
data() {
return {
size: 'small',
editChildRef: 'editChildRef',
merchantId: this.$route.query.merchantId ? this.$route.query.merchantId : '',
editForm: {
channelIds: [],
vehicleSeriesRequests: [],
merchantId: '',
merchantName: ''
},
merchantFlag: false,
editFormData: [
{
label: '选择门店',
name: 'merchantId',
addHtml: 'merchantHtml'
},
{
label: '频道名称',
name: 'channel',
addHtml: 'channelHtml'
},
{
label: '主营品牌车系',
name: 'carId',
addHtml: 'carSeriesHtml',
isHide: true
},
],
selectedList: [],
channelList: [],
relateStoreVisible: false, // 选择门店
carDialogVisible: false, //选择车系
editRule: {
merchantId: [{ required: true,validator: (rule, value, callback) => {
if(this.editForm.merchantId){
callback()
}else{
callback(new Error(`请选择门店`))
}
}, trigger: 'change' }],
channel: [{ required: true,validator: (rule, value, callback) => {
if(this.editForm.channelIds && this.editForm.channelIds.length ){
callback()
}else{
callback(new Error(`请选择频道`))
}
}, trigger: 'change' }],
carId: [{ required: true, validator: (rule, value, callback) => {
if(this.editForm.vehicleSeriesRequests && this.editForm.vehicleSeriesRequests.length){
callback()
}else{
callback(new Error(`请选择主营品牌车系`))
}
}, trigger: 'change' }]
}
}
},
mounted() {
this.getChannelList()
if (this.merchantId) {
this.getconfigMerchant()
this.getMerchantData()
this.getCategoryDetail()
}
},
methods: {
//获取频道名称
getChannelList() {
this.$apis.channel
.getChannelListApi({
pageSize: 100,
pageNum: 1
})
.then(res => {
this.channelList = res.list
})
},
getCategoryDetail(){
this.$apis.store.getCategoryByMerchant({merchantId: this.merchantId}).then(res => {
if(res?.vehicleSeriesList?.length){
this.editForm.vehicleSeriesRequests = res.vehicleSeriesList
}
})
},
getMerchantData() {
var params = {
merchantId: this.merchantId,
pageSize: 100,
currentPage: 1
}
this.$apis.common.getMerchantList(params).then(res => {
if (res.list.length) {
this.editForm.merchantId = res.list[0].merchantNo
this.editForm.merchantName = res.list[0].merchantName
}
})
},
//获取频道配置
getconfigMerchant() {
this.$apis.store.getconfigMerchant({ merchantId: this.merchantId }).then(res => {
this.editForm.channelIds = []
res.forEach(item => {
this.editForm.channelIds.push(item.channelId)
if(item.channelId==5) {
const _target = this.editFormData.find(item => item.name == 'carId')
_target.isHide = false
}
})
})
},
handleCancel() {
this.$router.go(-1)
},
handleSave() {
this.$refs.editFormRef.$refs[this.editChildRef].validate(valid => {
if (!this.editForm.merchantName) {
this.merchantFlag = true
return
}
if (valid) {
let params = {
merchantId: this.editForm.merchantId,
merchantName: this.editForm.merchantName,
channelIds: this.editForm.channelIds,
vehicleSeriesRequests: this.editForm?.channelIds?.includes(5) ? this.editForm.vehicleSeriesRequests : []
}
const loading = this.$loading({
lock: true,
text: 'Loading',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.3)'
})
this.$apis.store.configMerchant(params).then(res => {
if (res.code == 0) {
this.loading = false
this.$router.go(-1)
}
this.$message({
message: res.code == '0' ? '编辑成功' : res.message,
type: res.code == '0' ? 'success' : 'error'
})
}).finally(end =>{
loading.close()
})
}
})
},
handleCheckedChannelChange(val) {
const _target = this.editFormData.find(item => item.name == 'carId')
if(val?.includes(5)){
_target.isHide = false
}else{
_target.isHide = true
this.editForm.vehicleSeriesRequests = []
}
},
//选择车系
handleCarSeriesClose(){
this.carDialogVisible = !this.carDialogVisible
},
// 选择门店
handleRelateStoreClose() {
this.relateStoreVisible = !this.relateStoreVisible
},
handleRelateStoreConfirm(selectedData) {
this.$refs.editFormRef.$refs[this.editChildRef].clearValidate('merchantId')
selectedData.merchantId && (this.editForm.merchantId = selectedData.merchantId)
selectedData.merchantName && ((this.editForm.merchantName = selectedData.merchantName), (this.merchantFlag = false))
this.handleRelateStoreClose()
},
handleClose(){
this.carDialogVisible = false
},
handleConfirm(e={}){
let carList = []
for(const key in e){
for(const sonKey in e[key]){
carList = [...carList, ...e[key][sonKey]]
}
}
this.editForm.vehicleSeriesRequests = carList.map(item =>{
const {id, name, parentId, parentName, rootId, rootName} = item
return {
brandId: rootId,
brandName: rootName,
childBrandId: parentId,
childBrandName: parentName,
vehicleSeriesId: id,
vehicleSeriesName: name
}
})
this.handleClose()
this.$refs.editFormRef.$refs[this.editChildRef].validateField('carId')
}
}
}
</script>
<style scoped lang="scss">
.add-wrap {
.container {
min-height: 680px;
padding: 0px 0px 20px;
margin-bottom: 16px;
}
.edit-title {
font-size: 16px;
font-weight: 600;
height: 58px;
line-height: 58px;
border-bottom: 1px solid #e7eaec;
margin: 0 0;
padding: 0 0 0 20px;
}
.edit-form-container {
margin-top: 20px;
}
.assignLabel {
color: #5850ff;
}
.merchantNameLabel {
width: 510px;
color: #1d1d1d;
// margin-left: 50px;
padding: 16px;
margin-top: 8px;
border: 1px solid #e6e6e6;
border-radius: 8rpx;
background: #f9f9f9;
.merchantName {
box-sizing: border-box;
width: 284px;
height: 32px;
background: #ffffff;
border: 1px solid #e6e6e6;
border-radius: 4px;
font-family: PingFangSC-Regular;
font-weight: 400;
font-size: 14px;
color: #999999;
line-height: 32px;
padding: 0 8px;
}
}
.car-series-wrap{
margin-top: 8px;
width: 580px;
height: 80px;
background: #FFFFFF;
border: 1px solid #E8E8EA;
border-radius: 4px;
padding: 6px 8px;
overflow-y: auto;
.car-series-item{
display: inline-block;
padding: 0 8px;
height: 24px;
color: #666666;
line-height: 24px;
background: #FAFBFE;
border: 1px solid #E5E5E5;
border-radius: 4px;
margin-right: 4px;
}
}
}
</style>