Blame view

antis-ncc-admin/src/views/lqCooperationCost/import-dialog.vue 5.02 KB
b717f998   李宇   最新代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  <template>
  	<el-dialog
  		title="导入合作成本"
  		:visible.sync="visible"
  		:close-on-click-modal="false"
  		class="NCC-dialog NCC-dialog_center"
  		width="600px"
  		@close="handleClose"
  	>
  		<div class="form-content">
  			<el-upload
  				ref="upload"
  				:auto-upload="false"
  				:on-change="handleFileChange"
  				:file-list="fileList"
  				:limit="1"
  				accept=".xlsx,.xls"
  				drag
  			>
  				<i class="el-icon-upload"></i>
  				<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  				<div class="el-upload__tip" slot="tip">只能上传xlsx/xls文件,且不超过10MB</div>
  			</el-upload>
8b44d4bd   “wangming”   feat: 添加健康师额外工资和合...
24
25
26
27
28
  			<div style="margin-top: 15px;">
  				<el-checkbox v-model="clearBeforeImport">
  					清理导入月份数据
  				</el-checkbox>
  			</div>
b717f998   李宇   最新代码
29
30
31
32
33
34
  			<div v-if="uploadResult" class="upload-result" :class="uploadResult.type">
  				<div class="result-title">{{ uploadResult.title }}</div>
  				<div class="result-description">{{ uploadResult.description }}</div>
  				<div v-if="uploadResult.failMessages && uploadResult.failMessages.length > 0" class="fail-messages">
  					<div v-for="(msg, index) in uploadResult.failMessages" :key="index" class="fail-message">{{ msg }}</div>
  				</div>
8b44d4bd   “wangming”   feat: 添加健康师额外工资和合...
35
36
37
38
39
40
41
42
  				<div v-if="uploadResult.successRecords && uploadResult.successRecords.length > 0" class="success-records">
  					<div class="success-title">成功导入的记录(包含成本类型):</div>
  					<div v-for="(record, index) in uploadResult.successRecords" :key="index" class="success-record">
  						门店ID: {{ record.storeId }}, 年份: {{ record.year }}, 月份: {{ record.month }}, 
  						金额: {{ record.totalAmount }}, 成本类型: {{ record.costType || '无' }}, 
  						备注: {{ record.remarks || '无' }}
  					</div>
  				</div>
b717f998   李宇   最新代码
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  			</div>
  		</div>
  		<div slot="footer" class="dialog-footer">
  			<el-button @click="handleClose">取消</el-button>
  			<el-button type="primary" @click="submitUpload" :loading="uploading" :disabled="!fileList.length">上传</el-button>
  		</div>
  	</el-dialog>
  </template>
  
  <script>
  import request from '@/utils/request'
  
  export default {
  	data() {
  		return {
  			visible: false,
  			fileList: [],
  			uploading: false,
8b44d4bd   “wangming”   feat: 添加健康师额外工资和合...
61
  			clearBeforeImport: true, // 是否需要清理导入月份数据,默认true
b717f998   李宇   最新代码
62
63
64
65
66
67
68
69
  			uploadResult: null
  		}
  	},
  	methods: {
  		init() {
  			this.visible = true
  			this.fileList = []
  			this.uploading = false
8b44d4bd   “wangming”   feat: 添加健康师额外工资和合...
70
  			this.clearBeforeImport = true
b717f998   李宇   最新代码
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  			this.uploadResult = null
  		},
  		handleFileChange(file, fileList) {
  			this.fileList = fileList
  			this.uploadResult = null
  		},
  		submitUpload() {
  			if (!this.fileList.length || !this.fileList[0]) {
  				this.$message.warning('请选择要上传的文件')
  				return
  			}
  			const file = this.fileList[0]
  			if (!file.raw) {
  				this.$message.warning('文件信息异常,请重新选择文件')
  				return
  			}
  			this.uploading = true
  			this.uploadResult = null
  			const formData = new FormData()
  			formData.append('file', file.raw)
8b44d4bd   “wangming”   feat: 添加健康师额外工资和合...
91
  			formData.append('clearBeforeImport', this.clearBeforeImport)
b717f998   李宇   最新代码
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
  			request({
  				url: '/api/Extend/LqCooperationCost/Actions/Import',
  				method: 'POST',
  				data: formData,
  				headers: {
  					'Content-Type': 'multipart/form-data'
  				}
  			}).then(res => {
  				this.uploading = false
  				if (res.code === 200) {
  					const data = res.data || {}
  					this.uploadResult = {
  						type: 'success',
  						title: '导入成功',
  						description: `成功导入 ${data.successCount || 0} 条,失败 ${data.failCount || 0} 条`,
8b44d4bd   “wangming”   feat: 添加健康师额外工资和合...
107
108
  						failMessages: data.failMessages || [],
  						successRecords: data.successRecords || []
b717f998   李宇   最新代码
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
  					}
  					this.$message.success('导入成功')
  					setTimeout(() => {
  						this.handleClose()
  						this.$emit('refresh')
  					}, 2000)
  				} else {
  					this.uploadResult = {
  						type: 'error',
  						title: '导入失败',
  						description: res.msg || '数据导入失败,请检查文件格式'
  					}
  				}
  			}).catch(err => {
  				this.uploading = false
  				this.uploadResult = {
  					type: 'error',
  					title: '导入失败',
  					description: err.message || '网络错误,请重试'
  				}
  				this.$message.error('导入失败')
  			})
  		},
  		handleClose() {
  			this.visible = false
  			this.fileList = []
  			this.uploadResult = null
  			if (this.$refs.upload) {
  				this.$refs.upload.clearFiles()
  			}
  		}
  	}
  }
  </script>
  
  <style lang="scss" scoped>
  .dialog-footer {
  	text-align: right;
  }
  
  .upload-result {
  	margin-top: 20px;
  	padding: 15px;
  	border-radius: 4px;
  
  	&.success {
  		background-color: #f0f9ff;
  		border: 1px solid #67C23A;
  	}
  
  	&.error {
  		background-color: #fef0f0;
  		border: 1px solid #F56C6C;
  	}
  
  	.result-title {
  		font-weight: 600;
  		margin-bottom: 8px;
  	}
  
  	.result-description {
  		margin-bottom: 10px;
  	}
  
  	.fail-messages {
  		margin-top: 10px;
  		padding-top: 10px;
  		border-top: 1px solid #ddd;
  
  		.fail-message {
  			color: #F56C6C;
  			margin-bottom: 5px;
  		}
  	}
8b44d4bd   “wangming”   feat: 添加健康师额外工资和合...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
  
  	.success-records {
  		margin-top: 10px;
  		padding-top: 10px;
  		border-top: 1px solid #ddd;
  
  		.success-title {
  			font-weight: 600;
  			margin-bottom: 8px;
  			color: #67C23A;
  		}
  
  		.success-record {
  			color: #606266;
  			margin-bottom: 5px;
  			font-size: 12px;
  		}
  	}
b717f998   李宇   最新代码
201
202
  }
  </style>