diff --git a/app.json b/app.json index 67d5e03..a966075 100644 --- a/app.json +++ b/app.json @@ -65,8 +65,8 @@ "text": "首页" }, { - "pagePath": "pages/buyer/index", - "text": "购物" + "pagePath": "pages/chat/index", + "text": "消息" }, { "pagePath": "pages/seller/index", diff --git a/custom-tab-bar/index.js b/custom-tab-bar/index.js index bd1cde4..f312d0b 100644 --- a/custom-tab-bar/index.js +++ b/custom-tab-bar/index.js @@ -15,8 +15,8 @@ Component({ // 记录tabBar数据,用于匹配 tabBarItems: [ { key: 'index', route: 'pages/index/index' }, - { key: 'buyer', route: 'pages/buyer/index', badgeKey: 'chat' }, // 聊天功能可能在buyer tab - { key: 'favorites', route: 'pages/favorites/index' }, + { key: 'chat', route: 'pages/chat/index', badgeKey: 'chat' }, // 消息中心 + { key: 'settlement', route: 'pages/settlement/index' }, { key: 'profile', route: 'pages/profile/index' } ] }, @@ -54,7 +54,7 @@ Component({ }) // 无论跳转到哪个页面,先确保用户身份被正确设置 - if (key === 'buyer' || key === 'seller') { + if (key === 'seller') { const userId = wx.getStorageSync('userId'); if (userId) { // 更新用户类型 @@ -90,13 +90,13 @@ Component({ // 跳转到tab页面的通用方法 navigateToTabPage(url) { // 定义tabBar页面列表 - const tabBarPages = [ - 'pages/index/index', - 'pages/buyer/index', - 'pages/seller/index', - 'pages/favorites/index', - 'pages/profile/index' - ]; + const tabBarPages = [ + 'pages/index/index', + 'pages/chat/index', + 'pages/seller/index', + 'pages/settlement/index', + 'pages/profile/index' + ]; // 检查是否为tabBar页面 if (tabBarPages.includes(url)) { diff --git a/custom-tab-bar/index.wxml b/custom-tab-bar/index.wxml index 63e8efe..1f1da78 100644 --- a/custom-tab-bar/index.wxml +++ b/custom-tab-bar/index.wxml @@ -11,14 +11,14 @@ 首页 - - {{badges['buyer']}} + {{badges['chat']}} - 商城 + 消息 @@ -32,14 +32,14 @@ - - {{badges['favorites']}} + {{badges['settlement']}} - 收藏 + 入驻 { + wx.navigateBack(); + }, 2000); return; } + console.log('最终使用的商品ID:', productId); + // 加载商品详情(即使已有goodsData,也调用API获取最新数据) this.loadGoodsDetail(productId, goodsData); @@ -146,6 +157,7 @@ Page({ console.log('使用预加载数据显示UI'); } + console.log('调用API获取商品详情,productId:', productId); API.getProductDetail({ productId: productId }) .then(res => { console.log('获取商品详情成功:', res); @@ -162,6 +174,9 @@ Page({ console.log(' - contactPhone:', product.contactPhone); console.log(' - phone:', product.phone); console.log(' - contact:', product.contact); + console.log(' - name:', product.name); + console.log(' - id:', product.id); + console.log(' - productId:', product.productId); // 检查完整的API响应字段,确保不错过任何重要信息 console.log('API响应完整字段列表:', Object.keys(product).sort()); @@ -199,27 +214,39 @@ Page({ supplyStatusValue = '预售'; } - // 关键修改:优先使用预加载数据中的联系人信息,如果有的话 + // 关键修改:优先使用预加载数据中的联系人信息,与buyer页面保持一致 let contactPhone = ''; let contactName = ''; let region = ''; - // 首先检查预加载数据 + // 首先检查预加载数据,与buyer页面保持一致 if (preloadedData) { + // 直接从预加载数据中获取联系人信息,与buyer页面保持一致 contactPhone = preloadedData.contact_phone || preloadedData.contactPhone || preloadedData.phone || ''; contactName = preloadedData.product_contact || preloadedData.contact || preloadedData.contactName || ''; region = preloadedData.region || ''; + console.log('从预加载数据获取联系人信息:', { contactName, contactPhone, region }); + console.log('preloadedData product_contact:', preloadedData.product_contact, 'contact_phone:', preloadedData.contact_phone); } // 如果预加载数据中没有,则使用API返回的数据 + if (!contactPhone && product) { + contactPhone = product.contact_phone || product.contactPhone || product.phone || ''; + } + if (!contactName && product) { + contactName = product.product_contact || product.contact || product.contactName || ''; + } + if (!region && product && product.region) { + region = product.region || ''; + } + + // 确保联系人信息不为空 if (!contactPhone) { - contactPhone = product.contact_phone !== null && product.contact_phone !== undefined ? product.contact_phone : - (product.contactPhone || product.phone || '暂无联系电话'); + contactPhone = product.contact_phone || product.contactPhone || product.phone || '暂无联系电话'; } if (!contactName) { - contactName = product.product_contact !== null && product.product_contact !== undefined ? product.product_contact : - (product.contact || product.contactName || '联系人信息暂不可用'); + contactName = product.product_contact || product.contact || product.contactName || '联系人信息暂不可用'; } if (!region && product.region) { region = extractProvince(product.region); @@ -242,9 +269,6 @@ Page({ yolk: product.yolk, spec: product.spec || product.specification || '暂无规格', region: region, - // 直接使用数据库字段名,确保与表结构完全一致 - product_contact: contactName, - contact_phone: contactPhone, // 保留原始字段引用,确保数据完整性 imageUrls: product.imageUrls || product.images || [], displayGrossWeight: formatGrossWeight(grossWeightValue, product.weight), @@ -257,8 +281,11 @@ Page({ sourceTypeColor: getSourceTypeColor(product.sourceType), // 复制原始产品对象中的所有字段,确保不丢失任何数据 ...product, - // 合并预加载数据中的字段,优先使用预加载数据中的联系人信息 + // 合并预加载数据中的字段 ...(preloadedData || {}), + // 直接使用数据库字段名,确保与表结构完全一致,放在后面覆盖前面的值 + product_contact: contactName, + contact_phone: contactPhone, // 确保reservedCount字段使用我们计算得到的值,放在最后以覆盖其他来源的值 reservedCount: finalReservationCount }; diff --git a/pages/index/index.js b/pages/index/index.js index 4f7f7e3..dd8c696 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -12,7 +12,34 @@ Page({ needPhoneAuth: false, // 测试模式开关,用于在未完成微信认证时进行测试 testMode: true, - partnerstatus: '' // 用户入驻状态,用于显示入驻/未入驻 + partnerstatus: '', // 用户入驻状态,用于显示入驻/未入驻 + + // 侧边栏相关 + showSidebar: false, + isDragging: false, + startY: 0, + currentY: 0, + sidebarBtnTop: 500, // 初始位置,单位rpx + + // 搜索相关 + searchKeyword: '', + selectedRegion: '全国', + showRegionPicker: false, + regions: ['全国', '北京', '上海', '广州', '深圳', '天津', '重庆', '河北', '山西', '辽宁', '吉林', '黑龙江', '江苏', '浙江', '安徽', '福建', '江西', '山东', '河南', '湖北', '湖南', '广东', '海南', '四川', '贵州', '云南', '陕西', '甘肃', '青海', '台湾', '内蒙古', '广西', '西藏', '宁夏', '新疆', '香港', '澳门'], + + // 商品相关 + goods: [], + filteredGoods: [], + selectedCategory: '全部', + loadingMore: false, + hasMoreData: true, + page: 1, + pageSize: 10, + + // 图片预览相关状态 + previewImageUrls: [], // 预览的图片URL列表 + previewImageIndex: 0, // 当前预览图片的索引 + showImagePreview: false, // 控制图片预览弹窗显示 }, // 跳转到聊天页面 @@ -67,11 +94,80 @@ Page({ } }); }, + + // 切换侧边栏显示 + toggleSidebar() { + if (this.data.isDragging) { + return; + } + this.setData({ + showSidebar: !this.data.showSidebar + }); + }, + + // 触摸开始事件 + handleTouchStart(e) { + this.setData({ + isDragging: false, + startY: e.touches[0].clientY + }); + }, + + // 触摸移动事件 + handleTouchMove(e) { + const moveY = e.touches[0].clientY; + const diffY = moveY - this.data.startY; + + // 如果移动距离超过20px,视为拖动 + if (Math.abs(diffY) > 20) { + this.setData({ + isDragging: true + }); + + // 更新按钮位置 + let newTop = this.data.sidebarBtnTop + diffY * 2; // 转换为rpx + + // 限制按钮在屏幕范围内 + const screenHeight = wx.getSystemInfoSync().screenHeight * 2; // 转换为rpx + const btnHeight = 80; // 按钮高度,单位rpx + + if (newTop < 100) { + newTop = 100; + } else if (newTop > screenHeight - btnHeight - 100) { + newTop = screenHeight - btnHeight - 100; + } + + this.setData({ + sidebarBtnTop: newTop, + startY: moveY + }); + } + }, + + // 触摸结束事件 + handleTouchEnd(e) { + // 如果拖动距离超过屏幕高度的1/3,隐藏按钮 + const moveY = e.changedTouches[0].clientY; + const diffY = moveY - this.data.startY; + const screenHeight = wx.getSystemInfoSync().screenHeight * 2; // 转换为rpx + + if (Math.abs(diffY) > screenHeight / 3) { + this.setData({ + sidebarBtnTop: -100 // 隐藏按钮 + }); + } + + this.setData({ + isDragging: false + }); + }, onLoad() { console.log('首页初始化') // 检查本地缓存并恢复登录状态 this.checkAndRestoreLoginStatus() + // 初始化加载商品数据 + this.loadGoods() }, onShow: function () { @@ -86,13 +182,442 @@ Page({ const app = getApp(); app.updateCurrentTab('index'); + // 重新显示tabBar + app.globalData.showTabBar = true; + // 检查并恢复登录状态 this.checkAndRestoreLoginStatus() + + // 刷新商品数据 + this.refreshGoodsList() }, - // 跳转到估价页面 - - + // 格式化毛重显示的辅助函数 + formatGrossWeight: function(grossWeight, weight) { + if (grossWeight !== null && grossWeight !== undefined && grossWeight !== '') { + return grossWeight; + } + if (weight !== null && weight !== undefined && weight !== '') { + return weight; + } + return ""; + }, + + // 提取地区中的省份信息 + extractProvince: function(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) { + return region.substring(0, municipalityEndIndex + 1); + } + + return region; + }, + + // 加载商品数据 + loadGoods: function(isLoadMore = false) { + if (isLoadMore && !this.data.hasMoreData) { + return + } + + const currentPage = isLoadMore ? this.data.page : 1 + const currentPageSize = this.data.pageSize + + this.setData({ + loadingMore: true + }) + + // 添加时间戳参数防止请求缓存 + const timestamp = new Date().getTime(); + + API.getProductList('published', { + timestamp: timestamp, + viewMode: 'shopping', + page: currentPage, + pageSize: currentPageSize, + // 增加搜索关键词和分类参数,与buyer页面保持一致 + keyword: this.data.searchKeyword, + category: this.data.selectedCategory === '全部' ? '' : this.data.selectedCategory + }) + .then(res => { + wx.hideLoading(); + + if (res.success && res.products) { + let newGoods = res.products.map(product => { + // 处理grossWeight为null或无效的情况 + const grossWeightValue = product.grossWeight !== null && product.grossWeight !== undefined ? product.grossWeight : ''; + + // 计算预约人数,增强逻辑确保能正确处理各种情况 + 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 = '预售'; + } + + // 处理图片URL,确保imageUrls字段存在且为数组 + const imageUrls = product.imageUrls || product.images || []; + // 确保imageUrls是数组 + const formattedImageUrls = Array.isArray(imageUrls) ? imageUrls : [imageUrls]; + + return { + ...product, + fullRegion: product.region || '', // 保存完整地区数据 + region: product.region ? this.extractProvince(product.region) : '', // 只显示省份 + grossWeight: grossWeightValue, + displayGrossWeight: this.formatGrossWeight(grossWeightValue, product.weight), + status: product.status || 'published', + createdAt: product.created_at || product.createTime || null, + reservedCount: finalReservationCount, + product_contact: product.product_contact || '', + contact_phone: product.contact_phone || '', + supplyStatus: supplyStatusValue, + sourceType: product.sourceType || '', + isReserved: false, + isFavorite: false, + currentImageIndex: 0, + // 确保imageUrls字段存在且为数组 + imageUrls: formattedImageUrls + } + }) + + // 过滤掉hidden状态的商品 + newGoods = newGoods.filter(item => { + const itemStatus = (item.status || '').toLowerCase() + return itemStatus !== 'hidden' + }) + + let updatedGoods = [] + if (isLoadMore) { + // 加载更多:合并数据,但要去重 + const existingIds = new Set(this.data.goods.map(item => item.id)); + const uniqueNewGoods = newGoods.filter(item => !existingIds.has(item.id)); + updatedGoods = [...this.data.goods, ...uniqueNewGoods]; + } else { + updatedGoods = newGoods + } + + // 应用筛选条件 + const filteredGoods = this.applyFilters(updatedGoods) + + // 计算是否还有更多数据 + const totalGoods = res.total || 0; + const totalPages = res.totalPages || Math.ceil(totalGoods / currentPageSize); + const hasMoreData = currentPage < totalPages && newGoods.length > 0; + + this.setData({ + goods: updatedGoods, + filteredGoods: filteredGoods, + loadingMore: false, + page: currentPage + 1, + hasMoreData: hasMoreData, + totalGoods: totalGoods, + totalPages: totalPages + }) + } else { + this.setData({ + loadingMore: false + }) + } + }) + .catch(err => { + console.error('加载商品数据失败:', err) + this.setData({ + loadingMore: false + }) + }) + }, + + // 刷新商品列表 + refreshGoodsList: function() { + this.setData({ + page: 1, + hasMoreData: true, + goods: [], + filteredGoods: [], + loadingMore: false + }, () => { + this.loadGoods() + }) + }, + + // 应用筛选条件 + applyFilters: function(goods) { + let filtered = [...goods] + + // 按品种筛选 + if (this.data.selectedCategory !== '全部') { + const category = this.data.selectedCategory + let keyword = category + + // 根据品种确定对应的关键字 + if (category === '粉壳') { + keyword = '粉' + } else if (category === '绿壳') { + keyword = '绿' + } else if (category === '红壳') { + keyword = '红' + } else if (category === '白壳') { + keyword = '白' + } + + filtered = filtered.filter(item => { + const name = item.name || '' + return name.includes(keyword) + }) + } + + // 按搜索关键词筛选(商品名称和地区都要匹配) + if (this.data.searchKeyword) { + const keyword = this.data.searchKeyword.toLowerCase() + filtered = filtered.filter(item => { + const name = item.name || '' + const region = item.region || '' + return name.toLowerCase().includes(keyword) || region.toLowerCase().includes(keyword) + }) + } + + // 按地区筛选 + if (this.data.selectedRegion !== '全国') { + filtered = filtered.filter(item => { + return item.region === this.data.selectedRegion + }) + } + + // 优先排序:按收藏人数、价格、创建时间排序 + filtered.sort((a, b) => { + // 首先按收藏人数降序排序 + const reservedCountA = a.reservedCount || 0 + const reservedCountB = b.reservedCount || 0 + if (reservedCountB !== reservedCountA) { + return reservedCountB - reservedCountA + } + + // 然后按价格升序排序 + const priceA = parseFloat(a.price || 0) + const priceB = parseFloat(b.price || 0) + if (!isNaN(priceB) && !isNaN(priceA) && priceA !== priceB) { + return priceA - priceB + } + + // 最后按创建时间降序排序 + const createdAtA = new Date(a.createdAt || 0).getTime() + const createdAtB = new Date(b.createdAt || 0).getTime() + return createdAtB - createdAtA + }) + + return filtered + }, + + // 搜索输入 + onSearchInput: function(e) { + this.setData({ + searchKeyword: e.detail.value + }) + }, + + // 搜索商品 + searchGoods: function() { + // 重新显示tabBar + const app = getApp(); + if (app && app.globalData) { + app.globalData.showTabBar = true; + } + + const filteredGoods = this.applyFilters(this.data.goods) + this.setData({ + filteredGoods: filteredGoods + }) + }, + + // 切换地区选择器 + toggleRegionPicker: function() { + this.setData({ + showRegionPicker: !this.data.showRegionPicker + }) + }, + + // 选择地区 + selectRegion: function(e) { + const region = e.currentTarget.dataset.region + this.setData({ + selectedRegion: region + }) + }, + + // 确认地区选择 + confirmRegion: function() { + // 重新显示tabBar + const app = getApp(); + if (app && app.globalData) { + app.globalData.showTabBar = true; + } + + const filteredGoods = this.applyFilters(this.data.goods) + this.setData({ + filteredGoods: filteredGoods, + showRegionPicker: false + }) + }, + + // 阻止事件冒泡 + stopPropagation: function() { + // 空函数,用于阻止事件冒泡 + }, + + // 选择品种 + selectCategory: function(e) { + // 重新显示tabBar + const app = getApp(); + if (app && app.globalData) { + app.globalData.showTabBar = true; + } + + const category = e.currentTarget.dataset.category + this.setData({ + selectedCategory: category + }) + + const filteredGoods = this.applyFilters(this.data.goods) + this.setData({ + filteredGoods: filteredGoods + }) + }, + + // 查看商品详情 + viewGoodsDetail: function(e) { + const item = e.currentTarget.dataset.item + // 确保productId存在,优先使用id,其次使用productId + const productId = String(item.id || item.productId || '') + + if (!productId) { + console.error('商品ID不存在,无法查看详情'); + wx.showToast({ + title: '商品信息有误', + icon: 'none', + duration: 2000 + }) + return; + } + + // 将完整的商品数据传递给详情页,包含联系人信息,与buyer页面保持一致 + wx.navigateTo({ + url: `/pages/goods-detail/goods-detail?goodsData=${encodeURIComponent(JSON.stringify(item))}&productId=${productId}` + }) + }, + + // 跳转到入驻页面 + navigateToSettlement: function() { + wx.navigateTo({ + url: '/pages/settlement/index' + }) + }, + + // 预览图片 + previewImage: function(e) { + // 阻止事件冒泡,避免触发商品点击事件 + e.stopPropagation(); + + // 获取图片信息 + const item = e.currentTarget.dataset.item; + const index = e.currentTarget.dataset.index; + + if (!item) { + return; + } + + // 确保图片URL存在且为数组 + let imageUrls = item.imageUrls || item.images || []; + if (!Array.isArray(imageUrls)) { + imageUrls = [imageUrls]; + } + + // 过滤掉无效的图片URL + const validImageUrls = imageUrls.filter(url => url && typeof url === 'string' && url.trim() !== ''); + + if (validImageUrls.length === 0) { + return; + } + + // 显示图片预览弹窗 + this.setData({ + previewImageUrls: validImageUrls, + previewImageIndex: parseInt(index || 0), + showImagePreview: true + }); + }, + + // 关闭图片预览 + closeImagePreview: function() { + this.setData({ + showImagePreview: false + }); + }, + + // 预览图片切换事件 + onPreviewImageChange: function(e) { + this.setData({ + previewImageIndex: e.detail.current + }); + }, + + // 滚动事件处理 + onScroll: function(e) { + // 获取滚动信息 + const { scrollTop, scrollHeight, clientHeight } = e.detail; + const distanceToBottom = scrollHeight - scrollTop - clientHeight; + + // 获取全局状态 + const app = getApp(); + if (!app || !app.globalData) { + return; + } + + // 当滚动到底部且没有更多数据时,隐藏tabBar + if (distanceToBottom < 100 && !this.data.hasMoreData) { + app.globalData.showTabBar = false; + } + // 当往上滚动不在底部时,立即重新显示tabBar + else { + app.globalData.showTabBar = true; + } + }, + + // 上拉加载更多 + onReachBottom: function() { + if (this.data.hasMoreData && !this.data.loadingMore) { + this.loadGoods(true) + } else if (!this.data.hasMoreData) { + // 没有更多数据时,隐藏tabBar + const app = getApp(); + if (app && app.globalData) { + app.globalData.showTabBar = false; + } + } + }, + // 显示一键登录弹窗 showOneKeyLogin() { this.setData({ diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 3e489dd..344cb08 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -1,41 +1,181 @@ - - - - - - - - - - - - - - + + 专业的鸡蛋现货交易平台 + + + + + + + + {{selectedRegion || '全国'}} + + + + 🔍 + + + + - - 专业的鸡蛋现货交易平台 - - - - - + + + + + 选择地区 + + + {{item}} + + + - - - - + + + + + + + 全部 + + + 粉壳 + + + 红壳 + + + 绿壳 + + + 白壳 + - - + + + + + 招商入驻 - + + + + 招商合作 + + + 🏠 + 立即入驻 + + + 🤝 + 成为供应商 + + + 📢 + 招商合作 + + + 📞 + 联系我们 + + + + + + + 精选货源 + + + + + + + {{item.supplyStatus || '现货'}} + + + + {{item.name}} + {{item.specification || '无'}} | {{item.yolk || '无'}} + ¥{{item.price}} + + {{item.region}} + 已有{{item.reservedCount || 0}}人收藏 + + + + + + + 暂无商品数据 + + + + + + + 加载中... + + @@ -95,5 +235,33 @@ - + + + + + + + + + + + + + + + diff --git a/pages/index/index.wxss b/pages/index/index.wxss index b1cb595..f29dfc2 100644 --- a/pages/index/index.wxss +++ b/pages/index/index.wxss @@ -9,154 +9,509 @@ page { } .container { - padding: 40rpx 0; + padding: 0; margin: 0; width: 100%; - display: flex; + height: 100vh; + display: flex;z flex-direction: column; - justify-content: space-around; - min-height: calc(100vh - 100rpx); + box-sizing: border-box; + background-color: #f5f7fa; +} + +/* 标题样式 */ +.title { + font-size: 36rpx; + font-weight: bold; + margin: 20rpx; + color: #333; + text-align: center; + flex: 0 1 auto; +} + +/* 搜索区域样式 */ +.search-section { + width: 100%; + margin: 0 20rpx 20rpx 20rpx; + flex: 0 1 auto; + box-sizing: border-box; } -.scrollarea { + +.search-bar { + display: flex; + align-items: center; + gap: 10rpx; + width: 100%; + background: linear-gradient(135deg, #ffffff 0%, #f5f7fa 100%); + padding: 6rpx; + border-radius: 50rpx; + box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.12); + box-sizing: border-box; + border: 1rpx solid rgba(22, 119, 255, 0.2); +} + +.search-input-wrapper { flex: 1; - overflow-y: hidden; + display: flex; + align-items: center; + position: relative; + background-color: white; + border-radius: 40rpx; + padding: 0 10rpx; } -/* 玻璃质感按钮样式 */ -.btn { - /* 基础样式重置 */ +.search-icon { + margin: 0 10rpx; + font-size: 28rpx; + color: #999; + transition: all 0.3s ease; +} + +.search-input { + flex: 1; + height: 70rpx; + font-size: 28rpx; + color: #333; border: none; - border-radius: 24rpx; + outline: none; + background: transparent; +} + +.search-placeholder { + color: #999; +} + +.region-selector { + display: flex; + align-items: center; + gap: 5rpx; + font-size: 26rpx; + font-weight: 500; + color: #333; + padding: 15rpx 20rpx; + background: linear-gradient(135deg, #1677ff 0%, #4096ff 100%); + color: white; + border-radius: 40rpx; + box-shadow: 0 2rpx 8rpx rgba(22, 119, 255, 0.3); + transition: all 0.3s ease; + margin-right: 10rpx; +} + +.region-selector:hover { + transform: translateY(-2rpx); + box-shadow: 0 4rpx 12rpx rgba(22, 119, 255, 0.4); +} + +.region-arrow { + font-size: 22rpx; + font-weight: bold; + color: white; +} + +.search-button { + background-color: #1677ff; + color: white; + border: none; + border-radius: 40rpx; + padding: 15rpx 30rpx; + font-size: 24rpx; + font-weight: bold; + white-space: nowrap; + box-shadow: 0 2rpx 8rpx rgba(22, 119, 255, 0.3); +} + +/* 地区选择器弹窗样式 */ +.region-picker-overlay { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: rgba(0, 0, 0, 0.5); + display: flex; + justify-content: center; + align-items: flex-end; + z-index: 9999; +} + +.region-picker-container { + background-color: white; + width: 100%; + border-radius: 20rpx 20rpx 0 0; + padding: 20rpx; + box-sizing: border-box; +} + +.region-picker-title { font-size: 32rpx; - font-weight: 600; - padding: 28rpx 0; - margin: 0 auto 24rpx; - width: 80%; - display: block; + font-weight: bold; text-align: center; + margin-bottom: 20rpx; + color: #333; +} + +.region-list { + max-height: 500rpx; + overflow-y: auto; + margin-bottom: 20rpx; +} + +.region-item { + padding: 20rpx; + font-size: 28rpx; + color: #333; + border-bottom: 1rpx solid #eee; +} + +.region-item.active { + color: #1677ff; + font-weight: bold; + background-color: #f0f7ff; +} + +.confirm-region-btn { + background-color: #1677ff; + color: white; + border: none; + border-radius: 40rpx; + padding: 20rpx; + font-size: 28rpx; + font-weight: bold; + width: 100%; + margin-top: 10rpx; + box-shadow: 0 2rpx 8rpx rgba(22, 119, 255, 0.3); +} + +/* 品种筛选区域样式 */ +.category-section { + width: 100%; + margin: 0 20rpx 20rpx 20rpx; + flex: 0 1 auto; + box-sizing: border-box; +} + +.category-scroll { + display: flex; + gap: 15rpx; + padding: 8rpx 15rpx; white-space: nowrap; - line-height: 1.5; - - /* 玻璃质感效果 */ - background: rgba(255, 255, 255, 0.15); - backdrop-filter: blur(12rpx); - -webkit-backdrop-filter: blur(12rpx); - border: 1rpx solid rgba(255, 255, 255, 0.3); - box-shadow: - 0 8rpx 32rpx rgba(31, 38, 135, 0.2), - 0 4rpx 16rpx rgba(0, 0, 0, 0.1), - inset 0 2rpx 4rpx rgba(255, 255, 255, 0.7), - inset 0 -2rpx 4rpx rgba(0, 0, 0, 0.1); - - /* 过渡效果 */ - transition: all 0.3s ease; + overflow-x: auto; + background-color: transparent; + border-radius: 10rpx; + box-shadow: none; +} + +/* 蛋形样式 - 玻璃质感 */ +.egg-item { position: relative; - overflow: hidden; + width: 80rpx; + height: 100rpx; + background-color: rgba(255, 255, 255, 0.3); + backdrop-filter: blur(10rpx); + border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; + display: flex; + justify-content: center; + align-items: center; + transition: all 0.3s ease; + box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1); + border: 1rpx solid rgba(255, 255, 255, 0.5); + flex-shrink: 0; +} + +/* 不同品种的颜色 */ +.egg-item:nth-child(2) { /* 粉壳 */ + background-color: rgba(255, 182, 193, 0.3); + border-color: rgba(255, 182, 193, 0.7); +} + +.egg-item:nth-child(3) { /* 红壳 */ + background-color: rgba(255, 105, 180, 0.3); + border-color: rgba(255, 105, 180, 0.7); +} + +.egg-item:nth-child(4) { /* 绿壳 */ + background-color: rgba(144, 238, 144, 0.3); + border-color: rgba(144, 238, 144, 0.7); } -/* 买家按钮样式 */ -.buyer-btn { - color: #07c160; - background: rgba(7, 193, 96, 0.15); +.egg-item:nth-child(5) { /* 白壳 */ + background-color: rgba(245, 245, 245, 0.5); + border-color: rgba(245, 245, 245, 0.8); } -/* 卖家按钮样式 */ -.seller-btn { +.egg-item.active { + background-color: rgba(22, 119, 255, 0.4); + border-color: rgba(22, 119, 255, 0.8); + box-shadow: 0 4rpx 16rpx rgba(22, 119, 255, 0.3); + transform: scale(1.05); +} + +.egg-inner { + font-size: 22rpx; + color: #333; + font-weight: bold; + text-align: center; +} + +.egg-item.active .egg-inner { color: #1677ff; - background: rgba(22, 119, 255, 0.15); + font-size: 24rpx; } -/* 估价按钮样式 */ -.evaluate-btn { - color: #4CAF50; - background: rgba(76, 175, 80, 0.15); +/* 侧边栏按钮样式 */ +.sidebar-btn { + position: fixed; + left: 20rpx; + z-index: 999; + width: 80rpx; + height: 80rpx; + background-color: #1677ff; + border-radius: 40rpx; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + box-shadow: 0 4rpx 16rpx rgba(22, 119, 255, 0.3); + transition: all 0.3s ease; + border: 2rpx solid #fff; + touch-action: none; /* 禁用浏览器默认的触摸行为 */ } -/* 按钮区域样式 */ -.buttons-section { - width: 80%; - margin: 20rpx auto; +.sidebar-btn:hover { + transform: scale(1.1); + box-shadow: 0 6rpx 20rpx rgba(22, 119, 255, 0.4); +} + +.sidebar-icon { + font-size: 32rpx; + color: white; + font-weight: bold; +} + +.sidebar-text { + font-size: 16rpx; + color: white; + font-weight: bold; +} + +/* 侧边栏样式 */ +.sidebar-overlay { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: rgba(0, 0, 0, 0.5); + z-index: 9998; + animation: fadeIn 0.3s ease; +} + +.sidebar { + position: fixed; + top: 0; + left: 0; + width: 60%; + height: 100%; + background-color: white; + z-index: 9999; + box-shadow: 4rpx 0 20rpx rgba(0, 0, 0, 0.2); + animation: slideIn 0.3s ease; display: flex; flex-direction: column; - gap: 20rpx; - flex: 0 1 auto; } -/* 按钮行样式 */ -.btn-row { +/* 动画效果 */ +@keyframes fadeIn { + from { opacity: 0; } + to { opacity: 1; } +} + +@keyframes slideIn { + from { transform: translateX(-100%); } + to { transform: translateX(0); } +} + +.sidebar-title { + font-size: 36rpx; + font-weight: bold; + color: #333; + padding: 40rpx 20rpx; + border-bottom: 2rpx solid #eee; + text-align: center; +} + +.sidebar-menu { + flex: 1; + padding: 20rpx 0; +} + +.sidebar-item { display: flex; - flex-direction: row; - justify-content: space-between; + align-items: center; + padding: 30rpx 40rpx; + transition: all 0.3s ease; + border-bottom: 1rpx solid #f0f0f0; +} + +.sidebar-item:hover { + background-color: #f5f5f5; + padding-left: 50rpx; +} + +.sidebar-item-icon { + font-size: 36rpx; + margin-right: 20rpx; +} + +.sidebar-item-text { + font-size: 28rpx; + color: #333; + font-weight: bold; +} + +/* 商品区域样式 - 调整为占据70%空间 */ +.goods-section { + background-color: white; + padding: 20rpx; + border-radius: 10rpx; + margin: 0 20rpx 20rpx 20rpx; + box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05); + flex: 7; + overflow-y: auto; + width: calc(100% - 40rpx); + box-sizing: border-box; +} + +.goods-title { + font-size: 28rpx; + font-weight: bold; + color: #333; + margin-bottom: 20rpx; +} + +.goods-list { + overflow-y: auto; + -webkit-overflow-scrolling: touch; +} + +.goods-list-container { + display: flex; + flex-wrap: wrap; gap: 20rpx; + justify-content: flex-start; + padding-bottom: 20rpx; } -/* 全宽按钮行样式 */ -.btn-row.full-width { - justify-content: center; +.goods-item { + width: calc((100% - 20rpx) / 2); + background-color: #f9f9f9; + border-radius: 10rpx; + overflow: hidden; + box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05); + transition: all 0.3s ease; } -/* 消息按钮样式 */ -.message-btn { - color: #FF6B6B; - background: rgba(255, 107, 107, 0.15); - margin: 0; - width: 48%; +.goods-item:hover { + box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1); + transform: translateY(-2rpx); } -/* 联系客服按钮样式 */ -.service-btn { - color: #1677ff; - background: rgba(22, 119, 255, 0.15); - margin: 0; - width: 48%; +.goods-image-container { + position: relative; + width: 100%; + padding-bottom: 100%; + overflow: hidden; } -/* 立即入驻按钮样式 */ -.settlement-btn { - color: #2196F3; - background: rgba(33, 150, 243, 0.15); - margin: 0; +.goods-image { + position: absolute; + top: 0; + left: 0; width: 100%; + height: 100%; + background-color: #eee; +} + +.goods-tag { + position: absolute; + top: 10rpx; + left: 10rpx; + background-color: rgba(255, 90, 90, 0.8); + color: white; + font-size: 20rpx; + padding: 5rpx 10rpx; + border-radius: 15rpx; + font-weight: bold; } -/* 未入驻按钮样式 */ -.settlement-btn.not-approved { - background: rgba(255, 77, 79, 0.15); +.goods-info { + padding: 15rpx; +} + +.goods-name { + font-size: 26rpx; + font-weight: bold; + color: #333; + margin-bottom: 10rpx; + overflow: hidden; + text-overflow: ellipsis; + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + min-height: 60rpx; +} + +.goods-spec { + font-size: 22rpx; + color: #999; + margin-bottom: 10rpx; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.goods-price { + font-size: 32rpx; + font-weight: bold; color: #ff4d4f; + margin-bottom: 10rpx; } -/* 按钮点击效果 */ -.btn:active { - transform: scale(0.98); - box-shadow: - 0 4rpx 16rpx rgba(31, 38, 135, 0.1), - 0 2rpx 8rpx rgba(0, 0, 0, 0.05), - inset 0 1rpx 2rpx rgba(255, 255, 255, 0.5), - inset 0 -1rpx 2rpx rgba(0, 0, 0, 0.05); +.goods-footer { + display: flex; + justify-content: space-between; + font-size: 20rpx; + color: #999; } -/* 按钮悬浮光晕效果 */ -.btn::after { - content: ''; - position: absolute; - top: -50%; - left: -50%; - width: 200%; - height: 200%; - background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.3), transparent); - transform: rotate(45deg); - animation: shine 3s infinite; - opacity: 0; +.goods-region { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; } -@keyframes shine { - 0% { transform: translateX(-100%) rotate(45deg); opacity: 0; } - 50% { opacity: 0.2; } - 100% { transform: translateX(100%) rotate(45deg); opacity: 0; } +.goods-reserved { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; } -.btn:active::after { - animation: none; +/* 空商品样式 */ +.empty-goods { + width: 100%; + text-align: center; + padding: 60rpx 0; + color: #999; + font-size: 28rpx; +} + +/* 加载更多样式 */ +.loading-more { + width: 100%; + text-align: center; + padding: 20rpx 0; + color: #999; + font-size: 24rpx; } /* 弹窗样式 */ @@ -226,21 +581,6 @@ page { border: 2rpx solid #e5e5e5; } -.primary-button { - background-color: #1677ff; - color: white; - width: 100%; - border-radius: 8rpx; - margin-bottom: 20rpx; - border: none; -} - -.cancel-button { - background: none; - color: #666; - border: none; -} - /* 头像选择样式 */ .avatar-section { text-align: center; @@ -305,64 +645,47 @@ page { color: #1677ff; } -/* 滚动图片区域样式 */ -.swiper-container { - width: 80%; - margin: 20rpx auto; - border-radius: 20rpx; - overflow: hidden; - box-shadow: 0 8rpx 32rpx rgba(31, 38, 135, 0.1); - position: relative; - flex: 0 1 auto; -} - -/* 轮播图指示器样式 */ -.swiper-container .wx-swiper-dots { - bottom: 15rpx; -} - -.swiper-container .wx-swiper-dot { - width: 12rpx; - height: 12rpx; - background: rgba(255, 255, 255, 0.6); -} - -.swiper-container .wx-swiper-dot-active { - width: 36rpx; - background: #fff; +/* 图片预览样式 */ +.image-preview-mask { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: rgba(0, 0, 0, 0.9); + display: flex; + justify-content: center; + align-items: center; + z-index: 9999; } -/* 图片提示框样式 */ -.swiper-hint { - background: rgba(0, 0, 0, 0.7); - color: #fff; - padding: 15rpx; - border-radius: 0 0 20rpx 20rpx; - font-size: 24rpx; - text-align: center; - margin-top: -10rpx; +.image-preview-swiper { + width: 100%; + height: 100%; } -.hint-text { +.preview-image { + width: 100%; + height: 100%; display: block; - line-height: 1.4; } -/* 顶部横幅图片样式 */ -.top-banner { - width: 100%; - height: 425rpx; - margin: -280rpx auto 10rpx; - display: block; +.image-preview-close { + position: absolute; + top: 40rpx; + right: 40rpx; + width: 60rpx; + height: 60rpx; + background-color: rgba(0, 0, 0, 0.5); + border-radius: 30rpx; + display: flex; + justify-content: center; + align-items: center; + z-index: 10000; } -/* 标题样式 */ -.title { - font-size: 40rpx; +.close-icon { + color: white; + font-size: 36rpx; font-weight: bold; - text-align: center; - color: #333; - margin: 20rpx auto; - padding: 0 20rpx; - flex: 0 1 auto; } diff --git a/pages/profile/index.js b/pages/profile/index.js index 9ca2fdb..dbd9d92 100644 --- a/pages/profile/index.js +++ b/pages/profile/index.js @@ -935,4 +935,11 @@ Page({ }); }, + // 跳转到收藏页面 + goToFavorites() { + wx.switchTab({ + url: '/pages/favorites/index' + }); + }, + }) diff --git a/pages/profile/index.wxml b/pages/profile/index.wxml index 7d4c67e..b801c76 100644 --- a/pages/profile/index.wxml +++ b/pages/profile/index.wxml @@ -34,6 +34,11 @@ {{item}} + + + + 收藏 + diff --git a/pages/settlement/index.js b/pages/settlement/index.js index 8e5c083..da9a455 100644 --- a/pages/settlement/index.js +++ b/pages/settlement/index.js @@ -196,6 +196,23 @@ Page({ wx.setStorageSync('settlement_status', status); }, + // 返回上一页 + goBack: function() { + wx.navigateBack({ + delta: 1, + success: function() { + console.log('成功返回上一页'); + }, + fail: function() { + console.error('返回上一页失败'); + // 如果返回失败,跳转到首页 + wx.reLaunch({ + url: '/pages/index/index' + }); + } + }); + }, + // 开始入驻流程 startSettlement: async function() { console.log('开始入驻流程'); @@ -811,21 +828,8 @@ Page({ const allRequiredFieldsExist = Object.values(requiredFieldsCheck).every(field => field.exists); console.log('是否所有后端必需字段都已填写:', allRequiredFieldsExist); - const result = await new Promise((resolve, reject) => { - wx.request({ - url: API.BASE_URL + '/api/settlement/submit', - method: 'POST', - data: submitData, - success: (res) => { - console.log('API请求成功,原始响应:', res); - resolve(res.data); - }, - fail: (err) => { - console.error('API请求失败:', err); - reject(err); - } - }); - }); + // 使用封装好的API.request函数发送请求,确保BASE_URL正确 + const result = await API.request('/api/settlement/submit', 'POST', submitData); console.log('入驻申请提交结果:', result); console.log('请求状态码:', result.code); console.log('请求消息:', result.message); diff --git a/pages/settlement/index.json b/pages/settlement/index.json index 19146bf..043cc34 100644 --- a/pages/settlement/index.json +++ b/pages/settlement/index.json @@ -1,4 +1,5 @@ { "usingComponents": {}, - "navigationBarTitleText": "立即入驻" + "navigationBarTitleText": "立即入驻", + "navigationBarBackButtonText": "返回" } \ No newline at end of file diff --git a/pages/settlement/index.wxml b/pages/settlement/index.wxml index d1d367c..8f578e2 100644 --- a/pages/settlement/index.wxml +++ b/pages/settlement/index.wxml @@ -7,6 +7,7 @@ 成为供应商 完成入驻后即可发布货源,开展鸡蛋贸易 + diff --git a/server-example/server-mysql.js b/server-example/server-mysql.js index b1205eb..ac29c89 100644 --- a/server-example/server-mysql.js +++ b/server-example/server-mysql.js @@ -620,18 +620,18 @@ User.init({ spec: { type: DataTypes.TEXT // 规格 }, - // 入驻相关必填字段 + // 入驻相关字段 collaborationid: { type: DataTypes.TEXT, - allowNull: false // 合作商身份,必填 + allowNull: true // 合作商身份,可选 }, cooperation: { type: DataTypes.STRING(255), - allowNull: false // 合作模式,必填 + allowNull: true // 合作模式,可选 }, businesslicenseurl: { type: DataTypes.TEXT, - allowNull: false // 营业执照,必填 + allowNull: true // 营业执照,可选 }, proofurl: { type: DataTypes.TEXT, @@ -6033,6 +6033,7 @@ app.post('/api/settlement/submit', async (req, res) => { province, city, district, + detailedaddress, businesslicenseurl, proofurl, brandurl @@ -6114,18 +6115,30 @@ app.post('/api/settlement/submit', async (req, res) => { province: province, // 省份 city: city, // 城市 district: district, // 区县 - businesslicenseurl: businesslicenseurl || '', // 营业执照 - NOT NULL约束,使用空字符串 - proofurl: proofurl || '', // 证明材料 - NOT NULL约束,使用空字符串 + detailedaddress: detailedaddress || '',// 详细地址 + businesslicenseurl: businesslicenseurl || '', // 营业执照 - 使用空字符串作为默认值 + proofurl: proofurl || '', // 证明材料 - 使用空字符串作为默认值 brandurl: brandurl || '', // 品牌授权链文件 partnerstatus: 'underreview', // 合作商状态明确设置为审核中,覆盖数据库默认值 updated_at: getBeijingTime() }, { - where: { userId: user.userId } + where: { openid: openid } // 改为使用openid作为查询条件,确保能找到用户 }); + // 检查更新结果 + console.log('更新结果:', updateResult); + if (updateResult[0] === 0) { + console.error('更新失败,未找到匹配的用户记录或没有更新任何字段'); + return res.status(500).json({ + success: false, + code: 500, + message: '更新用户信息失败,未找到匹配的记录' + }); + } + // 验证更新是否成功 - const updatedUser = await User.findOne({ where: { userId: user.userId } }); - console.log('更新后的用户状态:', updatedUser.partnerstatus); + const updatedUser = await User.findOne({ where: { openid: openid } }); + console.log('更新后的用户状态:', updatedUser ? updatedUser.partnerstatus : '未找到用户'); // 双重确认:如果状态仍不是underreview,再次更新 if (updatedUser && updatedUser.partnerstatus !== 'underreview') { @@ -6133,7 +6146,7 @@ app.post('/api/settlement/submit', async (req, res) => { await User.update({ partnerstatus: 'underreview' }, { - where: { userId: user.userId } + where: { openid: openid } }); } diff --git a/utils/api.js b/utils/api.js index e109b9d..57d2254 100644 --- a/utils/api.js +++ b/utils/api.js @@ -3466,6 +3466,10 @@ module.exports = { console.log('- 是否包含supplyStatus:', 'supplyStatus' in data.data); console.log('- sourceType值:', data.data.sourceType); console.log('- supplyStatus值:', data.data.supplyStatus); + console.log('- 是否包含product_contact:', 'product_contact' in data.data); + console.log('- 是否包含contact_phone:', 'contact_phone' in data.data); + console.log('- product_contact值:', data.data.product_contact); + console.log('- contact_phone值:', data.data.contact_phone); console.log('- 完整字段:', Object.keys(data.data)); } return data;