|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+<template>
|
|
|
2
|
+ <div class="excel-import-simple">
|
|
|
3
|
+ <el-card class="import-card">
|
|
|
4
|
+ <template #header>
|
|
|
5
|
+ <div class="card-header">
|
|
|
6
|
+ <span class="title">采、销执行表及库存业务Excel导入</span>
|
|
|
7
|
+ </div>
|
|
|
8
|
+ </template>
|
|
|
9
|
+
|
|
|
10
|
+ <!-- 文件上传区域 -->
|
|
|
11
|
+ <div class="upload-area">
|
|
|
12
|
+ <el-upload
|
|
|
13
|
+ ref="uploadRef"
|
|
|
14
|
+ class="upload-demo"
|
|
|
15
|
+ drag
|
|
|
16
|
+ action="#"
|
|
|
17
|
+ :auto-upload="false"
|
|
|
18
|
+ :on-change="handleFileChange"
|
|
|
19
|
+ :on-remove="handleFileRemove"
|
|
|
20
|
+ :file-list="fileList"
|
|
|
21
|
+ :limit="1"
|
|
|
22
|
+ accept=".xlsx,.xls"
|
|
|
23
|
+ >
|
|
|
24
|
+ <el-icon class="el-icon--upload"><upload-filled /></el-icon>
|
|
|
25
|
+ <div class="el-upload__text">
|
|
|
26
|
+ 将Excel文件拖到此处,或<em>点击上传</em>
|
|
|
27
|
+ </div>
|
|
|
28
|
+ <template #tip>
|
|
|
29
|
+ <div class="el-upload__tip">
|
|
|
30
|
+ 只能上传 .xlsx 或 .xls 格式的Excel文件
|
|
|
31
|
+ </div>
|
|
|
32
|
+ </template>
|
|
|
33
|
+ </el-upload>
|
|
|
34
|
+ </div>
|
|
|
35
|
+
|
|
|
36
|
+ <!-- 导入按钮 -->
|
|
|
37
|
+ <div class="action-buttons">
|
|
|
38
|
+ <el-button
|
|
|
39
|
+ type="primary"
|
|
|
40
|
+ :loading="loading"
|
|
|
41
|
+ :disabled="!fileList.length"
|
|
|
42
|
+ @click="handleImport"
|
|
|
43
|
+ >
|
|
|
44
|
+ {{ loading ? '采销导入中...' : '开始导入采销执行表' }}
|
|
|
45
|
+ </el-button>
|
|
|
46
|
+ <el-button
|
|
|
47
|
+ type="primary"
|
|
|
48
|
+ :loading="stockLoading"
|
|
|
49
|
+ :disabled="!fileList.length"
|
|
|
50
|
+ @click="handleStockImport"
|
|
|
51
|
+ style="margin-left: 10px"
|
|
|
52
|
+ >
|
|
|
53
|
+ {{ stockLoading ? '库存导入中...' : '导入库存业务' }}
|
|
|
54
|
+ </el-button>
|
|
|
55
|
+ <el-button @click="handleReset">重置</el-button>
|
|
|
56
|
+ </div>
|
|
|
57
|
+
|
|
|
58
|
+ <!-- 错误信息显示 -->
|
|
|
59
|
+ <div v-if="errorMessage" class="error-message-area">
|
|
|
60
|
+ <el-alert
|
|
|
61
|
+ title="导入错误"
|
|
|
62
|
+ type="error"
|
|
|
63
|
+ :description="errorMessage"
|
|
|
64
|
+ show-icon
|
|
|
65
|
+ :closable="false"
|
|
|
66
|
+ />
|
|
|
67
|
+ </div>
|
|
|
68
|
+
|
|
|
69
|
+ <!-- 成功信息显示 -->
|
|
|
70
|
+ <div v-if="successMessage" class="success-message-area">
|
|
|
71
|
+ <el-alert
|
|
|
72
|
+ title="导入成功"
|
|
|
73
|
+ type="success"
|
|
|
74
|
+ :description="successMessage"
|
|
|
75
|
+ show-icon
|
|
|
76
|
+ :closable="false"
|
|
|
77
|
+ />
|
|
|
78
|
+ </div>
|
|
|
79
|
+
|
|
|
80
|
+ <!-- 导入说明 -->
|
|
|
81
|
+ <div class="import-tips">
|
|
|
82
|
+ <el-alert
|
|
|
83
|
+ title="导入说明"
|
|
|
84
|
+ type="info"
|
|
|
85
|
+ :closable="false"
|
|
|
86
|
+ >
|
|
|
87
|
+ <template #default>
|
|
|
88
|
+ <div class="tips-content">
|
|
|
89
|
+ <p>1. 请确保Excel文件包含所有需要的Sheet页,每个Sheet页对应一张表</p>
|
|
|
90
|
+ <p>2. 系统会自动处理合并字段,按照逗号分隔存储</p>
|
|
|
91
|
+ <p>3. 导入过程中如有错误,会在上方错误信息区域显示</p>
|
|
|
92
|
+ </div>
|
|
|
93
|
+ </template>
|
|
|
94
|
+ </el-alert>
|
|
|
95
|
+ </div>
|
|
|
96
|
+ </el-card>
|
|
|
97
|
+ </div>
|
|
|
98
|
+</template>
|
|
|
99
|
+
|
|
|
100
|
+<script setup>
|
|
|
101
|
+import { ref } from 'vue'
|
|
|
102
|
+import { ElMessage } from 'element-plus'
|
|
|
103
|
+import { UploadFilled } from '@element-plus/icons-vue'
|
|
|
104
|
+import { importPsExeExcel, importStockExcel } from '../api/contractApi' // 新增导入库存的API
|
|
|
105
|
+
|
|
|
106
|
+// 响应式数据
|
|
|
107
|
+const uploadRef = ref()
|
|
|
108
|
+const fileList = ref([])
|
|
|
109
|
+const loading = ref(false)
|
|
|
110
|
+const stockLoading = ref(false) // 库存导入的加载状态
|
|
|
111
|
+const errorMessage = ref('')
|
|
|
112
|
+const successMessage = ref('')
|
|
|
113
|
+
|
|
|
114
|
+// 处理文件选择
|
|
|
115
|
+const handleFileChange = (file) => {
|
|
|
116
|
+ const isExcel = file.name.endsWith('.xlsx') || file.name.endsWith('.xls')
|
|
|
117
|
+
|
|
|
118
|
+ if (!isExcel) {
|
|
|
119
|
+ ElMessage.error('只能上传Excel文件!')
|
|
|
120
|
+ uploadRef.value.handleRemove(file)
|
|
|
121
|
+ return false
|
|
|
122
|
+ }
|
|
|
123
|
+
|
|
|
124
|
+ const isLt50M = file.size / 1024 / 1024 < 50
|
|
|
125
|
+ if (!isLt50M) {
|
|
|
126
|
+ ElMessage.error('Excel文件大小不能超过50MB!')
|
|
|
127
|
+ uploadRef.value.handleRemove(file)
|
|
|
128
|
+ return false
|
|
|
129
|
+ }
|
|
|
130
|
+
|
|
|
131
|
+ fileList.value = [file]
|
|
|
132
|
+ errorMessage.value = ''
|
|
|
133
|
+ successMessage.value = ''
|
|
|
134
|
+}
|
|
|
135
|
+
|
|
|
136
|
+// 处理文件移除
|
|
|
137
|
+const handleFileRemove = () => {
|
|
|
138
|
+ fileList.value = []
|
|
|
139
|
+ errorMessage.value = ''
|
|
|
140
|
+ successMessage.value = ''
|
|
|
141
|
+}
|
|
|
142
|
+
|
|
|
143
|
+// 执行采销导入
|
|
|
144
|
+const handleImport = async () => {
|
|
|
145
|
+ if (!fileList.value.length) {
|
|
|
146
|
+ ElMessage.warning('请先选择Excel文件')
|
|
|
147
|
+ return
|
|
|
148
|
+ }
|
|
|
149
|
+
|
|
|
150
|
+ const file = fileList.value[0].raw
|
|
|
151
|
+ loading.value = true
|
|
|
152
|
+ errorMessage.value = ''
|
|
|
153
|
+ successMessage.value = ''
|
|
|
154
|
+
|
|
|
155
|
+ try {
|
|
|
156
|
+ console.log('开始上传采销文件:', file.name)
|
|
|
157
|
+
|
|
|
158
|
+ // 调用后端API
|
|
|
159
|
+ const response = await importPsExeExcel(file)
|
|
|
160
|
+
|
|
|
161
|
+ console.log('API响应成功:', response.status)
|
|
|
162
|
+ console.log('响应数据:', response.data)
|
|
|
163
|
+
|
|
|
164
|
+ // 处理响应数据
|
|
|
165
|
+ if (response.status === 200) {
|
|
|
166
|
+ const resultData = response.data
|
|
|
167
|
+
|
|
|
168
|
+ if (resultData.code === 200 || resultData.success === true) {
|
|
|
169
|
+ successMessage.value = resultData.message || '采销执行表导入成功'
|
|
|
170
|
+ ElMessage.success('采销执行表导入成功')
|
|
|
171
|
+ } else {
|
|
|
172
|
+ errorMessage.value = resultData.message || '采销执行表导入失败'
|
|
|
173
|
+ ElMessage.error('采销执行表导入失败')
|
|
|
174
|
+ }
|
|
|
175
|
+ }
|
|
|
176
|
+
|
|
|
177
|
+ } catch (error) {
|
|
|
178
|
+ console.error('详细错误信息:', error)
|
|
|
179
|
+ errorMessage.value = error.message || '网络请求失败'
|
|
|
180
|
+ ElMessage.error('采销执行表导入失败')
|
|
|
181
|
+ } finally {
|
|
|
182
|
+ loading.value = false
|
|
|
183
|
+ }
|
|
|
184
|
+}
|
|
|
185
|
+
|
|
|
186
|
+// 新增:执行库存业务导入
|
|
|
187
|
+const handleStockImport = async () => {
|
|
|
188
|
+ if (!fileList.value.length) {
|
|
|
189
|
+ ElMessage.warning('请先选择Excel文件')
|
|
|
190
|
+ return
|
|
|
191
|
+ }
|
|
|
192
|
+
|
|
|
193
|
+ const file = fileList.value[0].raw
|
|
|
194
|
+ stockLoading.value = true
|
|
|
195
|
+ errorMessage.value = ''
|
|
|
196
|
+ successMessage.value = ''
|
|
|
197
|
+
|
|
|
198
|
+ try {
|
|
|
199
|
+ console.log('开始上传库存文件:', file.name)
|
|
|
200
|
+
|
|
|
201
|
+ // 调用库存导入API
|
|
|
202
|
+ const response = await importStockExcel(file)
|
|
|
203
|
+
|
|
|
204
|
+ console.log('库存API响应成功:', response.status)
|
|
|
205
|
+ console.log('响应数据:', response.data)
|
|
|
206
|
+
|
|
|
207
|
+ // 处理响应数据
|
|
|
208
|
+ if (response.status === 200) {
|
|
|
209
|
+ const resultData = response.data
|
|
|
210
|
+
|
|
|
211
|
+ if (resultData.code === 200 || resultData.success === true) {
|
|
|
212
|
+ successMessage.value = resultData.data || '库存业务导入成功'
|
|
|
213
|
+ ElMessage.success('库存业务导入成功')
|
|
|
214
|
+ } else {
|
|
|
215
|
+ errorMessage.value = resultData.data || '库存业务导入失败'
|
|
|
216
|
+ ElMessage.error('库存业务导入失败')
|
|
|
217
|
+ }
|
|
|
218
|
+ }
|
|
|
219
|
+
|
|
|
220
|
+ } catch (error) {
|
|
|
221
|
+ console.error('库存导入错误信息:', error)
|
|
|
222
|
+ errorMessage.value = error.message || '网络请求失败'
|
|
|
223
|
+ ElMessage.error('库存业务导入失败')
|
|
|
224
|
+ } finally {
|
|
|
225
|
+ stockLoading.value = false
|
|
|
226
|
+ }
|
|
|
227
|
+}
|
|
|
228
|
+
|
|
|
229
|
+// 重置
|
|
|
230
|
+const handleReset = () => {
|
|
|
231
|
+ fileList.value = []
|
|
|
232
|
+ errorMessage.value = ''
|
|
|
233
|
+ successMessage.value = ''
|
|
|
234
|
+ uploadRef.value?.clearFiles()
|
|
|
235
|
+}
|
|
|
236
|
+</script>
|
|
|
237
|
+
|
|
|
238
|
+<style scoped>
|
|
|
239
|
+/* 样式保持不变 */
|
|
|
240
|
+.excel-import-simple {
|
|
|
241
|
+ padding: 20px;
|
|
|
242
|
+ max-width: 900px;
|
|
|
243
|
+ margin: 0 auto;
|
|
|
244
|
+}
|
|
|
245
|
+
|
|
|
246
|
+.import-card {
|
|
|
247
|
+ min-height: 500px;
|
|
|
248
|
+}
|
|
|
249
|
+
|
|
|
250
|
+.card-header {
|
|
|
251
|
+ display: flex;
|
|
|
252
|
+ justify-content: space-between;
|
|
|
253
|
+ align-items: center;
|
|
|
254
|
+}
|
|
|
255
|
+
|
|
|
256
|
+.title {
|
|
|
257
|
+ font-size: 18px;
|
|
|
258
|
+ font-weight: bold;
|
|
|
259
|
+}
|
|
|
260
|
+
|
|
|
261
|
+.upload-area {
|
|
|
262
|
+ margin: 20px 0;
|
|
|
263
|
+}
|
|
|
264
|
+
|
|
|
265
|
+.action-buttons {
|
|
|
266
|
+ text-align: center;
|
|
|
267
|
+ margin: 20px 0;
|
|
|
268
|
+}
|
|
|
269
|
+
|
|
|
270
|
+.error-message-area {
|
|
|
271
|
+ margin-top: 20px;
|
|
|
272
|
+}
|
|
|
273
|
+
|
|
|
274
|
+.success-message-area {
|
|
|
275
|
+ margin-top: 20px;
|
|
|
276
|
+}
|
|
|
277
|
+
|
|
|
278
|
+.import-tips {
|
|
|
279
|
+ margin-top: 20px;
|
|
|
280
|
+}
|
|
|
281
|
+
|
|
|
282
|
+.tips-content {
|
|
|
283
|
+ font-size: 13px;
|
|
|
284
|
+ line-height: 1.6;
|
|
|
285
|
+}
|
|
|
286
|
+
|
|
|
287
|
+.tips-content p {
|
|
|
288
|
+ margin: 5px 0;
|
|
|
289
|
+}
|
|
|
290
|
+</style>
|