numDialog.vue
2.79 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
<!-- 退货 -->
<template>
<GLDialog title="退货"
:visible.sync="numVisible"
class="numDailog"
@onCancel="handleClose"
@onOk="handleAddConfirm">
<div class="gl-form-page gl-form-min">
<el-form ref="inventoryNumForm"
:model="infoForm"
:rules="formRules"
label-width="154px"
size="small">
<el-form-item label="退货数量:"
prop="inventoryNum">
<el-input placeholder="请输入退货数量"
v-model="infoForm.inventoryNum"
clearable
@input="handleUpgradeNum"></el-input>
</el-form-item>
</el-form>
</div>
</GLDialog>
</template>
<script>
import { limitPrice } from '@/common/format'
import BigNumber from 'bignumber.js'
export default {
name: 'NumDialog',
data() {
return {
infoForm: {
inventoryNum: ''
},
oldVal: {
inventoryNum: ''
},
formRules: {
inventoryNum: [
{ required: true, message: '请输入退货数量', trigger: 'blur' },
{
validator: (rule, value, callback) => {
// 先转成数字
const num = Number(value)
// 检查是否为有效数字
if (isNaN(num)) {
return callback(new Error('请输入有效数字'))
}
// 检查是否为 0
if (num === 0) {
return callback(new Error('退货数量不能为 0'))
}
// 校验通过
callback()
},
trigger: 'blur' // 或 'change'/'input'
}
]
},
selectLoading: false,
// 基本数据
baseData: {
noRelatcategoryList: []
}
}
},
props: {
numVisible: {
type: Boolean,
default: false
},
recordInfo: {
type: Object,
default: () => { }
}
},
watch: {},
created() { },
components: {},
computed: {},
mounted() { },
methods: {
handleUpgradeNum(newVal) {
this.infoForm.inventoryNum = limitPrice(newVal, this.oldVal.inventoryNum, 8, 2, 0, this.recordInfo.stock)
this.oldVal.inventoryNum = this.infoForm.inventoryNum
},
handleAddConfirm() {
this.$refs.inventoryNumForm.validate(valid => {
if (valid) {
this.recordInfo.refundStock = parseFloat(this.infoForm.inventoryNum)
this.recordInfo.profitAndLoss = BigNumber(parseFloat(this.infoForm.inventoryNum))
.minus(parseFloat(this.recordInfo.stock))
.toString()
this.handleClose(this.recordInfo)
}
})
},
handleClose(info) {
this.$emit('dialogClose', info)
}
}
}
</script>
<style></style>