heshaofeng
14 小时以前 673b5a596f611099eaacc310f6e7def0e022daca
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
<template>
    <!-- 遮罩层 -->
    <div class="mask-layer" v-if="loading"></div>
 
    <vol-box v-model="show" title="批量Excel盘点出库" :width="800" :height="500">
        <template #content>
            <el-form ref="form" :model="form" label-width="90px" class="mt-10">
                <!-- 出库区域(和你直接出库完全一样) -->
                <el-form-item label="出库区域:">
                    <el-select v-model="station" placeholder="请选择出库区域" style="width: 100%">
                        <el-option 
                            v-for="item in stations" 
                            :key="item.key" 
                            :label="item.label" 
                            :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
 
                <!-- Excel上传 -->
                <el-form-item label="Excel文件:" prop="file">
                    <el-upload
                        ref="upload"
                        :auto-upload="false"
                        :limit="1"
                        accept=".xlsx"
                        :file-list="fileList"
                        @change="handleFileChange"
                    >
                        <el-button type="primary" :disabled="loading">选择Excel文件</el-button>
                        <template #tip>
                            <div class="text-gray-500 text-xs mt-1">
                                仅支持 .xlsx<br>
                                第一列:仓库号  第二列:物料编码
                            </div>
                        </template>
                    </el-upload>
                </el-form-item>
 
                <!-- 结果 -->
                <el-form-item label="处理结果:">
                    <div class="result-box p-3 border rounded bg-gray-50 h-32 overflow-auto">
                        <div v-if="resultText" class="text-sm whitespace-pre-line">{{ resultText }}</div>
                        <div v-else class="text-gray-400 text-sm">请选择文件并执行批量出库</div>
                    </div>
                </el-form-item>
            </el-form>
        </template>
 
        <template #footer>
            <div class="dialog-footer">
                <el-button size="small" plain @click="resetForm">重置</el-button>
                <el-button size="small" type="danger" plain @click="batchImport" :loading="loading">
                    <i class="el-icon-check"></i> 确认批量出库
                </el-button>
                <el-button size="small" type="primary" plain @click="show = false">
                    <i class="el-icon-close"></i> 关闭
                </el-button>
            </div>
        </template>
    </vol-box>
</template>
 
<script>
import VolBox from '@/components/basic/VolBox.vue'
import { stationManager } from "@/../src/uitils/stationManager";
 
export default {
    components: { VolBox },
    props: {
        value: { type: Boolean, default: false }
    },
    data() {
        return {
            show: false,
            loading: false,
            station: stationManager.getStation(), // 从本地缓存获取站台
            stations: [
                { label: "站台2", value: "2-1" },
                { label: "站台3", value: "3-1" },
            ],
            fileList: [],
            resultText: '',
            form: {}
        }
    },
    methods: {
        open() {
            this.show = true
            this.station = stationManager.getStation() // 每次打开重新获取
            this.resetForm()
        },
        handleFileChange(file) {
            this.fileList = [file.raw]
        },
        async batchImport() {
            // 验证站台
            if (!this.station) {
                this.$message.warning("请选择出库区域")
                return
            }
            if (this.fileList.length === 0) {
                this.$message.warning("请选择Excel文件")
                return
            }
 
            this.loading = true
            this.resultText = "正在处理..."
 
            try {
                const formData = new FormData()
                formData.append('file', this.fileList[0])
                formData.append('outStation', this.station) // 提交站台!
 
                const res = await this.http.post(
                    '/api/Task/BatchOutboundByExcel',
                    formData,
                    { headers: { 'Content-Type': 'multipart/form-data' } }
                )
 
                if (res.status) {
                    const d = res.data
                    this.resultText = `总条数:${d.总条数}\n成功:${d.成功条数}\n失败:${d.失败条数}`
                    if (d.失败明细?.length) this.resultText += `\n\n失败:\n${d.失败明细.join('\n')}`
                    this.$message.success("批量完成")
                } else {
                    this.resultText = "失败:" + res.message
                    this.$message.error(res.message)
                }
            } catch (err) {
                this.resultText = "异常:" + err.message
                this.$message.error("批量失败:" + err.message)
            } finally {
                this.loading = false
            }
        },
        resetForm() {
            this.fileList = []
            this.resultText = ''
            this.$refs.upload?.clearFiles()
        }
    },
    watch: {
        show(val) {
            if (!val) this.resetForm()
        }
    }
}
</script>
 
<style scoped>
.dialog-footer { text-align: right; }
.text-gray-500 { color: #909399; font-size: 12px; }
.result-box { white-space: pre-line; line-height: 1.5; }
 
/* 遮罩层 和你页面完全一样 */
.mask-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}
.mask-layer::after {
    content: "";
    width: 40px;
    height: 40px;
    border: 4px solid #fff;
    border-top: 4px solid #409eff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
</style>