into.vue
13.1 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
<template>
<div>
<div class="container">
<div class="table-header">
<h2 class="title">采购明细</h2>
<el-button type="primary" size="small" @click="addLine">添加一行</el-button>
</div>
<el-form ref="addForm" :model="formdata" size="small" :rules="rules">
<GLTable ref="orderRef" :tableData="formdata.tableData" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :hasPage="false">
<template slot="upgradeGoodsId" slot-scope="scope">
<el-form-item style="margin-bottom: 0px" :prop="'tableData.' + scope.index + '.upgradeGoodsId'" :rules="rules.upgradeGoodsId">
<el-select style="width: 100%" v-model="scope.scope.upgradeGoodsId" placeholder="请选择" @change="getGoodsName(scope.scope, scope.scope.upgradeGoodsId)">
<el-option v-for="item in goodsList" :key="item.upgradeGoodsId" :label="item.goodsName" :value="item.upgradeGoodsId"></el-option>
</el-select>
</el-form-item>
</template>
<template slot="goodsNumber" slot-scope="scope">
<el-form-item style="margin-bottom: 0px" :prop="'tableData.' + scope.index + '.goodsNumber'" :rules="rules.goodsNumber">
<el-input v-model="scope.scope.goodsNumber" placeholder="请输入" @blur="handleCalculate(scope.scope, 'goodsNumber')"></el-input>
</el-form-item>
</template>
<template slot="upgradePurchasePrice" slot-scope="scope">
<el-form-item style="margin-bottom: 0px" :prop="'tableData.' + scope.index + '.upgradePurchasePrice'" :rules="rules.upgradePurchasePrice">
<el-input v-model="scope.scope.upgradePurchasePrice" placeholder="请输入" @blur="handleCalculate(scope.scope, 'upgradePurchasePrice')"></el-input>
</el-form-item>
</template>
<template slot="goodsTotalPrice" slot-scope="scope">
<el-form-item style="margin-bottom: 0px" :prop="'tableData.' + scope.index + '.goodsTotalPrice'" :rules="rules.goodsTotalPrice">
<el-input v-model="scope.scope.goodsTotalPrice" placeholder="请输入" @blur="handleCalculate(scope.scope, 'goodsTotalPrice')"></el-input>
</el-form-item>
</template>
<!-- 入库仓库 -->
<template slot="putYqMerchantId" slot-scope="scope">
<el-form-item style="margin-bottom: 0px" :prop="'tableData.' + scope.index + '.putYqMerchantId'" :rules="rules.putYqMerchantId">
<el-select style="width: 100%" v-model="scope.scope.putYqMerchantId" placeholder="请选择" @change="handleSelect(scope.scope, scope.scope.putYqMerchantId)">
<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="putMerchantId" slot-scope="scope">
<el-form-item style="margin-bottom: 0px" :prop="'tableData.' + scope.index + '.putMerchantId'" :rules="rules.putMerchantId">
<el-select style="width: 100%" v-model="scope.scope.putMerchantId" placeholder="请选择" @change="handleStoreSelect(scope.scope, scope.scope.putMerchantId)">
<el-option v-for="item in scope.scope.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(scope.index)">删除</el-button>
</div>
</GLTable>
</el-form>
</div>
<GLFooter style="margin-top: 16px">
<el-button @click="goBack" size="medium">取消</el-button>
<el-button @click="handleSave(1)" type="primary" plain size="medium">保存</el-button>
<el-button type="primary" @click="handleSave(2)" size="medium">保存并入库</el-button>
</GLFooter>
</div>
</template>
<script>
import BigNumber from 'bignumber.js'
export default {
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 {
orderCode: this.$route.query.orderCode || '',
rules: {
upgradeGoodsId: [{ required: true, message: '请选择商品名称', trigger: 'change' }],
goodsTotalPrice: [
{ required: true, message: '请输入采购总额', trigger: 'blur' },
{ validator: checkPrice, trigger: 'blur' }
],
goodsNumber: [
{ required: true, message: '请输入采购数量', trigger: 'blur' },
{ validator: checkPrice, trigger: 'blur' }
],
upgradePurchasePrice: [
{ required: true, message: '请输入采购单价', trigger: 'blur' },
{ validator: checkPrice, trigger: 'blur' }
],
putYqMerchantId: [{ required: true, message: '请选择入库仓库', trigger: 'change' }],
putMerchantId: [{ required: true, message: '请选择入库门店', trigger: 'change' }]
},
formdata: {
tableData: [{ upgradeGoodsId: '', type: '', goodsName: '', goodsNumber: '', upgradePurchasePrice: '', goodsTotalPrice: '', putYqMerchantId: '', putYqMerchantName: '', putMerchantId: '', putMerchantName: '' , refByYqShopList: []}]
},
tableParams: {
tableOption: true,
tableColumns: [
{
label: '商品名称',
prop: 'upgradeGoodsId',
addHtml: 'upgradeGoodsId'
},
{
label: '商品编码',
prop: 'type'
},
{
label: '所属系列',
prop: 'goodsName'
},
{
label: '采购数量',
prop: 'goodsNumber',
addHtml: 'goodsNumber'
},
{
label: '采购单价',
prop: 'upgradePurchasePrice',
addHtml: 'upgradePurchasePrice'
},
{
label: '采购总额/元',
prop: 'goodsTotalPrice',
addHtml: 'goodsTotalPrice'
},
{
label: '入库仓库',
prop: 'putYqMerchantId',
addHtml: 'putYqMerchantId'
},
{
label: '入库门店',
prop: 'putMerchantId',
addHtml: 'putMerchantId'
}
]
},
goodsList: [],
storeUsageList: [],
refByYqShopList: []
}
},
created() {
this.getfwsGoodsList()
this.getMerchantList()
if (this.orderCode) this.getData()
},
methods: {
getMerchantList() {
this.$apis.purchaseShopping.getMerchantList({ mainPartnerMerchant: true }).then(res => {
this.storeUsageList = res
if (this.storeUsageList.length == 1) this.defaultSelect()
})
},
defaultSelect() {
let {
formdata: { tableData },
storeUsageList
} = this
tableData.forEach(item => {
item.putYqMerchantName = storeUsageList[0].merchantName
item.putYqMerchantId = storeUsageList[0].merchantNo
})
this.getRefByYqShopList(tableData[0], storeUsageList[0].merchantNo)
},
getRefByYqShopList(data, value) {
this.$apis.purchaseShopping.get4SRefByYqShopList({ scene: 1, merchantId: value }).then(res => {
data.refByYqShopList = res
if (data) {
data.refByYqShopList.unshift({
merchantName: data.putYqMerchantName,
merchantId: Number(data.putYqMerchantId)
})
}
})
},
handleSave(saveOrWarehousing) {
this.$refs['addForm'].validate(valid => {
if (valid) {
let purchaseOrderGoodsList = []
this.formdata.tableData.forEach(item => {
purchaseOrderGoodsList.push({
upgradeGoodsId: item.upgradeGoodsId,
goodsName: item.goodsName,
goodsNumber: item.goodsNumber,
upgradePurchasePrice: item.upgradePurchasePrice,
goodsTotalPrice: item.goodsTotalPrice,
putYqMerchantId: item.putYqMerchantId,
putYqMerchantName: item.putYqMerchantName,
putMerchantId: item.putMerchantId,
putMerchantName: item.putMerchantName
})
})
let params = {
saveOrWarehousing,
purchaseOrderGoodsList
}
if (this.orderCode) params.orderCode = this.orderCode
if (saveOrWarehousing == 2) {
this.$confirm('入库后自动更新对应的库存且不可撤回,可在入库管理中查看记录。是否确定入库?', '入库提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$apis.product.addSelfOrder(params).then(res => {
this.$notify({
type: 'success',
title: '操作成功'
})
this.goBack()
})
})
} else {
this.$apis.product.addSelfOrder(params).then(res => {
this.$notify({
type: 'success',
title: '操作成功'
})
this.goBack()
})
}
}
})
},
getData() {
this.$apis.purchaseShopping.selectByOrderCode({ orderCode: this.orderCode }).then(res => {
res.forEach(item => {
item.putYqMerchantId = String(item.putYqMerchantId)
item.refByYqShopList = []
this.getRefByYqShopList(item, item.putYqMerchantId)
})
this.$nextTick(() => {
this.formdata.tableData = res
})
})
},
handleDelete(index) {
if (this.formdata.tableData.length == 1) return
this.formdata.tableData.splice(index, 1)
},
getfwsGoodsList() {
this.$apis.product.getfwsGoodsList({}).then(res => {
this.goodsList = res
})
},
getGoodsName(data, id) {
this.goodsList.forEach(item => {
if (item.upgradeGoodsId == id) {
data.type = item.type
data.goodsName = item.goodsCodeName
}
})
},
handleSelect(data, id) {
this.storeUsageList.forEach(item => {
if (item.merchantNo == id) {
data.putYqMerchantName = item.merchantName
data.putMerchantId = ''
}
})
this.getRefByYqShopList(data, id)
},
handleStoreSelect(data, id) {
data.refByYqShopList.forEach(item => {
if (item.merchantId == id) {
data.putMerchantName = item.merchantName
}
})
},
handleCalculate(data, key) {
if (key == 'goodsNumber') {
data[key] = data[key] ? new BigNumber(data[key]).dp(0).toNumber() : ''
data.goodsTotalPrice =
data.upgradePurchasePrice && data.goodsNumber
? new BigNumber(data.upgradePurchasePrice)
.times(data.goodsNumber)
.dp(2)
.toNumber()
: ''
return
}
if (!data.goodsNumber) return
data[key] = data[key] ? new BigNumber(data[key]).dp(2).toNumber() : ''
let params = {
upgradePurchasePrice: data => {
data.goodsTotalPrice = data.upgradePurchasePrice
? new BigNumber(data.upgradePurchasePrice)
.times(data.goodsNumber)
.dp(2)
.toNumber()
: ''
},
goodsTotalPrice: data => {
data.upgradePurchasePrice = data.goodsTotalPrice
? new BigNumber(data.goodsTotalPrice)
.div(data.goodsNumber)
.dp(2)
.toNumber()
: ''
}
}
params[key](data)
},
addLine() {
let {
storeUsageList,
formdata: { tableData }
} = this
tableData.unshift({
refByYqShopList: [],
upgradeGoodsId: '',
type: '',
goodsName: '',
goodsNumber: '',
upgradePurchasePrice: '',
goodsTotalPrice: '',
putYqMerchantId: storeUsageList.length == 1 ? storeUsageList[0].merchantNo : '',
putYqMerchantName: storeUsageList.length == 1 ? storeUsageList[0].merchantName : '',
putMerchantId: '',
putMerchantName: ''
})
if (storeUsageList.length == 1) {
this.getRefByYqShopList(tableData[0], tableData[0].putYqMerchantId)
}
},
goBack() {
this.$router.go(-1)
}
}
}
</script>
<style lang="scss" scoped>
.container {
background: #fff;
padding: 20px;
.table-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15px;
}
.title {
font-weight: 600;
font-size: 16px;
color: #333333;
margin-bottom: 15px;
}
/deep/ .el-form-item__error {
padding-top: 2px;
z-index: 9999999;
position: static;
}
/deep/ td.el-table__cell {
height: 64px;
}
}
</style>