支付功能
This commit is contained in:
parent
bbab09950b
commit
1ec179d2ae
@ -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}),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,11 +32,10 @@
|
||||
v-for="item in cartList"
|
||||
:key="item.goods_id"
|
||||
>
|
||||
<goodsItem
|
||||
:item="item"
|
||||
v-if="item.goods_select"
|
||||
/>
|
||||
<block v-if="item.goods_select">
|
||||
<goodsItem :item="item"/>
|
||||
<text class="goods_count">x{{ item.goods_count }}</text>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -79,11 +78,36 @@ 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);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user