index.vue
9.75 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
315
316
317
<template>
<div class="equity-dialog">
<GLDialog mode="mid" :title="type == 1 ? '添加汽车权益' : '添加商品权益'" v-if="show" :visible.sync="show" :show-close="true" :close-on-press-escape="false" :close-on-click-modal="false" :before-close="closeListPoup">
<div class="form gl-form-page gl-form-min">
<el-form class="equityForm" :model="form" :rules="rules" ref="ruleForm" label-width="154px">
<el-form-item v-if="type == 1" label="服务提供方:" prop="supplier">
<el-select v-model="form.supplier" @change="changeSupplier" size="small">
<el-option v-for="item in supplierList" :key="item.value" :label="item.label" :value="item.value"></el-option>
</el-select>
</el-form-item>
<template v-if="type == 2">
<el-form-item label="产品提供方:" prop="supplier">
<el-select v-model="form.supplier" size="small">
<el-option label="海威" value="HW"></el-option>
</el-select>
</el-form-item>
<el-form-item label="选择品牌:" prop="brandName">
<el-select v-model="form.brandName" @change="changeBrandName" filterable size="small">
<el-option v-for="item in brandList" :key="item.brandName" :value="item.brandName" :label="item.brandName"></el-option>
</el-select>
</el-form-item>
<el-form-item label="商品形态:" prop="appearance" v-if="form.brandName">
<el-select v-model="form.appearance" size="small">
<el-option v-for="item in appearanceList" :key="item.appearance" :value="item.label" :label="item.label"></el-option>
</el-select>
</el-form-item>
</template>
<el-form-item label="权益名称:" prop="equityName">
<el-input size="small" v-model="form.equityName" :maxlength="type == 1 ? 8 : 6" placeholder="请输入权益名称"></el-input>
</el-form-item>
<el-form-item label="描述:" prop="equityDesc">
<el-input size="small" v-model="form.equityDesc" :maxlength="type == 1 ? 8 : 6" placeholder="请输入"></el-input>
</el-form-item>
<div>
<el-form-item label="图标:" required prop="equityIcon">
<el-upload action="#" class="avatar-uploader" :show-file-list="false" :before-upload="upLoadImg" id="dialogIcon">
<img v-if="form.equityIcon" :src="form.equityIcon" class="avatar" />
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
<div class="suggestion">建议尺寸:80*80像素,支持jpg,png。</div>
</el-form-item>
</div>
</el-form>
</div>
<div slot="footer" class="dialog-footer">
<el-button size="small" @click="close">取 消</el-button>
<el-button size="small" type="primary" @click="submit(type)">确 定</el-button>
</div>
</GLDialog>
</div>
</template>
<script>
const validatorgoodsImage = (rule, value, callback) => {
if (!value) {
callback('请上传图标')
} else {
callback()
}
}
export default {
name: 'equity-dialog',
data() {
return {
form: {
appearance: '',
equityName: '',
brandName: ''
},
brandList: [],
appearanceList: [],
supplierList: [
{
label: '广联-加油',
value: 'GL_OIL'
},
{
label: '广联-道路救援',
value: 'GL_ROAD_RESCUE'
},
{
label: '广联-轮胎保障',
value: 'GL_TIRE_PROTECTION'
},
{
label: '广联-盗抢无忧',
value: 'GL_ROBBERY_PROTECTION'
},
{
label: '广联-碰撞维修',
value: 'GL_COLLISION_REPAIR'
},
{
label: '广联-整车全损',
value: 'GL_CAR_TOTAL_LOSS'
},
{
label: 'e代驾',
value: 'EDJ'
}
],
rules: {
supplier: [{ required: true, message: '请选择提供方', trigger: 'change' }],
brandName: [{ required: true, message: '请选择品牌', trigger: 'change' }],
appearance: [{ required: true, message: '请选择商品形态', trigger: 'change' }],
equityName: [{ required: true, message: '请输入权益名称', trigger: 'blur' }],
equityDesc: [{ required: true, message: '请输入描述', trigger: 'blur' }],
equityIcon: [{ validator: validatorgoodsImage }]
}
}
},
props: {
show: {
type: Boolean,
default: false
},
type: Number,
isEdit: Boolean,
data: {
type: Object,
default: () => {}
}
},
mounted() {
this.$apis.goodsEquityManageApi.getGoodsBrandList().then(({ data }) => {
this.brandList = data
})
},
watch: {
isEdit(n) {
if (n) {
this.form = JSON.parse(JSON.stringify(this.$parent.editData))
if (this.type == 2) {
this.form.appearance = { 1: '卡券', 2: '直充' }[this.$parent.editData.appearance]
}
}
}
},
methods: {
closeListPoup(done) {
this.$emit('update:show', false)
this.$emit('update:isEdit', false)
this.form = {}
done()
},
close() {
;(this.form.appearance = ''), (this.form.equityName = '')
this.$emit('update:show', false)
this.$emit('update:isEdit', false)
this.$refs.ruleForm.resetFields()
this.form = {}
// console.log("???????????");
},
upLoadImg(file) {
let fileName = file.name
if (file.name.lastIndexOf('.') === -1) {
this.$message.info('路径不正确')
document.getElementById('dialogIcon').value = ''
return false
}
let AllImgExt = '.jpg|.jpeg|.gif|.bmp|.png|.swf'
let extName = file.name.substring(file.name.lastIndexOf('.')).toLowerCase()
if (AllImgExt.indexOf(extName + '|') === -1) {
this.$message.info('图片格式不正确')
document.getElementById('dialogIcon').value = ''
return false
}
// if (fileSize < 3145728) {
if (window.FileReader) {
let reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = img => {
let type = fileName.split('.')[fileName.split('.').length - 1]
let imgUrl = img.target.result.split(',')[1]
this.$apis.commonApi
.upLoadImg({
file: `${type}@${imgUrl}`
})
.then(({ code, message, data }) => {
if (code == 0) {
this.$set(this.form, 'equityIcon', data)
} else {
this.$message.error(message)
}
document.getElementById('dialogIcon').value = ''
})
}
}
},
changeSupplier(e) {
this.supplierList.map(i => {
if (i.value == e) {
this.form.equityName = i.label
}
})
},
getAppearanceList(brandName) {
this.$apis.goodsEquityManageApi.getAppearanceList({ brandName, supplier: 'HW' }).then(({ data }) => {
data.map(i => (i.label = { 1: '卡券', 2: '直充' }[i.appearance]))
this.appearanceList = data
this.form.appearance = ''
})
},
changeBrandName(e) {
this.getAppearanceList(e)
this.form.equityName = this.form.brandName
},
submit(type) {
let { form, isEdit } = this
let obj = JSON.parse(JSON.stringify(form))
let target = type == 1 ? this.$apis.carEquityManageApi : this.$apis.goodsEquityManageApi
this.$refs.ruleForm.validate(valid => {
if (valid) {
if (type == 2) {
obj.goodsCategoryId = this.$parent.goodsCategoryId
obj.appearance = form.appearance == '直充' ? 2 : 1
}
let apiName = 'createEquity'
if (isEdit) apiName = 'updateEquity'
target[apiName](obj).then(({ code, data, message }) => {
if (code == 0) {
this.close()
type == 1 ? this.$parent.getCarList() : this.$parent.getCategoryList()
} else {
this.$message.error(message)
}
})
} else {
return
}
})
}
}
}
</script>
<style scope>
.equity-dialog {
padding: 0;
}
.avatar-uploader {
box-sizing: border-box;
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
width: 80px;
height: 80px;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 80px;
height: 80px;
display: flex;
align-items: center;
justify-content: center;
}
.avatar {
width: 80px;
height: 80px;
display: block;
}
/* .baseinformation {
width: 100%;
height: 28px;
border-bottom: 1px solid #d8d8d8;
padding-bottom: 18px;
} */
/* .form {
padding: 16px;
} */
/* .equity-dialog .el-dialog__body {
color: #606266;
font-size: 14px;
word-break: break-all;
} */
/* .equityForm .el-input--small .el-input__inner {
height: 32px;
line-height: 32px;
width: 432px !important;
} */
.suggestion {
font-size: 14px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #999999;
line-height: 20px;
margin-top: 8px;
}
.titleDialogText {
margin-left: 20px;
font-size: 20px;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #333333;
line-height: 28px;
}
/* .buttonBtn .el-button + .el-button {
margin-left: 40px;
} */
/* .equityDialog .el-dialog__header {
padding: 20px 20px 20px;
border-bottom: 1px solid #d8d8d8;
font-size: 20px;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
} */
/* .equityDialog .el-dialog__footer {
padding: 16px 20px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border-top: 1px solid #e6e6e6;
} */
</style>