import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' import { HTTPMethod, DOMAIN_TYPE } from './config' import { wrapBaseQuery } from '@/utils/request' import { getUrlParam } from '@/utils/tools' import type { FormDataType, SubmitValueType, LogisticsType, WorkOrderListType, OrderListType, AddressItemType, OrderDetailValueType, ShopItemType } from '@/types' type SubmitDataType = { isAdd: boolean operateParams: { nodeId: string flowTemplateId: string flowTemplateKey: string flowVersion: number flowWorkOrderId: string } workOrder: { needTransForm: boolean shopUniqueKey: string source: string templateId: string workOrderComponents: SubmitValueType[] } [key: string]: any } type RepeatCheckResType = { resultList: { componentKey: string repeatCount: number }[] } export type RepeatCheckReqType = { templateId: string needCheckComponentList: { componentKey: string componentValue: string }[] } interface WorkOrderListQueryType { flowTemplateKey?: string tid?: string shopId?: string buyerOpenUid?: string startCreatedTime?: string endCreatedTime?: string shopUniqueKey?: string flowWorkOrderStatus?: string pageNo?: number pageSize?: number companyKey: string } interface OrderListQueryType { shopId: string buyerOpenId?: string shopUniqueKey?: string companyKey: string buyerNick: string } type ShopListReqType = { apiName: string companyKey?: string flowTemplateKey?: string } type UploadFileReqType = { url: string formData: FormData } type GrayResType = { isGray: boolean } export type SkuItem = { code?: string outerSkuId: string picUrl: string price: string properties: string propertiesName: string quantity: number skuId: number } type SkuType = { numIid: number skus: Array } export type SkuReqType = { shopId: string numIids: number } type GoodItem = { productId: string outId: string productName: string picUrl: string price: string skuInfoList: any[] status: string [key: string]: any } type ProductType = { pageNo: number pageSize: number result: GoodItem[] total: number nextKey?: number } export type ProductReqType = { pageNo: number pageSize: number shopId: string shopName: string platform: string status: number [key: string]: any } type QueryItemsType = { items: Array<{ numIid: number outerId: string picUrl: string title: string price: string platform: string [key: string]: any }> totalCount: number } type QueryItemReqType = { pageNo: number pageSize: number shopId: string [key: string]: any } export const flowApi = createApi({ reducerPath: 'flow', baseQuery: wrapBaseQuery( fetchBaseQuery({ baseUrl: `${DOMAIN_TYPE.API}`, prepareHeaders: headers => { //统一添加请求头 mp companyKey 后端判断免登逻辑 headers.set('mp', 'true') headers.set('companyKey', getUrlParam('companyKey')) return headers } }) ), endpoints: builder => ({ // 根据节点id,回去模板节点信息详情 templateDetail: builder.query< FormDataType, { flowTemplateKey: string companyKey: string shopUniqueKey: string } >({ transformResponse: (res: { data: FormDataType }) => res.data, query: params => ({ url: 'qy/mp/workOrder/detail/noLogin', method: HTTPMethod.GET, params }) }), workOrderList: builder.query({ transformResponse: (res: { data: WorkOrderListType }) => res.data, query: (params: WorkOrderListQueryType) => ({ url: `/qy/mp/queryFlowWorkOrders/${params.companyKey}/noLogin`, method: HTTPMethod.POST, body: { ...params } }) }), orderList: builder.query({ transformResponse: (res: { data: OrderListType[] }) => res.data, query: (params: OrderListQueryType) => ({ url: `/qy/mp/trades/list/noLogin`, method: HTTPMethod.POST, body: { ...params } }) }), listLogisticsWithInterceptInfo: builder.query({ transformResponse: (res: { data: LogisticsType[] }) => res.data, query: (platformType: number) => ({ url: `/qy/logistics/listLogisticsWithInterceptInfo`, method: HTTPMethod.POST, body: { platformType } }) }), orderDetail: builder.query< OrderDetailValueType, { orderNo: string shopId: string templateId: string companyKey: string } >({ transformResponse: (res: { data: OrderDetailValueType }) => res.data, query: params => ({ url: `/qy/mp/orderDetail/${params.companyKey}/noLogin`, method: HTTPMethod.POST, // headers: { // workordersessioncompanyuser: '964688061' // }, body: params }) }), repeatCheck: builder.query({ transformResponse: (res: { data: RepeatCheckResType }) => res.data, query: (data: RepeatCheckReqType) => ({ url: 'qy/gdfw/workOrder/repeatCheck/noLogin', method: HTTPMethod.POST, // headers: { // workordersessioncompanyuser: '964688061' // }, body: data }) }), inputRepeatCheck: builder.query({ transformResponse: (res: { data: RepeatCheckResType }) => res.data, query: (data: RepeatCheckReqType) => ({ url: 'qy/gdfw/workOrder/repeatCheck/noLogin', method: HTTPMethod.POST, // headers: { // workordersessioncompanyuser: '964688061' // }, body: data // useCache: false, // keepUnusedDataFor:0 }) }), flowSubmit: builder.mutation({ transformResponse: (res: { data: FormDataType }) => res.data, query: (data: SubmitDataType) => ({ // url: 'local/qy/mp/submit', url: 'qy/mp/workOrder/submit/noLogin', method: HTTPMethod.POST, // headers: { // workordersessioncompanyuser: '964688061' // // workordersessioncompanyuser: '964688061' // }, body: { ...data } }) }), addressList: builder.query({ transformResponse: (res: { data: AddressItemType[] }) => res.data, query: () => ({ url: '/qy/gdfw/template/queryAreas', method: HTTPMethod.GET }) }), addressAnalysis: builder.query({ transformResponse: (res: { data: string }) => res.data, query: (value: string) => ({ url: '/qy/logistics/addressAnalysis/noLogin', method: HTTPMethod.POST, body: { fullAddress: value } }) }), shopList: builder.query({ transformResponse: (res: { data: ShopItemType[] }) => res.data, query: (data: ShopListReqType) => ({ url: '/qy/shop/listShop', method: HTTPMethod.POST, body: data }) }), getIsWhite: builder.query({ transformResponse: (res: { data: GrayResType }) => res.data, query: (value: string) => ({ url: `/qy/mp/isGray/${value}/noLogin`, method: HTTPMethod.GET, headers: { env: 'h5' } }) }), uploadFile: builder.mutation({ transformResponse: (res: { data: string }) => res.data, query: (data: UploadFileReqType) => ({ url: data.url, method: HTTPMethod.POST, body: data.formData }) }), queryItemSkus: builder.query({ transformResponse: (res: { data: SkuType[] }) => res.data, query: (data: SkuReqType) => ({ url: '/qy/gdfw/workOrder/queryItemSkus', method: HTTPMethod.POST, body: data }) }), listProduct: builder.query({ transformResponse: (res: { data: ProductType }) => res.data, query: (data: ProductReqType) => ({ url: '/qy/gdfw/product/listProduct', method: HTTPMethod.POST, body: data }) }), queryItems: builder.query({ transformResponse: (res: { data: QueryItemsType }) => res.data, query: (data: ProductReqType) => ({ url: '/qy/gdfw/workOrder/queryItems', method: HTTPMethod.POST, body: data }) }) }) }) export const { useTemplateDetailQuery, useWorkOrderListQuery, useListLogisticsWithInterceptInfoQuery, useOrderDetailQuery, useRepeatCheckQuery, useInputRepeatCheckQuery, useOrderListQuery, useFlowSubmitMutation, useAddressListQuery, useShopListQuery, useUploadFileMutation, useGetIsWhiteQuery, useQueryItemSkusQuery, useListProductQuery } = flowApi