单商品选购下单支付的过程,接口对接完成
This commit is contained in:
parent
4a51a530a5
commit
34a4e5b14e
|
|
@ -1211,6 +1211,182 @@ const myAddressList = [{
|
|||
}],
|
||||
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
|
||||
}, {
|
||||
id: 2,
|
||||
person2Contact: '卢翰',
|
||||
phone: '12434455432',
|
||||
area: [{
|
||||
id: 1,
|
||||
name: '广西壮族自治区'
|
||||
}, {
|
||||
id: 2,
|
||||
name: '梧桐洲'
|
||||
}, {
|
||||
id: 3,
|
||||
name: '藤县'
|
||||
}],
|
||||
address: '同心镇同心村同心路88号',
|
||||
isDefault: false
|
||||
}]
|
||||
|
||||
const myOperator = {
|
||||
|
|
|
|||
|
|
@ -1,124 +1,156 @@
|
|||
import globalData from '@/common/js/globalData.js';
|
||||
|
||||
export default {
|
||||
// 异步接口拦截
|
||||
addInterceptor() {
|
||||
uni.addInterceptor('request', {
|
||||
invoke(args) {
|
||||
// request 触发前拼接 url
|
||||
args.url = 'http://127.0.0.1:80' + args.url;
|
||||
// console.log("停止触发");
|
||||
// return false;
|
||||
},
|
||||
// success(args) {
|
||||
// console.log('interceptor-success', args);
|
||||
// },
|
||||
// fail(err) {
|
||||
// console.log('interceptor-fail', err)
|
||||
// },
|
||||
// complete(res) {
|
||||
// console.log('interceptor-complete', res)
|
||||
// res = res.data;
|
||||
// }
|
||||
})
|
||||
},
|
||||
checkAndAuth() {
|
||||
let _this = this;
|
||||
// 通过 wx.getSetting 先查询一下用户是否授权了 "scope.userInfo" 这个 scope
|
||||
wx.getSetting({
|
||||
success(res) {
|
||||
if (!res.authSetting['scope.userInfo']) {
|
||||
// 用户授权
|
||||
wx.authorize({
|
||||
scope: 'scope.userInfo',
|
||||
success() {
|
||||
// 用户已经同意, 后续调用此接口不会弹窗询问
|
||||
_this.login();
|
||||
},
|
||||
fail() {
|
||||
// 用户已经拒绝过授权
|
||||
wx.openSetting({
|
||||
success(res) {
|
||||
if (res['scope.userInfo']) {
|
||||
_this.checkAndAuth();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
import globalData from '@/common/js/globalData.js';
|
||||
|
||||
export default {
|
||||
// 异步接口拦截
|
||||
addInterceptor() {
|
||||
uni.addInterceptor('request', {
|
||||
invoke(args) {
|
||||
// request 触发前拼接 url
|
||||
args.url = 'http://127.0.0.1:80' + args.url;
|
||||
// console.log("停止触发");
|
||||
// return false;
|
||||
},
|
||||
success(res) {
|
||||
if (res.data.code !== 0) {
|
||||
uni.showToast({
|
||||
title: '系统开小差啦T_T,请稍后重试',
|
||||
icon: 'error'
|
||||
})
|
||||
} else {
|
||||
_this.login();
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
async login() {
|
||||
// 从缓存中获取登录信息
|
||||
let userInfo = uni.getStorageSync('userProfile');
|
||||
if (userInfo) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 获取微信登录凭证
|
||||
const wxLoginCode = wx.login();
|
||||
// TODO:调用小程序服务端确认是否是授权登录过的用户
|
||||
let loginRes = {
|
||||
logined: false,
|
||||
userInfo: {}
|
||||
};
|
||||
// 未登录过的获取微信用户信息
|
||||
if (!loginRes || !loginRes.logined) {
|
||||
userInfo = await wx.getUserProfile({
|
||||
desc: '用于小程序登录'
|
||||
});
|
||||
// 再次请求小程序服务端存储用户,服务端添加附加用户信息后返回
|
||||
loginRes = {
|
||||
logined: true,
|
||||
userInfo: {
|
||||
userId: 1
|
||||
}
|
||||
};
|
||||
}
|
||||
userInfo = loginRes.userInfo;
|
||||
if (!userInfo) {
|
||||
uni.showToast({
|
||||
icon: 'error',
|
||||
title: '用户信息获取失败,请退出小程序重试'
|
||||
})
|
||||
return false;
|
||||
}
|
||||
// 页面存储用户登录有效信息,以便其他页面调用
|
||||
uni.setStorageSync('userProfile', userInfo);
|
||||
return true;
|
||||
},
|
||||
getCurUserInfo() {
|
||||
let userProfile = uni.getStorageSync('userProfile');
|
||||
console.log("curUser:" + userProfile)
|
||||
return userProfile;
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
uni.showToast({
|
||||
title: '系统开小差啦T_T,请稍后重试',
|
||||
icon: 'error'
|
||||
})
|
||||
},
|
||||
complete(res) {
|
||||
console.log('interceptor-complete', res)
|
||||
}
|
||||
})
|
||||
},
|
||||
checkAndAuth() {
|
||||
let _this = this;
|
||||
// 通过 wx.getSetting 先查询一下用户是否授权了 "scope.userInfo" 这个 scope
|
||||
wx.getSetting({
|
||||
success(res) {
|
||||
if (!res.authSetting['scope.userInfo']) {
|
||||
// 用户授权
|
||||
wx.authorize({
|
||||
scope: 'scope.userInfo',
|
||||
success() {
|
||||
// 用户已经同意, 后续调用此接口不会弹窗询问
|
||||
_this.login();
|
||||
},
|
||||
fail() {
|
||||
// 用户已经拒绝过授权
|
||||
wx.openSetting({
|
||||
success(res) {
|
||||
if (res['scope.userInfo']) {
|
||||
_this.checkAndAuth();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
_this.login();
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
async login() {
|
||||
// 从缓存中获取登录信息
|
||||
let userInfo = uni.getStorageSync('userProfile');
|
||||
if (userInfo) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 获取微信登录凭证
|
||||
const wxLoginRes = await wx.login();
|
||||
console.log(wxLoginRes)
|
||||
const wxAuthRes = await uni.request({
|
||||
url: '/wx/auth',
|
||||
header: {
|
||||
code: wxLoginRes.code
|
||||
}
|
||||
})
|
||||
console.log(wxAuthRes)
|
||||
// TODO:调用小程序服务端确认是否是授权登录过的用户
|
||||
let loginRes = {
|
||||
logined: false,
|
||||
userInfo: {}
|
||||
};
|
||||
// 未登录过的获取微信用户信息
|
||||
if (!loginRes || !loginRes.logined) {
|
||||
userInfo = await wx.getUserProfile({
|
||||
desc: '用于小程序登录'
|
||||
});
|
||||
// 再次请求小程序服务端存储用户,服务端添加附加用户信息后返回
|
||||
loginRes = {
|
||||
logined: true,
|
||||
userInfo: {
|
||||
userId: 1,
|
||||
wxLoginCode: wxLoginRes.code,
|
||||
openId: wxAuthRes[1].data.data.openid
|
||||
}
|
||||
};
|
||||
}
|
||||
userInfo = loginRes.userInfo;
|
||||
if (!userInfo) {
|
||||
uni.showToast({
|
||||
icon: 'error',
|
||||
title: '用户信息获取失败,请退出小程序重试'
|
||||
})
|
||||
return false;
|
||||
}
|
||||
// 页面存储用户登录有效信息,以便其他页面调用
|
||||
uni.setStorageSync('userProfile', userInfo);
|
||||
return true;
|
||||
},
|
||||
wxLogin() {
|
||||
return wx.login();
|
||||
},
|
||||
getCurUserInfo() {
|
||||
let userProfile = uni.getStorageSync('userProfile');
|
||||
console.log("curUser:" + userProfile)
|
||||
return userProfile;
|
||||
},
|
||||
getProductCategories(params = {}) {
|
||||
return uni.request({
|
||||
url: '/goods/deptcategory/app/list',
|
||||
method: 'POST',
|
||||
method: 'POST',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
qryProductPage(params = {}) {
|
||||
},
|
||||
qryProductPage(params = {}) {
|
||||
return uni.request({
|
||||
url: '/goods/goods/list',
|
||||
method: 'POST',
|
||||
data: params,
|
||||
header: {
|
||||
pageNum: params.pageNum,
|
||||
pageSize: params.pageSize
|
||||
method: 'POST',
|
||||
data: params,
|
||||
header: {
|
||||
pageNum: params.pageNum,
|
||||
pageSize: params.pageSize
|
||||
}
|
||||
})
|
||||
},
|
||||
placeOrder(params = {}) {
|
||||
return uni.request({
|
||||
url: '/goods/goods/list',
|
||||
method: 'POST',
|
||||
})
|
||||
},
|
||||
async placeOrder(params = {}) {
|
||||
let res = await uni.request({
|
||||
url: '/order/server/app',
|
||||
method: 'POST',
|
||||
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;
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
"root": "pages/order/",
|
||||
"pages": [{
|
||||
"path": "order-detail"
|
||||
}, {
|
||||
"path": "pay-result"
|
||||
}]
|
||||
}, {
|
||||
"root": "pages/product/",
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
</view>
|
||||
<!-- 底部操作栏 -->
|
||||
<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>
|
||||
</form>
|
||||
</view>
|
||||
|
|
@ -51,13 +51,19 @@
|
|||
areaList: [],
|
||||
multiIndex: [0, 0, 0],
|
||||
formData: {
|
||||
}
|
||||
},
|
||||
mode: 1 // 1为新增,0
|
||||
}
|
||||
},
|
||||
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();
|
||||
const addressInfo = JSON.parse(decodeURIComponent(options.addressInfo));
|
||||
this.fillForm(addressInfo);
|
||||
},
|
||||
methods: {
|
||||
async loadData() {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<block slot="content">地址列表</block>
|
||||
</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 @click="chooseAddress(item)">
|
||||
<view class="flex justify-start align-center">
|
||||
|
|
@ -21,11 +21,15 @@
|
|||
</view>
|
||||
</view>
|
||||
<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>
|
||||
</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-dialog">
|
||||
|
|
@ -74,9 +78,23 @@
|
|||
offBindEvent() {
|
||||
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({
|
||||
url: '/pages/my/edit-address?addressInfo=' + encodeURIComponent(JSON.stringify(addressInfo))
|
||||
url: '/pages/my/edit-address?params=' + encodeURIComponent(JSON.stringify(params))
|
||||
})
|
||||
},
|
||||
confirm2DelAddress(addressInfo, index) {
|
||||
|
|
|
|||
|
|
@ -237,19 +237,47 @@
|
|||
}
|
||||
let curUserInfo = this.$request.getCurUserInfo();
|
||||
let params = {
|
||||
customerId: curUserInfo.userId,
|
||||
// customerId: curUserInfo.userId,
|
||||
customerId: 2,
|
||||
serverTime: this.formInfo.doorTime,
|
||||
addressId: this.formInfo.defaultAddress.id,
|
||||
payType: this.formInfo.payWay,
|
||||
remark: this.formInfo.comments,
|
||||
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);
|
||||
// 拉起微信支付窗口,支付成功跳转到支付成功页面,支付失败跳转到我的订单待支付页
|
||||
// wx.requestPayment(res);
|
||||
try {
|
||||
// 获取微信支付所需参数
|
||||
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'
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
.bg-back {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.line-default {
|
||||
color: #aaaaaa;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,4 +94,4 @@
|
|||
.cu-form-group textarea {
|
||||
margin: 0 0 20rpx 0 !important;
|
||||
padding: 20rpx !important;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue