From 1d472eb06970c85b0edfb58871956bc2c8d69916 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期四, 25 十二月 2025 17:44:46 +0800
Subject: [PATCH] fix: 甲方小程序
---
packages/hooks/standardOrder.ts | 65 ++++++++++++++++++++++++++++++++
1 files changed, 64 insertions(+), 1 deletions(-)
diff --git a/packages/hooks/standardOrder.ts b/packages/hooks/standardOrder.ts
index 585b716..d18be38 100644
--- a/packages/hooks/standardOrder.ts
+++ b/packages/hooks/standardOrder.ts
@@ -1,6 +1,7 @@
import { useQuery, useQueryClient } from '@tanstack/vue-query';
import * as standardServiceServices from '@12333/services/apiV2/standardService';
-import { MaybeRef, unref } from 'vue';
+import { computed, MaybeRef, unref } from 'vue';
+import { groupBy } from 'lodash';
type UseStandardServiceDetailOptions = {
id: MaybeRef<string>;
@@ -25,10 +26,72 @@
},
});
+ const minPrice = computed(() => {
+ if (!data.value?.specs?.length) {
+ return 0;
+ } else {
+ return Math.min(...data.value.specs.map((x) => x.price));
+ }
+ });
+
return {
detail: data,
refetch,
isLoading,
isError,
+ 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,
};
}
--
Gitblit v1.10.0