暂无回收规则
' + } + this.showRulePopup = true + }) }, showMore() { uni.showToast({ @@ -426,7 +457,7 @@ export default { // 获取所有选中的衣物 const selectedItems = this.recycleList.filter(item => item.quantity > 0).map(item => ({ name: item.name, - icon: item.icon, + icon: item.image, quantity: item.quantity, unitPrice: item.price, desc: '允许脏破烂,160码以上' @@ -494,13 +525,60 @@ export default { closeRulePopup() { this.showRulePopup = false }, + loadMoreGoods() { + const categoryId = this.categories[this.currentCategory]?.id + const page = (this.allProductsPage[categoryId] || 1) + 1 + const total = this.allProductsTotal[categoryId] || 0 + const loaded = (this.allProducts[categoryId] || []).length + + if (this.loadingMore || this.finished) return + + if (loaded < total) { + this.loadingMore = true + this.fetchGoodsList(categoryId, page, () => { + this.loadingMore = false + // 判断是否加载完 + const newLoaded = (this.allProducts[categoryId] || []).length + this.finished = newLoaded >= (this.allProductsTotal[categoryId] || 0) + }) + } else { + this.finished = true + } + }, + openBrandConfirm(brand) { + this.brandConfirmInfo = { + logo: brand.logo, + name: brand.name + } + this.showBrandConfirm = true + }, + closeBrandConfirm() { + this.showBrandConfirm = false + }, + confirmBrand() { + this.showBrandConfirm = false + this.showBrandPopup = false + // 确认后将待加一的商品数量+1 + if (this.pendingBrandIndex !== null) { + const categoryId = this.categories[this.currentCategory]?.id + const item = this.allProducts[categoryId]?.[this.pendingBrandIndex] + if (item) { + this.$set(item, 'quantity', 1) + } + this.pendingBrandIndex = null + } + }, }, created() { - // 初始化用静态数据 - this.categories = this.staticCategories - this.allProducts = JSON.parse(JSON.stringify(this.staticAllProducts)) - this.currentCategory = this.categories[0].id - this.fetchClassGoodsList() + this.currentCategory = 0 + this.$nextTick(() => { + if (this.categories.length > 0) { + const firstCategoryId = this.categories[0]?.id + if (firstCategoryId) { + this.fetchGoodsList(firstCategoryId, 1) + } + } + }) }, mounted() { this.$nextTick(() => { @@ -515,12 +593,64 @@ export default { }).exec() }) }, - // 添加下拉刷新生命周期 - onPullDownRefresh() { - this.refreshData() + onLoad(options) { + if (options && options.categoryId) { + const idx = this.categories.findIndex(c => c.id == options.categoryId) + if (idx !== -1) this.currentCategory = idx + } + this.fetchGoodsList(this.categories[this.currentCategory].id, 1) + uni.$on('bannerListUpdated', () => { + this.$forceUpdate && this.$forceUpdate() + }) + if (getApp().globalData.bannerList && getApp().globalData.bannerList.length > 0) { + this.$forceUpdate && this.$forceUpdate() + } + }, + onUnload() { + uni.$off('bannerListUpdated') + }, + onShow() { + const id = getApp().globalData.targetRecycleCategoryId + if (id) { + const trySwitch = () => { + if (this.categories.length > 0) { + const idx = this.categories.findIndex(c => String(c.id) === String(id)) + if (idx !== -1) { + this.currentCategory = idx + const categoryId = this.categories[idx]?.id + if (categoryId && !this.allProducts[categoryId]) { + this.loadingMore = false + this.finished = false + this.fetchGoodsList(categoryId, 1) + } + } + getApp().globalData.targetRecycleCategoryId = null + } else { + setTimeout(trySwitch, 100) + } + } + trySwitch() + } }, - onLoad() { - this.fetchClassGoodsList() + watch: { + categories(newVal) { + const id = getApp().globalData.targetRecycleCategoryId + console.log('targetRecycleCategoryId', id) + console.log('categories:', newVal.map(c => c.id)) + const idx = newVal.findIndex(c => String(c.id) === String(id)) + console.log('findIndex result:', idx) + if (id && newVal.length > 0 && idx !== -1) { + this.currentCategory = idx + getApp().globalData.targetRecycleCategoryId = null + // 自动加载右侧商品 + const categoryId = newVal[idx]?.id + if (categoryId && !this.allProducts[categoryId]) { + this.loadingMore = false + this.finished = false + this.fetchGoodsList(categoryId, 1) + } + } + } }, } @@ -1451,4 +1581,99 @@ export default { .uv-tabbar { z-index: 1000; } +.loading-more { + text-align: center; + color: #999; + padding: 20rpx 0; + font-size: 26rpx; +} + +.brand-confirm-mask { + position: fixed; + left: 0; + right: 0; + top: 0; + bottom: 0; + background: rgba(0,0,0,0.25); + z-index: 5001; + display: flex; + align-items: center; + justify-content: center; +} +.brand-confirm-popup { + width: 70vw; + max-width: 270px; + background: #fff; + border-radius: 32rpx; + box-shadow: 0 8rpx 32rpx rgba(0,0,0,0.12); + display: flex; + flex-direction: column; + align-items: center; + padding: 48rpx 20rpx 36rpx 20rpx; + position: relative; +} +.brand-confirm-title { + font-size: 36rpx; + color: #222; + font-weight: bold; + text-align: center; + margin-bottom: 24rpx; +} +.brand-confirm-logo-wrap { + width: 120rpx; + height: 120rpx; + background: #f8f8f8; + border-radius: 50%; + display: flex; + align-items: center; + justify-content: center; + margin-bottom: 18rpx; +} +.brand-confirm-logo { + width: 80rpx; + height: 80rpx; + border-radius: 50%; +} +.brand-confirm-name { + font-size: 28rpx; + color: #222; + font-weight: bold; + text-align: center; + margin-bottom: 16rpx; +} +.brand-confirm-desc { + font-size: 24rpx; + color: #999; + text-align: center; + margin-bottom: 32rpx; + line-height: 1.6; +} +.brand-confirm-btn-row { + width: 100%; + display: flex; + justify-content: space-between; + gap: 24rpx; +} +.brand-confirm-btn { + flex: 1; + height: 72rpx; + border-radius: 36rpx; + font-size: 28rpx; + font-weight: bold; + display: flex; + align-items: center; + justify-content: center; + border: none; + margin: 0 0; +} +.brand-confirm-btn.retry { + background: #fff; + color: #ff9c00; + border: 2rpx solid #ff9c00; +} +.brand-confirm-btn.confirm { + background: linear-gradient(to right, #ffd01e, #ff8917); + color: #fff; + border: none; +} \ No newline at end of file diff --git a/pages/index/index.vue b/pages/index/index.vue index a409a8b..a0a5f90 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -2,8 +2,8 @@