单商品选购下单支付的过程,接口对接完成

This commit is contained in:
donqi 2022-05-12 15:59:05 +08:00
parent 4a51a530a5
commit 34a4e5b14e
9 changed files with 463 additions and 126 deletions

View File

@ -1211,6 +1211,182 @@ const myAddressList = [{
}], }],
address: '同心镇同心村同心路88号', address: '同心镇同心村同心路88号',
isDefault: false isDefault: false
}, {
id: 2,
person2Contact: '卢翰',
phone: '12434455432',
area: [{
id: 1,
name: '广西壮族自治区'
}, {
id: 2,
name: '梧桐洲'
}, {
id: 3,
name: '藤县'
}],
address: '同心镇同心村同心路88号',
isDefault: false
}, {
id: 2,
person2Contact: '卢翰',
phone: '12434455432',
area: [{
id: 1,
name: '广西壮族自治区'
}, {
id: 2,
name: '梧桐洲'
}, {
id: 3,
name: '藤县'
}],
address: '同心镇同心村同心路88号',
isDefault: false
}, {
id: 2,
person2Contact: '卢翰',
phone: '12434455432',
area: [{
id: 1,
name: '广西壮族自治区'
}, {
id: 2,
name: '梧桐洲'
}, {
id: 3,
name: '藤县'
}],
address: '同心镇同心村同心路88号',
isDefault: false
}, {
id: 2,
person2Contact: '卢翰',
phone: '12434455432',
area: [{
id: 1,
name: '广西壮族自治区'
}, {
id: 2,
name: '梧桐洲'
}, {
id: 3,
name: '藤县'
}],
address: '同心镇同心村同心路88号',
isDefault: false
}, {
id: 2,
person2Contact: '卢翰',
phone: '12434455432',
area: [{
id: 1,
name: '广西壮族自治区'
}, {
id: 2,
name: '梧桐洲'
}, {
id: 3,
name: '藤县'
}],
address: '同心镇同心村同心路88号',
isDefault: false
}, {
id: 2,
person2Contact: '卢翰',
phone: '12434455432',
area: [{
id: 1,
name: '广西壮族自治区'
}, {
id: 2,
name: '梧桐洲'
}, {
id: 3,
name: '藤县'
}],
address: '同心镇同心村同心路88号',
isDefault: false
}, {
id: 2,
person2Contact: '卢翰',
phone: '12434455432',
area: [{
id: 1,
name: '广西壮族自治区'
}, {
id: 2,
name: '梧桐洲'
}, {
id: 3,
name: '藤县'
}],
address: '同心镇同心村同心路88号',
isDefault: false
}, {
id: 2,
person2Contact: '卢翰',
phone: '12434455432',
area: [{
id: 1,
name: '广西壮族自治区'
}, {
id: 2,
name: '梧桐洲'
}, {
id: 3,
name: '藤县'
}],
address: '同心镇同心村同心路88号',
isDefault: false
}, {
id: 2,
person2Contact: '卢翰',
phone: '12434455432',
area: [{
id: 1,
name: '广西壮族自治区'
}, {
id: 2,
name: '梧桐洲'
}, {
id: 3,
name: '藤县'
}],
address: '同心镇同心村同心路88号',
isDefault: false
}, {
id: 2,
person2Contact: '卢翰',
phone: '12434455432',
area: [{
id: 1,
name: '广西壮族自治区'
}, {
id: 2,
name: '梧桐洲'
}, {
id: 3,
name: '藤县'
}],
address: '同心镇同心村同心路88号',
isDefault: false
}, {
id: 2,
person2Contact: '卢翰',
phone: '12434455432',
area: [{
id: 1,
name: '广西壮族自治区'
}, {
id: 2,
name: '梧桐洲'
}, {
id: 3,
name: '藤县'
}],
address: '同心镇同心村同心路88号',
isDefault: false
}] }]
const myOperator = { const myOperator = {

View File

@ -10,16 +10,23 @@ export default {
// console.log("停止触发"); // console.log("停止触发");
// return false; // return false;
}, },
// success(args) { success(res) {
// console.log('interceptor-success', args); if (res.data.code !== 0) {
// }, uni.showToast({
// fail(err) { title: '系统开小差啦T_T请稍后重试',
// console.log('interceptor-fail', err) icon: 'error'
// }, })
// complete(res) { }
// console.log('interceptor-complete', res) },
// res = res.data; fail(err) {
// } uni.showToast({
title: '系统开小差啦T_T请稍后重试',
icon: 'error'
})
},
complete(res) {
console.log('interceptor-complete', res)
}
}) })
}, },
checkAndAuth() { checkAndAuth() {
@ -60,7 +67,15 @@ export default {
} }
// 获取微信登录凭证 // 获取微信登录凭证
const wxLoginCode = wx.login(); const wxLoginRes = await wx.login();
console.log(wxLoginRes)
const wxAuthRes = await uni.request({
url: '/wx/auth',
header: {
code: wxLoginRes.code
}
})
console.log(wxAuthRes)
// TODO:调用小程序服务端确认是否是授权登录过的用户 // TODO:调用小程序服务端确认是否是授权登录过的用户
let loginRes = { let loginRes = {
logined: false, logined: false,
@ -75,7 +90,9 @@ export default {
loginRes = { loginRes = {
logined: true, logined: true,
userInfo: { userInfo: {
userId: 1 userId: 1,
wxLoginCode: wxLoginRes.code,
openId: wxAuthRes[1].data.data.openid
} }
}; };
} }
@ -91,6 +108,9 @@ export default {
uni.setStorageSync('userProfile', userInfo); uni.setStorageSync('userProfile', userInfo);
return true; return true;
}, },
wxLogin() {
return wx.login();
},
getCurUserInfo() { getCurUserInfo() {
let userProfile = uni.getStorageSync('userProfile'); let userProfile = uni.getStorageSync('userProfile');
console.log("curUser:" + userProfile) console.log("curUser:" + userProfile)
@ -114,11 +134,23 @@ export default {
} }
}) })
}, },
placeOrder(params = {}) { async placeOrder(params = {}) {
return uni.request({ let res = await uni.request({
url: '/goods/goods/list', url: '/order/server/app',
method: 'POST', method: 'POST',
data: params data: params
}) })
return res[1].data;
},
async getWxPayParams(params = {}) {
let res = await uni.request({
url: '/pay/wx/lite',
method: 'POST',
header: {
code: params.code,
orderMasterCode: params.orderMasterCode
} }
})
return res[1].data;
},
} }

