zhengyiming
22 小时以前 6ac59f6fa91e51272b8cd4797458995e168ec0f9
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
import { useQuery } from '@tanstack/vue-query';
import {
  useLifeRechargeContext,
  CreateEditPayChannelsInput,
  GetShowingLifePayAnnouncementInput,
} from '@life-payment/core-vue';
import { MaybeRef } from 'vue';
import { Message } from '@/utils';
import Taro from '@tarojs/taro';
 
export function useOnlineService() {
  const { blLifeRecharge } = useLifeRechargeContext();
 
  const { data } = useQuery({
    queryKey: ['blLifeRecharge/getOnlineService'],
    queryFn: async () => {
      return await blLifeRecharge.services.getOnlineService({
        showLoading: false,
      });
    },
    placeholderData: () => '',
  });
 
  return {
    onlineServiceLink: data,
  };
}
 
type UseLifePayChannlesAllListOptions = {
  params?: MaybeRef<API.QueryLifePayChannlesInput>;
  onSuccess?: (data: API.CreateEditPayChannelsInput[]) => any;
};
 
export function useLifePayChannlesAllList(options: UseLifePayChannlesAllListOptions = {}) {
  const { onSuccess, params = {} } = options;
 
  const { blLifeRecharge } = useLifeRechargeContext();
 
  const {
    data: allChannlesList,
    isLoading,
    refetch,
  } = useQuery({
    queryKey: ['blLifeRecharge/getLifePayChannlesAllList', params],
    queryFn: async () => {
      return await blLifeRecharge.services.getLifePayChannlesAllList(unref(params), {
        showLoading: false,
      });
    },
    placeholderData: () => [] as CreateEditPayChannelsInput[],
    onSuccess: (data) => {
      onSuccess?.(data);
    },
  });
 
  function getChannlesNameByNum(channlesNum: string) {
    return (
      allChannlesList.value.find((item) => item.channlesNum === channlesNum)?.channlesName ?? ''
    );
  }
 
  return {
    allChannlesList,
    isLoading,
    refetch,
    getChannlesNameByNum,
  };
}
 
type UseShowingLifePayAnnouncementOptions = {
  params?: MaybeRef<API.GetShowingLifePayAnnouncementInput>;
  onSuccess?: (data: API.CreateEditLifePayAnnouncementOutput) => any;
  staleTime?: MaybeRef<number>;
};
 
export function useShowingLifePayAnnouncement(options: UseShowingLifePayAnnouncementOptions = {}) {
  const { onSuccess, params = {}, staleTime } = options;
 
  const { blLifeRecharge } = useLifeRechargeContext();
 
  const {
    data: announcement,
    isLoading,
    refetch,
  } = useQuery({
    queryKey: ['blLifeRecharge/getShowingLifePayAnnouncement', params],
    queryFn: async () => {
      return await blLifeRecharge.services.getShowingLifePayAnnouncement(unref(params), {
        showLoading: false,
        skipErrorHandler: true,
      });
    },
    onSuccess: (data) => {
      onSuccess?.(data);
    },
    staleTime: staleTime,
  });
 
  return {
    announcement,
    isLoading,
    refetch,
  };
}
 
const dialogShowingLifePayAnnouncementCache = {};
 
export function useDialogShowingLifePayAnnouncement() {
  const { blLifeRecharge } = useLifeRechargeContext();
  const router = Taro.useRouter();
 
  useShowingLifePayAnnouncement({
    params: {
      announcementType: blLifeRecharge.constants.AnnouncementTypeEnum.Dialog,
    },
    onSuccess(data) {
      if (!dialogShowingLifePayAnnouncementCache[router.path]) {
        dialogShowingLifePayAnnouncementCache[router.path] = true;
        Message.confirm({
          title: '公告',
          message: data.announcementContent ?? '',
          showCancelBtn: false,
        });
      }
    },
    staleTime: Infinity,
  });
}