| | |
| | | import { useQuery, useQueryClient } from '@tanstack/vue-query'; |
| | | import * as standardServiceServices from '@12333/services/apiV2/standardService'; |
| | | import { computed, MaybeRef, unref } from 'vue'; |
| | | import { groupBy } from 'lodash'; |
| | | |
| | | type UseStandardServiceDetailOptions = { |
| | | id: MaybeRef<string>; |
| | |
| | | minPrice, |
| | | }; |
| | | } |
| | | |
| | | type UseStandardServiceListOptions = { |
| | | params?: MaybeRef<API.GetOpenStandardServiceListQuery>; |
| | | onSuccess?: (data: API.GetStandardServicesQueryResultItem[]) => any; |
| | | }; |
| | | |
| | | export function useStandardServiceList(options: UseStandardServiceListOptions = {}) { |
| | | const { params = {}, onSuccess } = options; |
| | | const { |
| | | data: standardServiceList, |
| | | refetch, |
| | | isLoading, |
| | | isError, |
| | | } = useQuery({ |
| | | queryKey: ['standardServiceServices/getOpenStandardServiceList', params], |
| | | queryFn: async () => { |
| | | return await standardServiceServices.getOpenStandardServiceList(unref(params), { |
| | | showLoading: false, |
| | | }); |
| | | }, |
| | | placeholderData: () => [] as API.GetStandardServicesQueryResultItem[], |
| | | onSuccess(data) { |
| | | onSuccess?.(data); |
| | | }, |
| | | }); |
| | | |
| | | const standardServiceListForCategory = computed(() => { |
| | | return standardServiceList.value.map((x) => ({ |
| | | ...x, |
| | | catName: x.name, |
| | | })); |
| | | }); |
| | | |
| | | const standardServiceListForCategoryMap = computed(() => { |
| | | const group = groupBy(standardServiceListForCategory.value, 'jobCode'); |
| | | return group; |
| | | }); |
| | | |
| | | const queryClient = useQueryClient(); |
| | | |
| | | function ensureStandardServiceList() { |
| | | return queryClient.ensureQueryData<API.GetStandardServicesQueryResultItem[]>({ |
| | | queryKey: ['standardServiceServices/getOpenStandardServiceList', params], |
| | | }); |
| | | } |
| | | |
| | | return { |
| | | standardServiceList, |
| | | ensureStandardServiceList, |
| | | standardServiceListForCategory, |
| | | standardServiceListForCategoryMap, |
| | | }; |
| | | } |