index.vue
11.2 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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<!--
* @Date: 2026-01-31
* @Description: 我的计划书 - 已改造为 NutTabs 版本
-->
<template>
<view class="h-screen bg-gray-50 flex flex-col">
<view class="bg-gray-50 z-10">
<!-- Navigation Header -->
<NavHeader title="我的计划书" />
<!-- Search Bar -->
<view class="bg-white px-[24rpx] py-[16rpx]">
<SearchBar
v-model="searchValue"
placeholder="搜索计划书名称、客户姓名..."
:show-clear="true"
@search="onSearch"
/>
</view>
<!-- Tabs Container -->
<view class="bg-white mt-[2rpx]">
<nut-tabs v-model="activeTabId">
<!-- 自定义标签栏 -->
<template #titles>
<view class="filter-tabs-wrapper">
<view
v-for="item in tabsData"
:key="item.id"
:class="[
'filter-tab-item',
activeTabId === item.id ? 'filter-tab-active' : 'filter-tab-inactive'
]"
@tap="onTabClick(item.id)"
>
<text class="filter-tab-text">{{ item.name }}</text>
</view>
</view>
</template>
</nut-tabs>
</view>
</view>
<!-- Plan List -->
<view
v-if="listVisible"
:key="listRenderKey"
class="flex-1 min-h-0 overflow-y-auto px-[24rpx] py-[24rpx] pb-[200rpx]"
>
<view v-for="(item, index) in filteredList" :key="index"
class="bg-white rounded-[24rpx] p-[24rpx] mb-[24rpx] shadow-sm plan-item"
:style="{ animationDelay: `${index * 50}ms` }">
<!-- Header -->
<view class="flex justify-between items-start mb-[16rpx]">
<view class="flex-1">
<view class="text-[30rpx] font-bold text-gray-900 leading-normal mb-[8rpx]">{{ item.title }}</view>
<view class="flex items-center gap-[12rpx]">
<view class="bg-blue-50 text-blue-600 text-[22rpx] px-[12rpx] py-[4rpx] rounded-[8rpx]" v-if="item.tag">
{{ item.tag }}
</view>
</view>
</view>
<view class="ml-[24rpx]">
<!-- Status Badge or Icon could go here -->
</view>
</view>
<!-- Info -->
<view class="flex justify-between items-center text-gray-500 text-[24rpx] mb-[24rpx]">
<text>{{ item.client }}</text>
<text>{{ item.date }}</text>
</view>
<!-- Divider -->
<view class="h-[1rpx] bg-gray-100 my-[20rpx]"></view>
<!-- Actions -->
<ListItemActions
:viewable="true"
:deletable="true"
@view="onView(item)"
@delete="onDelete(item)"
/>
</view>
<!-- Empty State -->
<view v-if="filteredList.length === 0"
class="flex flex-col items-center justify-center py-[100rpx] text-gray-400">
<IconFont name="order" size="48" class="mb-[24rpx] opacity-50" />
<text class="text-[28rpx]">暂无相关计划书</text>
</view>
</view>
<!-- TabBar -->
<!-- <TabBar current="" /> -->
</view>
</template>
<script setup>
import { ref, computed, nextTick } from 'vue'
import { useFileOperation } from '@/composables/useFileOperation'
import IconFont from '@/components/IconFont.vue'
import NavHeader from '@/components/NavHeader.vue'
import ListItemActions from '@/components/ListItemActions/index.vue'
import SearchBar from '@/components/SearchBar.vue'
import Taro from '@tarojs/taro'
const { viewFile } = useFileOperation()
const searchValue = ref('')
const activeTabId = ref('')
const listVisible = ref(true)
const listRenderKey = ref(0)
/**
* Tab 数据源
* @description 包含分类信息和对应的计划书列表
*/
const tabsData = ref([
{ id: '', name: '全部', list: [] },
{ id: 'processing', name: '生成中', list: [] },
{ id: 'generated', name: '已生成', list: [] },
])
/**
* Mock 数据:计划书列表
*
* @description 使用真实 PDF 文件进行测试
* downloadUrl 使用 Mozilla 的公开 PDF 测试文件
*/
const allList = ref([
{
id: 1,
title: '家庭财富传承保障计划(分红)',
client: '客户:李*生',
date: '2024-03-15 10:12',
tag: '年金保险',
status: 'generated',
// 文档信息
fileName: '家庭财富传承保障计划(分红).pdf',
downloadUrl: 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf'
},
{
id: 2,
title: '财富传承保障金融理财计划(分红)',
client: '客户:孙*',
date: '2024-03-14 12:01',
tag: '',
status: 'processing',
// 生成中的文档没有下载地址
fileName: '',
downloadUrl: ''
},
{
id: 3,
title: '企业高管年金计划',
client: '客户:王*江',
date: '2024-03-13 09:23',
tag: '年金保险',
status: 'generated',
// 文档信息
fileName: '企业高管年金计划.pdf',
downloadUrl: 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf'
},
{
id: 4,
title: '家庭财富传承保障计划',
client: '客户:李*生',
date: '2024-03-12 15:12',
tag: '年金保险',
status: 'generated',
// 文档信息
fileName: '家庭财富传承保障计划.pdf',
downloadUrl: 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf'
},
{
id: 5,
title: '高净值家庭资产配置计划',
client: '客户:赵*琪',
date: '2024-03-11 18:40',
tag: '资产配置',
status: 'generated',
fileName: '高净值家庭资产配置计划.pdf',
downloadUrl: 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf'
},
{
id: 6,
title: '企业主税务筹划方案',
client: '客户:陈*明',
date: '2024-03-11 11:05',
tag: '税务筹划',
status: 'processing',
fileName: '',
downloadUrl: ''
},
{
id: 7,
title: '家庭保障升级计划(重疾)',
client: '客户:周*然',
date: '2024-03-10 14:22',
tag: '健康保障',
status: 'generated',
fileName: '家庭保障升级计划(重疾).pdf',
downloadUrl: 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf'
},
{
id: 8,
title: '家庭教育金规划方案',
client: '客户:许*雅',
date: '2024-03-10 09:48',
tag: '教育金',
status: 'generated',
fileName: '家庭教育金规划方案.pdf',
downloadUrl: 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf'
},
{
id: 9,
title: '中长期养老规划',
client: '客户:刘*文',
date: '2024-03-09 16:05',
tag: '养老规划',
status: 'processing',
fileName: '',
downloadUrl: ''
},
{
id: 10,
title: '企业员工福利保障计划',
client: '客户:沈*杰',
date: '2024-03-09 10:33',
tag: '团体保障',
status: 'generated',
fileName: '企业员工福利保障计划.pdf',
downloadUrl: 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf'
},
{
id: 11,
title: '家族信托规划方案',
client: '客户:唐*豪',
date: '2024-03-08 17:50',
tag: '家族信托',
status: 'generated',
fileName: '家族信托规划方案.pdf',
downloadUrl: 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf'
},
{
id: 12,
title: '企业接班人保障方案',
client: '客户:何*峰',
date: '2024-03-08 09:12',
tag: '传承保障',
status: 'generated',
fileName: '企业接班人保障方案.pdf',
downloadUrl: 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf'
}
])
/**
* 初始化数据分布
* @description 根据分类规则将 allList 中的数据分配到各个 tab 中
*/
const initTabsData = () => {
tabsData.value.forEach((tab) => {
if (tab.id === '') {
tab.list = [...allList.value]
} else {
tab.list = allList.value.filter(item => item.status === tab.id)
}
})
}
/**
* 根据标签页和搜索关键词过滤列表
*/
const filteredList = computed(() => {
// 找到当前选中的 tab
const currentTab = tabsData.value.find(tab => tab.id === activeTabId.value)
if (!currentTab) return []
let result = currentTab.list
// Filter by Search
if (searchValue.value) {
const key = searchValue.value.toLowerCase()
result = result.filter(item =>
item.title.toLowerCase().includes(key) ||
item.client.toLowerCase().includes(key)
)
}
return result
})
/**
* Tab 点击处理
*/
const onTabClick = (id) => {
activeTabId.value = id
listVisible.value = false
nextTick(() => {
listRenderKey.value += 1
listVisible.value = true
})
}
/**
* 搜索处理
*/
const onSearch = (val) => {
console.log('Search:', val)
}
/**
* 查看计划书文档
*
* @description 使用 useFileOperation 的 viewFile 功能查看 PDF 文档
* @param {Object} item - 计划书对象
*/
const onView = async (item) => {
// 检查是否已生成
if (item.status === 'processing') {
Taro.showToast({
title: '计划书生成中,请稍后',
icon: 'none'
})
return
}
// 使用 useFileOperation 查看文档
await viewFile({
downloadUrl: item.downloadUrl,
fileName: item.fileName
})
}
/**
* 删除计划书
*/
const onDelete = (item) => {
Taro.showModal({
title: '提示',
content: '确定要删除该计划书吗?',
success: (res) => {
if (res.confirm) {
// 从 allList 中删除
const index = allList.value.findIndex(i => i.id === item.id)
if (index !== -1) {
allList.value.splice(index, 1)
// 重新初始化 tabsData
initTabsData()
Taro.showToast({ title: '已删除', icon: 'success' })
}
}
}
})
}
// 初始化数据
initTabsData()
</script>
<style lang="less">
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(20rpx);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.plan-item {
animation: slideIn 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}
// FilterTabs 风格的标签栏
.filter-tabs-wrapper {
display: flex;
overflow-x: auto;
padding: 24rpx 24rpx;
gap: 24rpx;
transition: all 0.3s ease;
background-color: #fff;
width: 100%;
// 隐藏滚动条
&::-webkit-scrollbar {
display: none;
width: 0;
height: 0;
}
-ms-overflow-style: none;
scrollbar-width: none;
}
.filter-tab-item {
display: flex;
align-items: center;
justify-content: center;
padding: 0 32rpx;
border-radius: 9999rpx;
white-space: nowrap;
transition: all 0.3s ease;
flex-shrink: 0;
}
.filter-tab-active {
background-color: #2563EB; // 蓝色背景
color: #fff;
}
.filter-tab-inactive {
background-color: #F3F4F6; // 灰色背景
color: #6B7280;
}
.filter-tab-text {
font-size: 28rpx;
font-weight: 500;
}
// 覆盖 NutUI Tabs 默认样式,隐藏原有的头部和内容(因为我们使用自定义头部和外部列表)
:deep(.nut-tabs__titles) {
display: none;
}
:deep(.nut-tabs__content) {
display: none;
}
</style>