View File

@ -7,6 +7,8 @@
"root": "pages/order/", "root": "pages/order/",
"pages": [{ "pages": [{
"path": "order-detail" "path": "order-detail"
}, {
"path": "pay-result"
}] }]
}, { }, {
"root": "pages/product/", "root": "pages/product/",

View File

@ -37,7 +37,7 @@
</view> </view>
<!-- 底部操作栏 --> <!-- 底部操作栏 -->
<view class="cu-bar tabbar border shop fixed-bottom-bar"> <view class="cu-bar tabbar border shop fixed-bottom-bar">
<button class="bg-main-color long-btn margin-lr-sm" form-type="submit">保存</button> <button class="cu-btn bg-main-color long-btn margin-lr-sm shadow-blur" form-type="submit">保存</button>
</view> </view>
</form> </form>
</view> </view>
@ -51,13 +51,19 @@
areaList: [], areaList: [],
multiIndex: [0, 0, 0], multiIndex: [0, 0, 0],
formData: { formData: {
} },
mode: 1 // 10
} }
}, },
onLoad(options) { onLoad(options) {
let params = JSON.parse(decodeURIComponent(options.params));
this.mode = params ? params.mode : this.mode;
console.log(this.mode)
if (this.mode === 0) {
//
this.fillForm(params.addressInfo);
}
this.loadData(); this.loadData();
const addressInfo = JSON.parse(decodeURIComponent(options.addressInfo));
this.fillForm(addressInfo);
}, },
methods: { methods: {
async loadData() { async loadData() {

View File

@ -6,7 +6,7 @@
<block slot="content">地址列表</block> <block slot="content">地址列表</block>
</cu-custom> </cu-custom>
<!-- 地址列表 --> <!-- 地址列表 -->
<view class="margin-bottom-lg"> <view class="margin-bottom-with-bar">
<view class="padding margin-lr-sm margin-top-sm bg-white flex justify-between align-center" v-for="(item, index) in myAddressList"> <view class="padding margin-lr-sm margin-top-sm bg-white flex justify-between align-center" v-for="(item, index) in myAddressList">
<view @click="chooseAddress(item)"> <view @click="chooseAddress(item)">
<view class="flex justify-start align-center"> <view class="flex justify-start align-center">
@ -21,11 +21,15 @@
</view> </view>
</view> </view>
<view class="oper-column text-xl flex justify-end"> <view class="oper-column text-xl flex justify-end">
<view class="cuIcon-edit padding-lr-xs padding-tb" @click="showAddressDetail(item)"></view> <view class="cuIcon-edit padding-lr-xs padding-tb" @click="addEditAddress(item)"></view>
<view class="cuIcon-close padding-lr-xs padding-tb" @click="confirm2DelAddress(item, index)"></view> <view class="cuIcon-close padding-lr-xs padding-tb" @click="confirm2DelAddress(item, index)"></view>
</view> </view>
</view> </view>
</view> </view>
<!-- 底部新增地址按钮 -->
<view class="cu-bar tabbar border shop fixed-bottom-bar bg-back">
<button class="cu-btn bg-main-color long-btn margin-lr-sm shadow-blur" @click="addEditAddress">新增地址</button>
</view>
<!-- 模态框 --> <!-- 模态框 -->
<view class="cu-modal" :class="modalName=='delAddress'?'show':''"> <view class="cu-modal" :class="modalName=='delAddress'?'show':''">
<view class="cu-dialog"> <view class="cu-dialog">
@ -74,9 +78,23 @@
offBindEvent() { offBindEvent() {
uni.$off(this.$globalFun.CONFIRM); uni.$off(this.$globalFun.CONFIRM);
}, },
showAddressDetail(addressInfo) { addEditAddress(addressInfo) {
let url = null;
let params = null;
if (addressInfo) {
//
params = {
addressInfo: addressInfo,
mode: 0
}
} else {
//
params = {
mode: 1
}
}
uni.navigateTo({ uni.navigateTo({
url: '/pages/my/edit-address?addressInfo=' + encodeURIComponent(JSON.stringify(addressInfo)) url: '/pages/my/edit-address?params=' + encodeURIComponent(JSON.stringify(params))
}) })
}, },
confirm2DelAddress(addressInfo, index) { confirm2DelAddress(addressInfo, index) {

View File

@ -237,19 +237,47 @@
} }
let curUserInfo = this.$request.getCurUserInfo(); let curUserInfo = this.$request.getCurUserInfo();
let params = { let params = {
customerId: curUserInfo.userId, // customerId: curUserInfo.userId,
customerId: 2,
serverTime: this.formInfo.doorTime, serverTime: this.formInfo.doorTime,
addressId: this.formInfo.defaultAddress.id, addressId: this.formInfo.defaultAddress.id,
payType: this.formInfo.payWay, payType: this.formInfo.payWay,
remark: this.formInfo.comments, remark: this.formInfo.comments,
isNeedBill: this.formInfo.isNeedBill, isNeedBill: this.formInfo.isNeedBill,
goodsList: this.parseGoodsList() // goodsList: this.parseGoodsList()
goodsList: [{
goodsId: 2,
num: 1
}, {
goodsId: 3,
num: 1
}]
} }
console.log(params); //
//
let res = await this.$request.placeOrder(params); let res = await this.$request.placeOrder(params);
// , try {
// wx.requestPayment(res); //
let exPayParams = {
code: this.$request.getCurUserInfo().openId,
orderMasterCode: res.data.code
}
let wxPayParamRes = await this.$request.getWxPayParams(exPayParams);
// ,
let payInfo = JSON.parse(wxPayParamRes.data.expend.pay_info);
let wxPayRes = await wx.requestPayment(payInfo);
if (wxPayRes.errMsg === "requestPayment:ok") {
uni.navigateTo({
url: '/pages/order/pay-result?payResult=0'
})
} else {
throw 'err';
}
} catch(e) {
//
uni.navigateTo({
url: '/pages/order/pay-result?payResult=1'
})
}
} }
}, },
} }

