将/miniprogram/user/onlineCarHailing和/miniprogram/user等API端点路径更新为/v2/miniprogram/user/onlineCarHailing和/v2/miniprogram/user,以适配后端API的v2版本
199 lines
4.3 KiB
JavaScript
199 lines
4.3 KiB
JavaScript
var t = getApp(), e = require("../../utils/login.js");
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
userInfo: {},
|
|
balance: 0,
|
|
loading: true,
|
|
paySuccess: false,
|
|
orderInfo: {},
|
|
token: '',
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
var a = this;
|
|
// 等待全局接口执行完成后再初始化页面
|
|
e.pageStart(t).then(function() {
|
|
a.initPage();
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 初始化页面数据
|
|
*/
|
|
initPage() {
|
|
var a = this;
|
|
a.setData({
|
|
loading: true
|
|
});
|
|
|
|
e.request('/v2/miniprogram/substituteWash/index', {}, true).then(function (res) {
|
|
a.setData({
|
|
loading: false
|
|
});
|
|
|
|
if (res.code === 200 && res.data) {
|
|
a.setData({
|
|
orderInfo: res.data.orderInfo || {},
|
|
balance: res.data.balance || 0,
|
|
token: res.data.token || '',
|
|
});
|
|
} else {
|
|
wx.showToast({
|
|
title: res.message || '获取数据失败',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
}
|
|
}).catch(function (err) {
|
|
a.setData({
|
|
loading: false
|
|
});
|
|
|
|
wx.showToast({
|
|
title: '获取数据失败',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 确认洗车
|
|
*/
|
|
confirmWash() {
|
|
var a = this;
|
|
|
|
wx.showModal({
|
|
title: '确认洗车',
|
|
content: '确定要进行帮洗服务吗?',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
a.payForWash();
|
|
}
|
|
}
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 支付洗车费用
|
|
*/
|
|
payForWash() {
|
|
var a = this;
|
|
|
|
wx.showLoading({
|
|
title: '处理中',
|
|
mask: true
|
|
});
|
|
|
|
e.request('/v2/miniprogram/substituteWash/pay', {token: a.data.token}, true).then(function (res) {
|
|
wx.hideLoading();
|
|
|
|
if (res.code === 200) {
|
|
wx.showToast({
|
|
title: '支付成功',
|
|
icon: 'success',
|
|
duration: 2000
|
|
});
|
|
|
|
// 更新余额信息和支付状态
|
|
let updateData = {
|
|
paySuccess: true
|
|
};
|
|
|
|
if (res.data && res.data.balance !== undefined) {
|
|
updateData.balance = res.data.balance;
|
|
}
|
|
|
|
if (res.data && res.data.orderInfo) {
|
|
updateData.orderInfo = res.data.orderInfo;
|
|
}
|
|
|
|
a.setData(updateData);
|
|
|
|
// 可以在这里添加支付成功后的其他操作
|
|
} else {
|
|
wx.showModal({
|
|
title: '支付失败',
|
|
content: res.message || '请稍后再试',
|
|
showCancel: false
|
|
});
|
|
}
|
|
}).catch(function (err) {
|
|
wx.hideLoading();
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
// 如果不是支付成功状态,则重新初始化页面
|
|
if (!this.data.paySuccess) {
|
|
var a = this;
|
|
e.pageStart(t).then(function() {
|
|
a.initPage();
|
|
});
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
var a = this;
|
|
e.pageStart(t).then(function() {
|
|
a.initPage();
|
|
wx.stopPullDownRefresh();
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 禁止页面分享
|
|
*/
|
|
onShareAppMessage: null,
|
|
|
|
/**
|
|
* 返回首页
|
|
*/
|
|
backToIndex() {
|
|
wx.redirectTo({
|
|
url: '/pages/index/index'
|
|
});
|
|
}
|
|
}) |