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 4096fd6..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; + } }, // 带分页的本地存储回退函数 @@ -840,53 +845,63 @@ Page({ const reservedGoodsIds = wx.getStorageSync('reservedGoodsIds') || [] // 将服务器返回的商品数据转换为本地需要的格式 - const newGoods = pagedProducts.map(product => { - // 处理grossWeight为null或无效的情况,返回空字符串以支持文字输入 - const grossWeightValue = product.grossWeight !== null && product.grossWeight !== undefined ? product.grossWeight : ''; - - // 确保商品ID的一致性 - const productIdStr = String(product.productId || product.id); - - // 增强的预约人数计算逻辑 - const selectedValue = product.selected; - const reservedCountValue = product.reservedCount; - const reservationCountValue = product.reservationCount; - - const finalReservationCount = selectedValue !== undefined && selectedValue !== null ? selectedValue : - (reservedCountValue !== undefined && reservedCountValue !== null ? reservedCountValue : - (reservationCountValue || 0)); - - return { - id: productIdStr, - productId: productIdStr, - name: product.productName, - price: product.price, - minOrder: product.quantity, - yolk: product.yolk, - spec: (product.spec && product.spec !== '无') ? product.spec : (product.specification && product.specification !== '无') ? product.specification : '', - specification: (product.spec && product.spec !== '无') ? product.spec : (product.specification && product.specification !== '无') ? product.specification : '', - region: product.region || '', // 【新增】添加地区字段 - grossWeight: grossWeightValue, - displayGrossWeight: formatGrossWeight(grossWeightValue, product.weight), - seller: product.seller && (product.seller.name || product.seller.nickName) ? (product.seller.name || product.seller.nickName) : '未知卖家', - status: product.status || 'published', - imageUrls: product.imageUrls || [], - createdAt: product.created_at || product.createTime || null, - reservedCount: finalReservationCount, - product_contact: product.product_contact || '', // 【新增】添加联系人字段 - contact_phone: product.contact_phone || '', // 【新增】添加联系人电话字段 - debugInfo: { - originalSelected: selectedValue, - originalReservedCount: reservedCountValue, - originalReservationCount: reservationCountValue - }, - isReserved: reservedGoodsIds.some(id => - String(id) === productIdStr || - String(id) === String(product.id) - ), - isFavorite: false, // 初始化收藏状态为false - currentImageIndex: 0 - }; + const newGoods = pagedProducts.map(product => { + // 处理grossWeight为null或无效的情况,返回空字符串以支持文字输入 + const grossWeightValue = product.grossWeight !== null && product.grossWeight !== undefined ? product.grossWeight : ''; + + // 确保商品ID的一致性 + const productIdStr = String(product.productId || product.id); + + // 增强的预约人数计算逻辑 + const selectedValue = product.selected; + const reservedCountValue = product.reservedCount; + const reservationCountValue = product.reservationCount; + + const finalReservationCount = selectedValue !== undefined && selectedValue !== null ? selectedValue : + (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, + name: product.productName, + price: product.price, + minOrder: product.quantity, + yolk: product.yolk, + spec: (product.spec && product.spec !== '无') ? product.spec : (product.specification && product.specification !== '无') ? product.specification : '', + specification: (product.spec && product.spec !== '无') ? product.spec : (product.specification && product.specification !== '无') ? product.specification : '', + region: product.region || '', // 【新增】添加地区字段 + grossWeight: grossWeightValue, + displayGrossWeight: formatGrossWeight(grossWeightValue, product.weight), + seller: product.seller && (product.seller.name || product.seller.nickName) ? (product.seller.name || product.seller.nickName) : '未知卖家', + status: product.status || 'published', + imageUrls: product.imageUrls || [], + createdAt: product.created_at || product.createTime || null, + reservedCount: finalReservationCount, + product_contact: product.product_contact || '', // 【新增】添加联系人字段 + contact_phone: product.contact_phone || '', // 【新增】添加联系人电话字段 + supplyStatus: supplyStatusValue, // 添加supplyStatus字段并进行转换 + sourceType: product.sourceType || '', // 新增sourceType字段 + debugInfo: { + originalSelected: selectedValue, + originalReservedCount: reservedCountValue, + originalReservationCount: reservationCountValue + }, + isReserved: reservedGoodsIds.some(id => + String(id) === productIdStr || + String(id) === String(product.id) + ), + isFavorite: false, // 初始化收藏状态为false + currentImageIndex: 0 + }; }); // 过滤掉hidden状态的商品 diff --git a/pages/buyer/index.wxml b/pages/buyer/index.wxml index 7ec3b49..8dfe355 100644 --- a/pages/buyer/index.wxml +++ b/pages/buyer/index.wxml @@ -55,9 +55,10 @@ - 金标蛋 - {{item.name}} - + {{item.supplyStatus || '暂无状态'}} + {{item.name}} + V + {{item.specification || '无'}} | {{item.yolk || '无'}} | {{item.minOrder || item.quantity || 1}}件 diff --git a/pages/favorites/index.js b/pages/favorites/index.js index 71c1e62..d80201c 100644 --- a/pages/favorites/index.js +++ b/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, diff --git a/pages/favorites/index.wxml b/pages/favorites/index.wxml index b3e1c7e..93a77a3 100644 --- a/pages/favorites/index.wxml +++ b/pages/favorites/index.wxml @@ -53,10 +53,11 @@ - - 金标蛋 - {{item.Product.productName || '未命名商品'}} - + + {{item.Product.supplyStatus || '暂无状态'}} + {{item.Product.productName || '未命名商品'}} + V + {{(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}}件 diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index e1fadf8..1db5793 100644 --- a/pages/goods-detail/goods-detail.js +++ b/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({ diff --git a/pages/goods-detail/goods-detail.wxml b/pages/goods-detail/goods-detail.wxml index 9c3aa63..ba5bf06 100644 --- a/pages/goods-detail/goods-detail.wxml +++ b/pages/goods-detail/goods-detail.wxml @@ -30,11 +30,18 @@ - - - {{goodsDetail.name}} + + + + {{goodsDetail.supplyStatus || '暂无状态'}} + {{goodsDetail.name}} + V + + + {{goodsDetail.sourceType || '暂无'}} + - + 价格: {{goodsDetail.price}} diff --git a/pages/goods-detail/goods-detail.wxss b/pages/goods-detail/goods-detail.wxss index cdf13cf..eee8ecc 100644 --- a/pages/goods-detail/goods-detail.wxss +++ b/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; 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 @@ 授权登录 - 请授权获取您的手机号用于登录 + 授权您的手机号后才能提交申请