diff --git a/custom-tab-bar/index.js b/custom-tab-bar/index.js index 0bd5a5a..bd1cde4 100644 --- a/custom-tab-bar/index.js +++ b/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 } diff --git a/images/轮播图3.jpg b/images/轮播图3.jpg new file mode 100644 index 0000000..92bf382 Binary files /dev/null and b/images/轮播图3.jpg differ diff --git a/pages/buyer/index.js b/pages/buyer/index.js index dfce519..0b09c70 100644 --- a/pages/buyer/index.js +++ b/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; + } }, // 带分页的本地存储回退函数 diff --git a/pages/index/index.js b/pages/index/index.js index ae91af7..4f7f7e3 100644 --- a/pages/index/index.js +++ b/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) { diff --git a/pages/index/index.wxml b/pages/index/index.wxml index b40a050..3a5c3c0 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -23,7 +23,10 @@ - + diff --git a/pages/index/index.wxss b/pages/index/index.wxss index 04920cc..b1cb595 100644 --- a/pages/index/index.wxss +++ b/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); diff --git a/pages/settlement/index.js b/pages/settlement/index.js index 4482887..c0ff419 100644 --- a/pages/settlement/index.js +++ b/pages/settlement/index.js @@ -523,47 +523,47 @@ Page({ const openid = wx.getStorageSync('openid'); const userId = wx.getStorageSync('userId'); - // 如果本地有openid,查询数据库验证用户是否真的存在 - if (openid) { - try { - const API = require('../../utils/api'); - console.log('查询数据库验证用户是否存在...'); - const userRes = await API.getUserInfo(openid); - - // 如果用户存在,继续提交申请 - if (userRes && userRes.success && userRes.data) { - console.log('用户已在数据库中存在,跳过登录验证'); - // 更新本地存储的用户信息 - wx.setStorageSync('userInfo', userRes.data); - // 继续执行后续逻辑 - } else { - // 用户不存在,需要登录 - console.log('用户不存在于数据库中,需要登录'); - // 保存当前表单数据 - this.saveSettlementProgress(); - // 显示登录弹窗 - this.setData({ - showAuthModal: true - }); - return; // 取消提交申请 - } - } catch (error) { - console.error('查询用户信息失败:', error); - // 查询失败,可能是网络问题或其他原因,继续使用本地存储的信息 - console.log('查询失败,继续使用本地存储的用户信息:', openid, userId); - } - } else if (!openid || !userId) { - // 本地没有openid或userId,显示登录弹窗 - console.log('本地没有用户信息,显示授权弹窗'); + // 如果本地没有openid或用户信息,直接显示一键登录弹窗 + if (!openid || !userId) { + console.log('本地没有用户信息,显示一键登录弹窗'); // 保存当前表单数据 this.saveSettlementProgress(); - // 显示登录弹窗 + // 直接显示一键登录弹窗 this.setData({ - showAuthModal: true + showOneKeyLoginModal: true }); return; // 取消提交申请 } + // 如果本地有openid,查询数据库验证用户是否真的存在 + try { + const API = require('../../utils/api'); + console.log('查询数据库验证用户是否存在...'); + const userRes = await API.getUserInfo(openid); + + // 如果用户存在,继续提交申请 + if (userRes && userRes.success && userRes.data) { + console.log('用户已在数据库中存在,跳过登录验证'); + // 更新本地存储的用户信息 + wx.setStorageSync('userInfo', userRes.data); + // 继续执行后续逻辑 + } else { + // 用户不存在,需要登录 + console.log('用户不存在于数据库中,需要登录'); + // 保存当前表单数据 + this.saveSettlementProgress(); + // 直接显示一键登录弹窗 + this.setData({ + showOneKeyLoginModal: true + }); + return; // 取消提交申请 + } + } catch (error) { + console.error('查询用户信息失败:', error); + // 查询失败,可能是网络问题或其他原因,继续使用本地存储的信息 + console.log('查询失败,继续使用本地存储的用户信息:', openid, userId); + } + 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,75 +967,182 @@ Page({ // 关闭登录弹窗 this.setData({ - showAuthModal: false + showOneKeyLoginModal: false }); - if (e.detail.errMsg === 'getPhoneNumber:ok') { - // 用户同意授权 - wx.showLoading({ - title: '登录中...', - mask: true + // 首先检查用户是否拒绝授权 + if (e.detail.errMsg !== 'getPhoneNumber:ok') { + console.log('用户拒绝授权手机号'); + wx.showToast({ + title: '您已拒绝授权,操作已取消', + icon: 'none' }); + return; + } + // 用户同意授权 + wx.showLoading({ + title: '登录中...', + mask: true + }); + + try { + // 引入API服务 + const API = require('../../utils/api.js'); + + // 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: phoneNumber, + gender: 0, + country: '', + province: '', + city: '', + language: 'zh_CN' + }; + try { - // 调用API解密手机号 - const app = getApp(); - if (app && app.uploadPhoneNumberData) { - const result = await app.uploadPhoneNumberData(e.detail); - - if (result && result.success) { - // 保存用户信息到全局和本地存储 - const userInfo = { - name: '微信用户', - avatarUrl: '/images/default-avatar.png', - phoneNumber: result.phoneNumber || '未绑定', - gender: 0, - country: '', - province: '', - city: '', - language: 'zh_CN' - }; - - // 保存到全局数据 - app.globalData.userInfo = userInfo; - - // 保存到本地存储 - wx.setStorageSync('userInfo', userInfo); - - console.log('用户信息已保存:', userInfo); - - wx.hideLoading(); - wx.showToast({ - title: '登录成功', - icon: 'success', - duration: 1500, - complete: () => { - // 登录成功后关闭弹窗,让用户决定是否继续提交 - setTimeout(() => { - this.closeOneKeyLoginModal(); - this.setData({ showAuthModal: false }); - }, 1500); - } - }); - } else { - throw new Error(result.message || '登录失败'); - } - } else { - // 备用方案:模拟登录 - await this.performBackupLogin(); + // 尝试获取用户微信头像和昵称 + const userProfileRes = await new Promise((resolve, reject) => { + wx.getUserProfile({ + desc: '用于完善会员资料', + success: resolve, + fail: reject + }); + }); + + if (userProfileRes && userProfileRes.userInfo) { + userInfo = { + ...userInfo, + ...userProfileRes.userInfo + }; } - } catch (error) { - wx.hideLoading(); - console.error('手机号授权登录失败:', error); - wx.showToast({ - title: '登录失败,请重试', - icon: 'none' + } catch (err) { + console.warn('获取用户头像昵称失败:', err); + // 不影响主流程,使用默认值 + } + + // 5. 更新用户信息到服务器 + try { + await API.updateUserInfo({ + openid: openid, + phoneNumber: phoneNumber, + ...userInfo }); + console.log('用户信息已更新到服务器'); + } catch (err) { + console.warn('更新用户信息到服务器失败:', err); + // 不影响主流程,继续执行 } - } else { - // 用户拒绝授权 + + // 6. 保存用户信息到全局和本地存储 + const app = getApp(); + if (app) { + app.globalData.userInfo = userInfo; + } + + wx.setStorageSync('userInfo', userInfo); + console.log('用户信息已保存到本地存储:', userInfo); + + wx.hideLoading(); wx.showToast({ - title: '需要手机号授权才能继续', + title: '登录成功', + icon: 'success', + duration: 1500, + complete: () => { + // 登录成功后关闭弹窗,让用户继续提交申请 + setTimeout(() => { + this.closeOneKeyLoginModal(); + // 用户登录成功后,可以选择自动提交申请 + // 这里保持原逻辑,让用户手动点击提交 + }, 1500); + } + }); + + } catch (error) { + wx.hideLoading(); + console.error('手机号授权登录失败:', error); + 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); }, // 重置申请流程 diff --git a/pages/settlement/index.wxml b/pages/settlement/index.wxml index 63e07e5..558ff35 100644 --- a/pages/settlement/index.wxml +++ b/pages/settlement/index.wxml @@ -357,7 +357,7 @@ 授权登录 - 请授权获取您的手机号用于登录 + 授权您的手机号后才能提交申请