complementCodeDialog.vue
5.03 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
<!-- 补库存标签码弹窗 -->
<template>
<baseDialog :config="config"
:dialog-config="dialogConfig"
:is-loading="isLoading"
:is-show.sync="visible"
@handleClick="handleConfirm">
<div class="complement-dialog-content">
<!-- 步骤1:填写补码信息 -->
<div v-if="!showQrCode">
<el-form ref="form"
label-width="120px"
:model="form"
:rules="rules">
<el-form-item label="产品名称:">
<span>{{ row.upgradeGoodsName || '-' }}</span>
</el-form-item>
<el-form-item label="产品编码:">
<span>{{ row.productCode || '-' }}</span>
</el-form-item>
<el-form-item label="产品ID:">
<span>{{ row.upgradeCommodityCode || '-' }}</span>
</el-form-item>
<el-form-item v-if="row.isFilm"
:error="errorMsg"
label="库存数量:"
prop="stockNum">
<el-input v-model="form.stockNum"
placeholder="请输入"
style="width: 200px"
@input="handleInput">
<template #append>
米
</template>
</el-input>
</el-form-item>
</el-form>
</div>
</div>
</baseDialog>
</template>
<script>
import { replenishCodeApi } from "@/api/stockManage";
import { limitPrice } from "@/common/format";
export default {
name: "ComplementCodeDialog",
props: {
visibleSync: {
type: Boolean,
default: false,
},
row: {
type: Object,
default: () => ({}),
},
},
data() {
return {
showQrCode: false,
form: {
stockNum: "",
},
rules: {
stockNum: [
{ required: true, message: "请输入库存数量", trigger: "blur" },
],
},
errorMsg: "",
isLoading: false,
config: {
showClose: true,
appendToBody: false,
isShowFooter: true,
cancel_name: "取消",
confirm_name: "下载",
},
dialogConfig: {
title: "补库存标签码",
width: "500px",
},
qrcode: null,
};
},
computed: {
visible: {
get() {
return this.visibleSync;
},
set(newVal) {
this.$emit("update:visibleSync", newVal);
},
},
},
methods: {
handleInput(val) {
// 只能输入数字,保留2位小数
let formatted = val.replace(/[^\d.]/g, "");
formatted = limitPrice(formatted, this.form.stockNum, 10, 2, 0);
this.form.stockNum = formatted;
if (this.form.stockNum && Number(this.form.stockNum) > Number(this.row.stock)) {
this.errorMsg = "输入值不能高于当前库存数量";
} else {
this.errorMsg = "";
}
},
handleConfirm() {
if (this.showQrCode) {
// 执行下载
this.downloadQrCode();
} else {
if (this.row.isFilm) {
if (!this.form.stockNum) {
this.$message.warning("请输入库存数量");
return;
}
if (Number(this.form.stockNum) > Number(this.row.stock)) {
this.errorMsg = "输入值不能高于当前库存数量";
this.$message.error("输入值不能高于当前库存数量");
return;
}
} else {
if (!this.row.stock || Number(this.row.stock) <= 0) {
this.$message.error("当前产品库存必须大于0,才允许补库存标签码");
return;
}
}
const params = {
merchantId: this.row.yqMerchantId,
upgradeGoodsId: this.row.upgradeGoodsId, // 产品ID
goodsType: this.row.goodsType, // 商品类型
};
if (this.row.isFilm) {
params.stockNum = this.form.stockNum;
}
this.isLoading = true;
replenishCodeApi({ dataString: JSON.stringify(params) }).then((res) => {
this.isLoading = false;
if (res && res.labelImageUrl) {
this.downloadFile(res.labelImageUrl);
this.visible = false;
this.$message.success("补库存标签码成功并开始下载");
} else {
this.$message.error("未获取到标签码下载链接");
}
}).catch(() => {
this.isLoading = false;
});
}
},
downloadFile(url, fileName) {
const link = document.createElement("a");
link.style.display = "none";
link.href = url;
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
},
},
};
</script>
<style scoped lang="scss">
.complement-dialog-content {
padding: 20px;
}
.qrcode-wrapper {
display: flex;
justify-content: center;
align-items: center;
padding: 10px;
}
.qrcode-capture-box {
width: 280px;
padding: 20px;
background: #fff;
border: 1px solid #eee;
border-radius: 8px;
display: flex;
flex-direction: column;
align-items: center;
.info-section {
width: 100%;
margin-bottom: 15px;
font-size: 14px;
color: #333;
line-height: 1.8;
.info-item {
word-break: break-all;
}
}
.qrcode-img {
margin-bottom: 10px;
}
.qr-text {
font-size: 16px;
font-weight: bold;
color: #333;
margin-top: 5px;
}
}
::v-deep .el-form-item__error {
position: relative;
margin-top: 4px;
}
</style>