完善茶室订单
This commit is contained in:
102
src/hooks/useOrder.ts
Normal file
102
src/hooks/useOrder.ts
Normal file
@ -0,0 +1,102 @@
|
||||
import { router } from '@/utils/tools'
|
||||
import { toast } from '@/utils/toast'
|
||||
import {
|
||||
cancelTeaRoomOrder,
|
||||
deleteTeaRoomOrder,
|
||||
confirmTeaRoomOrder
|
||||
} from '@/api/tea-room'
|
||||
import { OrderType } from '@/utils/order'
|
||||
|
||||
|
||||
/**
|
||||
* 包间-取消订单
|
||||
* @param orderId 订单ID
|
||||
*/
|
||||
export async function handleTRCancelOrderHooks(orderId: number) {
|
||||
try {
|
||||
await cancelTeaRoomOrder({ id: orderId })
|
||||
uni.$emit('refreshOrderList')
|
||||
uni.$emit('refreshOrderDetail')
|
||||
} catch (error) {
|
||||
router.navigateBack()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新支付
|
||||
* @param orderId 订单ID
|
||||
* @param teaSpecialistId 茶艺师ID
|
||||
* @returns
|
||||
*/
|
||||
export function handleTRToPayHooks(orderId: number, teaRoomName: string, storeId: number) {
|
||||
try {
|
||||
uni.$on('payment', params => {
|
||||
setTimeout(() => {
|
||||
uni.$off("payment")
|
||||
uni.$emit('refreshOrderList')
|
||||
uni.$emit('refreshOrderDetail')
|
||||
if (params.result) {
|
||||
uni.redirectTo({
|
||||
url: `/pages/notice/reserve?type=room&orderId=${orderId}`
|
||||
})
|
||||
} else {
|
||||
uni.redirectTo({
|
||||
url: '/bundle/order/tea-room/order-list?orderStatus=all'
|
||||
})
|
||||
}
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
router.navigateTo(`/pages/cashier/cashier?from=${OrderType.TeaRoomOrder}&orderId=${orderId}&teaRoomName=${teaRoomName}&storeId=${storeId}`)
|
||||
}, 800)
|
||||
} catch (error) {
|
||||
toast.info('订单提交失败,请稍后重试')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 包间-删除订单
|
||||
*/
|
||||
export async function handleTRDeleteOrderHooks(orderId: number) {
|
||||
try {
|
||||
await deleteTeaRoomOrder({ id: orderId })
|
||||
uni.$emit('refreshOrderList')
|
||||
uni.$emit('refreshOrderDetail')
|
||||
} catch (error) {
|
||||
router.navigateBack()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认(完成)订单
|
||||
*/
|
||||
export async function handleTRConfirmOrderHooks(orderId: number) {
|
||||
try {
|
||||
await confirmTeaRoomOrder({ id: orderId })
|
||||
uni.$emit('refreshOrderList')
|
||||
uni.$emit('refreshOrderDetail')
|
||||
} catch (error) {
|
||||
router.navigateBack()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款
|
||||
* @param orderId 订单ID
|
||||
* @param orderType 订单类型
|
||||
*/
|
||||
// export async function handleRefundOrderHooks(orderId: number, orderType: string) {
|
||||
// try {
|
||||
// const response = await refundTeaSpecialistOrder({ id: orderId, order_type: orderType })
|
||||
// uni.$emit('refreshOrderList')
|
||||
// uni.$emit('refreshOrderDetail')
|
||||
// } catch (error) {
|
||||
// router.navigateBack()
|
||||
// throw error
|
||||
// }
|
||||
// }
|
||||
37
src/hooks/usePay.ts
Normal file
37
src/hooks/usePay.ts
Normal file
@ -0,0 +1,37 @@
|
||||
export function wxpay(opt) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let params;
|
||||
// #ifdef MP-WEIXIN
|
||||
params = {
|
||||
timeStamp: opt.timeStamp,
|
||||
// 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
|
||||
nonceStr: opt.nonceStr,
|
||||
// 支付签名随机串,不长于 32 位
|
||||
package: opt.package,
|
||||
// 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
|
||||
signType: opt.signType,
|
||||
// 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
|
||||
paySign: opt.paySign,
|
||||
}
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
params = {
|
||||
orderInfo: opt
|
||||
}
|
||||
// #endif
|
||||
console.log(params)
|
||||
uni.requestPayment({
|
||||
provider: 'wxpay',
|
||||
...params,
|
||||
success: res => {
|
||||
resolve('success');
|
||||
},
|
||||
cancel: res => {
|
||||
resolve('fail');
|
||||
},
|
||||
fail: res => {
|
||||
resolve('fail');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user