hookehuyr

模拟支付流程代码更新

/*
* @Date: 2023-12-22 10:29:37
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-12-27 14:08:21
* @LastEditTime: 2023-12-27 17:27:31
* @FilePath: /meihuaApp/src/api/index.js
* @Description: 文件描述
*/
......@@ -16,6 +16,8 @@ const Api = {
GET_LIST: '/srv/?a=room_data&t=get_list',
GET_ROOM: '/srv/?a=room_data&t=get_room',
ADD_ORDER: '/srv/?a=room_data&t=add_order',
PAY: '/srv/?a=pay',
PAY_CHECK: '/srv/?a=pay_check',
}
/**
......@@ -84,3 +86,17 @@ export const getRoomAPI = (params) => fn(fetch.get(Api.GET_ROOM, params));
* @returns
*/
export const addOrderAPI = (params) => fn(fetch.post(Api.ADD_ORDER, params));
/**
* @description: 支付
* @param order_id 订单ID
* @returns
*/
export const payAPI = (params) => fn(fetch.post(Api.PAY, params));
/**
* @description: 检查是否支付成功
* @param order_id 订单ID
* @returns
*/
export const payCheckAPI = (params) => fn(fetch.post(Api.PAY_CHECK, params));
......
<!--
* @Date: 2023-12-20 14:11:11
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-12-27 11:47:33
* @LastEditTime: 2023-12-27 17:37:35
* @FilePath: /meihuaApp/src/components/payCard.vue
* @Description: 文件描述
-->
......@@ -22,6 +22,7 @@
import Taro from '@tarojs/taro'
import { ref, watch, onMounted, onUnmounted } from 'vue'
import { getCurrentPageUrl } from "@/utils/weapp";
import { payAPI, payCheckAPI } from '@/api/index'
/**
* 格式化时间
......@@ -98,8 +99,8 @@ onUnmounted(() => {
timeId && clearInterval(timeId);
})
const goToPay = () => {
// TODO:支付成功后的操作
const goToPay = async () => {
// TODO:模拟代码
emit('close'); // 关闭支付弹框
//
Taro.showToast({
......@@ -122,35 +123,45 @@ const goToPay = () => {
});
}
}, 1000);
// this.$parent.sdk.post('c/app/prepay', {
// id: this.params.id
// }).then(res => {
// if (res.data.ret === 'OK') {
// let pay = res.data.content.payargs;
// TODO:实际操作代码等待接口放上去
// // 获取支付参数
// const pay = await payAPI({ order_id: id.value });
// if (pay.code) {
// let pay = pay.data.payargs;
// // 触发微信支付操作
// wx.requestPayment({
// timeStamp: pay.timeStamp,
// nonceStr: pay.nonceStr,
// package: pay.package,
// signType: pay.signType,
// paySign: pay.paySign,
// success: (result) => {
// that.$parent.sdk.post('c/order/paySuccess', {
// id: that.params.id
// }).then(pRes => {
// if (pRes.data.ret === 'OK') {
// that.Toast('success', '感谢您的捐赠', 3000)
// } else {
// that.Toast('fail', pRes.data.err, 3000);
// success: async (result) => {
// emit('close'); // 关闭支付弹框
// Taro.showToast({
// title: '支付成功',
// icon: 'success',
// duration: 1000
// });
// // 支付成功后,调用检查接口
// const pay_success = await payCheckAPI({ order_id: id.value });
// if (pay_success.code) {
// let current_page = getCurrentPageUrl();
// if (current_page === 'pages/my/index') { // 我的页面打开
// // 刷新当前页面
// Taro.reLaunch({
// url: '/pages/my/index?tab_index=1'
// });
// }
// if (current_page === 'pages/detail/index') { // 订房确认页打开
// // 跳转订单成功页
// Taro.navigateTo({
// url: '/pages/payInfo/index',
// });
// }
// }
// }).catch(err => {
// console.error(err)
// })
// }
// });
// } else {
// this.Toast('fail', res.data.msg, 3000);
// }
// })
}
</script>
......