You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.4 KiB

10 months ago
import { linkNavigateTo } from '~/utils/util'
import { cartBatchAddApi, orderCancelApi, orderDeleteApi, orderTakeDeliveryApi, preOrderApi } from '~/server/orderApi'
import { CartBatchAdd } from '~/types/order'
import { ItemObject } from '~/types/global'
import { cartCountApi } from '~/server/goodsApi'
import { useAppStore } from '~/stores/app'
export default function useOrder() {
//预下单
const getPreOrder = (preOrderType: string, orderDetails: any,seckillStatus?:number,datatime?:number) => {
return preOrderApi({
preOrderType: preOrderType,
orderDetails: orderDetails,
}).then((result: any) => {
linkNavigateTo(`/order/order_confirm`, { orderNo: result.orderNo,seckillStatus:seckillStatus,datatime:datatime })
})
}
//确认收货
const onConfirmOrder = (orderNo: string) => {
return new Promise((resolve, reject) => {
feedback.confirm('为保障权益,请收到货确认无误后,再确认收货').then(async () => {
await orderTakeDeliveryApi(orderNo).then(async () => {
await linkNavigateTo(`/users/order_list`, { type: 1 })
await feedback.msgSuccess('收货成功')
return resolve()
})
})
})
}
//再次购买
const onByAgain = (cartListRequest: Array<CartBatchAdd>) => {
return cartBatchAddApi(cartListRequest).then(() => {
linkNavigateTo(`/order/shopping_cart`, { type: 0 })
})
}
//删除订单
const onDeleteOrder = (orderNo: string) => {
return new Promise((resolve, reject) => {
feedback.confirm('确认删除订单吗?').then(async () => {
await orderDeleteApi(orderNo).then(async () => {
await linkNavigateTo(`/users/order_list`, { type: 1 })
await feedback.msgSuccess('删除成功')
return resolve()
})
})
})
}
//取消订单
const onCancelOrder = (orderNo: string) => {
return new Promise((resolve, reject) => {
feedback.confirm('确认取消订单吗?').then(async () => {
await orderCancelApi(orderNo).then(async () => {
await linkNavigateTo(`/users/order_list`, { type: 1 })
await feedback.msgSuccess('取消成功')
return resolve()
})
})
})
}
//跳转商品详情
const handlerNuxtLink = async (id: number, type: string, seckillStatus?: number, datatime?: number) => {
await linkNavigateTo(`/product/detail/${id}`, { type: type, seckillStatus: seckillStatus, datatime: datatime })
}
//客服配置
const chatConfig = async (chatConfig: ItemObject) => {
switch (chatConfig.serviceType) {
case 'H5':
case 'h5':
window.open(chatConfig.serviceLink)
break
case 'phone':
case 'hotline':
feedback.confirm(`联系电话${chatConfig.servicePhone}`)
break
}
}
//购物车数量
const cartCount = ref<number>(0)
const useStore = useAppStore()
const onGetCartCount = async () => {
try {
let data = await cartCountApi({ numType: true, type: 'total' })
useStore.getCarNumber(data.count)
} catch (e) {
useStore.getCarNumber(0)
}
}
// 跳入页面
const handleIntoPage = async (url: string, params:ItemObject) => {
await linkNavigateTo(url, params)
}
return {
getPreOrder,
onConfirmOrder,
onByAgain,
onDeleteOrder,
onCancelOrder,
handlerNuxtLink,
onGetCartCount,
cartCount,
chatConfig,
handleIntoPage,
}
}