deliverAdd.vue
16.2 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
<template>
<div v-if="dialogShow">
<GLDialog bigTitle="详细信息" mode="big" :visible.sync="dialogShow" :close-on-click-modal="false">
<div class="detail-info">
<div>
发货单号:
<span>{{ detailInfo.deliveryNumber }}</span>
</div>
<div>
承运公司:
<span>{{ detailInfo.deliveryCompany }}</span>
</div>
<div>
发货时间:
<span>{{ dayjs(detailInfo.deliveryDate).format('YYYY-MM-DD HH:mm:ss') }}</span>
</div>
</div>
<template v-for="(item, index) in detailInfo.deliveryDetailList">
<div class="table-wrap" :key="index">
<div class="detail-info">
<div>
商品名称:
<span>{{ item.upgradeGoodsName }} {{ detailInfo.specificationData }}</span>
</div>
<div>
发货数量:
<span>{{ membraneTypeList.includes(item.goodsType) ? `${item.purchaseNumber}卷` : `${item.purchaseNumber}件` }}</span>
<span class="lookNumber" @click="lookNumber(item.deliveryCardList)" v-if="item.deliveryCardList && item.deliveryCardList.length > 0">查看卡号</span>
</div>
<div>
可用库存数量:
<span>{{ item.stockNum }}{{ membraneTypeList.includes(item.goodsType) ? `米` : `件` }}</span>
</div>
<div class="add-btn" @click="addLineTable(index)" v-if="item.deliveryCardList === null || item.deliveryCardList.length == 0">添加入库记录</div>
</div>
<el-form ref="addForm" :model="item" size="small" :rules="rules" v-if="item.deliveryCardList === null || item.deliveryCardList.length == 0">
<GLTable :tableData="item.goodsWarehousingList" :noDataImg="url" :tableParams="tableParams" :hasPage="false">
<template slot="increaseStockNum" slot-scope="scope">
<el-form-item style="margin-bottom: 0px" :prop="'goodsWarehousingList.' + scope.index + '.increaseStockNum'" :rules="rules.increaseStockNum">
<el-input v-model="scope.scope.increaseStockNum" placeholder="请输入" @blur="handleCalculate(scope.scope, 'increaseStockNum', index)"></el-input>
</el-form-item>
</template>
<template slot="film" slot-scope="scope">
<div v-if="manageMode && filmTypeList.includes(detailInfo.goodsType)">
<el-button v-if="!scope.scope.filmRollList" type="text" @click="handleSelectFilm(scope.scope, index, scope.index)">请选择</el-button>
<div v-else>
<span class="film-txt">...({{ scope.scope.filmRollList.length }})</span>
<el-button type="text" @click="handleSelectFilm(scope.scope, index, scope.index)">重新选择</el-button>
</div>
</div>
<div v-else>--</div>
</template>
<!-- 入库仓库 -->
<template slot="yqMerchantId" slot-scope="scope">
<el-form-item style="margin-bottom: 0px" :prop="'goodsWarehousingList.' + scope.index + '.yqMerchantId'" :rules="rules.shopMerchantName">
<el-select style="width: 100%" v-model="scope.scope.yqMerchantId" placeholder="请选择" @change="handleSelect(scope.scope, scope.scope.yqMerchantId)">
<el-option v-for="item in storeUsageList" :key="item.merchantNo" :label="item.merchantName" :value="item.merchantNo"></el-option>
</el-select>
</el-form-item>
</template>
<!-- 入库门店 -->
<template slot="merchantId" slot-scope="scope">
<el-form-item style="margin-bottom: 0px" :prop="'goodsWarehousingList.' + scope.index + '.merchantId'" :rules="rules.merchantId">
<el-select style="width: 100%" v-model="scope.scope.merchantId" placeholder="请选择" @change="handleStoreSelect(scope.scope, scope.scope.merchantId)">
<el-option v-for="item in refByYqShopList" :key="item.merchantId" :label="item.merchantName" :value="item.merchantId"></el-option>
</el-select>
</el-form-item>
</template>
<div class="table-btns" slot="auth-button" slot-scope="scope">
<el-button type="text" @click="handleDelete(index, scope.index)">删除</el-button>
</div>
</GLTable>
</el-form>
<div v-else class="message">已自动入库至商户的权益卡管理中,可前往“库存管理-权益卡管理”中查询</div>
</div>
</template>
<el-dialog width="750px" title="查看发货卡号" :visible.sync="innerVisible" append-to-body>
<GLTable class="look-card-wrap" :tableData="tableData" :noDataImg="url" :tableParams="innerParams" :hasPage="false"></GLTable>
</el-dialog>
<span slot="footer" class="dialog-footer">
<el-button size="small" @click="dialogShow = false">关闭</el-button>
<el-button type="primary" size="small" @click="handleSave" :loading="loading">保存入库</el-button>
</span>
</GLDialog>
<filmDialog :visible.sync="filmVisible" :info="info" maxAddNumAttr="stockAddNum" @handleConfirm="handleFilmConfirm"></filmDialog>
</div>
</template>
<script>
import BigNumber from 'bignumber.js'
import * as dayjs from 'dayjs'
import { membraneTypeList } from '@/utils/constants.js'
import filmDialog from '../purchaseOrder/components/FilmDialog'
export default {
name: 'DeliverAdd',
props: {
visible: {
type: Boolean,
default: false
},
id: {
type: String,
default: ''
}
},
computed: {
dialogShow: {
get() {
if (this.visible) {
this.getDetail()
}
return this.visible
},
set(val) {
this.$emit('update:visible', val)
}
}
},
data() {
var checkPrice = (rule, value, callback) => {
if (isNaN(+value)) {
callback(new Error('请输入数字值'))
} else {
if (value <= 0 || value > 999999) {
callback(new Error('仅支持输入0~999999'))
} else {
callback()
}
}
}
return {
membraneTypeList: membraneTypeList,
dayjs: dayjs,
goodsList: [],
storeUsageList: [],
refByYqShopList: [],
goodsWarehousingList: [],
tableParams: {
tableOption: true,
tableColumns: [
{
label: '入库数量/卷',
prop: 'increaseStockNum',
addHtml: 'increaseStockNum'
},
{
label: '膜卷号',
prop: 'filmRollList',
addHtml: 'film'
},
{
label: '入库仓库',
prop: 'yqMerchantId',
addHtml: 'yqMerchantId'
},
{
label: '入库门店',
prop: 'merchantId',
addHtml: 'merchantId'
}
]
},
rules: {
yqMerchantId: [{ required: true, message: '请选择入库仓库', trigger: 'change' }],
merchantId: [{ required: true, message: '请选择入库门店', trigger: 'change' }],
increaseStockNum: [
{ required: true, message: '请输入入库数量', trigger: 'blur' },
{ validator: checkPrice, trigger: 'blur' }
]
},
detailInfo: {},
innerVisible: false,
innerParams: {
tableOption: false,
tableColumns: [
{
label: '卡号',
prop: 'cardNum',
width: 630
}
]
},
tableData: [],
filmVisible: false,
info: {},
filmTypeList: [1, 4, 6, 12, 14],
manageMode: false,
loading: false
}
},
components: {
filmDialog
},
created() {
this.getManageMode()
},
methods: {
lookNumber(data) {
this.innerVisible = true
this.tableData = data.map(item => {
return { cardNum: item }
})
},
handleCalculate(data, key, index) {
// 膜类商品判断发货数量;其他判断可用库存数量
let attr = this.filmTypeList.includes(this.detailInfo.goodsType) ? 'purchaseNumber' : 'stockNum'
if (data[key] > this.detailInfo.deliveryDetailList[index][attr]) {
data[key] = this.detailInfo.deliveryDetailList[index][attr]
return
}
data[key] = data[key] ? new BigNumber(data[key]).dp(2).toNumber() : ''
},
getMerchantList() {
this.$apis.purchaseShopping.getMerchantList({ mainPartnerMerchant: true }).then(res => {
this.storeUsageList = res
if (this.storeUsageList.length == 1) this.defaultSelect()
})
},
getManageMode() {
this.$apis.purchaseShopping.getManageMode({}).then(res => {
this.manageMode = res
})
},
defaultSelect() {
let {
detailInfo: { deliveryDetailList },
storeUsageList
} = this
deliveryDetailList.forEach(item => {
item.goodsWarehousingList[0].yqMerchantName = storeUsageList[0].merchantName
item.goodsWarehousingList[0].yqMerchantId = storeUsageList[0].merchantNo
})
this.getRefByYqShopList(deliveryDetailList[0].goodsWarehousingList[0], storeUsageList[0].merchantNo)
},
getRefByYqShopList(data, value) {
this.$apis.purchaseShopping.get4SRefByYqShopList({ scene: 1, merchantId: value }).then(res => {
this.refByYqShopList = res
if (data) {
this.refByYqShopList.unshift({
merchantName: data.yqMerchantName,
merchantId: data.yqMerchantId
})
}
})
},
handleSelect(data, id) {
this.storeUsageList.forEach(item => {
if (item.merchantNo == id) {
data.yqMerchantName = item.merchantName
data.merchantId = ''
}
})
this.getRefByYqShopList(data, id)
},
handleStoreSelect(data, id) {
this.refByYqShopList.forEach(item => {
if (item.merchantId == id) {
data.merchantName = item.merchantName
}
})
},
filmIsVisible() {
this.filmVisible = !this.filmVisible
},
handleSelectFilm(row, pIdx, idx) {
if (!row.increaseStockNum) {
this.$message({
message: '请先完善采购数量',
type: 'error',
customClass: 'message-Z-zinde'
})
return
}
this.filmIsVisible()
this.filmIds = {
pIdx: pIdx,
idx: idx
}
this.info = row
this.info.stockAddNum = Math.ceil(row.increaseStockNum)
},
handleFilmConfirm(list) {
this.detailInfo.deliveryDetailList[this.filmIds.pIdx].goodsWarehousingList[this.filmIds.idx].filmRollList = list
this.filmIsVisible()
},
handleDetailClose() {
this.dialogShow = false
},
getDetail() {
this.$apis.delivery.getDeliveryDetail({ id: this.id }).then(res => {
let { data } = res
if (res.code == 0) {
data.deliveryDetailList = [
{
upgradeGoodsName: data.upgradeGoodsName,
goodsType: data.goodsType,
purchaseNumber: data.purchaseNumber,
deliveryCardList: data.deliveryCardList,
stockNum: data.stockNum,
orderCode: data.orderCode,
orderDeliveryId: data.orderDeliveryId,
upgradeGoodsId: data.upgradeGoodsId,
goodsWarehousingList: [
{
increaseStockNum: '',
yqMerchantId: '',
yqMerchantName: '',
merchantId: '',
merchantName: ''
}
]
}
]
this.detailInfo = data
this.getMerchantList()
}
})
},
handleDelete(index, line) {
if (this.detailInfo.deliveryDetailList[index].goodsWarehousingList.length > 1) {
this.detailInfo.deliveryDetailList[index].goodsWarehousingList.splice(line, 1)
}
},
addLineTable(index) {
let { storeUsageList } = this
this.detailInfo.deliveryDetailList[index].goodsWarehousingList.push({
increaseStockNum: '',
yqMerchantId: storeUsageList.length == 1 ? storeUsageList[0].merchantNo : '',
yqMerchantName: storeUsageList.length == 1 ? storeUsageList[0].merchantName : '',
merchantId: '',
merchantName: ''
})
let data = this.detailInfo.deliveryDetailList
this.$set(data, index, data[index])
},
validateForm(form) {
return new Promise(resolve => {
form.validate(valid => {
if (valid) {
resolve()
}
})
})
},
handleSave() {
let num = 0
this.$refs['addForm'].forEach(async item => {
try {
await this.validateForm(item)
num++
} catch (err) {
console.log(err)
}
if (num == this.$refs['addForm'].length) {
let deliveryDetailList = this.detailInfo.deliveryDetailList.filter(item => {
if (item.deliveryCardList.length == 0) {
return item
}
})
let params = {
deliveryDetailList: this.$common.utils.deepClone(deliveryDetailList)
}
// console.log(this.detailInfo, 'this.detailInfo---')
for (let i = 0; i < params.deliveryDetailList.length; i++) {
item = params.deliveryDetailList[i]
item.id = this.detailInfo.id
for (let j = 0; j < item.goodsWarehousingList.length; j++) {
let subItem = item.goodsWarehousingList[j]
if (this.manageMode) {
// 校验:膜卷号必填
if (!subItem.filmRollList || (subItem.filmRollList && subItem.filmRollList.length == 0)) {
this.$message({
message: item.upgradeGoodsName + '请选择膜卷号',
type: 'error',
customClass: 'message-Z-zinde'
})
return true
}
// 校验:入库数量和膜卷号数量相等
if (subItem.filmRollList && subItem.filmRollList.length != Math.ceil(subItem.increaseStockNum)) {
this.$message({
message: item.upgradeGoodsName + '的入库数量和膜卷号数量不相等',
type: 'error',
customClass: 'message-Z-zinde'
})
return true
}
}
subItem.increaseStockNum = subItem.increaseStockNum * (item.stockNum / item.purchaseNumber)
}
params.id = this.detailInfo.orderDeliveryId
}
// console.log(params, 'params----')
this.loading = true
this.$apis.delivery.addPurchaseOrder(params).then(res => {
this.loading = false
if (res.code == 0) {
this.$message({
type: 'success',
message: '操作成功!'
})
this.dialogShow = false
this.$emit('handleSuccess')
} else {
this.$message({
type: 'error',
message: res.message
})
}
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
.detail-info {
display: flex;
align-items: center;
justify-content: space-between;
color: #666666ff;
font-size: 14px;
margin-bottom: 16px;
span {
color: #333333ff;
}
.add-btn {
font-size: 14px;
color: #5850ff;
cursor: pointer;
}
}
.table-wrap {
border: 1px solid #e5e5e5;
padding: 16px;
box-sizing: border-box;
margin-top: 16px;
/deep/ .el-form-item__error {
padding-top: 2px;
z-index: 9999999;
position: static;
}
/deep/ td.el-table__cell {
height: 64px;
}
}
.lookNumber {
font-size: 14px;
color: #5850ff !important;
cursor: pointer;
margin-left: 8px;
}
.look-card-wrap {
/deep/.el-table th.el-table__cell > .cell {
padding: 0 16px;
text-align: center;
}
/deep/.el-table__body td.el-table__cell {
text-align: center;
}
}
.film-txt {
box-sizing: border-box;
height: 32px;
line-height: 32px;
background: #f4f6fc;
border: 1px solid #eaeaec;
font-weight: 400;
font-size: 14px;
color: #666666;
padding: 6px;
margin-right: 6px;
}
</style>