|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+<template>
|
|
|
2
|
+ <div class="app-container">
|
|
|
3
|
+ <!-- 检索区 -->
|
|
|
4
|
+ <el-card shadow="never" class="search-card">
|
|
|
5
|
+ <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
|
|
|
6
|
+ <el-form-item label="库存搜索" prop="keyword">
|
|
|
7
|
+ <el-input
|
|
|
8
|
+ v-model="queryParams.keyword"
|
|
|
9
|
+ placeholder="请输入商品名称/商品规格"
|
|
|
10
|
+ clearable
|
|
|
11
|
+ style="width: 260px"
|
|
|
12
|
+ @keyup.enter.native="handleQuery"
|
|
|
13
|
+ >
|
|
|
14
|
+ <el-button slot="append" icon="el-icon-search" @click="handleQuery" />
|
|
|
15
|
+ </el-input>
|
|
|
16
|
+ </el-form-item>
|
|
|
17
|
+ <el-form-item>
|
|
|
18
|
+ <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
|
|
19
|
+ </el-form-item>
|
|
|
20
|
+ </el-form>
|
|
|
21
|
+ </el-card>
|
|
|
22
|
+
|
|
|
23
|
+ <br/>
|
|
|
24
|
+
|
|
|
25
|
+ <!-- 列表区 -->
|
|
|
26
|
+ <el-card shadow="never" class="table-card">
|
|
|
27
|
+ <el-row :gutter="10" class="mb8">
|
|
|
28
|
+ <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
|
|
29
|
+ </el-row>
|
|
|
30
|
+
|
|
|
31
|
+ <el-table border v-loading="loading" :data="goodsList" :empty-text="emptyTableText">
|
|
|
32
|
+ <el-table-column label="商品名称" align="left" min-width="260">
|
|
|
33
|
+ <template slot-scope="scope">
|
|
|
34
|
+ <div class="goods-cell">
|
|
|
35
|
+ <image-preview v-if="scope.row.mainPic" :src="scope.row.mainPic" :width="44" :height="44" />
|
|
|
36
|
+ <span class="goods-name">{{ scope.row.goodsName || '—' }}</span>
|
|
|
37
|
+ </div>
|
|
|
38
|
+ </template>
|
|
|
39
|
+ </el-table-column>
|
|
|
40
|
+ <el-table-column label="商品规格" align="center" width="120" :show-overflow-tooltip="true">
|
|
|
41
|
+ <template slot-scope="scope">
|
|
|
42
|
+ <span>{{ specText(scope.row.specText) }}</span>
|
|
|
43
|
+ </template>
|
|
|
44
|
+ </el-table-column>
|
|
|
45
|
+ <el-table-column label="操作" align="center" width="140" fixed="right">
|
|
|
46
|
+ <template slot-scope="scope">
|
|
|
47
|
+ <el-button size="mini" type="text" @click="openAdjust(scope.row)" v-hasPermi="['agri:seller:stock:adjust:edit']">调整</el-button>
|
|
|
48
|
+ <el-button size="mini" type="text" @click="openRecords(scope.row)" v-hasPermi="['agri:seller:stock:adjust:list']">记录</el-button>
|
|
|
49
|
+ </template>
|
|
|
50
|
+ </el-table-column>
|
|
|
51
|
+ </el-table>
|
|
|
52
|
+
|
|
|
53
|
+ <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
|
|
|
54
|
+ </el-card>
|
|
|
55
|
+
|
|
|
56
|
+ <!-- 库存调整弹窗 -->
|
|
|
57
|
+ <el-dialog title="库存调整" :visible.sync="adjustOpen" width="560px" append-to-body @close="resetAdjust">
|
|
|
58
|
+ <div v-if="currentRow" class="adjust-goods-brief">
|
|
|
59
|
+ <image-preview v-if="currentRow.mainPic" :src="currentRow.mainPic" :width="48" :height="48" />
|
|
|
60
|
+ <div class="brief-text">
|
|
|
61
|
+ <div class="brief-name">{{ currentRow.goodsName || '—' }}</div>
|
|
|
62
|
+ <div class="brief-spec">规格:{{ specText(currentRow.specText) }}</div>
|
|
|
63
|
+ </div>
|
|
|
64
|
+ </div>
|
|
|
65
|
+ <el-form ref="adjustFormRef" :model="adjustForm" :rules="adjustRules" label-width="90px" size="small">
|
|
|
66
|
+ <el-form-item label="调整方式" prop="adjustMode">
|
|
|
67
|
+ <el-radio-group v-model="adjustForm.adjustMode" @change="handleAdjustModeChange">
|
|
|
68
|
+ <div class="mode-option">
|
|
|
69
|
+ <el-radio label="1">增量更新</el-radio>
|
|
|
70
|
+ <p class="mode-tip">在现有库存上增加或减少配额数量,调整数量为负数表示减少</p>
|
|
|
71
|
+ </div>
|
|
|
72
|
+ <div class="mode-option">
|
|
|
73
|
+ <el-radio label="2">覆盖更新</el-radio>
|
|
|
74
|
+ <p class="mode-tip">将原有库存数量进行覆盖,覆盖后更新为调整数量填写的库存数量</p>
|
|
|
75
|
+ </div>
|
|
|
76
|
+ </el-radio-group>
|
|
|
77
|
+ </el-form-item>
|
|
|
78
|
+ <el-form-item label="调整数量" prop="adjustQty">
|
|
|
79
|
+ <el-input-number
|
|
|
80
|
+ v-model="adjustForm.adjustQty"
|
|
|
81
|
+ :min="adjustQtyMin"
|
|
|
82
|
+ :precision="0"
|
|
|
83
|
+ controls-position="right"
|
|
|
84
|
+ style="width: 200px"
|
|
|
85
|
+ />
|
|
|
86
|
+ </el-form-item>
|
|
|
87
|
+ </el-form>
|
|
|
88
|
+ <div slot="footer" class="dialog-footer">
|
|
|
89
|
+ <el-button @click="adjustOpen = false">取 消</el-button>
|
|
|
90
|
+ <el-button type="primary" :loading="adjustSubmitting" @click="submitAdjust">确 认</el-button>
|
|
|
91
|
+ </div>
|
|
|
92
|
+ </el-dialog>
|
|
|
93
|
+
|
|
|
94
|
+ <!-- 调整记录弹窗 -->
|
|
|
95
|
+ <el-dialog title="记录" :visible.sync="recordsOpen" width="760px" append-to-body @close="resetRecords">
|
|
|
96
|
+ <div v-if="currentRow" class="records-toolbar">
|
|
|
97
|
+ <el-select v-model="recordQuery.adjustType" placeholder="调整类型" clearable size="small" style="width: 160px" @change="loadRecords">
|
|
|
98
|
+ <el-option v-for="item in adjustTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
|
|
|
99
|
+ </el-select>
|
|
|
100
|
+ </div>
|
|
|
101
|
+ <el-table border v-loading="recordsLoading" :data="recordList" max-height="420" :empty-text="recordsEmptyText">
|
|
|
102
|
+ <el-table-column label="调整类型" align="center" prop="adjustTypeText" width="110">
|
|
|
103
|
+ <template slot-scope="scope">
|
|
|
104
|
+ <span>{{ scope.row.adjustTypeText || adjustTypeLabel(scope.row.adjustType) }}</span>
|
|
|
105
|
+ </template>
|
|
|
106
|
+ </el-table-column>
|
|
|
107
|
+ <el-table-column label="调整前数量" align="center" prop="stockBefore" width="110">
|
|
|
108
|
+ <template slot-scope="scope">
|
|
|
109
|
+ <span>{{ scope.row.stockBefore != null ? scope.row.stockBefore : '—' }}</span>
|
|
|
110
|
+ </template>
|
|
|
111
|
+ </el-table-column>
|
|
|
112
|
+ <el-table-column label="调整后数量" align="center" prop="stockAfter" width="110">
|
|
|
113
|
+ <template slot-scope="scope">
|
|
|
114
|
+ <span>{{ scope.row.stockAfter != null ? scope.row.stockAfter : '—' }}</span>
|
|
|
115
|
+ </template>
|
|
|
116
|
+ </el-table-column>
|
|
|
117
|
+ <el-table-column label="操作账号" align="center" prop="operatorName" width="100" :show-overflow-tooltip="true">
|
|
|
118
|
+ <template slot-scope="scope">
|
|
|
119
|
+ <span>{{ scope.row.operatorName || '—' }}</span>
|
|
|
120
|
+ </template>
|
|
|
121
|
+ </el-table-column>
|
|
|
122
|
+ <el-table-column label="创建时间" align="center" width="160">
|
|
|
123
|
+ <template slot-scope="scope">
|
|
|
124
|
+ <span>{{ parseTime(scope.row.createTime) || '—' }}</span>
|
|
|
125
|
+ </template>
|
|
|
126
|
+ </el-table-column>
|
|
|
127
|
+ </el-table>
|
|
|
128
|
+ </el-dialog>
|
|
|
129
|
+ </div>
|
|
|
130
|
+</template>
|
|
|
131
|
+
|
|
|
132
|
+<script>
|
|
|
133
|
+import {
|
|
|
134
|
+ listSellerStockAdjust,
|
|
|
135
|
+ confirmSellerStockAdjust,
|
|
|
136
|
+ listSellerStockAdjustRecords
|
|
|
137
|
+} from "@/api/agri/seller/stock/adjust"
|
|
|
138
|
+import { getSellerContext } from "@/api/agri/seller/context"
|
|
|
139
|
+import { setSellerShopContext } from "@/utils/sellerShop"
|
|
|
140
|
+
|
|
|
141
|
+const ADJUST_TYPE_MAP = {
|
|
|
142
|
+ "1": "增加库存",
|
|
|
143
|
+ "2": "减少库存",
|
|
|
144
|
+ "3": "覆盖库存"
|
|
|
145
|
+}
|
|
|
146
|
+
|
|
|
147
|
+export default {
|
|
|
148
|
+ name: "AgriSellerStockAdjust",
|
|
|
149
|
+ data() {
|
|
|
150
|
+ const validateAdjustQty = (rule, value, callback) => {
|
|
|
151
|
+ if (value == null || value === "") {
|
|
|
152
|
+ callback(new Error("请输入调整数量"))
|
|
|
153
|
+ return
|
|
|
154
|
+ }
|
|
|
155
|
+ if (!Number.isInteger(Number(value))) {
|
|
|
156
|
+ callback(new Error("请输入正确的库存数量"))
|
|
|
157
|
+ return
|
|
|
158
|
+ }
|
|
|
159
|
+ if (this.adjustForm.adjustMode === "1") {
|
|
|
160
|
+ if (Number(value) === 0) {
|
|
|
161
|
+ callback(new Error("调整数量不能为 0"))
|
|
|
162
|
+ return
|
|
|
163
|
+ }
|
|
|
164
|
+ } else if (Number(value) < 0) {
|
|
|
165
|
+ callback(new Error("请输入正确的库存数量"))
|
|
|
166
|
+ return
|
|
|
167
|
+ }
|
|
|
168
|
+ callback()
|
|
|
169
|
+ }
|
|
|
170
|
+ return {
|
|
|
171
|
+ loading: false,
|
|
|
172
|
+ showSearch: true,
|
|
|
173
|
+ total: 0,
|
|
|
174
|
+ goodsList: [],
|
|
|
175
|
+ queryParams: {
|
|
|
176
|
+ pageNum: 1,
|
|
|
177
|
+ pageSize: 10,
|
|
|
178
|
+ keyword: undefined
|
|
|
179
|
+ },
|
|
|
180
|
+ currentRow: null,
|
|
|
181
|
+ adjustOpen: false,
|
|
|
182
|
+ adjustSubmitting: false,
|
|
|
183
|
+ adjustForm: {
|
|
|
184
|
+ adjustMode: "1",
|
|
|
185
|
+ adjustQty: 1
|
|
|
186
|
+ },
|
|
|
187
|
+ adjustRules: {
|
|
|
188
|
+ adjustMode: [{ required: true, message: "请选择调整方式", trigger: "change" }],
|
|
|
189
|
+ adjustQty: [{ validator: validateAdjustQty, trigger: "blur" }]
|
|
|
190
|
+ },
|
|
|
191
|
+ recordsOpen: false,
|
|
|
192
|
+ recordsLoading: false,
|
|
|
193
|
+ recordList: [],
|
|
|
194
|
+ recordQuery: {
|
|
|
195
|
+ adjustType: undefined
|
|
|
196
|
+ },
|
|
|
197
|
+ adjustTypeOptions: [
|
|
|
198
|
+ { value: "1", label: "增加库存" },
|
|
|
199
|
+ { value: "2", label: "减少库存" },
|
|
|
200
|
+ { value: "3", label: "覆盖库存" }
|
|
|
201
|
+ ]
|
|
|
202
|
+ }
|
|
|
203
|
+ },
|
|
|
204
|
+ computed: {
|
|
|
205
|
+ hasSearchFilter() {
|
|
|
206
|
+ return !!this.queryParams.keyword
|
|
|
207
|
+ },
|
|
|
208
|
+ emptyTableText() {
|
|
|
209
|
+ return this.hasSearchFilter ? "未找到符合条件的商品" : "暂无可调整商品"
|
|
|
210
|
+ },
|
|
|
211
|
+ adjustQtyMin() {
|
|
|
212
|
+ return this.adjustForm.adjustMode === "2" ? 0 : undefined
|
|
|
213
|
+ },
|
|
|
214
|
+ recordsEmptyText() {
|
|
|
215
|
+ return this.recordQuery.adjustType ? "未找到符合条件的调整记录" : "暂无数据"
|
|
|
216
|
+ }
|
|
|
217
|
+ },
|
|
|
218
|
+ created() {
|
|
|
219
|
+ this.initPage()
|
|
|
220
|
+ },
|
|
|
221
|
+ methods: {
|
|
|
222
|
+ specText(text) {
|
|
|
223
|
+ const val = text ? String(text).trim() : ""
|
|
|
224
|
+ return val && val !== "—" ? val : "—"
|
|
|
225
|
+ },
|
|
|
226
|
+ adjustTypeLabel(type) {
|
|
|
227
|
+ return ADJUST_TYPE_MAP[type] || "—"
|
|
|
228
|
+ },
|
|
|
229
|
+ initPage() {
|
|
|
230
|
+ this.loadShopContext().then(() => {
|
|
|
231
|
+ this.getList()
|
|
|
232
|
+ }).catch(() => {
|
|
|
233
|
+ this.getList()
|
|
|
234
|
+ })
|
|
|
235
|
+ },
|
|
|
236
|
+ loadShopContext() {
|
|
|
237
|
+ return getSellerContext().then(response => {
|
|
|
238
|
+ const data = response.data || {}
|
|
|
239
|
+ if (data.shopId != null) {
|
|
|
240
|
+ setSellerShopContext(data.shopId, data.shopName)
|
|
|
241
|
+ }
|
|
|
242
|
+ })
|
|
|
243
|
+ },
|
|
|
244
|
+ getList() {
|
|
|
245
|
+ this.loading = true
|
|
|
246
|
+ listSellerStockAdjust(this.queryParams).then(response => {
|
|
|
247
|
+ this.goodsList = response.rows || []
|
|
|
248
|
+ this.total = response.total || 0
|
|
|
249
|
+ this.loading = false
|
|
|
250
|
+ }).catch(() => {
|
|
|
251
|
+ this.loading = false
|
|
|
252
|
+ })
|
|
|
253
|
+ },
|
|
|
254
|
+ handleQuery() {
|
|
|
255
|
+ this.queryParams.pageNum = 1
|
|
|
256
|
+ this.getList()
|
|
|
257
|
+ },
|
|
|
258
|
+ resetQuery() {
|
|
|
259
|
+ this.resetForm("queryForm")
|
|
|
260
|
+ this.queryParams.pageNum = 1
|
|
|
261
|
+ this.getList()
|
|
|
262
|
+ },
|
|
|
263
|
+ openAdjust(row) {
|
|
|
264
|
+ this.currentRow = row
|
|
|
265
|
+ this.adjustForm = {
|
|
|
266
|
+ adjustMode: "1",
|
|
|
267
|
+ adjustQty: 1
|
|
|
268
|
+ }
|
|
|
269
|
+ this.adjustOpen = true
|
|
|
270
|
+ this.$nextTick(() => {
|
|
|
271
|
+ if (this.$refs.adjustFormRef) {
|
|
|
272
|
+ this.$refs.adjustFormRef.clearValidate()
|
|
|
273
|
+ }
|
|
|
274
|
+ })
|
|
|
275
|
+ },
|
|
|
276
|
+ handleAdjustModeChange(mode) {
|
|
|
277
|
+ if (mode === "2" && this.adjustForm.adjustQty != null && this.adjustForm.adjustQty < 0) {
|
|
|
278
|
+ this.adjustForm.adjustQty = 0
|
|
|
279
|
+ }
|
|
|
280
|
+ this.$nextTick(() => {
|
|
|
281
|
+ if (this.$refs.adjustFormRef) {
|
|
|
282
|
+ this.$refs.adjustFormRef.clearValidate("adjustQty")
|
|
|
283
|
+ }
|
|
|
284
|
+ })
|
|
|
285
|
+ },
|
|
|
286
|
+ resetAdjust() {
|
|
|
287
|
+ this.currentRow = null
|
|
|
288
|
+ this.adjustSubmitting = false
|
|
|
289
|
+ this.adjustForm = {
|
|
|
290
|
+ adjustMode: "1",
|
|
|
291
|
+ adjustQty: 1
|
|
|
292
|
+ }
|
|
|
293
|
+ if (this.$refs.adjustFormRef) {
|
|
|
294
|
+ this.$refs.adjustFormRef.resetFields()
|
|
|
295
|
+ }
|
|
|
296
|
+ },
|
|
|
297
|
+ submitAdjust() {
|
|
|
298
|
+ if (!this.currentRow || !this.currentRow.goodsId) {
|
|
|
299
|
+ return
|
|
|
300
|
+ }
|
|
|
301
|
+ this.$refs.adjustFormRef.validate(valid => {
|
|
|
302
|
+ if (!valid) {
|
|
|
303
|
+ return
|
|
|
304
|
+ }
|
|
|
305
|
+ this.adjustSubmitting = true
|
|
|
306
|
+ confirmSellerStockAdjust(this.currentRow.goodsId, {
|
|
|
307
|
+ adjustMode: this.adjustForm.adjustMode,
|
|
|
308
|
+ adjustQty: Number(this.adjustForm.adjustQty)
|
|
|
309
|
+ }).then(() => {
|
|
|
310
|
+ this.$modal.msgSuccess("调整成功")
|
|
|
311
|
+ this.adjustOpen = false
|
|
|
312
|
+ this.adjustSubmitting = false
|
|
|
313
|
+ }).catch(() => {
|
|
|
314
|
+ this.adjustSubmitting = false
|
|
|
315
|
+ })
|
|
|
316
|
+ })
|
|
|
317
|
+ },
|
|
|
318
|
+ openRecords(row) {
|
|
|
319
|
+ this.currentRow = row
|
|
|
320
|
+ this.recordQuery.adjustType = undefined
|
|
|
321
|
+ this.recordsOpen = true
|
|
|
322
|
+ this.loadRecords()
|
|
|
323
|
+ },
|
|
|
324
|
+ loadRecords() {
|
|
|
325
|
+ if (!this.currentRow || !this.currentRow.goodsId) {
|
|
|
326
|
+ return
|
|
|
327
|
+ }
|
|
|
328
|
+ this.recordsLoading = true
|
|
|
329
|
+ listSellerStockAdjustRecords(this.currentRow.goodsId, this.recordQuery).then(response => {
|
|
|
330
|
+ this.recordList = response.data || []
|
|
|
331
|
+ this.recordsLoading = false
|
|
|
332
|
+ }).catch(() => {
|
|
|
333
|
+ this.recordList = []
|
|
|
334
|
+ this.recordsLoading = false
|
|
|
335
|
+ })
|
|
|
336
|
+ },
|
|
|
337
|
+ resetRecords() {
|
|
|
338
|
+ this.currentRow = null
|
|
|
339
|
+ this.recordList = []
|
|
|
340
|
+ this.recordQuery.adjustType = undefined
|
|
|
341
|
+ this.recordsLoading = false
|
|
|
342
|
+ }
|
|
|
343
|
+ }
|
|
|
344
|
+}
|
|
|
345
|
+</script>
|
|
|
346
|
+
|
|
|
347
|
+<style scoped lang="scss">
|
|
|
348
|
+.mb8 {
|
|
|
349
|
+ margin-bottom: 8px;
|
|
|
350
|
+}
|
|
|
351
|
+.goods-cell {
|
|
|
352
|
+ display: flex;
|
|
|
353
|
+ align-items: center;
|
|
|
354
|
+ gap: 8px;
|
|
|
355
|
+}
|
|
|
356
|
+.goods-name {
|
|
|
357
|
+ flex: 1;
|
|
|
358
|
+ min-width: 0;
|
|
|
359
|
+ line-height: 1.4;
|
|
|
360
|
+}
|
|
|
361
|
+.adjust-goods-brief {
|
|
|
362
|
+ display: flex;
|
|
|
363
|
+ align-items: flex-start;
|
|
|
364
|
+ gap: 12px;
|
|
|
365
|
+ margin-bottom: 16px;
|
|
|
366
|
+ padding: 12px;
|
|
|
367
|
+ background: #fafafa;
|
|
|
368
|
+ border-radius: 4px;
|
|
|
369
|
+}
|
|
|
370
|
+.brief-text {
|
|
|
371
|
+ flex: 1;
|
|
|
372
|
+ min-width: 0;
|
|
|
373
|
+}
|
|
|
374
|
+.brief-name {
|
|
|
375
|
+ font-weight: 500;
|
|
|
376
|
+ color: #303133;
|
|
|
377
|
+ line-height: 1.4;
|
|
|
378
|
+}
|
|
|
379
|
+.brief-spec {
|
|
|
380
|
+ margin-top: 4px;
|
|
|
381
|
+ font-size: 12px;
|
|
|
382
|
+ color: #909399;
|
|
|
383
|
+}
|
|
|
384
|
+.mode-option {
|
|
|
385
|
+ margin-bottom: 12px;
|
|
|
386
|
+ &:last-child {
|
|
|
387
|
+ margin-bottom: 0;
|
|
|
388
|
+ }
|
|
|
389
|
+}
|
|
|
390
|
+.mode-tip {
|
|
|
391
|
+ margin: 4px 0 0 24px;
|
|
|
392
|
+ font-size: 12px;
|
|
|
393
|
+ color: #909399;
|
|
|
394
|
+ line-height: 1.5;
|
|
|
395
|
+}
|
|
|
396
|
+.records-toolbar {
|
|
|
397
|
+ margin-bottom: 12px;
|
|
|
398
|
+}
|
|
|
399
|
+</style>
|