View File

@ -0,0 +1,71 @@
<template>
<view>
<!-- 顶部操作条 -->
<cu-custom :bgColor="'bg-main-color'" :isBack="true">
<block slot="backText">返回</block>
<block slot="content">支付结果</block>
</cu-custom>
<view class="padding-lg margin-xl text-center">
<view class="text-xxl">{{payResult ? '支付成功' : '支付失败'}}</view>
<view class="margin-top">
<view class="cu-btn bg-main-color radius text-xl shadow-blur" @click="showMyOrder">查看我的订单</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
payResult: false,
servOrderTabList: [{
type: 'ordersWait2Pay',
name: '待付款'
}, {
type: 'ordersWait2Serv',
name: '待服务'
}, {
type: 'ordersServing',
name: '服务中'
}, {
type: 'ordersAfterServ',
name: '售后中'
}, {
type: 'ordersFinish',
name: '已完成'
}],
servOrderType: 'servOrder'
}
},
onLoad(options) {
if (options.payResult === '0') {
this.payResult = true;
}
},
methods: {
showMyOrder() {
let params = null;
if (this.payResult) {
params = {
orderType: this.servOrderType,
tabHeaderList: this.servOrderTabList,
tabCur: 1
}
} else {
params = {
orderType: this.servOrderType,
tabHeaderList: this.servOrderTabList,
tabCur: 0
}
}
uni.navigateTo({
url: '/pages/my/my-order?tabInfo=' + encodeURIComponent(JSON.stringify(params))
})
}
},
}
</script>
<style>
</style>

View File

@ -1,3 +1,7 @@
.bg-back {
background-color: #f5f5f5;
}
.line-default { .line-default {
color: #aaaaaa; color: #aaaaaa;
} }