purchase-detail.vue
9.52 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<template>
<view class="container">
<!-- 详情卡片 -->
<view class="detail-card">
<view class="card-header">物品购买详情</view>
<view class="detail-content">
<!-- 加载状态 -->
<view v-if="loading" class="loading">正在加载详情...</view>
<!-- 错误状态 -->
<view v-else-if="error" class="error-state">
<view>{{ error }}</view>
<u-button class="retry-btn" @click="retryLoad" type="primary" size="small">重试</u-button>
</view>
<!-- 详情内容 -->
<view v-else-if="detailData" class="info-sections">
<!-- 基本信息 -->
<view class="info-section">
<view class="section-title">基本信息</view>
<view class="info-grid">
<view class="info-item">
<text class="info-label">分类</text>
<text class="info-value">{{ detailData.reimbursementCategoryName || '无' }}</text>
</view>
<view class="info-item">
<text class="info-label">单价</text>
<text class="info-value amount">¥{{ detailData.unitPrice || 0 }}</text>
</view>
<view class="info-item">
<text class="info-label">数量</text>
<text class="info-value">{{ detailData.quantity || 0 }}</text>
</view>
<view class="info-item">
<text class="info-label">总金额</text>
<text class="info-value amount">¥{{ detailData.amount || 0 }}</text>
</view>
<view class="info-item">
<text class="info-label">购买时间</text>
<text class="info-value">{{ formatTime(detailData.purchaseTime) }}</text>
</view>
<view class="info-item">
<text class="info-label">审批状态</text>
<!-- {{ detailData.approveStatus || '未审批' }} -->
<view class="status-badge" :class="detailData.approveStatus=='已审批'?'approved':detailData.approveStatus=='待审批'?'pending':detailData.approveStatus=='未通过'?'rejected':'unapproved'">
{{ detailData.approveStatus?detailData.approveStatus=='未审批'?'未提交':detailData.approveStatus :'未提交' }}
</view>
</view>
</view>
</view>
<!-- 备注信息 -->
<view class="info-section" v-if="detailData.memo">
<view class="section-title">备注说明</view>
<view class="memo-content">
<text class="memo-text">{{ detailData.memo }}</text>
</view>
</view>
<!-- 附件信息 -->
<view class="info-section" v-if="detailData.attachment && detailData.attachment.length > 0">
<view class="section-title">附件</view>
<view class="attachment-list">
<view v-for="(file, index) in detailData.attachment" :key="index" class="attachment-item">
<view class="file-info" @click="previewFile(file)">
<text class="file-icon">📎</text>
<text class="file-name">{{ file.name || file.url || '文件' }}</text>
</view>
</view>
</view>
</view>
<!-- 创建信息 -->
<view class="info-section">
<view class="section-title">创建信息</view>
<view class="info-grid">
<view class="info-item">
<text class="info-label">创建人</text>
<text class="info-value">{{ detailData.createUserName || detailData.createUser || '无' }}</text>
</view>
<view class="info-item">
<text class="info-label">门店</text>
<text class="info-value">{{ detailData.createUserStoreName || '无' }}</text>
</view>
<view class="info-item">
<text class="info-label">创建时间</text>
<text class="info-value">{{ formatTime(detailData.createTime) }}</text>
</view>
</view>
</view>
<!-- 审批信息 -->
<view class="info-section" v-if="detailData.approveStatus && detailData.approveStatus !== '未审批'">
<view class="section-title">审批信息</view>
<view class="info-grid">
<view class="info-item" v-if="detailData.approveUser">
<text class="info-label">审批人</text>
<text class="info-value">{{ detailData.approveUserName || detailData.approveUser || '无' }}</text>
</view>
<view class="info-item" v-if="detailData.approveTime">
<text class="info-label">审批时间</text>
<text class="info-value">{{ formatTime(detailData.approveTime) }}</text>
</view>
<view class="info-item" v-if="detailData.applicationId">
<text class="info-label">审批单编号</text>
<text class="info-value">{{ detailData.applicationId }}</text>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import purchaseApi from '@/apis/modules/purchase.js'
import config from '@/common/config.js'
export default {
data() {
return {
loading: false,
error: null,
detailData: null,
purchaseId: null
}
},
onLoad(options) {
if (options.id) {
this.purchaseId = options.id
this.loadDetail()
} else {
this.error = '缺少记录ID'
}
},
methods: {
// 加载详情数据
async loadDetail() {
if (!this.purchaseId) return
try {
this.loading = true
this.error = null
const res = await purchaseApi.getPurchaseDetail(this.purchaseId)
if (res.code === 200 && res.data) {
this.detailData = res.data
} else {
this.error = res.message || '加载详情失败'
}
} catch (error) {
console.error('加载详情失败:', error)
this.error = '加载详情失败,请重试'
} finally {
this.loading = false
}
},
// 重试加载
retryLoad() {
this.loadDetail()
},
// 格式化时间
formatTime(timestamp) {
if (!timestamp) return '无'
const date = new Date(timestamp)
return date.toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
})
},
// 获取状态样式类
getStatusClass(status) {
switch (status) {
case '已审批':
return 'approved'
case '待审批':
return 'pending'
case '未通过':
return 'rejected'
case '未审批':
default:
return 'unapproved'
}
},
// 预览文件
previewFile(file) {
if (file.url) {
const baseUrl = config.getImgBaseUrl()
const fullUrl = file.url.startsWith('http') ? file.url : `${baseUrl}${file.url}`
// 如果是图片,使用预览图片功能
if (file.url.match(/\.(jpg|jpeg|png|gif|bmp|webp)$/i)) {
uni.previewImage({
urls: [fullUrl],
current: fullUrl
})
} else {
// 其他文件类型,尝试打开
uni.showToast({
title: '暂不支持预览此文件类型',
icon: 'none'
})
}
}
}
}
}
</script>
<style lang="scss" scoped>
.container {
min-height: 100vh;
background: linear-gradient(135deg, #e8f5e9 0%, #b2dfdb 100%);
padding: 40rpx;
box-sizing: border-box;
}
.detail-card {
background: #fff;
border-radius: 32rpx;
box-shadow: 0 8rpx 32rpx rgba(76, 175, 80, 0.1);
overflow: hidden;
}
.card-header {
background: linear-gradient(120deg, #43e97b 0%, #38f9d7 100%);
padding: 32rpx 40rpx;
color: #fff;
font-size: 36rpx;
font-weight: 600;
letter-spacing: 2rpx;
text-align: center;
}
.detail-content {
padding: 40rpx;
}
.loading {
text-align: center;
padding: 80rpx 40rpx;
color: #6a9c6a;
font-size: 28rpx;
}
.error-state {
text-align: center;
padding: 80rpx 40rpx;
color: #f56c6c;
font-size: 28rpx;
}
.retry-btn {
margin-top: 32rpx;
}
.info-sections {
display: flex;
flex-direction: column;
gap: 32rpx;
}
.info-section {
background: #f9fff9;
border-radius: 24rpx;
padding: 32rpx;
border: 2rpx solid #e8f5e9;
}
.section-title {
font-size: 32rpx;
font-weight: 600;
color: #2e7d32;
margin-bottom: 24rpx;
padding-bottom: 16rpx;
border-bottom: 2rpx solid #c8e6c9;
}
.info-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 24rpx;
}
.info-item {
display: flex;
flex-direction: column;
gap: 8rpx;
}
.info-label {
font-size: 24rpx;
color: #6a9c6a;
font-weight: 500;
}
.info-value {
font-size: 28rpx;
color: #2e7d32;
font-weight: 500;
word-break: break-all;
}
.info-value.amount {
color: #f57c00;
font-weight: 600;
font-size: 32rpx;
}
.status-badge {
display: inline-block;
padding: 8rpx 24rpx;
border-radius: 40rpx;
font-size: 24rpx;
font-weight: 500;
text-align: center;
width: fit-content;
}
.status-badge.unapproved {
background: #fff3e0;
color: #ef6c00;
border: 2rpx solid #ffe0b2;
}
.status-badge.pending {
background: #e3f2fd;
color: #1976d2;
border: 2rpx solid #bbdefb;
}
.status-badge.approved {
background: #e8f5e9;
color: #2e7d32;
border: 2rpx solid #c8e6c9;
}
.status-badge.rejected {
background: #ffebee;
color: #c62828;
border: 2rpx solid #ffcdd2;
}
.memo-content {
background: #fff;
border-radius: 16rpx;
padding: 24rpx;
border: 2rpx solid #e0e0e0;
}
.memo-text {
font-size: 28rpx;
color: #555;
line-height: 1.6;
word-break: break-all;
}
.attachment-list {
display: flex;
flex-direction: column;
gap: 16rpx;
}
.attachment-item {
background: #fff;
border-radius: 16rpx;
padding: 24rpx;
border: 2rpx solid #e0e0e0;
transition: all 0.2s ease;
}
.attachment-item:active {
background: #f5f5f5;
transform: translateX(4rpx);
}
.file-info {
display: flex;
align-items: center;
gap: 16rpx;
}
.file-icon {
font-size: 32rpx;
}
.file-name {
font-size: 28rpx;
color: #2e7d32;
flex: 1;
word-break: break-all;
}
</style>