into.vue
8.78 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
<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>
<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' }
]
},
formdata: {
tableData: [{ upgradeGoodsId: '', type: '', goodsName: '', goodsNumber: '', upgradePurchasePrice: '', goodsTotalPrice: '' }]
},
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'
}
]
},
goodsList: []
}
},
created() {
this.getfwsGoodsList()
if (this.orderCode) this.getData()
},
methods: {
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
})
})
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 => {
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
}
})
},
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() {
this.formdata.tableData.unshift({
upgradeGoodsId: '',
type: '',
goodsName: '',
goodsNumber: '',
upgradePurchasePrice: '',
goodsTotalPrice: ''
})
},
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>