Browse Source

修复结算页面完成按钮返回首页,优化手机号授权流程,修复applicationId设置警告

pull/1/head
徐飞洋 2 months ago
parent
commit
f9b5d7f2c0
  1. 10
      custom-tab-bar/index.js
  2. BIN
      images/轮播图3.jpg
  3. 17
      pages/buyer/index.js
  4. 3
      pages/buyer/index.wxml
  5. 17
      pages/favorites/index.js
  6. 3
      pages/favorites/index.wxml
  7. 55
      pages/goods-detail/goods-detail.js
  8. 11
      pages/goods-detail/goods-detail.wxml
  9. 38
      pages/goods-detail/goods-detail.wxss
  10. 17
      pages/index/index.js
  11. 5
      pages/index/index.wxml
  12. 6
      pages/index/index.wxss
  13. 280
      pages/settlement/index.js
  14. 2
      pages/settlement/index.wxml

10
custom-tab-bar/index.js

@ -199,7 +199,15 @@ Component({
// 检查全局数据中是否有控制tab-bar显示的状态
let showTabBar = true
if (app && app.globalData && typeof app.globalData.showTabBar !== 'undefined') {
// 如果是tabBar页面,默认显示tab-bar
const tabBarPages = this.data.tabBarItems.map(item => item.route)
if (tabBarPages.includes(currentRoute)) {
showTabBar = true
// 同时更新全局状态,确保一致性
if (app && app.globalData) {
app.globalData.showTabBar = true
}
} else if (app && app.globalData && typeof app.globalData.showTabBar !== 'undefined') {
showTabBar = app.globalData.showTabBar
}

BIN
images/轮播图3.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

17
pages/buyer/index.js

@ -493,12 +493,17 @@ Page({
// 更新自定义tabBar状态
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({
selected: 1
selected: 1,
show: true // 确保导航栏显示
});
}
// 更新全局tab状态
const app = getApp();
app.updateCurrentTab('buyer');
// 确保全局tabBar显示状态为true
if (app.globalData) {
app.globalData.showTabBar = true;
}
},
// 带分页的本地存储回退函数
@ -856,6 +861,14 @@ Page({
(reservedCountValue !== undefined && reservedCountValue !== null ? reservedCountValue :
(reservationCountValue || 0));
// 转换supplyStatus字段值
let supplyStatusValue = product.supplyStatus || '';
if (['平台货源', '三方认证'].includes(supplyStatusValue)) {
supplyStatusValue = '现货';
} else if (supplyStatusValue === '三方未认证') {
supplyStatusValue = '预售';
}
return {
id: productIdStr,
productId: productIdStr,
@ -875,6 +888,8 @@ Page({
reservedCount: finalReservationCount,
product_contact: product.product_contact || '', // 【新增】添加联系人字段
contact_phone: product.contact_phone || '', // 【新增】添加联系人电话字段
supplyStatus: supplyStatusValue, // 添加supplyStatus字段并进行转换
sourceType: product.sourceType || '', // 新增sourceType字段
debugInfo: {
originalSelected: selectedValue,
originalReservedCount: reservedCountValue,

3
pages/buyer/index.wxml

@ -55,8 +55,9 @@
<view style="flex: 0.6; padding: 0rpx 15rpx 15rpx 15rpx; cursor: pointer;" bindtap="showGoodsDetail" data-item="{{item}}">
<view>
<view style="margin-bottom: 15rpx; margin-top: -5rpx;">
<view style="display: inline-block; margin-right: 10rpx; font-size: 18rpx; color: #fff; background-color: #DAA520; padding: 2rpx 8rpx; border-radius: 10rpx; vertical-align: middle;">金标蛋</view>
<view style="display: inline-block; margin-right: 10rpx; font-size: 18rpx; color: #fff; background: rgba(218, 165, 32, 0.8); padding: 4rpx 10rpx; border-radius: 15rpx; vertical-align: middle; backdrop-filter: blur(10rpx); border: 1rpx solid rgba(255, 255, 255, 0.3); box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15), inset 0 1rpx 0 rgba(255, 255, 255, 0.5); text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.2); font-weight: bold;">{{item.supplyStatus || '暂无状态'}}</view>
<span style="vertical-align: middle; font-size: 36rpx; font-weight: bold;">{{item.name}}</span>
<span style="vertical-align: middle; font-size: 20rpx; color: white; background: linear-gradient(135deg, #4a90e2 0%, #2b66f0 50%, #1a4bbd 100%); padding: 4rpx 8rpx; clip-path: polygon(50% 0%, 70% 10%, 100% 30%, 100% 70%, 70% 90%, 50% 100%, 30% 90%, 0% 70%, 0% 30%, 30% 10%); margin-left: 8rpx; box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.3), inset 0 1rpx 2rpx rgba(255, 255, 255, 0.5); text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.5); font-weight: bold;">V</span>
</view>
<view style="font-size: 28rpx; font-weight: bold; margin-top: 30rpx;">
{{item.specification || '无'}} | {{item.yolk || '无'}} | {{item.minOrder || item.quantity || 1}}件

17
pages/favorites/index.js

@ -160,7 +160,22 @@ Page({
console.log('获取收藏列表成功:', res);
// 检查API返回是否成功
if (res && res.code === 200 && res.data) {
const favorites = res.data.favorites || [];
let favorites = res.data.favorites || [];
// 转换supplyStatus字段值
favorites = favorites.map(item => {
if (item.Product && item.Product.supplyStatus) {
// 将supplyStatus由"平台货源"、"三方认证"、"三方未认证"修改为"预售"、"现货"
// 平台货源和三方认证转为现货,三方未认证转为预售
if (['平台货源', '三方认证'].includes(item.Product.supplyStatus)) {
item.Product.supplyStatus = "现货";
} else if (item.Product.supplyStatus === '三方未认证') {
item.Product.supplyStatus = "预售";
}
}
return item;
});
this.setData({
favoritesList: favorites,
hasFavorites: favorites.length > 0,

3
pages/favorites/index.wxml

@ -54,8 +54,9 @@
<view style="flex: 0.6; padding: 0rpx 15rpx 15rpx 15rpx; cursor: pointer;" bindtap="goToGoodsDetail" data-item="{{item}}">
<view>
<view style="margin-bottom: 15rpx; margin-top: -5rpx;">
<view style="display: inline-block; margin-right: 10rpx; font-size: 18rpx; color: #fff; background-color: #DAA520; padding: 2rpx 8rpx; border-radius: 10rpx; vertical-align: middle;">金标蛋</view>
<view style="display: inline-block; margin-right: 10rpx; font-size: 18rpx; color: #fff; background: rgba(218, 165, 32, 0.8); padding: 4rpx 10rpx; border-radius: 15rpx; vertical-align: middle; backdrop-filter: blur(10rpx); border: 1rpx solid rgba(255, 255, 255, 0.3); box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15), inset 0 1rpx 0 rgba(255, 255, 255, 0.5); text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.2); font-weight: bold;">{{item.Product.supplyStatus || '暂无状态'}}</view>
<span style="vertical-align: middle; font-size: 36rpx; font-weight: bold;">{{item.Product.productName || '未命名商品'}}</span>
<span style="vertical-align: middle; font-size: 20rpx; color: white; background: linear-gradient(135deg, #4a90e2 0%, #2b66f0 50%, #1a4bbd 100%); padding: 4rpx 8rpx; clip-path: polygon(50% 0%, 70% 10%, 100% 30%, 100% 70%, 70% 90%, 50% 100%, 30% 90%, 0% 70%, 0% 30%, 30% 10%); margin-left: 8rpx; box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.3), inset 0 1rpx 2rpx rgba(255, 255, 255, 0.5); text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.5); font-weight: bold;">V</span>
</view>
<view style="font-size: 28rpx; font-weight: bold; margin-top: 30rpx;">
{{(item.Product.spec && item.Product.spec !== '无') ? item.Product.spec : (item.Product.specification && item.Product.specification !== '无') ? item.Product.specification : '无'}} | {{item.Product.yolk || '无'}} | {{item.Product.minOrder || item.Product.quantity || 1}}件

55
pages/goods-detail/goods-detail.js

@ -1,6 +1,16 @@
// pages/goods-detail/goods-detail.js
const API = require('../../utils/api.js')
// 根据sourceType获取对应的颜色
function getSourceTypeColor(sourceType) {
const colorMap = {
'三方认证': '#4d9dff',
'三方未认证': '#ff4d4f',
'平台货源': '#2ad21f'
};
return colorMap[sourceType] || '#4d9dff';
}
// 格式化毛重显示的辅助函数
function formatGrossWeight(grossWeight, weight) {
console.log('===== formatGrossWeight 函数调用 =====');
@ -24,6 +34,36 @@ function formatGrossWeight(grossWeight, weight) {
return "";
}
// 提取地区中的省份信息
function extractProvince(region) {
if (!region || typeof region !== 'string') {
return region;
}
// 查找各种省份格式的位置
const provinceEndIndex = region.indexOf('省');
const autonomousRegionEndIndex = region.indexOf('自治区');
const municipalityEndIndex = region.indexOf('市'); // 用于直辖市,如北京市、上海市
const specialRegionEndIndex = region.indexOf('特别行政区'); // 用于香港、澳门
if (provinceEndIndex !== -1) {
// 包含"省"字,提取到"省"字结束
return region.substring(0, provinceEndIndex + 1);
} else if (autonomousRegionEndIndex !== -1) {
// 包含"自治区",提取到"自治区"结束
return region.substring(0, autonomousRegionEndIndex + 3);
} else if (specialRegionEndIndex !== -1) {
// 包含"特别行政区",提取到"特别行政区"结束
return region.substring(0, specialRegionEndIndex + 5);
} else if (municipalityEndIndex === 2) {
// 直辖市(如北京市、上海市),市字在第2个字符位置
return region.substring(0, municipalityEndIndex + 1);
}
// 如果没有找到匹配的格式,返回原字符串
return region;
}
Page({
data: {
goodsDetail: {}, // 当前商品详情
@ -128,6 +168,14 @@ Page({
// 处理grossWeight为null或无效的情况,返回空字符串以支持文字输入
const grossWeightValue = product.grossWeight !== null && product.grossWeight !== undefined ? product.grossWeight : '';
// 转换supplyStatus字段值
let supplyStatusValue = product.supplyStatus || '';
// 将"平台货源"、"三方认证"、"三方未认证"修改为"预售"、"现货"
if (supplyStatusValue === '平台货源' || supplyStatusValue === '三方认证') {
supplyStatusValue = '现货';
} else if (supplyStatusValue === '三方未认证') {
supplyStatusValue = '预售';
}
// 转换商品数据格式
const formattedGoods = {
id: productIdStr,
@ -137,7 +185,7 @@ Page({
minOrder: product.minOrder || product.quantity,
yolk: product.yolk,
spec: product.spec || product.specification,
region: product.region,
region: extractProvince(product.region),
contact_phone: product.contact_phone || product.contactPhone,
product_contact: product.product_contact || product.contactName,
imageUrls: product.imageUrls || product.images || [],
@ -146,7 +194,10 @@ Page({
reservedCount: finalReservationCount,
created_at: product.created_at || product.createdAt,
updated_at: product.updated_at || product.updatedAt,
status: product.status
status: product.status,
supplyStatus: supplyStatusValue,
sourceType: product.sourceType || '',
sourceTypeColor: getSourceTypeColor(product.sourceType)
};
this.setData({

11
pages/goods-detail/goods-detail.wxml

@ -30,11 +30,18 @@
</view>
<!-- 商品基本信息 -->
<view class="goods-info">
<view class="goods-info" style="margin-top: -40rpx;">
<view style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 10rpx;">
<view style="display: flex; align-items: center;">
<view style="display: inline-block; margin-right: 10rpx; font-size: 18rpx; color: #fff; background: rgba(218, 165, 32, 0.8); padding: 4rpx 10rpx; border-radius: 15rpx; vertical-align: middle; backdrop-filter: blur(10rpx); border: 1rpx solid rgba(255, 255, 255, 0.3); box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15), inset 0 1rpx 0 rgba(255, 255, 255, 0.5); text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.2); font-weight: bold; margin-top: -20rpx;">{{goodsDetail.supplyStatus || '暂无状态'}}</view>
<text class="goods-name">{{goodsDetail.name}}</text>
<span style="vertical-align: middle; font-size: 20rpx; color: white; background: linear-gradient(135deg, #4a90e2 0%, #2b66f0 50%, #1a4bbd 100%); padding: 4rpx 8rpx; clip-path: polygon(50% 0%, 70% 10%, 100% 30%, 100% 70%, 70% 90%, 50% 100%, 30% 90%, 0% 70%, 0% 30%, 30% 10%); margin-left: 8rpx; box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.3), inset 0 1rpx 2rpx rgba(255, 255, 255, 0.5); text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.5); font-weight: bold; margin-top: -20rpx;">V</span>
</view>
<view class="goods-price">
<view class="source-type-badge">
<text style="color: {{goodsDetail.sourceTypeColor}}; font-weight: bold;">{{goodsDetail.sourceType || '暂无'}}</text>
</view>
</view>
<view class="goods-price" style="position: relative; display: flex; align-items: center;">
<text class="price-symbol">价格:</text>
<text class="price-value">{{goodsDetail.price}}</text>
</view>

38
pages/goods-detail/goods-detail.wxss

@ -136,30 +136,60 @@
.goods-price {
display: flex;
align-items: baseline;
align-items: center;
margin-bottom: 4px;
}
.price-symbol {
font-size: 15px;
font-size: 18px;
color: #666;
margin-right: 4px;
font-weight: 500;
display: inline-flex;
align-items: center;
justify-content: center;
}
.price-value {
font-size: 28px;
font-size: 24px;
color: #ff4d4f;
font-weight: 700;
letter-spacing: -0.5px;
display: inline-flex;
align-items: center;
justify-content: center;
}
.price-value::before {
content: '¥';
font-size: 20px;
font-size: 24px;
margin-right: 2px;
}
.source-type-badge {
font-size: 24rpx;
color: #ffffff;
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(12rpx);
-webkit-backdrop-filter: blur(12rpx);
border: 1rpx solid rgba(255, 255, 255, 0.25);
padding: 4rpx 12rpx;
border-radius: 8rpx;
font-weight: bold;
box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.12), inset 0 1rpx 0 rgba(255, 255, 255, 0.3);
text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.2);
transition: all 0.3s ease;
display: inline-flex;
align-items: center;
justify-content: center;
margin-top: -22rpx;
}
.source-type-badge:active {
transform: scale(0.98);
box-shadow: 0 3rpx 8rpx rgba(0, 0, 0, 0.15), inset 0 1rpx 0 rgba(255, 255, 255, 0.3);
}
/* 商品详细信息网格 */
.info-grid {
background-color: #ffffff;

17
pages/index/index.js

@ -11,7 +11,8 @@ Page({
userInfo: {},
needPhoneAuth: false,
// 测试模式开关,用于在未完成微信认证时进行测试
testMode: true
testMode: true,
partnerstatus: '' // 用户入驻状态,用于显示入驻/未入驻
},
// 跳转到聊天页面
@ -952,7 +953,12 @@ Page({
app.globalData.userInfo = updatedUserInfo
wx.setStorageSync('userInfo', updatedUserInfo)
this.setData({ userInfo: updatedUserInfo })
// 设置用户入驻状态
this.setData({
userInfo: updatedUserInfo,
partnerstatus: serverUserInfo.partnerstatus || ''
})
// 同步更新用户身份信息(当前身份由数据库决定)
if (serverUserInfo.type) {
@ -979,7 +985,12 @@ Page({
app.globalData.userInfo = updatedUserInfo
wx.setStorageSync('userInfo', updatedUserInfo)
this.setData({ userInfo: updatedUserInfo })
// 设置用户入驻状态
this.setData({
userInfo: updatedUserInfo,
partnerstatus: serverUserInfo.partnerstatus || ''
})
// 同步更新用户身份信息(当前身份由数据库决定)
if (serverUserInfo.type) {

5
pages/index/index.wxml

@ -23,7 +23,10 @@
<!-- 第一行 -->
<view class="btn-row">
<button class="btn message-btn" bindtap="navigateToChat">消息中心</button>
<button class="btn settlement-btn" bindtap="navigateToSettlement">立即入驻</button>
<button
class="btn settlement-btn {{partnerstatus !== 'approved' ? 'not-approved' : ''}}"
bindtap="navigateToSettlement"
>{{partnerstatus === 'approved' ? '已入驻' : '立即入驻'}}</button>
</view>
<!-- 第二行 -->
<view class="btn-row full-width">

6
pages/index/index.wxss

@ -119,6 +119,12 @@ page {
width: 100%;
}
/* 未入驻按钮样式 */
.settlement-btn.not-approved {
background: rgba(255, 77, 79, 0.15);
color: #ff4d4f;
}
/* 按钮点击效果 */
.btn:active {
transform: scale(0.98);

280
pages/settlement/index.js

@ -523,8 +523,19 @@ Page({
const openid = wx.getStorageSync('openid');
const userId = wx.getStorageSync('userId');
// 如果本地没有openid或用户信息,直接显示一键登录弹窗
if (!openid || !userId) {
console.log('本地没有用户信息,显示一键登录弹窗');
// 保存当前表单数据
this.saveSettlementProgress();
// 直接显示一键登录弹窗
this.setData({
showOneKeyLoginModal: true
});
return; // 取消提交申请
}
// 如果本地有openid,查询数据库验证用户是否真的存在
if (openid) {
try {
const API = require('../../utils/api');
console.log('查询数据库验证用户是否存在...');
@ -541,9 +552,9 @@ Page({
console.log('用户不存在于数据库中,需要登录');
// 保存当前表单数据
this.saveSettlementProgress();
// 显示登录弹窗
// 直接显示一键登录弹窗
this.setData({
showAuthModal: true
showOneKeyLoginModal: true
});
return; // 取消提交申请
}
@ -552,17 +563,6 @@ Page({
// 查询失败,可能是网络问题或其他原因,继续使用本地存储的信息
console.log('查询失败,继续使用本地存储的用户信息:', openid, userId);
}
} else if (!openid || !userId) {
// 本地没有openid或userId,显示登录弹窗
console.log('本地没有用户信息,显示授权弹窗');
// 保存当前表单数据
this.saveSettlementProgress();
// 显示登录弹窗
this.setData({
showAuthModal: true
});
return; // 取消提交申请
}
console.log('使用用户信息提交申请:', openid, userId);
@ -697,27 +697,7 @@ Page({
return;
}
// 检查用户是否已经获取手机号
let userInfo = wx.getStorageSync('userInfo');
if (!userInfo || !userInfo.phoneNumber || userInfo.phoneNumber === '未绑定') {
wx.showToast({
title: '请先授权手机号',
icon: 'none'
});
// 显示登录弹窗,引导用户授权手机号
this.setData({
showAuthModal: true
});
return;
}
// 如果用户已经获取手机号,确保手机号字段正确赋值
if (userInfo.phoneNumber && userInfo.phoneNumber !== '未绑定') {
submitData.phoneNumber = userInfo.phoneNumber;
contactPhone = userInfo.phoneNumber;
console.log('使用登录获取的手机号:', contactPhone);
}
// 先检查所有必填表单字段
if (!this.data.collaborationid) {
wx.showToast({
title: '请选择合作商身份',
@ -742,6 +722,21 @@ Page({
return;
}
// 检查用户是否已经获取手机号
let userInfo = wx.getStorageSync('userInfo');
if (!userInfo || !userInfo.phoneNumber || userInfo.phoneNumber === '未绑定') {
// 直接显示一键登录弹窗,引导用户授权手机号
this.setData({
showOneKeyLoginModal: true
});
return;
}
// 如果用户已经获取手机号,确保手机号字段正确赋值
submitData.phoneNumber = userInfo.phoneNumber;
contactPhone = userInfo.phoneNumber;
console.log('使用登录获取的手机号:', contactPhone);
// 强制要求手机号
if (!contactPhone) {
wx.showToast({
@ -751,10 +746,6 @@ Page({
return;
}
// 更新submitData中的手机号
submitData.phoneNumber = contactPhone;
console.log('使用的手机号:', contactPhone);
// 验证省市区字段是否填写完整(用于构建region字段)
if (!this.data.province || !this.data.city || !this.data.district) {
wx.showToast({
@ -764,6 +755,10 @@ Page({
return;
}
// 更新submitData中的手机号
submitData.phoneNumber = contactPhone;
console.log('使用的手机号:', contactPhone);
// 记录省市区字段内容
console.log('省市区字段内容:', this.data.province, this.data.city, this.data.district);
@ -873,14 +868,26 @@ Page({
console.log('用户完整数据:', userRes.data);
// 更新用户的申请状态
if (userRes.data && userRes.data.partnerstatus) {
this.setData({
partnerstatus: userRes.data.partnerstatus,
applicationId: userRes.data.applicationId
});
// 构建要更新的数据对象,确保只设置存在的值
const updateData = {
partnerstatus: userRes.data.partnerstatus
};
// 只有当applicationId存在且不为undefined时才设置
if (userRes.data.applicationId) {
updateData.applicationId = userRes.data.applicationId;
} else {
updateData.applicationId = null; // 设置为null而不是undefined
}
this.setData(updateData);
// 保存最新状态到本地存储
wx.setStorageSync('settlementStatus', userRes.data.partnerstatus);
if (userRes.data.applicationId) {
wx.setStorageSync('applicationId', userRes.data.applicationId);
} else {
wx.removeStorageSync('applicationId'); // 如果不存在则移除本地存储
}
}
}).catch(err => {
@ -960,10 +967,19 @@ Page({
// 关闭登录弹窗
this.setData({
showAuthModal: false
showOneKeyLoginModal: false
});
// 首先检查用户是否拒绝授权
if (e.detail.errMsg !== 'getPhoneNumber:ok') {
console.log('用户拒绝授权手机号');
wx.showToast({
title: '您已拒绝授权,操作已取消',
icon: 'none'
});
return;
}
if (e.detail.errMsg === 'getPhoneNumber:ok') {
// 用户同意授权
wx.showLoading({
title: '登录中...',
@ -971,17 +987,92 @@ Page({
});
try {
// 调用API解密手机号
const app = getApp();
if (app && app.uploadPhoneNumberData) {
const result = await app.uploadPhoneNumberData(e.detail);
// 引入API服务
const API = require('../../utils/api.js');
if (result && result.success) {
// 保存用户信息到全局和本地存储
const userInfo = {
// 1. 先执行微信登录获取code
const loginRes = await new Promise((resolve, reject) => {
wx.login({
success: resolve,
fail: reject
});
});
if (!loginRes.code) {
throw new Error('获取登录code失败');
}
console.log('获取登录code成功:', loginRes.code);
// 2. 使用code换取openid
const openidRes = await API.getOpenid(loginRes.code);
// 增强版响应处理逻辑,支持多种返回格式
let openid = null;
let userId = null;
let sessionKey = null;
// 优先从data字段获取数据
if (openidRes && openidRes.data && typeof openidRes.data === 'object') {
openid = openidRes.data.openid || openidRes.data.OpenID || null;
userId = openidRes.data.userId || openidRes.data.userid || null;
sessionKey = openidRes.data.session_key || openidRes.data.sessionKey || null;
}
// 如果data为空或不存在,尝试从响应对象直接获取
if (!openid && openidRes && typeof openidRes === 'object') {
console.warn('服务器返回格式可能不符合预期,data字段为空或不存在,但尝试从根对象提取信息:', openidRes);
openid = openidRes.openid || openidRes.OpenID || null;
userId = openidRes.userId || openidRes.userid || null;
sessionKey = openidRes.session_key || openidRes.sessionKey || null;
}
// 检查服务器状态信息
const isSuccess = openidRes && (openidRes.success === true || openidRes.code === 200);
if (!openid) {
throw new Error('获取openid失败: ' + (openidRes && openidRes.message ? openidRes.message : '未知错误'));
}
// 存储openid和session_key
wx.setStorageSync('openid', openid);
if (sessionKey) {
wx.setStorageSync('sessionKey', sessionKey);
}
// 确保始终使用从服务器获取的正式用户ID
if (userId) {
wx.setStorageSync('userId', userId);
}
console.log('获取openid成功并存储:', openid);
// 3. 上传手机号加密数据到服务器解密
const phoneData = {
...e.detail,
openid: openid,
sessionKey: sessionKey || ''
};
console.log('准备上传手机号加密数据到服务器');
const phoneRes = await API.uploadPhoneNumberData(phoneData);
// 改进手机号解密结果的处理逻辑
if (!phoneRes || (!phoneRes.success && !phoneRes.phoneNumber)) {
// 如果服务器返回格式不标准但包含手机号,也接受
if (!(phoneRes && phoneRes.phoneNumber)) {
throw new Error('获取手机号失败: ' + (phoneRes && phoneRes.message ? phoneRes.message : '未知错误'));
}
}
const phoneNumber = phoneRes.phoneNumber || '未绑定';
console.log('获取手机号成功:', phoneNumber);
// 4. 获取用户信息
let userInfo = {
name: '微信用户',
avatarUrl: '/images/default-avatar.png',
phoneNumber: result.phoneNumber || '未绑定',
phoneNumber: phoneNumber,
gender: 0,
country: '',
province: '',
@ -989,13 +1080,48 @@ Page({
language: 'zh_CN'
};
// 保存到全局数据
try {
// 尝试获取用户微信头像和昵称
const userProfileRes = await new Promise((resolve, reject) => {
wx.getUserProfile({
desc: '用于完善会员资料',
success: resolve,
fail: reject
});
});
if (userProfileRes && userProfileRes.userInfo) {
userInfo = {
...userInfo,
...userProfileRes.userInfo
};
}
} catch (err) {
console.warn('获取用户头像昵称失败:', err);
// 不影响主流程,使用默认值
}
// 5. 更新用户信息到服务器
try {
await API.updateUserInfo({
openid: openid,
phoneNumber: phoneNumber,
...userInfo
});
console.log('用户信息已更新到服务器');
} catch (err) {
console.warn('更新用户信息到服务器失败:', err);
// 不影响主流程,继续执行
}
// 6. 保存用户信息到全局和本地存储
const app = getApp();
if (app) {
app.globalData.userInfo = userInfo;
}
// 保存到本地存储
wx.setStorageSync('userInfo', userInfo);
console.log('用户信息已保存:', userInfo);
console.log('用户信息已保存到本地存储:', userInfo);
wx.hideLoading();
wx.showToast({
@ -1003,20 +1129,15 @@ Page({
icon: 'success',
duration: 1500,
complete: () => {
// 登录成功后关闭弹窗,让用户决定是否继续提交
// 登录成功后关闭弹窗,让用户继续提交申请
setTimeout(() => {
this.closeOneKeyLoginModal();
this.setData({ showAuthModal: false });
// 用户登录成功后,可以选择自动提交申请
// 这里保持原逻辑,让用户手动点击提交
}, 1500);
}
});
} else {
throw new Error(result.message || '登录失败');
}
} else {
// 备用方案:模拟登录
await this.performBackupLogin();
}
} catch (error) {
wx.hideLoading();
console.error('手机号授权登录失败:', error);
@ -1025,13 +1146,6 @@ Page({
icon: 'none'
});
}
} else {
// 用户拒绝授权
wx.showToast({
title: '需要手机号授权才能继续',
icon: 'none'
});
}
},
// 备用登录方案
@ -1182,15 +1296,15 @@ Page({
});
}
// 跳转到seller页面,不显示提示
// 跳转到index页面,不显示提示
wx.reLaunch({
url: '/pages/seller/index'
url: '/pages/index/index'
});
}).catch(err => {
console.error('获取用户数据失败:', err);
// 即使获取失败也跳转到seller页面
// 即使获取失败也跳转到index页面
wx.reLaunch({
url: '/pages/seller/index'
url: '/pages/index/index'
});
});
},
@ -1263,18 +1377,10 @@ Page({
completeApplication() {
// 更新入驻状态为审核通过
this.updateGlobalSettlementStatus('approved');
wx.showToast({
title: '感谢您的提交,我们将尽快与您联系!',
icon: 'success'
});
// 延迟跳转到seller页面
setTimeout(() => {
// 返回首页
wx.reLaunch({
url: '/pages/seller/index'
url: '/pages/index/index'
});
}, 1500);
},
// 重置申请流程

2
pages/settlement/index.wxml

@ -357,7 +357,7 @@
<view wx:if="{{showOneKeyLoginModal}}" class="auth-modal-overlay">
<view class="auth-modal-container">
<view class="auth-modal-title">授权登录</view>
<view class="auth-modal-content">请授权获取您的手机号用于登录</view>
<view class="auth-modal-content">授权您的手机号后才能提交申请</view>
<view class="auth-modal-buttons">
<button class="auth-primary-button" open-type="getPhoneNumber" bind:getphonenumber="onGetPhoneNumber">授权获取手机号</button>
<button class="auth-cancel-button" bindtap="closeOneKeyLoginModal">取消</button>

Loading…
Cancel
Save