支付功能

This commit is contained in:
jqtmviyu@gmail.com 2021-03-06 22:59:04 +08:00
parent bbab09950b
commit 1ec179d2ae
2 changed files with 48 additions and 13 deletions

View File

@ -23,6 +23,13 @@ const USERS_WXLOGIN_URL = '/users/wxlogin'
// 创建订单 // 创建订单
const MY_ORDERS_CREATE_URL = '/my/orders/create' 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') || '' const token = uni.getStorageSync('token') || ''
// 此处第二个参数vm就是我们在页面使用的this你可以通过vm获取vuex等操作 // 此处第二个参数vm就是我们在页面使用的this你可以通过vm获取vuex等操作
@ -52,10 +59,14 @@ const install = (Vue, vm) => {
// 获取token // 获取token
getUserToken: (params = {}) => vm.$u.post(USERS_WXLOGIN_URL, params), getUserToken: (params = {}) => vm.$u.post(USERS_WXLOGIN_URL, params),
// 创建订单 // 创建订单
createOrders: (params = {}) => vm.$u.post(MY_ORDERS_CREATE_URL, params, { createOrders: (params = {}) => vm.$u.post(MY_ORDERS_CREATE_URL, params,
Authorization: token {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}),
} }
} }

View File

@ -32,11 +32,10 @@
v-for="item in cartList" v-for="item in cartList"
:key="item.goods_id" :key="item.goods_id"
> >
<goodsItem <block v-if="item.goods_select">
:item="item" <goodsItem :item="item"/>
v-if="item.goods_select"
/>
<text class="goods_count">x{{ item.goods_count }}</text> <text class="goods_count">x{{ item.goods_count }}</text>
</block>
</view> </view>
</view> </view>
</view> </view>
@ -79,11 +78,36 @@ export default {
}) })
}, },
// //
payHandle(){ async payHandle(){
if (!this.address.userName) { if (!this.address.userName) {
uni.showToast({ title: "请选择收货地址", icon: "none" }); return uni.showToast({ title: "请选择收货地址", icon: "none" });
} else { } 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);
} }
}, },
}, },