|
|
@@ -1,12 +1,7 @@
|
|
|
<template>
|
|
|
<view class="recommendation-page" :style="{ '--font-scale': fontScale }">
|
|
|
|
|
|
- <scroll-view class="content" scroll-y :refresher-enabled="true" :refresher-triggered="refreshing" @refresherrefresh="onRefresh">
|
|
|
- <!-- ===== 推荐食材 ===== -->
|
|
|
- <view class="section-title-bar">
|
|
|
- <text class="section-title">推荐食材</text>
|
|
|
- <text class="section-subtitle">查看家庭成员适合与戒备的食材</text>
|
|
|
- </view>
|
|
|
+ <scroll-view class="content" scroll-y :refresher-enabled="true" :refresher-triggered="refreshing" @refresherrefresh="onRefresh" @scrolltolower="loadMore">
|
|
|
|
|
|
<view class="food-section">
|
|
|
<!-- 成员切换条(统一组件 MemberSelector:家庭总览 / 个人 / 各成员) -->
|
|
|
@@ -17,9 +12,29 @@
|
|
|
:selected-member-id="currentMemberId"
|
|
|
:show-overview="true"
|
|
|
:overview-active="currentView === 'family'"
|
|
|
+ self-label="我"
|
|
|
@overview="switchView('family')"
|
|
|
@select="switchMember" />
|
|
|
|
|
|
+ <!-- 4 Tab 切换行:今日食谱 | 适合 | 戒备 | 全部 -->
|
|
|
+ <view class="filter-bar">
|
|
|
+ <view class="filter-item" :class="{'filter-active': currentTab === 'recipe'}" @tap="switchTab('recipe')">
|
|
|
+ <text>🍽️ 今日食谱</text>
|
|
|
+ </view>
|
|
|
+ <view class="filter-item" :class="{'filter-active': currentTab === 'suitable'}" @tap="switchTab('suitable')">
|
|
|
+ <text>✅ 适合</text>
|
|
|
+ </view>
|
|
|
+ <view class="filter-item" :class="{'filter-active': currentTab === 'unsuitable'}" @tap="switchTab('unsuitable')">
|
|
|
+ <text>❌ 戒备</text>
|
|
|
+ </view>
|
|
|
+ <view class="filter-item" :class="{'filter-active': currentTab === 'all'}" @tap="switchTab('all')">
|
|
|
+ <text>📋 全部</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+
|
|
|
+ <!-- 食材区(适合 / 戒备 / 全部)-->
|
|
|
+ <view class="food-section" v-if="currentTab !== 'recipe'">
|
|
|
<!-- 模式切换(仅家庭模式展示) -->
|
|
|
<view class="mode-bar" v-if="familyMode">
|
|
|
<view class="mode-btn" :class="{'active': sortType === 'desc'}" @tap="setSort('desc')">
|
|
|
@@ -61,19 +76,6 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
- <!-- 筛选栏 -->
|
|
|
- <view class="filter-bar">
|
|
|
- <view class="filter-item" :class="{'filter-active': filterType === 'suitable'}" @tap="setFilter('suitable')">
|
|
|
- <text>✅ 适合</text>
|
|
|
- </view>
|
|
|
- <view class="filter-item" :class="{'filter-active': filterType === 'unsuitable'}" @tap="setFilter('unsuitable')">
|
|
|
- <text>❌ 戒备</text>
|
|
|
- </view>
|
|
|
- <view class="filter-item" :class="{'filter-active': filterType === 'all'}" @tap="setFilter('all')">
|
|
|
- <text>📋 全部</text>
|
|
|
- </view>
|
|
|
- </view>
|
|
|
-
|
|
|
<!-- 家庭总览(取家庭成员该项食材推荐指数的最小值) -->
|
|
|
<view class="family-overview" v-if="currentView === 'family' && familyOverview && familyOverview.length > 0">
|
|
|
<view class="overview-title">
|
|
|
@@ -101,7 +103,7 @@
|
|
|
|
|
|
<!-- 食材列表 -->
|
|
|
<view class="food-list" v-if="currentView === 'personal'">
|
|
|
- <view class="food-card" v-for="(item, idx) in filteredFoods" :key="getFoodKey(item, idx)">
|
|
|
+ <view class="food-card" v-for="(item, idx) in pagedFoods" :key="getFoodKey(item, idx)">
|
|
|
<view class="food-left">
|
|
|
<view class="ingredient-badge" :class="item.scoreClass">
|
|
|
<text class="ingredient-badge-text">{{ idx + 1 }}</text>
|
|
|
@@ -132,10 +134,8 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
- <!-- ===== 今日食谱 ===== -->
|
|
|
- <view class="section-title-bar">
|
|
|
- <text class="section-title">今日食谱</text>
|
|
|
- </view>
|
|
|
+ <!-- 今日食谱区(currentTab === 'recipe')-->
|
|
|
+ <view v-if="currentTab === 'recipe'">
|
|
|
|
|
|
<!-- 无推荐状态 -->
|
|
|
<view class="empty-state" v-if="!recommendation">
|
|
|
@@ -233,6 +233,7 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
+ </view>
|
|
|
</scroll-view>
|
|
|
</view>
|
|
|
</template>
|
|
|
@@ -260,6 +261,9 @@ export default {
|
|
|
filterType: 'suitable',
|
|
|
sortType: 'desc',
|
|
|
currentView: 'personal',
|
|
|
+ currentTab: 'recipe',
|
|
|
+ visibleCount: 20,
|
|
|
+ memberSelectLocked: false,
|
|
|
allFoods: [],
|
|
|
familyData: null,
|
|
|
familyMembers: [],
|
|
|
@@ -331,6 +335,9 @@ export default {
|
|
|
}
|
|
|
|
|
|
return result
|
|
|
+ },
|
|
|
+ pagedFoods: function() {
|
|
|
+ return this.filteredFoods.slice(0, this.visibleCount)
|
|
|
}
|
|
|
},
|
|
|
onLoad: function(options) {
|
|
|
@@ -407,11 +414,13 @@ export default {
|
|
|
generateRecipe: function() {
|
|
|
var self = this
|
|
|
self.loading = true
|
|
|
+ uni.showLoading({ title: '正在生成食谱...' })
|
|
|
generateDietRecommendation({
|
|
|
date: self.formatDate(new Date()),
|
|
|
meal_type: 'all'
|
|
|
}).then(function(res) {
|
|
|
self.loading = false
|
|
|
+ uni.hideLoading()
|
|
|
if (res && res.data && res.data.id) {
|
|
|
uni.showToast({ title: '食谱生成成功', icon: 'success' })
|
|
|
self.loadRecommendation()
|
|
|
@@ -420,6 +429,7 @@ export default {
|
|
|
}
|
|
|
}).catch(function() {
|
|
|
self.loading = false
|
|
|
+ uni.hideLoading()
|
|
|
uni.showToast({ title: '生成失败', icon: 'none' })
|
|
|
})
|
|
|
},
|
|
|
@@ -471,16 +481,19 @@ export default {
|
|
|
var self = this
|
|
|
var token = uni.getStorageSync('token')
|
|
|
if (!token) return
|
|
|
+ // config 经 stubImports 取 default import 可能为 undefined(测试契约桩),此处做防御性取址
|
|
|
+ var baseUrl = (config && config.API_BASE_URL) || ''
|
|
|
|
|
|
uni.request({
|
|
|
- url: config.API_BASE_URL + '/api/food/recommendation/members',
|
|
|
+ url: baseUrl + '/api/food/recommendation/members',
|
|
|
method: 'POST',
|
|
|
header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
|
|
|
success: function(res) {
|
|
|
if (res.data && res.data.code === 200 && res.data.data) {
|
|
|
self.memberList = res.data.data
|
|
|
// 默认选中「个人」= isSelf 行(统一身份键 familyMemberId,不再用 userId)
|
|
|
- if (!self.currentMemberId && self.memberList.length > 0) {
|
|
|
+ // 仅首次加载(未显式切到家庭总览)时默认选中;switchView('family') 后不得再默认
|
|
|
+ if (!self.memberSelectLocked && !self.currentMemberId && self.memberList.length > 0) {
|
|
|
var defaultMember = self.getSelfRow() || self.memberList[0]
|
|
|
self.currentMemberId = memberIdOf(defaultMember)
|
|
|
}
|
|
|
@@ -631,6 +644,7 @@ export default {
|
|
|
},
|
|
|
switchCategory: function(category) {
|
|
|
this.activeCategory = category
|
|
|
+ this.visibleCount = 20
|
|
|
},
|
|
|
getCategoryKeywords: function(category) {
|
|
|
var map = {
|
|
|
@@ -651,12 +665,30 @@ export default {
|
|
|
} else {
|
|
|
this.sortType = 'desc'
|
|
|
}
|
|
|
+ this.visibleCount = 20
|
|
|
},
|
|
|
setSort: function(type) {
|
|
|
this.sortType = type
|
|
|
},
|
|
|
+ switchTab: function(tab) {
|
|
|
+ this.currentTab = tab
|
|
|
+ this.visibleCount = 20
|
|
|
+ if (tab !== 'recipe') {
|
|
|
+ this.filterType = tab
|
|
|
+ this.sortType = tab === 'unsuitable' ? 'asc' : 'desc'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ loadMore: function() {
|
|
|
+ if (this.visibleCount < this.filteredFoods.length) {
|
|
|
+ this.visibleCount += 20
|
|
|
+ }
|
|
|
+ },
|
|
|
switchView: function(view) {
|
|
|
this.currentView = view
|
|
|
+ if (view === 'family') {
|
|
|
+ this.currentMemberId = null
|
|
|
+ this.memberSelectLocked = true
|
|
|
+ }
|
|
|
},
|
|
|
// 取「本人」行(isSelf):后端已按 user_id 折叠,此处仅取第一行 isSelf
|
|
|
getSelfRow: function() {
|
|
|
@@ -670,6 +702,7 @@ export default {
|
|
|
// 统一身份键:familyMemberId(= family_members.id);userId 仅用于折叠,不再作主键
|
|
|
this.currentMemberId = memberIdOf(member)
|
|
|
this.currentView = 'personal'
|
|
|
+ this.visibleCount = 20
|
|
|
this.loadFoods()
|
|
|
},
|
|
|
onRefresh: function() {
|