index.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import type { wxpay } from '@/api/globals'
  2. import router from '@/router'
  3. export function handleCommonPayMent(orderNumber: string): Promise<wxpay> {
  4. return new Promise((resolve, reject) => {
  5. if (!orderNumber) {
  6. useGlobalToast().show({ msg: '订单号为空!请联系管理员' })
  7. reject(new Error('订单号为空!请联系管理员'))
  8. return
  9. }
  10. uni.showLoading({ mask: true })
  11. Apis.common.hybridPayment({ data: { orderNumber } }).then((res) => {
  12. resolve(res.data)
  13. }).finally(() => uni.hideLoading()).catch(err => reject(err))
  14. })
  15. }
  16. const { selectedAddress, userInfo } = storeToRefs(useUserStore())
  17. /**
  18. *
  19. * @param businessType
  20. * @param dvyType 配送类型 1:快递 2:自提 3:及时配送
  21. * @param remarks
  22. * @param shopId
  23. * @param orderItemList
  24. * @returns 下单获取待支付订单号
  25. */
  26. export function getOrderPayMent(businessType: string, dvyType: number, shopId: number, orderItemList: {
  27. prodCount?: number
  28. skuId?: number
  29. }[], remarks?: string): Promise<string> {
  30. uni.showLoading({ mask: true })
  31. return new Promise((resolve, reject) => {
  32. if (!selectedAddress.value) {
  33. reject(new Error('请选择收货地址'))
  34. return
  35. }
  36. Apis.common.addOrder({
  37. data: {
  38. channelId: unref(userInfo).channelId,
  39. businessType,
  40. addressId: selectedAddress.value.id,
  41. dvyType,
  42. freightAmount: Number(userInfo.value.freightFee),
  43. shopId,
  44. orderItemList,
  45. remarks,
  46. },
  47. }).then(res => resolve(res.data)).catch(err => reject(err)).finally(() => uni.hideLoading())
  48. })
  49. }
  50. /**
  51. *
  52. * @param orderInfo
  53. * @returns 统一拉起微信支付
  54. */
  55. export function getWxCommonPayment(orderPay: wxpay) {
  56. console.log(orderPay, 'orderInfo')
  57. uni.showLoading({ mask: true })
  58. return new Promise((resolve, reject) => {
  59. const orderInfo = {
  60. appid: orderPay.appId,
  61. timeStamp: orderPay.timeStamp,
  62. nonceStr: orderPay.nonceStr,
  63. package: orderPay.package,
  64. signType: orderPay.signType,
  65. paySign: orderPay.paySign,
  66. }
  67. uni.requestPayment({
  68. provider: 'wxpay',
  69. orderInfo,
  70. ...orderInfo,
  71. success(res) {
  72. paySuccess()
  73. resolve(res)
  74. },
  75. fail(e) {
  76. console.log(e, '失败')
  77. reject(e)
  78. },
  79. complete() {
  80. uni.hideLoading()
  81. },
  82. })
  83. })
  84. }
  85. /**
  86. * 星闪豹
  87. * 支付成功统一跳转
  88. */
  89. export function paySuccess() {
  90. const { paySuccessPath, payBackIndexPath } = storeToRefs(useSysStore())
  91. paySuccessPath.value = 'xsb-order'
  92. payBackIndexPath.value = 'subPack-xsb/commonTab/index'
  93. router.replace({ name: 'common-paySuccess' })
  94. }