Files
oil-client-wechat/pages/wodeOil/wodeOil.js
2025-12-19 11:20:59 +08:00

316 lines
6.2 KiB
JavaScript

const app = getApp();
import { totalMoney,getDriverMoney } from "../../utils/withdraw"
Page({
data: {
money: "",
rewards: "",
renzheng: "",
showName: false,
stationName: "",
nvabarData: {
showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
title: "个人主页", //导航栏 中间的标题
},
uerName: "",
uerPhone: "",
// 此页面 页面内容距最顶部的距离
height: app.globalData.height,
userType: 0,
oilstaList: [],
totalMoney: 0,
oilName: '',
value: '',
// 额度查询弹窗相关
showLimitModal: false,
phoneNumber: '',
phoneError: ''
},
onLoad() {
this.detail();
this.resetUserInfo()
this.oilStationsList()
},
onPullDownRefresh: function () {
this.detail();
wx.stopPullDownRefresh();
},
sao: function () {
// 允许从相机和相册扫码
wx.scanCode({
success: (res) => {
var url = res.path.slice(6);
wx.navigateTo({
url: "../" + url,
});
},
});
},
contactPhone() {
wx.makePhoneCall({
phoneNumber: "4000885256",
});
},
detail() {
// wx.showLoading({
// title: '加载中...',
// });
let that = this;
var name = wx.getStorageSync("name");
if (name == null || name == undefined || name == "") {
name = "";
} else {
that.setData({
showName: true,
});
}
that.setData({
phone: wx.getStorageSync("phoneOil"),
number: wx.getStorageSync("number"),
renzheng: wx.getStorageSync("state"),
name: name,
});
},
handleContact(e) { },
login: function () {
wx.showModal({
title: "提示",
content: "您确定要退出当前账户吗?",
cancel: true,
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url:
"../login-wx/login-wx?weChatId=" + wx.getStorageSync("weChatId"),
});
} else if (res.cancel) {
console.log("用户点击取消");
}
},
});
},
// 可提现金额
oilStationsList() {
let id = wx.getStorageSync("cooperation").id
totalMoney(id).then(res => {
this.setData({
totalMoney: res.data
})
})
},
resetUserInfo() {
const { userType } = wx.getStorageSync("kybUser");
const { name, phone, } = wx.getStorageSync("cooperation");
const company = wx.getStorageSync("cooperation").company;
const pho = /(\d{3})\d*(\d{4})/;
const uerPhone = phone ? phone.replace(pho, "$1****$2") : '';
this.setData({
userType,
uerName: name,
uerPhone: uerPhone,
stationName: company,
oilstaList: wx.getStorageSync("cooperations"),
});
},
bindPickerChange(event) {
const { value } = event.detail;
let { oilstaList } = this.data
wx.setStorageSync("cooperation", oilstaList[value]);
this.oilStationsList()
this.resetUserInfo()
},
// 钱包详情
wallet() {
wx.navigateTo({
url: "/pages/wallet/detail",
});
},
// 提现记录
withdrawList() {
wx.navigateTo({
url: "/pages/wallet/withdrawList",
});
},
//修改密码
resetPassword() {
wx.navigateTo({
url: '/pages/password/password',
})
},
oilHistory() {
wx.navigateTo({
url: "/pages/oilHistory/oilHistory",
});
},
userManagement() {
wx.navigateTo({
url: "/pages/userManagement/userManagement",
});
},
oilHistory() {
wx.navigateTo({
url: "/pages/oilHistory/oilHistory",
});
},
onShow() {
this.resetUserInfo()
this.oilStationsList()
},
qianbao: function () {
wx.navigateTo({
url: "../wallet/wallet",
});
},
youka: function () {
wx.navigateTo({
url: "../youka/youka",
});
},
lingYK: function () {
wx.navigateTo({
url: "../lingYK/lingYK",
});
},
renzheng: function () {
wx.navigateTo({
url: "../approve/approve",
});
},
phone: function () {
wx.makePhoneCall({
phoneNumber: "400-0885256", //仅为示例,并非真实的电话号码
});
},
mingxi: function () {
wx.navigateTo({
url: "../walletDetail/wallet.detail",
});
},
mima: function () {
wx.navigateTo({
url: "../pasManange/pasManange",
});
},
// 额度查询相关函数
queryLimit: function() {
this.setData({
showLimitModal: true,
phoneNumber: '',
phoneError: ''
});
},
// 关闭弹窗
closeLimitModal: function() {
this.setData({
showLimitModal: false,
phoneNumber: '',
phoneError: ''
});
},
// 手机号码输入
inputPhoneNumber: function(e) {
this.setData({
phoneNumber: e.detail.value,
phoneError: ''
});
},
// 手机号码校验
validatePhone: function(phone) {
const reg = /^1[3-9]\d{9}$/;
return reg.test(phone);
},
// 确认查询
confirmQueryLimit: function() {
const { phoneNumber } = this.data;
// 校验手机号码
if (!phoneNumber) {
this.setData({
phoneError: '请输入手机号码'
});
return;
}
if (!this.validatePhone(phoneNumber)) {
this.setData({
phoneError: '请输入正确的手机号码'
});
return;
}
// 真实接口调用
wx.showLoading({
title: '查询中...',
});
// 准备请求数据
const requestData = {
phone: phoneNumber
};
// 使用封装的 getDriverMoney 函数发送请求
getDriverMoney(requestData)
.then((res) => {
wx.hideLoading();
console.log('API返回结果:', res);
// 从res.data.data中获取实际数据
const walletList = res.data;
console.log('walletList:', walletList);
console.log('walletList类型:', typeof walletList);
if (Array.isArray(walletList)) {
console.log('walletList长度:', walletList.length);
}
// 关闭弹窗
this.closeLimitModal();
// 检查是否有数据
if (walletList && walletList.length > 0) {
// 跳转到新页面展示数据
wx.navigateTo({
url: '/pages/limitDetail/limitDetail',
success: function(res) {
console.log('跳转成功');
// 传递数据
res.eventChannel.emit('limitData', { walletList: walletList });
},
fail: function(err) {
console.error('跳转失败:', err);
wx.showToast({
title: '跳转失败',
icon: 'none'
});
}
});
} else {
wx.showToast({
title: '当前用户钱包无可用金额',
icon: 'none'
});
}
})
.catch((err) => {
wx.hideLoading();
wx.showToast({
title: err.msg || '查询失败,请稍后重试',
icon: 'none'
});
});
},
noop: () => {}
});