diff --git a/src/common/http.api.js b/src/common/http.api.js index d652423..1ea818b 100644 --- a/src/common/http.api.js +++ b/src/common/http.api.js @@ -23,6 +23,13 @@ const USERS_WXLOGIN_URL = '/users/wxlogin' // 创建订单 const MY_ORDERS_CREATE_URL = '/my/orders/create' +// 获取支付参数 +const MY_ORDERS_REQ_UNIFIEDORDER = '/my/orders/req_unifiedorder' + +// 查看支付状态 +const MY_ORDERS_CHKORDER = '/my/orders/chkOrder' + +// 拿到token const token = uni.getStorageSync('token') || '' // 此处第二个参数vm,就是我们在页面使用的this,你可以通过vm获取vuex等操作 @@ -52,10 +59,14 @@ const install = (Vue, vm) => { // 获取token getUserToken: (params = {}) => vm.$u.post(USERS_WXLOGIN_URL, params), // 创建订单 - createOrders: (params = {}) => vm.$u.post(MY_ORDERS_CREATE_URL, params, { - Authorization: token - }), - + createOrders: (params = {}) => vm.$u.post(MY_ORDERS_CREATE_URL, params, + {Authorization: token}), + // 获取支付参数 + orderPayParams: (params = {}) => vm.$u.post(MY_ORDERS_REQ_UNIFIEDORDER, params, + { Authorization: token}), + // 更新支付状态 + checkOrder: (params = {}) => vm.$u.post(MY_ORDERS_CHKORDER, params, + { Authorization: token}), } } diff --git a/src/pages/pay/pay.vue b/src/pages/pay/pay.vue index e0c6315..fbbe6e1 100644 --- a/src/pages/pay/pay.vue +++ b/src/pages/pay/pay.vue @@ -32,11 +32,10 @@ v-for="item in cartList" :key="item.goods_id" > - - x{{ item.goods_count }} + + + x{{ item.goods_count }} + @@ -79,15 +78,40 @@ export default { }) }, // 去付款 - payHandle(){ + async payHandle(){ if (!this.address.userName) { - uni.showToast({ title: "请选择收货地址", icon: "none" }); + return uni.showToast({ title: "请选择收货地址", icon: "none" }); } else { - console.log("走支付逻辑"); + // console.log("走支付逻辑"); + // 创建订单 + // 解构拿到goods参数 + const goods = this.cartList + .filter(item => item.goods_select) + .map(({goods_id, goods_count:goods_number, goods_price})=>({ + goods_id, + goods_number, + goods_price + })) + // 拿到订单号 + let {message: {order_number}} = await this.$u.api.createOrders({ + order_price:this.totalPrice, + consignee_addr: this.addressDetail, + goods + }) + console.log(order_number); + // 获取支付参数 + const {message: {pay}} = await this.$u.api.orderPayParams({order_number}) + console.log(pay); + // 调用支付接口 + const res1 = await wx.requestPayment(pay) + console.log(res1) + // 更新支付状态 + const res2 = await this.$u.api.checkOrder(order_number) + console.log(res2); } }, }, - computed: { + computed: { // 拼接收货地址 addressDetail (){ const {detailInfo, countyName, cityName, provinceName} = this.address