add.vue
18.9 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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
<!-- 新建/编辑采购上架 -->
<template>
<div class="edit-purchase-grounding purchase-grounding edit-box">
<div class="container edit-container">
<p class="edit-title">基础信息</p>
<glsx-combi-form class="edit-form-container m-r-20" ref="editFormRef" :isEdit="isEdit" :pageThat="this" :labelWidth="defaultLabelWidth" :isBlock="true" :formRef="editChildRef" :formObj="editForm" :formData="editFormData" :formRules="editRule">
<div slot="selectGoods">
<el-select
v-model="editForm.upgradeGoodsId"
placeholder="请选择上架商品"
@change="handleGoodsChange"
style="width: 432px"
@focus="handleGoodsFocus"
remote
reserve-keyword
@visible-change="visibleChange"
:remote-method="remoteMethod"
v-el-select-loadmore="interestsLoadmore"
filterable>
<el-option v-for="subItem in goodsList"
:key="subItem.id"
:label="subItem.upgradeGoodsName"
:value="subItem.id">
</el-option>
</el-select>
</div>
<div slot="goodsInfo">
<div class="goodsInfo-box">
<div class="item" v-for="(subItem, subIndex) in copyGoodsDetailForm" :key="subIndex">
<div v-if="subItem.addHtml" class="item_box">
<div class="label">{{ (membraneTypeList.includes(selectedGoodsInfo['goodsType']) ? subItem.label + `(元)/卷` : (subItem.label + '(元)/件')) }}:</div>
<div class="value">{{ priceFilter(selectedGoodsInfo[subItem.value]) }}</div>
</div>
<div v-else class="item_box">
<div class="label">{{ subItem.label + ':' }}</div>
<div class="value">{{ selectedGoodsInfo[subItem.value] || '-' }}</div>
</div>
</div>
</div>
</div>
</glsx-combi-form>
</div>
<div class="container edit-container">
<p class="edit-title">上架门店</p>
<glsx-combi-form class="edit-form-container" ref="editFormMerchantRef" :isEdit="isEdit" :labelWidth="defaultLabelWidth" :isBlock="true" :formRef="editChildRef" :formObj="editForm" :formData="merchantEditFormData" :formRules="editRule">
<div slot="merchantTable" :style="{ width: `calc(100% - ${defaultLabelWidth} )` }">
<div class="table-title">
上架门店列表
<el-button type="primary" plain @click="handleRelateStoreClose(scope)">选择门店</el-button>
</div>
<GLTable ref="warehousListRef" :hasPage="false" :tableParams="tableParams" :tableData="editForm.merchantList">
<span slot="customBtn" slot-scope="scope">
<el-button class="p-0" type="text" @click="handleMerchantDelete(scope)">删除</el-button>
</span>
</GLTable>
</div>
</glsx-combi-form>
</div>
<GLFooter>
<el-button @click="handleCancel" size="medium">取消</el-button>
<!-- 新增/草稿显示 -->
<el-button v-if="editType == 'add' || editForm.status == 0" type="primary" @click="handleConfirm(true)" plain size="medium" :loading="loading">草稿</el-button>
<el-button type="primary" @click="handleConfirm(false)" size="medium" :loading="loading">保存上架</el-button>
</GLFooter>
<!-- 门店弹窗 -->
<relate-store-dialog v-if="relateStoreVisible" ref="relateStore" :relateStoreVisible="relateStoreVisible" :storeApi="storeApi" :storeSearchForm="storeSearchForm" :storeSelected="selectedList" @handleRelateStoreConfirm="handleRelateStoreConfirm" @handleRelateStoreClose="handleRelateStoreClose">
<el-row slot>
<el-form :model="storeSearchForm" ref="relate" :inline="true" label-width="90px">
<el-form-item label="客户名称:" prop="merchantName">
<el-input :size="size" v-model.trim="storeSearchForm.merchantName" placeholder="请输入客户名称" clearable></el-input>
</el-form-item>
<el-form-item label="商户号:" prop="merchantName">
<el-input :size="size" v-model.trim="storeSearchForm.merchantId" placeholder="请输入商户号" clearable></el-input>
</el-form-item>
<el-form-item>
<el-button :size="size" type="primary" @click="handleSearchStore">搜索</el-button>
<el-button :size="size" @click="handleSearchReset">重置</el-button>
</el-form-item>
</el-form>
</el-row>
</relate-store-dialog>
</div>
</template>
<script>
import { goodsSourceOptions, membraneTypeList } from '@/utils/constants.js'
import relateStoreDialog from './relateStoreDialog'
export default {
name: 'editPurchaseGrounding',
components: {
relateStoreDialog
},
data() {
var checkPrice = (rule, value, callback) => {
if (isNaN(+value)) {
callback(new Error('请输入数字值'))
} else {
if (!/^(?:\d{1,6})(?:\.\d{1,2})?$/.test(value)) {
callback(new Error('仅支持输入0~999999小数点后两位'))
} else {
callback()
}
}
}
return {
size: 'small',
editChildRef: 'editChildRef',
routeInfo: {
editType: 'add',
id: ''
},
editStatus: false,
editForm: {
goodsSource: '',
upgradeGoodsId: '',
shopPurchasePrice: '',
merchantList: [],
status: ''
},
editRule: {
goodsSource: [{ required: true, message: '请选择商品来源', trigger: 'change' }],
upgradeGoodsId: [{ required: true, message: '请选择上架商品', trigger: 'change' }],
shopPurchasePrice: [
{ required: true, message: '请输入门店采购价', trigger: 'blur' },
{ validator: checkPrice, trigger: 'blur' }
]
},
isEdit: true,
editFormData: [
{
label: '商品来源',
name: 'goodsSource',
type: 'radio',
optionList: goodsSourceOptions,
optionId: 'id',
optionLabel: 'label',
handleRadioChange: this.handleRadioChange
},
{
label: '上架商品',
name: 'upgradeGoodsId',
addHtml: 'selectGoods'
},
{
label: '门店采购价(元)/件',
name: 'shopPurchasePrice',
type: 'input'
}
],
merchantEditFormData: [
{
addHtml: 'merchantTable'
}
],
// 选择门店
relateStoreVisible: false,
storeApi: this.$apis.grounding.getSimpleMerchantListByPage,
storeSearchForm: {
merchantName: '',
merchantId: ''
},
selectedList: [],
// 门店表格
tableParams: {
tableColumns: [
{
label: '门店名称',
prop: 'merchantName'
},
{
label: '商户号',
prop: 'merchantId'
},
{
label: '操作',
prop: '',
addHtml: 'customBtn'
}
]
},
selectedGoodsInfo: {},
goodsDetailForm: [
{
label: '商品名称',
value: 'upgradeGoodsName',
},
{
label: '商品编码',
value: 'type'
},
{
label: '嘀加采购价',
addHtml: 'DJPurchasePrice',
value: 'purchasePrice'
},
{
label: '所属分类',
value: 'goodsTypeName'
},
{
label: '所属系列',
value: 'goodsName'
}
],
membraneTypeList, // 膜类code集合
goodsList: [], // 上架商品下拉框数据
currentPage: 1,
requestFlag: true
}
},
watch: {
editForm: {
handler(val) {
this.editStatus = true
},
deep: true
},
'editForm.upgradeGoodsId': {
handler(val) {
if (val && this.editFormData[2]?.name !== 'goodsInfo') {
this.editFormData.splice(2, 0, {
name: 'goodsInfo',
addHtml: 'goodsInfo'
})
}
},
deep: true
},
goodsList: {
handler(val) {
if (val.length) {
let upgradeGoodsId = this.editForm?.upgradeGoodsId
let obj = this.editForm?.goodsSource == 0 ? val[val.findIndex(subVal => subVal.id == upgradeGoodsId)] : val[val.findIndex(subVal => subVal.id == upgradeGoodsId)]
this.selectedGoodsInfo = this.filterGoodsData(obj)
}
},
deep: true
},
selectedGoodsInfo: {
handler(val) {
this.setUnit() // 修改采购价单位
// 嘀加采购价字段
let copyGoodsDetailForm = this.$common.utils.deepClone(this.goodsDetailForm)
if (this.editForm?.goodsSource == 1) { // 自营
let index = copyGoodsDetailForm.findIndex(val => val.value == 'purchasePrice')
if (index > -1) {
copyGoodsDetailForm.splice(index, 1)
this.copyGoodsDetailForm = copyGoodsDetailForm
}
} else if (this.editForm?.goodsSource == 0) { // 嘀加
this.copyGoodsDetailForm = copyGoodsDetailForm
}
},
deep: true
}
},
directives: {
'el-select-loadmore': {
bind (el, binding) {
const SELECTWRAP_DOM = el.querySelector(
'.el-select-dropdown .el-select-dropdown__wrap'
)
SELECTWRAP_DOM.addEventListener('scroll', function () {
const condition =
this.scrollHeight - this.scrollTop <= this.clientHeight + 40
if (condition) {
binding.value()
}
})
}
}
},
mounted() {
this.keyDown()
this.routeInfo = this.$route.query
this.routeInfo.editType != 'add' ? this.getInfo() : ''
},
methods: {
keyDown() {
document.onkeydown = function() {
var evt = window.event || arguments[0]
if (evt && evt.keyCode == 13) {
if (typeof evt.cancelBubble != 'undefined') evt.cancelBubble = true
if (typeof evt.stopPropagation == 'function') evt.stopPropagation()
return false
}
return true
}
},
setUnit() {
let index = this.editFormData.findIndex(val => val.name == 'shopPurchasePrice')
if (this.membraneTypeList.includes(this.selectedGoodsInfo?.goodsType)) { // 所选商品是膜类 门店采购价单位修改
if(index > -1) this.editFormData[index].label = '门店采购价(元)/卷'
} else {
if(index > -1) this.editFormData[index].label = '门店采购价(元)/件'
}
},
// 获取上架数据
remoteMethod(query) {
this.goodsNameKeyword = query
this.currentPage = 1
this.goodsList = []
this.getSelectingList(this.editForm?.goodsSource) // 请求接口
},
visibleChange(data) {
// 获取焦点重新渲染下拉框数据
if (data) {
if (this.goodsNameKeyword) {
this.goodsNameKeyword = ''
this.currentPage = 1
this.goodsList = []
this.getSelectingList(this.editForm?.goodsSource)
}
}
},
handleGoodsFocus() {
if ((this.editForm?.goodsSource ?? '') === '')return this.$message.error('请选择商品来源')
if (!this.goodsList?.length && this.requestFlag) return this.$message.error('暂无商品')
},
// 获取更多上架商品
interestsLoadmore() {
setTimeout(() => {
this.currentPage = this.currentPage + 1
if (this.allPages < this.currentPage) {
this.currentPage = this.allPages
return
}
this.getSelectingList(this.editForm?.goodsSource)
}, 10)
},
handleRadioChange(val) {
this.goodsList = []
this.editForm.upgradeGoodsId = ''
this.$nextTick(() => {
this.$refs['editFormRef'].$refs['editChildRef'].clearValidate()
// 清空已选商品的附带信息
this.selectedGoodsInfo = {}
let index = this.editFormData.findIndex(subVal => subVal.name == 'goodsInfo')
if (index > -1) this.editFormData.splice(index, 1)
})
this.currentPage = 1
// 获取上架商品数据
this.getSelectingList(val)
},
filterGoodsData(obj) {
// 已选商品是拉取商品的首页数据或用于回显concat的数据适配
if (obj) {
obj.id = obj?.upgradeGoods?.id || obj?.id
obj.upgradeGoodsName = obj?.upgradeGoods?.upgradeGoodsName || obj?.upgradeGoodsName
obj.type = obj?.upgradeGoods?.type || obj?.type
obj.purchasePrice = obj?.upgradeGoods?.purchasePrice || obj?.purchasePrice
obj.goodsTypeName = obj?.goodsInfo?.goodsTypeName || obj?.goodsTypeName
obj.goodsName = obj?.goodsInfo?.goodsName || obj?.goodsName
obj.goodsType = obj?.goodsInfo?.goodsType || obj?.goodsType
}
return obj || {}
},
priceFilter(num) {
var pow = Math.pow(10, 2)
if ((num ?? '') === '') return '-'
return (Math.round(num * pow) / pow).toFixed(2)
},
// 获取上架商品数据
getSelectingList(goodsSource, defaultSelect) {
let params = {
upgradeGoodsNameOrType: this.goodsNameKeyword,
currentPage: this.currentPage,
pageSize: 10,
partnerMerchantId: goodsSource == 1 ? this.$globalState?.session?.merchantId : undefined, // 自营服务商商户号
partnerMerchantId2: goodsSource == 0 ? this.$globalState?.session?.merchantId : undefined, // 嘀加服务商商户号
shoppingMallFlag: goodsSource == 0 ? 1 : undefined, // 是否上架到采购商城 自营商品不需传
status: 1,
goodsSource,
partnerSceneType: 1
}
this.requestFlag = false
this.$apis.grounding['getGroundingGoodsList'](params).then(res => {
this.allPages = res?.pages
if (defaultSelect?.length && res?.list) res.list = res?.list.concat(defaultSelect)
this.goodsList = this.unique(this.goodsList.concat(res?.list || [])) || []
this.requestFlag = true
})
},
// 去重(回显concat数据后)
unique(arr) {
const res = new Map()
return arr.filter((a) => !res.has(a.id) && res.set(a.id, 1))
},
// 选择上架商品
handleGoodsChange(value) {
let targetItem = this.goodsList
let obj = this.editForm?.goodsSource == 0 ? targetItem[targetItem.findIndex(val => val.id == value)] : targetItem[targetItem.findIndex(val => val.id == value)]
this.selectedGoodsInfo = this.filterGoodsData(obj)
},
getInfo() {
let params = {
id: this.routeInfo?.id
}
this.$apis.grounding.getPurchaseGroundingDetail(params).then(res => {
const defaultSelect = [this.filterGoodsData(this.$common.utils.deepClone(res))]
let resData = {
id: res.id,
goodsSource: res?.goodsSource,
upgradeGoodsId: res?.upgradeGoods?.id || '',
shopPurchasePrice: res?.shopPurchasePrice || '',
merchantList: res?.merchantList || [],
status: res?.status
}
this.editForm = resData
this.getSelectingList(res.goodsSource, defaultSelect)
this.$nextTick(() => {
this.editStatus = false
})
})
},
// 选择门店
handleRelateStoreClose() {
this.selectedList = this.$common.utils.deepClone(this.editForm.merchantList)
this.relateStoreVisible = !this.relateStoreVisible
},
handleRelateStoreConfirm(selectedData) {
this.editForm.merchantList = selectedData
this.selectedList = selectedData
this.handleRelateStoreClose()
this.$refs.editFormMerchantRef.$refs[this.editChildRef].validateField('merchantList')
},
handleSearchStore() {
this.$refs.relateStore.handleCurrentChange(1)
},
handleSearchReset() {
this.storeSearchForm = {
merchantName: '',
merchantId: ''
}
this.$nextTick(() => {
this.$refs.relateStore.handleCurrentChange(1)
})
},
handleMerchantDelete(obj) {
this.$messageBox.confirm('是否删除该门店?', '删除', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
callback: action => {
if (action == 'confirm') {
var idx = this.editForm.merchantList.findIndex(item => item.merchantId == obj.scope.merchantId)
this.editForm.merchantList.splice(idx--, 1)
}
}
})
},
handleConfirm(isDraft = false) {
this.$refs.editFormRef.$refs[this.editChildRef].validate(valid => {
if (valid) {
var params = this.$common.utils.deepClone(this.editForm)
if (!params?.merchantList?.length) return this.$message.error('请选择上架门店')
const arr = []
params?.merchantList?.forEach(val => { // 上架门店组合数据 防止请求参数过长
arr.push({
merchantId: val.merchantId,
merchantName: val.merchantName
})
})
params.merchantList = arr
params.status = isDraft ? 0 : params.status ? params.status : 2 // 是否存草稿
this.$apis.grounding.addOrUpdatePurchaseGrounding(params).then(res => {
this.$message({
message: res.code == '0' ? '操作成功' : res.message,
type: res.code == '0' ? 'success' : 'error'
})
if (res.code == '0') {
this.cancelJump()
}
})
}
})
},
cancelJump() {
this.$router.push({
path: '/purchaseGrounding/index'
})
},
handleCancel() {
if (this.editStatus) {
this.$confirm('当前有内容信息未保存,是否继续返回?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
this.cancelJump()
})
.catch(() => {})
} else {
this.cancelJump()
}
}
}
}
</script>
<style scoped lang="scss">
.purchase-grounding{
.container{
padding: 0 0 20px;
background: #fff;
.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;
}
.goodsInfo-box{
margin: 0 70px 0 154px;
background: #F9F9F9;
display: flex;
flex-wrap: wrap;
padding: 15px 0;
.item{
flex: 0 0 33%;
.item_box{
display: flex;
align-items: start;
.label{
flex-shrink: 0;
color: #666666;
width: 150px;
text-align: right;
}
}
}
}
}
.edit-container{
margin-bottom: 16px;
}
.edit-form-container {
margin:20px 20px 0 0;
.table-title {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
}
}
.purchase-grounding.edit-purchase-grounding .select-merchant {
/* width: calc(98% - 140px); */
width: 98%;
}
.merchant-table {
margin: 0 20px;
}
</style>