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
| import { useInfiniteLoading } from '@12333/hooks';
| import {
| EnumPagedListOrder,
| EnumSettlementCycle,
| EnumTaskRecommendStatus,
| EnumTaskReleaseStatus,
| EnumTaskStatus,
| EnumUserGender,
| } from '@12333/constants';
| import _ from 'lodash';
| import { trim } from '@12333/utils';
| import { MaybeRef, reactive, ref, unref } from 'vue';
| import * as taskServices from '@12333/services/apiV2/task';
|
| export enum HomeOrderType {
| Recommend = 'Recommend',
| LastShelfTime = 'LastShelfTime',
| }
|
| type UseTaskListOptions = {
| cityCode?: MaybeRef<string>;
| enabled?: MaybeRef<boolean>;
| releaseStatus?: MaybeRef<EnumTaskReleaseStatus>;
| status?: MaybeRef<EnumTaskStatus>;
| };
|
| export function useTaskList(options: UseTaskListOptions = {}) {
| const {
| cityCode = '',
| enabled = true,
| status = '' as any as EnumTaskStatus,
| releaseStatus = '' as any as EnumTaskReleaseStatus,
| } = options;
|
| const searchValue = ref('');
|
| const queryMenuState = reactive({
| genderLimit: '' as any as EnumUserGender,
| settlementCycle: '' as any as EnumSettlementCycle,
| benefitCodes: '',
| status: status,
| releaseStatus: releaseStatus,
| });
|
| const queryState = reactive({
| searchValueTrim: '',
| orderType: HomeOrderType.Recommend,
| });
|
| const handleSearch = _.debounce(function () {
| queryState.searchValueTrim = trim(searchValue.value);
| }, 300);
|
| const { infiniteLoadingProps, invalidateQueries } = useInfiniteLoading(
| ({ pageParam }) => {
| let params: API.GetTaskInfosQuery = {
| pageModel: {
| rows: 20,
| page: pageParam,
| orderInput: [
| queryState.orderType === HomeOrderType.Recommend
| ? { property: 'recommendStatus', order: EnumPagedListOrder.Desc }
| : { property: 'createdTime', order: EnumPagedListOrder.Desc },
| ],
| },
| keywords: queryState.searchValueTrim,
| cityCode: unref(cityCode),
| settlementCycle: queryMenuState.settlementCycle,
| benefitCodes: [queryMenuState.benefitCodes].filter(Boolean),
| genderLimit: queryMenuState.genderLimit,
| status: queryMenuState.status,
| releaseStatus: queryMenuState.releaseStatus,
| };
|
| return taskServices.getTaskInfos(params, {
| showLoading: false,
| });
| },
| {
| queryKey: ['taskServices/getTaskInfos', queryState, queryMenuState, cityCode],
| enabled: enabled,
| }
| );
|
| return {
| searchValue,
| queryState,
| queryMenuState,
| handleSearch,
| infiniteLoadingProps,
| invalidateQueries,
| };
| }
|
|