addGoods.vue
17.3 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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
<template>
<div class="equity-wrap">
<div class="equity-wrap contain gl-form-page">
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="154px" size="medium" :key="resetTime">
<div class="box">
<div class="title">商品类型</div>
<el-radio-group size="small" :value="1">
<el-radio-button :label="1">品牌商品</el-radio-button>
<el-radio-button :label="2" disabled>门店服务</el-radio-button>
</el-radio-group>
</div>
<div class="box">
<div class="title baseTitle">基本信息</div>
<el-form-item label="产品提供方:" required>
<el-select v-model="ruleForm.supplier" :disabled="isEdit">
<el-option label="海威" value="HW"></el-option>
</el-select>
</el-form-item>
<el-form-item label="商品形态:" required>
<el-radio-group size="small" v-model="ruleForm.appearance" :disabled="isEdit" @change="changeAppearance">
<el-radio-button label="1">卡券</el-radio-button>
<el-radio-button label="2">直充</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="商品编码:" prop="productId">
<el-input v-model="ruleForm.productId" :disabled="isEdit" placeholder="365淘券所对应的商品编码" maxlength="20" @blur="getEquityOutGoodsBySupplierProductId"></el-input>
</el-form-item>
<el-form-item label="品牌名称:" prop="brandName">
<el-select filterable v-model="ruleForm.brandName" @change="changeBrandName" :disabled="isEdit">
<el-option v-for="item in brandNameList" :key="item.brandId" :label="item.brandName" :value="item.brandName"></el-option>
</el-select>
</el-form-item>
<el-form-item label="商品名称:" prop="productName">
<el-input v-model="ruleForm.productName" maxlength="30"></el-input>
</el-form-item>
<el-form-item label="商品图片:" :required="ruleForm.appearance == 1" prop="goodsImage">
<el-upload action="" class="avatar-uploader" :show-file-list="false" :before-upload="upLoadImg" id="goodsIconId">
<template v-if="ruleForm.goodsImage">
<img :src="ruleForm.goodsImage" class="avatar" />
<i class="el-icon-delete-solid uploader-del-icon" @click.stop="delImg"></i>
</template>
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</el-form-item>
</div>
<div class="box">
<div class="title priceMsgTitle">价格信息</div>
<el-form-item v-if="ruleForm.appearance != 1" label="直充面额" prop="denomination">
<el-input v-model="ruleForm.denomination" maxlength="10"></el-input>
</el-form-item>
<el-form-item label="会员价/元:" prop="salesPrice">
<el-input v-model="ruleForm.salesPrice"></el-input>
</el-form-item>
<el-form-item label="非会员价/元:" prop="noMemberPrice">
<el-input v-model="ruleForm.noMemberPrice"></el-input>
</el-form-item>
<el-form-item label="成本含税价/元:" prop="costPrice">
<el-input v-model="ruleForm.costPrice"></el-input>
</el-form-item>
<el-form-item label="官方价/划线价/元:" prop="lineationPrice">
<el-input v-model="ruleForm.lineationPrice"></el-input>
</el-form-item>
<el-form-item label="商品质保期/小时:" prop="warrantyPeriod" :required="ruleForm.appearance == 1">
<el-input v-model.number="ruleForm.warrantyPeriod">
<!-- <template slot="append">小时</template> -->
</el-input>
</el-form-item>
<el-form-item label="商品有效期:">
<el-input v-model.number="ruleForm.validityPeriod">
<template slot="prepend">兑换到账户内</template>
<template slot="append">天有效</template>
</el-input>
</el-form-item>
<el-form-item label="商品库存:">
<el-input v-model="ruleForm.stock" disabled>
<template slot="append">保存或上架商品后将自动检查库存</template>
</el-input>
</el-form-item>
<el-form-item class="editor" label="购买页使用须知:" prop="buysNotes" required>
<quill-editor v-model="ruleForm.buysNotes" :options="editorOption"></quill-editor>
</el-form-item>
<template v-if="ruleForm.appearance == 1">
<el-form-item class="editor" label="卡券页使用须知:" prop="useNotes" required>
<quill-editor v-model="ruleForm.useNotes" :options="editorOption"></quill-editor>
</el-form-item>
</template>
<template v-else>
<el-form-item class="editor" label="直充使用须知:">
<quill-editor v-model="ruleForm.useNotes" :options="editorOption"></quill-editor>
</el-form-item>
</template>
</div>
</el-form>
</div>
<div class="footer-panel">
<el-button plain class="btn-three" @click="$router.go(-1)">取消</el-button>
<div class="wrap_driver">
<el-button plain type="primary" @click="onSubmit">提交</el-button>
</div>
<el-button @click="onSubmit('save')" type="primary">保存</el-button>
</div>
</div>
</template>
<script type="text/ecmascript-6">
import Vue from 'vue'
const validatorWarrantyPeriod = (rule, value, callback) => {
if (window.vm.$children[0].$children[0].ruleForm.appearance == 1) {
if (!value) {
callback('请输入商品质保期')
} else {
callback()
}
} else {
callback()
}
}
const validatorbuysNotes = (rule, value, callback) => {
if (!value) {
callback('请输入购买页使用须知')
} else {
callback()
}
}
const validatoruseNotes = (rule, value, callback) => {
if (window.vm.$children[0].$children[0].ruleForm.appearance == 1) {
if (!value) {
callback('请输入卡券页使用须知')
} else {
callback()
}
} else {
callback()
}
}
const validatorgoodsImage = (rule, value, callback) => {
if (window.vm.$children[0].$children[0].ruleForm.appearance == 1) {
if (!value) {
callback('请上传商品图片')
} else {
callback()
}
} else {
callback()
}
}
const validatorNoMemberPrice = (rule, value, callback) => {
let { salesPrice } = window.vm.$children[0].$children[0].ruleForm
if (value) {
var reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
console.log(reg.test(value))
if (reg.test(value)) {
if (salesPrice && value < salesPrice) {
callback('非会员价需 ≥ 会员价!')
} else {
callback()
}
} else {
callback('请输入正确格式的价格')
}
} else {
callback()
}
}
const validatorSalesPrice = (rule, value, callback) => {
if (value) {
var reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
if (reg.test(value)) {
callback()
} else {
callback('请输入正确格式的价格')
}
} else {
callback('请输入会员价')
}
}
const validatorCostPrice = (rule, value, callback) => {
if (value) {
var reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
if (reg.test(value)) {
callback()
} else {
callback('请输入正确格式的价格')
}
} else {
callback('请输入成本含税价')
}
}
const validatorLineationPrice = (rule, value, callback) => {
if (value) {
var reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
if (reg.test(value)) {
callback()
} else {
callback('请输入正确格式的价格')
}
} else {
callback('请输入官方价/划线价')
}
}
export default {
name: '',
data() {
return {
defaultwidth: 432,
eventBus: new Vue(),
isEdit: false,
isNewGoods: false,
resetTime: new Date().getTime(),
editorOption: {
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'],
[{ list: 'ordered' }],
[{ script: 'sub' }, { script: 'super' }],
[{ size: ['small', false, 'large', 'huge'] }],
[{ color: [] }, { background: [] }],
[{ align: [] }],
['clean']
// ['link', 'image']
]
}
},
ruleForm: {
supplier: 'HW',
appearance: 1,
costPrice: '',
lineationPrice: '',
noMemberPrice: '',
salesPrice: '',
brandName: '',
productName: '',
productId: '',
goodsImage: '',
denomination: 0,
warrantyPeriod: 0,
buysNotes: '',
useNotes: ''
},
stock: '',
brandNameList: [],
rules: {
brandName: [{ required: true, message: '请输入品牌名称', trigger: 'change' }],
productName: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
productId: [{ required: true, message: '请输入商品编码', trigger: 'blur' }],
goodsImage: [{ validator: validatorgoodsImage }],
denomination: [{ required: true, message: '请输入直值面额', trigger: 'blur' }],
salesPrice: [{ validator: validatorSalesPrice, trigger: 'blur' }],
noMemberPrice: [{ validator: validatorNoMemberPrice, trigger: 'blur' }],
costPrice: [{ validator: validatorCostPrice, trigger: 'blur' }],
lineationPrice: [{ validator: validatorLineationPrice, trigger: 'blur' }],
warrantyPeriod: [{ validator: validatorWarrantyPeriod, type: 'number', trigger: 'blur' }],
buysNotes: [{ validator: validatorbuysNotes }],
useNotes: [{ validator: validatoruseNotes }]
}
}
},
mounted() {
this.getListWithPageOutGoods()
let id = this.$route.query.id
let edit = this.$route.query.edit
if (id) {
this.getEquityGoodsById(id)
this.isEdit = !edit
} else {
this.isNewGoods = true
}
},
methods: {
changeBrandName() {
console.log('1')
},
getEquityGoodsById(id) {
this.$apis.orderApi.getEquityGoodsById({ id }).then(({ code, data, message }) => {
if (code == 0) {
Object.keys(data).map(key => {
if (data[key] == null) delete data[key]
let ketList = 'salesPrice|costPrice|lineationPrice|'
if (ketList.indexOf(`${key}|`) != -1) {
data[key] = data[key] ? Number(data[key]) : 0
}
})
data.stock = data.stock == -1 ? '无限制' : data.stock
data.buysNotes = data.buysNotes ? decodeURIComponent(data.buysNotes) : ''
data.useNotes = data.useNotes ? decodeURIComponent(data.useNotes) : ''
this.ruleForm = data
} else {
this.$message.error(message)
}
})
},
getListWithPageOutGoods() {
let { appearance } = this.ruleForm
this.$apis.orderApi.getListWithPageOutGoods({ appearance }).then(({ code, data: { list } }) => {
if (code == 0) {
this.brandNameList = list
}
})
},
getEquityOutGoodsBySupplierProductId() {
let { productId, appearance } = this.ruleForm
if (!productId) return
this.$apis.orderApi
.getEquityOutGoodsBySupplierProductId({
productId,
supplier: 'HW',
appearance
})
.then(({ code, message, data }) => {
if (code == 0) {
this.ruleForm.brandName = data.brandName
this.ruleForm.productName = data.productName
this.ruleForm.costPrice = Number(data.salesPrice)
this.resetTime = new Date().getTime()
} else {
this.$message.error(message)
}
})
},
upLoadImg(file) {
let fileName = file.name
if (file.name.lastIndexOf('.') === -1) {
this.$message.info('路径不正确')
document.getElementById('goodsIconId').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('goodsIconId').value = ''
return false
}
// if (fileSize < 3145728) {
if (window.FileReader) {
let reader = new FileReader()
reader.readAsDataURL(file)
reader.onload = img => {
// console.log(file)
let type = fileName.split('.')[fileName.split('.').length - 1]
let imgUrl = img.target.result.split(',')[1]
this.$apis.commonApi
.upLoadImg({
file: `${type}@${imgUrl}`
})
.then(({ code, data, message }) => {
if (code == 0) {
window.vm.$set(this.ruleForm, 'goodsImage', data)
} else {
this.$message.error(message)
}
document.getElementById('goodsIconId').value = ''
})
}
}
},
delImg() {
this.ruleForm.goodsImage = ''
},
changeAppearance() {
this.getListWithPageOutGoods()
this.$refs.ruleForm.resetFields()
},
onSubmit(flag) {
this.ruleForm.insertOperationType = flag == 'save' ? 0 : 1
if (flag == 'save') {
this.createGoods()
return
}
this.$refs.ruleForm.validate(valid => {
if (!valid) {
console.log('error submit!!')
return false
} else {
if (!this.isNewGoods) {
this.createGoods()
return
}
let { supplier, brandName, productId, appearance } = this.ruleForm
this.$apis.orderApi
.sameGoodsCheck({
supplier,
brandName,
productId
})
.then(res => {
if (res.code == 0) {
this.$apis.orderApi
.stockAndStatusCheck({
productId,
supplier,
appearance
})
.then(_res => {
if (_res.code == 0) {
this.createGoods()
return
}
if (_res.errId == -1006) {
this.$confirm(_res.message, '提示', {
confirmButtonText: '保存',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.createGoods()
})
} else if (_res.errId == -1003) {
this.$confirm(_res.message, '提示', {
confirmButtonText: '提交',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.createGoods()
})
}
})
} else {
this.$message.error('已存在相同商品编码的商品')
}
})
}
})
},
createGoods(name = 'createGoods') {
let obj = JSON.parse(JSON.stringify(this.ruleForm))
obj.buysNotes = encodeURIComponent(obj.buysNotes)
if (obj.useNotes) obj.useNotes = encodeURIComponent(obj.useNotes)
if (obj.appearance == 1) delete obj.denomination
if (!this.isNewGoods) name = 'updateGoods'
this.$apis.orderApi[name](obj).then(({ code, message }) => {
if (code == 0) {
this.$message({
message: '操作成功!',
type: 'success'
})
this.$router.push('/goods/index')
} else {
this.$message.error(message)
}
})
}
}
}
</script>
<style lang="scss" scoped>
.equity-wrap .contain{
padding: 16px 0;
}
.footer-panel {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
margin: 16px 0;
.wrap_driver {
margin: 0 20px;
}
}
.uploader-del-icon {
position: absolute;
width: 28px;
height: 28px;
display: flex;
align-items: center;
justify-content: center;
top: 0px;
right: -28px;
}
.box .title {
padding: 0 0 20px;
font-weight: 700;
}
.box .baseTitle {
padding-top: 40px;
}
.box .priceMsgTitle {
padding-top: 18px;
}
.box .el-form-item {
width: 470px;
}
.box .el-form-item .el-input-group__prepend,
.box .el-form-item .el-input-group__append {
background-color: transparent;
border: none;
}
.box .el-form-item .el-input--suffix .el-input__inner {
padding-right: 45px;
}
.box .el-form-item .el-input__suffix {
right: 20px;
}
.box .el-select {
width: 100%;
}
.box .editor {
width: 800px;
}
.box .avatar-uploader {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
width: 148px;
height: 148px;
}
.box .avatar-uploader-file {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
}
.box .avatar-uploader:hover {
border-color: #409eff;
}
.box .avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 148px;
height: 148px;
line-height: 148px;
text-align: center;
}
.box .avatar {
width: 148px;
height: 148px;
display: block;
}
</style>