inventory-form.vue
4.99 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
<template>
<el-dialog title="添加库存" :close-on-click-modal="false" :visible.sync="visible" class="NCC-dialog NCC-dialog_center"
lock-scroll width="800px">
<el-form ref="elForm" :model="dataForm" size="small" label-width="120px" label-position="right" :rules="rules">
<el-row :gutter="15">
<el-col :span="12">
<el-form-item label="产品" prop="productId">
<el-select v-model="dataForm.productId" placeholder="请选择产品" clearable filterable
:style='{"width":"100%"}' :disabled="!!defaultProductId" @change="onProductChange">
<el-option v-for="item in productOptions" :key="item.id" :label="item.productName"
:value="item.id" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="数量" prop="quantity">
<el-input-number v-model="dataForm.quantity" placeholder="请输入数量" :min="1" :precision="0"
:style='{"width":"100%"}' />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="入库时间" prop="stockInTime">
<el-date-picker v-model="dataForm.stockInTime" type="date" placeholder="请选择入库时间"
value-format="yyyy-MM-dd" format="yyyy-MM-dd" :style='{"width":"100%"}' />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="生产日期" prop="productionDate">
<el-date-picker v-model="dataForm.productionDate" type="date" placeholder="请选择生产日期"
value-format="yyyy-MM-dd" format="yyyy-MM-dd" :style='{"width":"100%"}' />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="保质期(天)" prop="shelfLife">
<el-input-number v-model="dataForm.shelfLife" placeholder="请输入保质期" :min="1" :precision="0"
:style='{"width":"100%"}' />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="批次号" prop="batchNumber">
<el-input v-model="dataForm.batchNumber" placeholder="请输入批次号" clearable
:style='{"width":"100%"}' />
</el-form-item>
</el-col>
</el-row>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">取 消</el-button>
<el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading">确 定</el-button>
</span>
</el-dialog>
</template>
<script>
import request from '@/utils/request'
export default {
data() {
return {
visible: false,
btnLoading: false,
defaultProductId: '',
dataForm: {
productId: '',
quantity: 1,
stockInTime: '',
productionDate: '',
shelfLife: 365,
batchNumber: ''
},
productOptions: [],
rules: {
productId: [
{ required: true, message: '请选择产品', trigger: 'change' }
],
quantity: [
{ required: true, message: '请输入数量', trigger: 'blur' }
],
stockInTime: [
{ required: true, message: '请选择入库时间', trigger: 'change' }
]
}
}
},
methods: {
init(productId) {
this.visible = true
this.defaultProductId = productId || ''
this.dataForm = {
productId: productId || '',
quantity: 1,
stockInTime: '',
productionDate: '',
shelfLife: 365,
batchNumber: ''
}
this.initProductOptions()
},
initProductOptions() {
// 如果传入了产品ID,只显示该产品;否则只显示上架的产品
const query = {
currentPage: 1,
pageSize: 1000
}
// 如果传入了产品ID,则查询该产品;否则只查询上架的产品
if (this.defaultProductId) {
query.id = this.defaultProductId
} else {
query.onShelfStatus = 1 // 只获取上架的产品
}
request({
url: '/api/Extend/LqProduct/GetList',
method: 'GET',
data: query
}).then(res => {
if (res.code == 200 && res.data && res.data.list) {
if (this.defaultProductId) {
// 如果传入了产品ID,只显示该产品
this.productOptions = res.data.list
} else {
// 只显示上架的产品
this.productOptions = res.data.list.filter(product => product.onShelfStatus === 1)
}
}
}).catch(() => {
this.productOptions = []
})
},
onProductChange() {
// 产品选择变化时的处理
},
dataFormSubmit() {
this.$refs.elForm.validate((valid) => {
if (!valid) {
return false
}
this.btnLoading = true
request({
url: '/api/Extend/LqInventory/Create',
method: 'POST',
data: {
productId: this.dataForm.productId,
quantity: this.dataForm.quantity,
stockInTime: this.dataForm.stockInTime,
productionDate: this.dataForm.productionDate,
shelfLife: this.dataForm.shelfLife,
batchNumber: this.dataForm.batchNumber
}
}).then(res => {
this.btnLoading = false
this.$message({
type: 'success',
message: res.msg || '添加成功',
onClose: () => {
this.visible = false
this.$emit('refresh')
}
})
}).catch(() => {
this.btnLoading = false
})
})
}
}
}
</script>
<style lang="scss" scoped>
</style>