| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773 |
- <template>
- <view class="recommendation-page" :style="{ '--font-scale': fontScale }">
- <scroll-view class="content" scroll-y :refresher-enabled="true" :refresher-triggered="refreshing" @refresherrefresh="onRefresh" @scrolltolower="loadMore">
- <view class="food-section">
- <!-- 成员切换条(统一组件 MemberSelector:家庭总览 / 个人 / 各成员) -->
- <MemberSelector
- variant="minimal"
- v-if="memberList.length > 1"
- :members="memberList"
- :selected-member-id="currentMemberId"
- :show-overview="true"
- :overview-active="currentView === 'family'"
- self-label="我"
- @overview="switchView('family')"
- @select="switchMember" />
- <!-- 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>
- <!-- 食材区(适合 / 戒备 / 全部 Tab 内容) -->
- <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')">
- <text>推荐值 ↓</text>
- </view>
- <view class="mode-btn" :class="{'active': sortType === 'asc'}" @tap="setSort('asc')">
- <text>推荐值 ↑</text>
- </view>
- </view>
- <!-- 搜索栏 -->
- <view class="search-bar">
- <input class="search-input" placeholder="搜索食材..." v-model="searchQuery" @confirm="searchFood" />
- <view class="search-btn" @tap="searchFood">搜索</view>
- </view>
- <!-- 分类标签 -->
- <view class="category-tabs">
- <view class="tab-item" :class="{'tab-active': activeCategory === 'all'}" @tap="switchCategory('all')">
- <text>全部</text>
- </view>
- <view class="tab-item" :class="{'tab-active': activeCategory === '蔬菜'}" @tap="switchCategory('蔬菜')">
- <text>蔬菜</text>
- </view>
- <view class="tab-item" :class="{'tab-active': activeCategory === '水果'}" @tap="switchCategory('水果')">
- <text>水果</text>
- </view>
- <view class="tab-item" :class="{'tab-active': activeCategory === '肉禽'}" @tap="switchCategory('肉禽')">
- <text>肉禽</text>
- </view>
- <view class="tab-item" :class="{'tab-active': activeCategory === '水产'}" @tap="switchCategory('水产')">
- <text>水产</text>
- </view>
- <view class="tab-item" :class="{'tab-active': activeCategory === '谷物'}" @tap="switchCategory('谷物')">
- <text>谷物</text>
- </view>
- <view class="tab-item" :class="{'tab-active': activeCategory === '蛋奶'}" @tap="switchCategory('蛋奶')">
- <text>蛋奶</text>
- </view>
- </view>
- <!-- 家庭总览(有一人戒备取全员最低值,全员适合取平均值) -->
- <view class="family-overview" v-if="currentView === 'family' && familyOverview && familyOverview.length > 0">
- <view class="overview-title">
- <text>🏠 家庭推荐概况(共 {{ familyMembers.length }} 人 · 一人戒备取最低,全员适合取平均)</text>
- </view>
- <view class="overview-item" v-for="(item, idx) in familyOverview" :key="idx">
- <view class="overview-header">
- <text class="food-name">{{ item.name }}</text>
- <view class="score-badge" :class="item.color">
- <text>{{ item.score }}</text>
- </view>
- </view>
- <view class="overview-detail">
- <text class="category-label">{{ item.category }}</text>
- <view class="member-scores">
- <text v-for="(s, mi) in item.memberScores" :key="mi"
- class="member-score"
- :class="s.score >= 0 ? 'score-green' : 'score-red'">
- {{ s.name }}:{{ s.score >= 0 ? '+' : '' }}{{ s.score }}
- </text>
- </view>
- </view>
- </view>
- </view>
- <!-- 食材列表 -->
- <view class="food-list" v-if="currentView === 'personal'">
- <view class="food-card" v-for="(item, idx) in pagedFoods" :key="getFoodKey(item, idx)">
- <!-- 健康问卷个性化调整提示条:blocked 红 / warning 黄 / boost 绿(normal/空不渲染) -->
- <view v-if="item.adjustment === 'blocked'" class="health-adjust-bar">
- <text class="health-adjust-text health-adjust-blocked">⚠ 健康问卷不建议:{{ item.adjustmentReason }}</text>
- </view>
- <view v-else-if="item.adjustment === 'warning'" class="health-adjust-bar">
- <text class="health-adjust-text health-adjust-warning">注意:{{ item.adjustmentReason }}</text>
- </view>
- <view v-else-if="item.adjustment === 'boost'" class="health-adjust-bar">
- <text class="health-adjust-text health-adjust-boost">✓ 符合饮食习惯偏好</text>
- </view>
- <view class="food-left">
- <view class="ingredient-badge" :class="item.scoreClass">
- <text class="ingredient-badge-text">{{ idx + 1 }}</text>
- </view>
- <view class="food-info">
- <text class="food-name">{{ item.name }}</text>
- <view class="food-meta" v-if="item.category">
- <text class="meta-item">{{ item.category }}</text>
- </view>
- </view>
- </view>
- <view class="food-right">
- <text class="score-value" :class="item.scoreClass">{{ item.score || '--' }}</text>
- <view class="food-status-badge" :class="'badge-' + item.status">
- <text>{{ item.statusText }}</text>
- </view>
- </view>
- <!-- 健康问卷个性化调整提示条(diet.food.healthAdjustUi · B2):blocked 红条 / warning 黄条 / boost 绿条,normal 或缺失不渲染 -->
- <view class="adjustment-tip" v-if="item.adjustment === 'blocked'">
- <text class="adjustment-tip-text adjustment-tip-blocked">⚠ 健康问卷不建议:{{ item.adjustmentReason }}</text>
- </view>
- <view class="adjustment-tip" v-if="item.adjustment === 'warning'">
- <text class="adjustment-tip-text adjustment-tip-warning">注意:{{ item.adjustmentReason }}</text>
- </view>
- <view class="adjustment-tip" v-if="item.adjustment === 'boost'">
- <text class="adjustment-tip-text adjustment-tip-boost">✓ 符合饮食习惯偏好</text>
- </view>
- </view>
- </view>
- <view class="food-empty-state" v-if="!foodLoading && filteredFoods.length === 0 && currentView === 'personal'">
- <text class="food-empty-icon">🥗</text>
- <text class="food-empty-text">暂无匹配食材</text>
- </view>
- <view class="loading-state" v-if="foodLoading">
- <text class="loading-text">加载中...</text>
- </view>
- </view>
- <!-- 今日食谱区(recipe Tab 内容) -->
- <view v-if="currentTab === 'recipe'">
- <!-- 局部加载态:切换视角 / 刷新期间先清空旧数据,不残留上一视角食谱(AC-36,不整页遮罩) -->
- <view class="recipe-loading" v-if="recipeLoading">
- <text class="recipe-loading-text">正在加载今日食谱...</text>
- </view>
- <!-- 失败态:接口异常 → 明确提示 + 重试入口,文案与空态区分(AC-16 / AC-38) -->
- <view class="empty-state" v-else-if="recipeError">
- <view class="empty-icon-wrap"><text class="empty-icon">⚠️</text></view>
- <text class="empty-title">今日食谱加载失败</text>
- <text class="empty-sub">{{ recipeError }}</text>
- <view class="generate-btn" @tap="retryRecommendation">
- <text>点击重试</text>
- </view>
- </view>
- <!-- 无推荐状态 / 视角级空态(AC-04;不回退展示其它视角食谱) -->
- <view class="empty-state" v-else-if="!recommendation">
- <view class="empty-icon-wrap"><text class="empty-icon">🍽️</text></view>
- <text class="empty-title">今日菜单空着</text>
- <text class="empty-sub">点击生成今日三餐食谱</text>
- <view class="generate-btn" @tap="generateRecipe">
- <text>生成食谱</text>
- </view>
- </view>
- <!-- 整份空态:所有餐次菜数为 0(删除后可能出现,AC-35) -->
- <view class="empty-state" v-else-if="allMealsEmpty">
- <view class="empty-icon-wrap"><text class="empty-icon">🍽️</text></view>
- <text class="empty-title">今天的菜品都删完啦</text>
- <text class="empty-sub">点击重新生成今日三餐食谱</text>
- <view class="generate-btn" @tap="regenerate">
- <text>重新生成</text>
- </view>
- </view>
- <!-- 有推荐状态 -->
- <view v-else>
- <!-- 日期和状态 -->
- <view class="card header-card">
- <view class="card-accent"></view>
- <view class="card-body">
- <text class="date-text">{{ recommendation.date }}</text>
- <view class="status-badge" :class="'status-' + recommendation.status">
- <text>{{ statusText }}</text>
- </view>
- </view>
- </view>
- <!-- 菜品列表 -->
- <view class="meal-section" v-for="(meal, index) in meals" :key="index">
- <view class="meal-header">
- <view class="meal-icon-wrap" :class="'meal-icon-' + meal.type">
- <text class="meal-icon">{{ meal.icon }}</text>
- </view>
- <text class="meal-name">{{ meal.name }}</text>
- <text class="meal-count">{{ meal.participants }} 人份</text>
- <!-- D2① 只读状态提示:当前 N 菜 1 汤 / 未达标准,不静默补菜 -->
- <text class="meal-standard" v-if="dishStandard(meal)">{{ dishStandard(meal) }}</text>
- </view>
- <view class="dish-list">
- <!-- 餐次级空态:某餐菜数删至 0(AC-34),提供「重新生成」入口 -->
- <view class="meal-empty" v-if="meal.dishes.length === 0">
- <text class="meal-empty-text">本餐暂无菜品</text>
- <view class="meal-empty-btn" @tap="regenerate"><text>重新生成</text></view>
- </view>
- <view class="dish-item" v-for="(dish, dIndex) in meal.dishes" :key="dIndex">
- <view class="dish-header">
- <text class="dish-name">{{ dish.name }}</text>
- <text class="dish-cal">{{ dish.calories }} kcal</text>
- </view>
- <view class="dish-ingredients">
- <text class="ingredient-tag" v-for="(ing, iIndex) in dish.ingredients" :key="iIndex">
- {{ ing.name }} {{ ing.amount }}g
- </text>
- </view>
- <view class="dish-method">
- <text class="method-text">🍳 {{ dish.method }}</text>
- </view>
- <!-- D1①:收敛为单一「🗑 删除」;按钮组合由 dishActions 数据位驱动,便于回退 -->
- <view class="dish-actions" v-if="dishActions === 'delete-only'">
- <view class="action-btn delete-btn"
- :class="{'action-btn-disabled': isDeleting(meal.name, dIndex)}"
- @tap="deleteDish(meal.name, dIndex)">🗑 删除</view>
- </view>
- </view>
- </view>
- </view>
- <!-- 营养汇总 -->
- <view class="card nutrition-card">
- <view class="card-accent"></view>
- <view class="card-body">
- <text class="card-title">今日营养汇总</text>
- <view class="nutrition-grid">
- <view class="nutrition-item">
- <text class="nutrition-value">{{ summary.calories }}</text>
- <text class="nutrition-unit">kcal</text>
- <text class="nutrition-label">热量</text>
- </view>
- <view class="nutrition-item">
- <text class="nutrition-value">{{ summary.protein }}</text>
- <text class="nutrition-unit">g</text>
- <text class="nutrition-label">蛋白质</text>
- </view>
- <view class="nutrition-item">
- <text class="nutrition-value">{{ summary.carbs }}</text>
- <text class="nutrition-unit">g</text>
- <text class="nutrition-label">碳水</text>
- </view>
- <view class="nutrition-item">
- <text class="nutrition-value">{{ summary.fat }}</text>
- <text class="nutrition-unit">g</text>
- <text class="nutrition-label">脂肪</text>
- </view>
- </view>
- </view>
- </view>
- <!-- 操作按钮 -->
- <view class="action-area">
- <view class="btn-row">
- <view class="btn-secondary" @tap="regenerate">重新生成</view>
- <view class="btn-primary" @tap="completeRecipe" v-if="recommendation.status !== 'completed'">
- 标记完成
- </view>
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
- <!-- 共餐人选择弹层(需求7:家庭总览「生成食谱」先选共餐人,确认后生成) -->
- <view class="participant-mask" v-if="showParticipantPicker" @tap="cancelParticipants">
- <view class="participant-sheet" @tap.stop>
- <view class="participant-sheet-header">
- <text class="participant-sheet-title">选择共餐人</text>
- <text class="participant-sheet-sub">为今天的食谱挑选一起用餐的家庭成员</text>
- </view>
- <view class="participant-list">
- <view class="participant-item" v-for="member in pendingParticipantOptions" :key="member.id"
- :class="{'participant-item-selected': member.selected}"
- @tap="toggleParticipant(member)">
- <view class="participant-check" v-if="member.selected">
- <text class="participant-check-icon">✓</text>
- </view>
- <text class="participant-name">{{ member.nickname }}</text>
- </view>
- <view class="participant-empty" v-if="pendingParticipantOptions.length === 0">
- <text class="participant-empty-text">暂无家庭成员可选</text>
- </view>
- </view>
- <view class="participant-actions">
- <view class="participant-btn participant-btn-cancel" @tap="cancelParticipants">
- <text>取消</text>
- </view>
- <view class="participant-btn participant-btn-confirm" @tap="confirmParticipants">
- <text>确认生成({{ pendingParticipantIds.length }} 人)</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { getDietRecommendation, generateDietRecommendation, completeDietRecommendation, regenerateDietRecommendation, updateDietRecommendation } from '@/utils/api.js'
- import config from '@/config.js'
- import MemberSelector from '@/components/MemberSelector.vue'
- import { memberIdOf } from '@/utils/memberNormalize.js'
- import fontScaleMixin from '@/mixins/font-scale.js'
- export default {
- mixins: [fontScaleMixin],
- components: { MemberSelector },
- data() {
- return {
- recommendation: null,
- meals: [],
- summary: {},
- loading: false,
- // ===== 推荐食材(原「食材查询」页迁移)=====
- searchQuery: '',
- activeCategory: 'all',
- filterType: 'suitable',
- sortType: 'desc',
- currentView: 'personal',
- currentTab: 'recipe',
- visibleCount: 20,
- memberSelectLocked: false,
- allFoods: [],
- familyData: null,
- familyMembers: [],
- familyOverview: [],
- currentMemberId: null,
- memberList: [],
- foodLoading: false,
- refreshing: false,
- // ===== 共餐人选择(需求7:家庭总览生成食谱先选共餐人)=====
- showParticipantPicker: false,
- pendingParticipantIds: [],
- // ===== 今日食谱视角隔离 / 删除交互 / 空·加载·失败三态(本轮增量)=====
- recipeLoading: false,
- recipeError: '',
- deleting: false,
- deletingKey: '',
- // D1① 可回退数据位:'delete-only'(当前)/ 'replace-and-delete'(备选,改此值 + 模板分支即可)
- dishActions: 'delete-only'
- }
- },
- computed: {
- statusText: function() {
- var map = {
- 'pending': '待确认',
- 'accepted': '已接受',
- 'completed': '已完成'
- }
- return map[this.recommendation && this.recommendation.status] || '待确认'
- },
- familyMode: function() {
- return this.currentView === 'family'
- },
- filteredFoods: function() {
- var self = this
- var result = self.currentView === 'family'
- ? self.familyOverview
- : self.allFoods
- // 分类筛选(食材分类为中文,用关键词集合匹配不同数据源的分类命名)
- if (self.activeCategory !== 'all') {
- var keywords = self.getCategoryKeywords(self.activeCategory)
- result = result.filter(function(f) {
- if (!f.category) return false
- for (var ki = 0; ki < keywords.length; ki++) {
- if (f.category.indexOf(keywords[ki]) !== -1) return true
- }
- return false
- })
- }
- // 搜索筛选
- if (self.searchQuery) {
- result = result.filter(function(f) {
- return (f.name && f.name.indexOf(self.searchQuery) !== -1) ||
- (f.category && f.category.indexOf(self.searchQuery) !== -1)
- })
- }
- // 适合/戒备筛选(戒备 = 推荐指数 < 0)
- if (self.filterType === 'suitable') {
- result = result.filter(function(f) {
- return f.score >= 0
- })
- } else if (self.filterType === 'unsuitable') {
- result = result.filter(function(f) {
- return f.score < 0
- })
- }
- // 排序(戒备模式默认升序,见 setFilter)
- var sortFn = self.sortType === 'asc'
- ? function(a, b) { return (a.score || 0) - (b.score || 0) }
- : function(a, b) { return (b.score || 0) - (a.score || 0) }
- // 健康问卷个性化调整(B3):suitable Tab 中 blocked 项整体排到列表末尾(保持可见不置顶;组内各按既有分值序)
- if (self.filterType === 'suitable') {
- var nonBlocked = []
- var blocked = []
- result.forEach(function(f) {
- if (f.adjustment === 'blocked') {
- blocked.push(f)
- } else {
- nonBlocked.push(f)
- }
- })
- result = nonBlocked.slice().sort(sortFn).concat(blocked.slice().sort(sortFn))
- } else {
- result = result.slice().sort(sortFn)
- }
- // 健康问卷个性化调整分组(diet.food.healthAdjustUi · B3):suitable Tab 中 blocked 项整体排到列表末尾
- // (保持可见但不置顶,组内仍按既有分值排序,stable 分组;unsuitable / all 位置不变、仅带提示条)
- if (self.filterType === 'suitable') {
- result = result.filter(function(f) { return f.adjustment !== 'blocked' })
- .concat(result.filter(function(f) { return f.adjustment === 'blocked' }))
- }
- return result
- },
- pagedFoods: function() {
- return this.filteredFoods.slice(0, this.visibleCount)
- },
- // 整份食谱空态:所有餐次菜数为 0(AC-35)
- allMealsEmpty: function() {
- var meals = this.meals || []
- if (meals.length === 0) return true
- for (var i = 0; i < meals.length; i++) {
- if (meals[i].dishes && meals[i].dishes.length > 0) return false
- }
- return true
- },
- // 共餐人选择弹层列表(原始 memberList 归一化为 {id, nickname, selected},避免模板内方法调用)
- pendingParticipantOptions: function() {
- var self = this
- var ids = self.pendingParticipantIds || []
- return (self.memberList || []).map(function(m) {
- var id = memberIdOf(m)
- return {
- id: id,
- nickname: m.nickname || m.roleLabel || '成员',
- selected: ids.indexOf(id) >= 0
- }
- })
- }
- },
- onLoad: function(options) {
- var opts = options || {}
- this.currentMemberId = opts.memberId ? parseInt(opts.memberId) : null
- this.loadRecommendation()
- this.loadMembers()
- this.loadFamilyData()
- this.loadFoods()
- },
- onShow: function() {
- this.loadRecommendation()
- },
- methods: {
- goBack: function() {
- uni.navigateBack()
- },
- // 按当前视角加载今日食谱:view_key 同源、局部 loading 先清空防串数据(AC-01/03/09/36)
- loadRecommendation: function() {
- var self = this
- var viewKey = self.buildViewKey()
- self.recipeError = ''
- // 视角尚未就绪(首次 onLoad 时 loadRecommendation 先于异步 loadMembers,personal 且无 currentMemberId):
- // 不发请求、清空残留,由 loadMembers 成功回调补发一次
- if (!viewKey) {
- self.recipeLoading = false
- self.recommendation = null
- self.meals = []
- self.summary = {}
- return Promise.resolve()
- }
- var today = self.formatDate(new Date())
- self.recipeLoading = true
- self.recommendation = null
- self.meals = []
- self.summary = {}
- return getDietRecommendation({ date: today, view_key: viewKey }).then(function(res) {
- self.recipeLoading = false
- var d = res && res.data
- if (d && d.id) {
- self.recommendation = d
- self.parseMenu(d.menu)
- var ns = d.nutritionSummary
- self.summary = ns ? (typeof ns === 'string' ? JSON.parse(ns) : ns) : {}
- } else {
- self.recommendation = null
- self.meals = []
- self.summary = {}
- }
- }).catch(function(err) {
- self.recipeLoading = false
- self.recommendation = null
- self.meals = []
- self.summary = {}
- self.recipeError = (err && err.message) || '加载失败,请重试'
- })
- },
- // 视角键生成(K1 可回退的唯一落点):家庭总览固定 'family';个人/成员 'member:<id>';
- // loadMembers 未完成、memberList 为空且无 currentMemberId 时返回 null 且不发请求。
- // 后端把 view_key 当不透明字符串,语义全在此方法一处。
- buildViewKey: function() {
- if (this.currentView === 'family') return 'family'
- if (this.currentView === 'personal') {
- if (this.currentMemberId !== null && this.currentMemberId !== undefined) {
- return 'member:' + this.currentMemberId
- }
- return null
- }
- return null
- },
- // 失败态重试:按当前视角重新加载,不重置用户当前视角
- retryRecommendation: function() {
- this.loadRecommendation()
- },
- parseMenu: function(menuJson) {
- try {
- var menu = (typeof menuJson === 'string') ? JSON.parse(menuJson || '{}') : (menuJson || {})
- this.meals = []
- var mealMap = {
- 'breakfast': { name: '早餐', icon: '🌅' },
- 'lunch': { name: '午餐', icon: '☀️' },
- 'dinner': { name: '晚餐', icon: '🌙' }
- }
- if (menu.meals) {
- var self = this
- menu.meals.forEach(function(meal) {
- var config = mealMap[meal.type] || { name: meal.name || meal.type, icon: '🍽️' }
- var dishes = (meal.dishes || []).map(function(dish) {
- var ing = (dish.ingredients || []).map(function(item) {
- return { name: item.name, amount: item.amount || item.grams || 0 }
- })
- return {
- name: dish.name,
- // 汤/菜可识别:dish.type = dish|soup,存量无 type 时默认 'dish'(AC-25)
- type: dish.type || 'dish',
- calories: dish.calories || (dish.nutrition && dish.nutrition.calories) || 0,
- ingredients: ing,
- method: dish.method || dish.cooking_method || ''
- }
- })
- self.meals.push({
- name: config.name,
- icon: config.icon,
- type: meal.type,
- participants: meal.participants || 1,
- dishes: dishes
- })
- })
- }
- } catch (e) {
- console.error('解析菜单失败', e)
- }
- },
- generateRecipe: function() {
- var self = this
- // 家庭总览:先弹共餐人多选,确认后再生成(需求7)
- if (self.currentView === 'family') {
- self.openParticipantPicker()
- return
- }
- // 个人/成员:只对当前选中人生成(participant_member_ids 只传当前成员)
- self.loading = true
- var participantIds = self.currentMemberId ? [self.currentMemberId] : []
- uni.showLoading({ title: '正在生成食谱...' })
- return generateDietRecommendation({
- date: self.formatDate(new Date()),
- meal_type: 'all',
- participant_member_ids: JSON.stringify(participantIds),
- view_key: self.buildViewKey()
- }).then(function(res) {
- self.loading = false
- uni.hideLoading()
- if (res && res.data && res.data.id) {
- uni.showToast({ title: '食谱生成成功', icon: 'success' })
- self.loadRecommendation()
- } else {
- uni.showToast({ title: (res && res.message) || '生成失败', icon: 'none' })
- }
- }).catch(function() {
- self.loading = false
- uni.hideLoading()
- uni.showToast({ title: '生成失败', icon: 'none' })
- })
- },
- // 打开共餐人多选弹层(默认勾选全部家庭成员)
- openParticipantPicker: function() {
- var self = this
- var ids = []
- var members = self.memberList || []
- for (var i = 0; i < members.length; i++) {
- var id = memberIdOf(members[i])
- if (id !== null && id !== undefined && ids.indexOf(id) < 0) ids.push(id)
- }
- self.pendingParticipantIds = ids
- self.showParticipantPicker = true
- },
- // 多选切换共餐人
- toggleParticipant: function(member) {
- var self = this
- if (!member) return
- var id = (member.id !== null && member.id !== undefined) ? member.id : memberIdOf(member)
- if (id === null || id === undefined) return
- var ids = (self.pendingParticipantIds || []).slice()
- var idx = ids.indexOf(id)
- if (idx >= 0) {
- ids.splice(idx, 1)
- } else {
- ids.push(id)
- }
- self.pendingParticipantIds = ids
- },
- // 确认共餐人 → 生成食谱(participant_member_ids = 所选共餐人)
- confirmParticipants: function() {
- var self = this
- self.showParticipantPicker = false
- self.loading = true
- generateDietRecommendation({
- date: self.formatDate(new Date()),
- meal_type: 'all',
- participant_member_ids: JSON.stringify(self.pendingParticipantIds || []),
- view_key: self.buildViewKey()
- }).then(function(res) {
- self.loading = false
- if (res && res.data && res.data.id) {
- uni.showToast({ title: '食谱生成成功', icon: 'success' })
- self.loadRecommendation()
- } else {
- uni.showToast({ title: (res && res.message) || '生成失败', icon: 'none' })
- }
- }).catch(function() {
- self.loading = false
- uni.showToast({ title: '生成失败', icon: 'none' })
- })
- },
- // 取消共餐人选择
- cancelParticipants: function() {
- this.showParticipantPicker = false
- this.pendingParticipantIds = []
- },
- // D2① 只读菜数状态:当前 X 菜 Y 汤 / 未达标准;与删除逻辑解耦,绝不触发补菜请求
- dishStandard: function(meal) {
- if (!meal || (meal.type !== 'lunch' && meal.type !== 'dinner')) return ''
- var dishes = meal.dishes || []
- var mainCount = 0
- var soupCount = 0
- for (var i = 0; i < dishes.length; i++) {
- if (dishes[i].type === 'soup') soupCount += 1
- else mainCount += 1
- }
- var n = meal.participants || 1
- var expected = 4 + Math.max(0, n - 3)
- var reached = mainCount >= expected && soupCount >= 1
- var text = '当前 ' + mainCount + ' 菜 ' + soupCount + ' 汤'
- return reached ? (text + ' · 达标') : (text + ' / 未达标准')
- },
- // 防重复点击:删除中的那一道菜按钮禁用(AC-37)
- isDeleting: function(mealName, dishIndex) {
- return this.deleting && this.deletingKey === (mealName + ':' + dishIndex)
- },
- // 从 this.meals 组装「移除目标菜」后的整份 menu_json(不含 icon 等纯展示字段,避免结构漂移)
- buildMenuPayload: function(mealName, dishIndex) {
- var payloadMeals = []
- var meals = this.meals || []
- for (var i = 0; i < meals.length; i++) {
- var meal = meals[i]
- var dishes = []
- var src = meal.dishes || []
- for (var j = 0; j < src.length; j++) {
- if (meal.name === mealName && j === dishIndex) continue
- var d = src[j]
- var ings = []
- var srcIng = d.ingredients || []
- for (var k = 0; k < srcIng.length; k++) {
- ings.push({ name: srcIng[k].name, amount: srcIng[k].amount || 0 })
- }
- dishes.push({
- name: d.name,
- type: d.type || 'dish',
- calories: d.calories || 0,
- ingredients: ings,
- method: d.method || ''
- })
- }
- payloadMeals.push({
- type: meal.type,
- name: meal.name,
- participants: meal.participants || 1,
- dishes: dishes
- })
- }
- return JSON.stringify({ meals: payloadMeals })
- },
- // D1① 单一主操作「🗑 删除」:复用 POST /api/diet/recommendation/update 整份覆盖。
- // 删除与补菜完全解耦(不调任何补菜 / 重新生成接口);失败保留原数据可重试(AC-13/15/16/18)
- deleteDish: function(mealName, dishIndex) {
- var self = this
- if (self.deleting) return
- if (!self.recommendation || !self.recommendation.id) return
- var targetMeal = null
- for (var i = 0; i < (self.meals || []).length; i++) {
- if (self.meals[i].name === mealName) {
- targetMeal = self.meals[i]
- break
- }
- }
- if (!targetMeal || !targetMeal.dishes || dishIndex < 0 || dishIndex >= targetMeal.dishes.length) return
- self.deleting = true
- self.deletingKey = mealName + ':' + dishIndex
- uni.showLoading({ title: '删除中...' })
- var payload = self.buildMenuPayload(mealName, dishIndex)
- return updateDietRecommendation({ id: self.recommendation.id, menu_json: payload }).then(function(res) {
- self.deleting = false
- self.deletingKey = ''
- uni.hideLoading()
- if (!res) {
- uni.showToast({ title: '删除失败,请重试', icon: 'none' })
- return
- }
- targetMeal.dishes.splice(dishIndex, 1)
- uni.showToast({ title: '已删除', icon: 'success' })
- }).catch(function(err) {
- self.deleting = false
- self.deletingKey = ''
- uni.hideLoading()
- uni.showToast({ title: (err && err.message) || '删除失败,请重试', icon: 'none' })
- })
- },
- // D1 可回退入口:当前 dishActions='delete-only' 时模板不渲染,与 deleteDish 完全独立、互不引用。
- // 若产品改选「双按钮」,只需把 dishActions 切为 'replace-and-delete' 并在模板补分支。
- replaceDish: function(mealName, dishIndex) {
- uni.showToast({ title: '该功能已下线,请用「删除」或「重新生成」', icon: 'none' })
- },
- regenerate: function() {
- var self = this
- if (!self.recommendation || !self.recommendation.id) return
- var regData = { id: self.recommendation.id }
- uni.showLoading({ title: '重新生成中...' })
- regenerateDietRecommendation(regData).then(function(res) {
- uni.hideLoading()
- if (res && res.data && res.data.id) {
- self.loadRecommendation()
- } else {
- uni.showToast({ title: (res && res.message) || '重新生成失败', icon: 'none' })
- }
- }).catch(function() {
- uni.hideLoading()
- uni.showToast({ title: '重新生成失败', icon: 'none' })
- })
- },
- completeRecipe: function() {
- var self = this
- if (!self.recommendation) return
- completeDietRecommendation({ id: self.recommendation.id }).then(function() {
- uni.showToast({ title: '已标记完成', icon: 'success' })
- self.loadRecommendation()
- })
- },
- formatDate: function(date) {
- var d = date
- var m = (d.getMonth() + 1).toString().padStart(2, '0')
- var day = d.getDate().toString().padStart(2, '0')
- return d.getFullYear() + '-' + m + '-' + day
- },
- // ===== 推荐食材(原「食材查询」页迁移)=====
- getFoodKey: function(item, idx) {
- return item.id || idx
- },
- loadMembers: function() {
- var self = this
- var token = uni.getStorageSync('token')
- if (!token) return
- uni.request({
- // config 在契约测试桩下可能为 undefined(stub 仅提供 default 键),防御性取址
- url: ((config && config.API_BASE_URL) || '') + '/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)。
- // 仅限首次 onLoad:切到家庭总览(switchView('family') 置 memberSelectLocked)后,
- // loadMembers 不得再自动默认选「个人」,个人/成员 chip 保持不高亮。
- if (!self.memberSelectLocked && !self.currentMemberId && self.memberList.length > 0) {
- var defaultMember = self.getSelfRow() || self.memberList[0]
- self.currentMemberId = memberIdOf(defaultMember)
- }
- // onLoad 先 loadRecommendation 后异步 loadMembers:此时个人视角键才就绪,补发一次(AC-01/10)
- self.loadRecommendation()
- }
- }
- })
- },
- loadFoods: function() {
- var self = this
- var token = uni.getStorageSync('token')
- if (!token) return
- self.foodLoading = true
- var url = config.API_BASE_URL + '/api/health/foods'
- var data = {}
- if (self.currentMemberId) {
- data.memberId = self.currentMemberId
- }
- uni.request({
- url: url,
- method: 'POST',
- data: data,
- header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
- success: function(res) {
- self.foodLoading = false
- if (res.data && res.data.code === 200 && res.data.data) {
- self.allFoods = res.data.data.map(function(f) {
- f.scoreClass = self.getScoreClass(f.score)
- f.statusText = self.getStatusText(f.score)
- f.status = f.score >= 0 ? 'suitable' : 'unsuitable'
- return f
- })
- }
- },
- fail: function() {
- self.foodLoading = false
- }
- })
- },
- loadFamilyData: function() {
- var self = this
- var token = uni.getStorageSync('token')
- if (!token) return
- var familyId = uni.getStorageSync('familyId')
- if (!familyId) return
- uni.request({
- url: config.API_BASE_URL + '/api/health/foods/by-family',
- method: 'POST',
- header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
- success: function(res) {
- if (res.data && res.data.code === 200 && res.data.data) {
- self.familyData = res.data.data
- self.familyMembers = Object.keys(res.data.data.byMember || {}).map(function(key) {
- return { userId: key, nickname: res.data.data.memberNames[key] || '成员' }
- })
- // 优先使用后端持久化总览(overview):overviewScore = 分段聚合展示值
- // (有成员<0取全员最低值、全员>=0取平均值);旧版后端无该字段时回退 minIndexScore
- if (res.data.data.overview && res.data.data.overview.length > 0) {
- self.familyOverview = res.data.data.overview.map(function(o) {
- var score = (o.overviewScore !== undefined && o.overviewScore !== null)
- ? o.overviewScore : o.minIndexScore
- return {
- id: o.foodId,
- name: o.foodName,
- category: o.category,
- score: score,
- scoreClass: self.getScoreClass(score),
- color: self.getScoreClass(score),
- statusText: self.getStatusText(score),
- status: score >= 0 ? 'suitable' : 'unsuitable',
- aggregateRule: o.aggregateRule || '',
- minScore: o.minIndexScore,
- memberCount: o.memberCount || 0,
- memberScores: (o.memberScores || []).map(function(s) {
- return { name: s.nickname || '', score: s.score }
- })
- }
- })
- } else {
- // 后端未返回 overview 时的降级路径:前端按同一分段聚合口径计算
- self.buildFamilyOverview(res.data.data.total || res.data.data.totalList, res.data.data.byMember, res.data.data.memberNames)
- }
- }
- }
- })
- },
- buildFamilyOverview: function(totalList, byMember, memberNames) {
- var self = this
- var overview = []
- var list = totalList || []
- for (var i = 0; i < list.length; i++) {
- var food = list[i]
- var memberScores = []
- for (var j = 0; j < self.familyMembers.length; j++) {
- var member = self.familyMembers[j]
- var memberFoods = byMember[member.userId]
- if (memberFoods) {
- for (var k = 0; k < memberFoods.length; k++) {
- if (memberFoods[k].foodId === food.id) {
- var score = memberFoods[k].indexScore || 0
- memberScores.push({ name: member.nickname, score: score })
- break
- }
- }
- }
- }
- // 降级路径:与后端同口径 —— 有人 < 0 取全员最低值,全员 >= 0 取平均值(四舍五入)
- if (memberScores.length > 0) {
- var minScore = memberScores[0].score
- var sum = 0
- var hasNegative = false
- for (var mi = 0; mi < memberScores.length; mi++) {
- var s = memberScores[mi].score
- if (s < minScore) minScore = s
- sum += s
- if (s < 0) hasNegative = true
- }
- var score = hasNegative ? minScore : Math.round(sum / memberScores.length)
- overview.push({
- id: food.id,
- name: food.name,
- category: food.category,
- score: score,
- scoreClass: self.getScoreClass(score),
- color: self.getScoreClass(score),
- statusText: self.getStatusText(score),
- status: score >= 0 ? 'suitable' : 'unsuitable',
- aggregateRule: hasNegative ? 'MIN_NEGATIVE' : 'AVG_POSITIVE',
- minScore: minScore,
- memberCount: memberScores.length,
- memberScores: memberScores
- })
- }
- }
- // 按总览展示值排序(从高到低)
- overview.sort(function(a, b) {
- return b.score - a.score
- })
- self.familyOverview = overview
- },
- getScoreClass: function(score) {
- if (score === undefined || score === null) return 'neutral'
- if (score >= 0) return 'good'
- return 'bad'
- },
- getStatusText: function(score) {
- if (score === undefined || score === null) return '未知'
- if (score >= 0) return '适合'
- return '戒备'
- },
- searchFood: function() {
- // 搜索由 computed 自动处理
- },
- switchCategory: function(category) {
- this.activeCategory = category
- this.visibleCount = 20
- },
- getCategoryKeywords: function(category) {
- var map = {
- '蔬菜': ['蔬菜'],
- '水果': ['水果'],
- '肉禽': ['肉类', '肉禽'],
- '水产': ['水产', '水产品'],
- '谷物': ['谷物', '主食', '全谷物'],
- '蛋奶': ['蛋类', '蛋奶', '乳制品']
- }
- return map[category] || []
- },
- setFilter: function(type) {
- this.filterType = type
- // 适合/全部:倒序,推荐值大的排前面;戒备:升序,推荐值小的排前面
- if (type === 'unsuitable') {
- this.sortType = 'asc'
- } else {
- this.sortType = 'desc'
- }
- this.visibleCount = 20
- },
- setSort: function(type) {
- this.sortType = type
- },
- switchTab: function(tab) {
- // 4 Tab:今日食谱 | 适合 | 戒备 | 全部;切 Tab 重置分页(请求式上滑加载从首批重新开始)
- this.currentTab = tab
- this.visibleCount = 20
- if (tab !== 'recipe') {
- this.filterType = tab
- this.sortType = tab === 'unsuitable' ? 'asc' : 'desc'
- } else {
- // 切回「今日食谱」按当前视角重载,避免展示切换前残留(AC-09)
- this.loadRecommendation()
- }
- },
- loadMore: function() {
- // 上滑触底加载更多:未达全量末尾时每批追加 20 条,到达末尾自动停止
- if (this.visibleCount < this.filteredFoods.length) {
- this.visibleCount += 20
- }
- },
- switchView: function(view) {
- this.currentView = view
- if (view === 'family') {
- // 家庭总览 ↔ 个人/成员互斥:清空成员选中态(个人/成员 chip 不高亮);
- // 并锁定「不再自动默认选个人」,loadMembers 再次加载时不回灌默认选中
- this.currentMemberId = null
- this.memberSelectLocked = true
- }
- // 视角切换后按新 buildViewKey() 重载今日食谱(AC-03)
- this.loadRecommendation()
- },
- // 取「本人」行(isSelf):后端已按 user_id 折叠,此处仅取第一行 isSelf
- getSelfRow: function() {
- var members = this.memberList || []
- for (var i = 0; i < members.length; i++) {
- if (members[i] && members[i].isSelf) return members[i]
- }
- return null
- },
- switchMember: function(member) {
- // 统一身份键:familyMemberId(= family_members.id);userId 仅用于折叠,不再作主键
- this.currentMemberId = memberIdOf(member)
- this.currentView = 'personal'
- this.visibleCount = 20
- this.loadFoods()
- // 成员切换联动今日食谱(AC-01/02),仍保留 loadFoods + visibleCount=20 既有行为
- this.loadRecommendation()
- },
- onRefresh: function() {
- var self = this
- self.refreshing = true
- self.loadFoods()
- self.loadFamilyData()
- // 下拉刷新按当前视角重载今日食谱(AC-09)
- self.loadRecommendation()
- setTimeout(function() {
- self.refreshing = false
- }, 500)
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .recommendation-page {
- /* 翻页失效根因修复:父容器必须是「确定高度」而不是由内容撑开的 min-height。
- 原 min-height:100vh 下 scroll-view 会随内容一起长高,退化为页面级滚动,
- @scrolltolower 永不触发 → visibleCount 卡在 20 → 下滑不追加食材。
- 页面内内容全部在 scroll-view 内部,弹层为 position:fixed,故固定 100vh 安全。 */
- height: 100vh;
- background-color: $app-bg;
- display: flex;
- flex-direction: column;
- }
- .nav-placeholder {
- width: 80rpx;
- }
- .content {
- /* 保留既有 flex 布局;height:0 给出确定基准,min-height:0 阻止 min-content 把
- 滚动容器撑高。配合父级 height:100vh,flex:1 才能算出确定高度,让
- scroll-y 形成内部滚动视口并派发 @scrolltolower(H5 / 小程序通用)。 */
- flex: 1;
- height: 0;
- min-height: 0;
- padding: $uni-space-page;
- box-sizing: border-box;
- width: 100%;
- overflow: hidden;
- }
- .empty-state { display: flex; flex-direction: column; align-items: center; padding: 120rpx 40rpx; }
- .empty-icon-wrap {
- width: 160rpx; height: 160rpx; border-radius: 50%;
- background: linear-gradient(135deg, $dim-body, $dim-body-light);
- display: flex; align-items: center; justify-content: center;
- box-shadow: 0 10rpx 30rpx rgba(255, 140, 66, 0.3);
- margin-bottom: 40rpx;
- }
- .empty-icon { font-size: calc($uni-font-size-5xl * var(--font-scale, 1)); }
- .empty-title { font-size: calc(34rpx * var(--font-scale, 1)); font-weight: 700; color: $facade-text-strong; display: block; margin-bottom: 16rpx; }
- .empty-sub { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-muted; display: block; margin-bottom: 48rpx; }
- .generate-btn {
- background: linear-gradient(135deg, $dim-body, $dim-body-light);
- color: $app-surface; padding: 28rpx 60rpx; border-radius: 999rpx;
- font-size: calc(30rpx * var(--font-scale, 1)); font-weight: 600;
- box-shadow: 0 6rpx 20rpx rgba(255, 140, 66, 0.25);
- }
- .card {
- display: flex;
- background-color: $app-surface;
- border-radius: 24rpx;
- margin-bottom: $uni-space-lg;
- box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
- overflow: hidden;
- }
- .card-accent { width: 8rpx; background: linear-gradient(180deg, $dim-body, $dim-body-light); flex-shrink: 0; }
- .card-body {
- flex: 1;
- padding: $uni-space-page;
- }
- .card-title {
- font-size: calc(30rpx * var(--font-scale, 1));
- font-weight: 600;
- color: $facade-text-strong;
- margin-bottom: 20rpx;
- display: block;
- }
- .header-card .card-body {
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .date-text {
- font-size: calc(28rpx * var(--font-scale, 1));
- color: $facade-text-strong;
- font-weight: 500;
- }
- .status-badge {
- padding: 8rpx 20rpx;
- border-radius: 24rpx;
- font-size: calc(24rpx * var(--font-scale, 1));
- }
- .status-pending { background: $tint-warm-soft; color: $brand-primary-deep; }
- .status-accepted {
- background: #E8F1FB;
- color: $mat-blue-base;
- }
- .status-completed {
- background-color: $mat-green-tint;
- color: $mat-green;
- }
- .meal-section {
- background-color: $app-surface;
- border-radius: 24rpx;
- margin-bottom: $uni-space-lg;
- overflow: hidden;
- box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
- }
- .meal-header { display: flex; flex-wrap: wrap; align-items: center; padding: 24rpx $uni-space-page; border-bottom: 1rpx solid #FDE8D0; }
- .meal-icon-wrap { width: 64rpx; height: 64rpx; border-radius: 24rpx; display: flex; align-items: center; justify-content: center; margin-right: 16rpx; }
- .meal-icon-breakfast { background: linear-gradient(135deg, $dim-body-light, #FFD48A); }
- .meal-icon-lunch { background: linear-gradient(135deg, $status-warning, $accent-amber-light); }
- .meal-icon-dinner { background: linear-gradient(135deg, $facade-violet-light, $accent-violet-300); }
- .meal-icon {
- font-size: calc(36rpx * var(--font-scale, 1));
- margin-right: 12rpx;
- }
- .meal-name {
- font-size: calc(28rpx * var(--font-scale, 1));
- font-weight: 600;
- color: $facade-text-strong;
- flex: 1;
- }
- .meal-count {
- font-size: calc(24rpx * var(--font-scale, 1));
- color: $facade-text-muted;
- }
- .dish-list {
- padding: 20rpx $uni-space-page;
- }
- .dish-item { padding: 24rpx; border-radius: 24rpx; background: $flat-bg; margin-bottom: 16rpx; }
- .dish-item:last-child { margin-bottom: 0; }
- .dish-header {
- display: flex;
- justify-content: space-between;
- margin-bottom: 12rpx;
- }
- .dish-name { font-size: calc(28rpx * var(--font-scale, 1)); font-weight: 600; color: $facade-text-strong; }
- .dish-cal { font-size: calc(24rpx * var(--font-scale, 1)); color: $brand-primary-deep; font-weight: 600; }
- .dish-ingredients {
- display: flex;
- flex-wrap: wrap;
- gap: 12rpx;
- margin-bottom: 12rpx;
- }
- .ingredient-tag {
- padding: 6rpx 16rpx;
- background-color: $facade-fill-2;
- border-radius: 24rpx;
- font-size: calc(22rpx * var(--font-scale, 1));
- color: $facade-text-body;
- }
- .dish-method {
- margin-bottom: 16rpx;
- }
- .method-text {
- font-size: calc(24rpx * var(--font-scale, 1));
- color: $facade-text-muted;
- }
- .dish-actions { display: flex; gap: 16rpx; margin-top: 8rpx; }
- .action-btn { padding: 12rpx 26rpx; border-radius: 999rpx; font-size: calc(24rpx * var(--font-scale, 1)); }
- /* 既有按钮样式保留备用,便于 D1 回退到双按钮组合(当前 dishActions='delete-only' 不渲染) */
- .like-btn { background: $mat-green-tint; color: $mat-green; }
- .swap-btn { background: #E8F1FB; color: $mat-blue-base; }
- .skip-btn { background: $fortune-0-tint; color: $mat-red; }
- /* 本轮增量:删除主操作 / 防重复点击 / 菜数只读状态 / 空·加载态 */
- .delete-btn { background: $fortune-0-tint; color: $mat-red; }
- .action-btn-disabled { opacity: 0.5; }
- .meal-standard {
- flex-basis: 100%;
- text-align: right;
- font-size: calc(22rpx * var(--font-scale, 1));
- color: $facade-text-muted;
- margin-top: 8rpx;
- }
- .meal-empty {
- padding: 40rpx 0;
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .meal-empty-text {
- font-size: calc(26rpx * var(--font-scale, 1));
- color: $facade-text-muted;
- margin-bottom: 20rpx;
- }
- .meal-empty-btn {
- padding: 12rpx 40rpx;
- border-radius: 999rpx;
- background: $tint-warm-soft;
- color: $brand-primary-deep;
- font-size: calc(24rpx * var(--font-scale, 1));
- }
- .recipe-loading {
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 60rpx 0;
- }
- .recipe-loading-text {
- font-size: calc(26rpx * var(--font-scale, 1));
- color: $facade-text-muted;
- }
- .nutrition-grid {
- display: flex;
- justify-content: space-around;
- }
- .nutrition-item {
- text-align: center;
- }
- .nutrition-card .card-body { background: $flat-bg; border-radius: 0 0 24rpx 24rpx; }
- .nutrition-value { font-size: calc(40rpx * var(--font-scale, 1)); font-weight: 700; color: $brand-primary-deep; display: block; }
- .nutrition-unit {
- font-size: calc(22rpx * var(--font-scale, 1));
- color: $facade-text-muted;
- }
- .nutrition-label {
- font-size: calc(22rpx * var(--font-scale, 1));
- color: $facade-text-body;
- display: block;
- margin-top: 4rpx;
- }
- .action-area {
- padding: 40rpx $uni-space-page;
- }
- .btn-row {
- display: flex;
- gap: 20rpx;
- }
- .btn-secondary {
- flex: 1; padding: 28rpx 0; background: $app-surface;
- border: 2rpx solid $dim-body; border-radius: 999rpx;
- text-align: center; font-size: calc(28rpx * var(--font-scale, 1)); color: $brand-primary-deep;
- }
- .btn-primary {
- flex: 1; padding: 28rpx 0;
- background: linear-gradient(135deg, $dim-body, $dim-body-light);
- border-radius: 999rpx; text-align: center;
- font-size: calc(28rpx * var(--font-scale, 1)); color: $app-surface; font-weight: 600;
- box-shadow: 0 6rpx 20rpx rgba(255, 140, 66, 0.25);
- }
- /* ===== 推荐食材(原「食材查询」页迁移)===== */
- .section-title-bar {
- display: flex;
- flex-direction: column;
- padding: 8rpx 0 16rpx;
- }
- .section-title {
- font-size: calc(34rpx * var(--font-scale, 1));
- font-weight: 700;
- color: $facade-text-strong;
- }
- .section-subtitle {
- font-size: calc(24rpx * var(--font-scale, 1));
- color: $facade-text-muted;
- margin-top: 6rpx;
- }
- .food-section {
- background-color: $app-surface;
- border-radius: 24rpx;
- padding: 20rpx;
- margin-bottom: 32rpx;
- }
- /* 模式切换(排序) */
- .mode-bar {
- display: flex;
- padding: 16rpx 0;
- gap: 20rpx;
- }
- .mode-btn {
- flex: 1;
- padding: 12rpx 0;
- text-align: center;
- border-radius: 24rpx;
- background: $facade-fill-2;
- color: $facade-text-body;
- font-size: calc(26rpx * var(--font-scale, 1));
- }
- .mode-btn.active {
- background: linear-gradient(135deg, $status-success, $status-success-light-3);
- color: $app-surface;
- }
- /* 搜索栏 */
- .search-bar {
- display: flex;
- padding: 20rpx 0;
- }
- .search-input {
- flex: 1;
- border: 1rpx solid $facade-border-soft;
- border-radius: 24rpx;
- padding: 16rpx 24rpx;
- font-size: calc(26rpx * var(--font-scale, 1));
- background-color: $facade-fill-ghost;
- }
- .search-btn {
- margin-left: 20rpx;
- padding: 16rpx 32rpx;
- background-color: $dim-body;
- color: $app-surface;
- border-radius: 24rpx;
- font-size: calc(26rpx * var(--font-scale, 1));
- }
- /* 分类标签 */
- .category-tabs {
- display: flex;
- flex-wrap: wrap;
- gap: 16rpx;
- margin-bottom: 20rpx;
- }
- .tab-item {
- padding: 12rpx 24rpx;
- border: 1rpx solid $facade-border-soft;
- border-radius: 24rpx;
- font-size: calc(24rpx * var(--font-scale, 1));
- color: $facade-text-body;
- background-color: $app-surface;
- }
- .tab-active {
- border-color: $dim-body;
- color: $dim-body;
- background-color: $flat-card;
- }
- /* 筛选栏 */
- .filter-bar {
- display: flex;
- gap: 20rpx;
- margin-bottom: 20rpx;
- }
- .filter-item {
- flex: 1;
- text-align: center;
- padding: 12rpx 8rpx;
- border: 1rpx solid $facade-border-soft;
- border-radius: 24rpx;
- font-size: calc(24rpx * var(--font-scale, 1));
- color: $facade-text-body;
- background-color: $app-surface;
- }
- .filter-active {
- border-color: $mat-green;
- color: $mat-green;
- background-color: $mat-green-tint;
- }
- /* 家庭总览 */
- .family-overview {
- background: $facade-fill-ghost-2;
- border-radius: 16rpx;
- padding: 20rpx;
- margin-bottom: 20rpx;
- }
- .overview-title {
- font-size: calc(28rpx * var(--font-scale, 1));
- font-weight: 600;
- color: $facade-text-strong;
- margin-bottom: 16rpx;
- padding-bottom: 16rpx;
- border-bottom: 1rpx solid $facade-fill;
- }
- .overview-item {
- padding: 16rpx 0;
- border-bottom: 1rpx solid $facade-fill-2;
- }
- .overview-item:last-child {
- border-bottom: none;
- }
- .overview-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 8rpx;
- }
- .overview-detail {
- display: flex;
- flex-direction: column;
- gap: 8rpx;
- }
- .category-label {
- font-size: calc(22rpx * var(--font-scale, 1));
- color: $facade-text-muted;
- }
- .member-scores {
- display: flex;
- flex-wrap: wrap;
- gap: 12rpx;
- }
- .member-score {
- font-size: calc(20rpx * var(--font-scale, 1));
- padding: 4rpx 12rpx;
- border-radius: 16rpx;
- background: $facade-fill-2;
- }
- .score-green {
- color: $status-success;
- background: $mat-green-tint;
- }
- .score-red {
- color: $status-danger;
- background: $status-danger-soft;
- }
- .score-badge {
- min-width: 72rpx;
- text-align: center;
- padding: 4rpx 14rpx;
- border-radius: 16rpx;
- font-size: calc(24rpx * var(--font-scale, 1));
- font-weight: 700;
- color: $app-surface;
- background: linear-gradient(135deg, $dim-body, $dim-body-light);
- }
- .score-badge.good {
- background: linear-gradient(135deg, $status-success, $status-success-light-3);
- }
- .score-badge.bad {
- background: linear-gradient(135deg, $status-danger, $status-danger-deep);
- }
- /* 食材列表 */
- .food-list {
- display: flex;
- flex-direction: column;
- gap: 16rpx;
- }
- .food-card {
- background: $facade-fill-ghost-2;
- border-radius: 16rpx;
- padding: 18rpx 20rpx;
- box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);
- display: flex;
- flex-wrap: wrap;
- align-items: center;
- justify-content: space-between;
- width: 100%;
- box-sizing: border-box;
- }
- /* 健康问卷个性化调整提示条(blocked 红 / warning 黄 / boost 绿;normal/空不渲染) */
- .health-adjust-bar {
- width: 100%;
- margin-bottom: 12rpx;
- }
- .health-adjust-text {
- display: block;
- padding: 8rpx 16rpx;
- border-radius: 8rpx;
- font-size: calc(22rpx * var(--font-scale, 1));
- line-height: 1.4;
- }
- .health-adjust-blocked {
- background: $fortune-0-tint;
- color: $mat-red;
- }
- .health-adjust-warning {
- background: rgba(245, 158, 11, 0.14);
- color: #b45309;
- }
- .health-adjust-boost {
- background: $mat-green-tint;
- color: $mat-green;
- }
- .food-left {
- display: flex;
- align-items: center;
- flex: 1;
- min-width: 0;
- }
- .ingredient-badge {
- width: 36rpx;
- height: 36rpx;
- border-radius: 8rpx;
- background: linear-gradient(135deg, $dim-body, $dim-body-light);
- display: flex;
- align-items: center;
- justify-content: center;
- margin-right: 16rpx;
- flex-shrink: 0;
- }
- .ingredient-badge.good {
- background: linear-gradient(135deg, $status-success, $status-success-light-3);
- }
- .ingredient-badge.bad {
- background: linear-gradient(135deg, $status-danger, $status-danger-deep);
- }
- .ingredient-badge-text {
- font-size: calc(18rpx * var(--font-scale, 1));
- color: $app-surface;
- font-weight: 600;
- }
- .food-info {
- display: flex;
- flex-direction: column;
- flex: 1;
- min-width: 0;
- overflow: hidden;
- }
- .food-name {
- font-size: calc(28rpx * var(--font-scale, 1));
- font-weight: 600;
- color: $text-charcoal;
- display: block;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- .food-meta {
- display: flex;
- flex-wrap: wrap;
- gap: 8rpx;
- margin-top: 6rpx;
- }
- .meta-item {
- flex-shrink: 0;
- font-size: calc(20rpx * var(--font-scale, 1));
- color: $facade-text-faint;
- background: $facade-fill-2;
- padding: 4rpx 14rpx;
- border-radius: 8rpx;
- }
- .food-right {
- display: flex;
- align-items: center;
- gap: 12rpx;
- flex-shrink: 0;
- }
- .score-value {
- font-size: calc(28rpx * var(--font-scale, 1));
- font-weight: 700;
- min-width: 60rpx;
- text-align: right;
- }
- .score-value.good { color: $status-success; }
- .score-value.bad { color: $status-danger; }
- .food-status-badge {
- padding: 6rpx 16rpx;
- border-radius: 24rpx;
- font-size: calc(22rpx * var(--font-scale, 1));
- font-weight: 500;
- }
- .badge-suitable {
- background: $mat-green-tint;
- color: $mat-green;
- }
- .badge-unsuitable {
- background: $fortune-0-tint;
- color: $mat-red;
- }
- /* 健康问卷个性化调整提示条(diet.food.healthAdjustUi · B2) */
- .adjustment-tip {
- margin-top: 12rpx;
- align-self: flex-start;
- max-width: 100%;
- }
- .adjustment-tip-text {
- display: inline-flex;
- align-items: center;
- padding: 6rpx 16rpx;
- border-radius: 10rpx;
- font-size: calc(22rpx * var(--font-scale, 1));
- line-height: 1.5;
- }
- .adjustment-tip-blocked {
- background: $status-danger-soft;
- color: $status-danger;
- }
- .adjustment-tip-warning {
- background: $status-warning-soft;
- color: $status-warning;
- }
- .adjustment-tip-boost {
- background: $status-success-soft;
- color: $status-success;
- }
- /* 空状态 */
- .food-empty-state {
- text-align: center;
- padding: 60rpx 40rpx;
- }
- .food-empty-icon {
- font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
- display: block;
- margin-bottom: 20rpx;
- }
- .food-empty-text {
- font-size: calc(30rpx * var(--font-scale, 1));
- color: $facade-text-strong;
- font-weight: 500;
- display: block;
- margin-bottom: 12rpx;
- }
- .loading-state {
- text-align: center;
- padding: 60rpx 0;
- }
- .loading-text {
- font-size: calc(26rpx * var(--font-scale, 1));
- color: $facade-text-muted;
- }
- /* ===== 共餐人选择弹层(需求7)===== */
- .participant-mask {
- position: fixed;
- left: 0;
- top: 0;
- right: 0;
- bottom: 0;
- background: rgba(0, 0, 0, 0.45);
- z-index: 999;
- display: flex;
- align-items: flex-end;
- }
- .participant-sheet {
- box-sizing: border-box;
- width: 100%;
- background: $app-surface;
- border-radius: 24rpx 24rpx 0 0;
- padding: 32rpx 32rpx 40rpx;
- }
- .participant-sheet-header {
- padding-bottom: 24rpx;
- }
- .participant-sheet-title {
- font-size: calc(32rpx * var(--font-scale, 1));
- font-weight: 600;
- color: $facade-text-strong;
- display: block;
- }
- .participant-sheet-sub {
- font-size: calc(24rpx * var(--font-scale, 1));
- color: $facade-text-muted;
- display: block;
- margin-top: 8rpx;
- }
- .participant-list {
- display: flex;
- flex-wrap: wrap;
- gap: 20rpx;
- padding: 16rpx 0 24rpx;
- max-height: 60vh;
- overflow-y: auto;
- }
- .participant-item {
- box-sizing: border-box;
- position: relative;
- display: flex;
- align-items: center;
- padding: 16rpx 24rpx;
- border: 2rpx solid $facade-fill-2;
- border-radius: 24rpx;
- background: $app-surface;
- min-width: 160rpx;
- }
- .participant-item-selected {
- border-color: $dim-body;
- background: linear-gradient(135deg, $dim-body, $dim-body-light);
- }
- .participant-name {
- font-size: calc(26rpx * var(--font-scale, 1));
- color: $facade-text-body;
- }
- .participant-item-selected .participant-name {
- color: $app-surface;
- font-weight: 600;
- }
- .participant-check {
- position: absolute;
- top: -8rpx;
- right: -8rpx;
- width: 32rpx;
- height: 32rpx;
- border-radius: 50%;
- background-color: $app-surface;
- color: $dim-body;
- display: flex;
- align-items: center;
- justify-content: center;
- z-index: 2;
- }
- .participant-check-icon {
- font-size: calc(20rpx * var(--font-scale, 1));
- font-weight: 700;
- }
- .participant-empty {
- width: 100%;
- padding: 20rpx 0;
- text-align: center;
- }
- .participant-empty-text {
- font-size: calc(24rpx * var(--font-scale, 1));
- color: $facade-text-muted;
- }
- .participant-actions {
- display: flex;
- gap: 20rpx;
- }
- .participant-btn {
- flex: 1;
- padding: 26rpx 0;
- border-radius: 999rpx;
- text-align: center;
- font-size: calc(28rpx * var(--font-scale, 1));
- }
- .participant-btn-cancel {
- background: $facade-fill-2;
- color: $facade-text-body;
- }
- .participant-btn-confirm {
- background: linear-gradient(135deg, $dim-body, $dim-body-light);
- color: $app-surface;
- font-weight: 600;
- }
- </style>
|