recommendation.vue 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868
  1. <template>
  2. <view class="recommendation-page" :style="{ '--font-scale': fontScale }">
  3. <scroll-view class="content" scroll-y :refresher-enabled="true" :refresher-triggered="refreshing" @refresherrefresh="onRefresh" @scrolltolower="loadMore">
  4. <view class="food-section">
  5. <!-- 成员切换条(统一组件 MemberSelector:家庭总览 / 个人 / 各成员) -->
  6. <MemberSelector
  7. variant="minimal"
  8. v-if="memberList.length > 1"
  9. :members="memberList"
  10. :selected-member-id="currentMemberId"
  11. :show-overview="true"
  12. :overview-active="currentView === 'family'"
  13. self-label="我"
  14. @overview="switchView('family')"
  15. @select="switchMember" />
  16. <!-- Tab 切换行:今日食谱 | 适合 | 戒备 | 全部(只读分享模式下隐藏,避免切到空食材区) -->
  17. <view class="filter-bar" v-if="!shareMode">
  18. <view class="filter-item" :class="{'filter-active': currentTab === 'recipe'}" @tap="switchTab('recipe')">
  19. <text>🍽️ 今日食谱</text>
  20. </view>
  21. <view class="filter-item" :class="{'filter-active': currentTab === 'suitable'}" @tap="switchTab('suitable')">
  22. <text>✅ 适合</text>
  23. </view>
  24. <view class="filter-item" :class="{'filter-active': currentTab === 'unsuitable'}" @tap="switchTab('unsuitable')">
  25. <text>❌ 戒备</text>
  26. </view>
  27. <view class="filter-item" :class="{'filter-active': currentTab === 'all'}" @tap="switchTab('all')">
  28. <text>📋 全部</text>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 食材区(适合 / 戒备 / 全部 Tab 内容) -->
  33. <view class="food-section" v-if="currentTab !== 'recipe'">
  34. <!-- 模式切换(仅家庭模式展示) -->
  35. <view class="mode-bar" v-if="familyMode">
  36. <view class="mode-btn" :class="{'active': sortType === 'desc'}" @tap="setSort('desc')">
  37. <text>推荐值 ↓</text>
  38. </view>
  39. <view class="mode-btn" :class="{'active': sortType === 'asc'}" @tap="setSort('asc')">
  40. <text>推荐值 ↑</text>
  41. </view>
  42. </view>
  43. <!-- 搜索栏 -->
  44. <view class="search-bar">
  45. <input class="search-input" placeholder="搜索食材..." v-model="searchQuery" @confirm="searchFood" />
  46. <view class="search-btn" @tap="searchFood">搜索</view>
  47. </view>
  48. <!-- 分类标签 -->
  49. <view class="category-tabs">
  50. <view class="tab-item" :class="{'tab-active': activeCategory === 'all'}" @tap="switchCategory('all')">
  51. <text>全部</text>
  52. </view>
  53. <view class="tab-item" :class="{'tab-active': activeCategory === '蔬菜'}" @tap="switchCategory('蔬菜')">
  54. <text>蔬菜</text>
  55. </view>
  56. <view class="tab-item" :class="{'tab-active': activeCategory === '水果'}" @tap="switchCategory('水果')">
  57. <text>水果</text>
  58. </view>
  59. <view class="tab-item" :class="{'tab-active': activeCategory === '肉禽'}" @tap="switchCategory('肉禽')">
  60. <text>肉禽</text>
  61. </view>
  62. <view class="tab-item" :class="{'tab-active': activeCategory === '水产'}" @tap="switchCategory('水产')">
  63. <text>水产</text>
  64. </view>
  65. <view class="tab-item" :class="{'tab-active': activeCategory === '谷物'}" @tap="switchCategory('谷物')">
  66. <text>谷物</text>
  67. </view>
  68. <view class="tab-item" :class="{'tab-active': activeCategory === '蛋奶'}" @tap="switchCategory('蛋奶')">
  69. <text>蛋奶</text>
  70. </view>
  71. </view>
  72. <!-- 家庭总览(有一人戒备取全员最低值,全员适合取平均值) -->
  73. <view class="family-overview" v-if="currentView === 'family' && familyOverview && familyOverview.length > 0">
  74. <view class="overview-title">
  75. <text>🏠 家庭推荐概况(共 {{ familyMembers.length }} 人 · 一人戒备取最低,全员适合取平均)</text>
  76. </view>
  77. <view class="overview-item" v-for="(item, idx) in familyOverview" :key="idx">
  78. <view class="overview-header">
  79. <text class="food-name">{{ item.name }}</text>
  80. <view class="score-badge" :class="item.color">
  81. <text>{{ item.score }}</text>
  82. </view>
  83. </view>
  84. <view class="overview-detail">
  85. <text class="category-label">{{ item.category }}</text>
  86. <view class="member-scores">
  87. <text v-for="(s, mi) in item.memberScores" :key="mi"
  88. class="member-score"
  89. :class="s.score >= 0 ? 'score-green' : 'score-red'">
  90. {{ s.name }}:{{ s.score >= 0 ? '+' : '' }}{{ s.score }}
  91. </text>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. <!-- 食材列表 -->
  97. <view class="food-list" v-if="currentView === 'personal'">
  98. <view class="food-card" v-for="(item, idx) in pagedFoods" :key="getFoodKey(item, idx)">
  99. <!-- 健康问卷个性化调整提示条:blocked 红 / warning 黄 / boost 绿(normal/空不渲染) -->
  100. <view v-if="item.adjustment === 'blocked'" class="health-adjust-bar">
  101. <text class="health-adjust-text health-adjust-blocked">⚠ 健康问卷不建议:{{ item.adjustmentReason }}</text>
  102. </view>
  103. <view v-else-if="item.adjustment === 'warning'" class="health-adjust-bar">
  104. <text class="health-adjust-text health-adjust-warning">注意:{{ item.adjustmentReason }}</text>
  105. </view>
  106. <view v-else-if="item.adjustment === 'boost'" class="health-adjust-bar">
  107. <text class="health-adjust-text health-adjust-boost">✓ 符合饮食习惯偏好</text>
  108. </view>
  109. <view class="food-left">
  110. <view class="ingredient-badge" :class="item.scoreClass">
  111. <text class="ingredient-badge-text">{{ idx + 1 }}</text>
  112. </view>
  113. <view class="food-info">
  114. <text class="food-name">{{ item.name }}</text>
  115. <view class="food-meta" v-if="item.category">
  116. <text class="meta-item">{{ item.category }}</text>
  117. </view>
  118. </view>
  119. </view>
  120. <view class="food-right">
  121. <text class="score-value" :class="item.scoreClass">{{ item.score || '--' }}</text>
  122. <view class="food-status-badge" :class="'badge-' + item.status">
  123. <text>{{ item.statusText }}</text>
  124. </view>
  125. </view>
  126. <!-- 健康问卷个性化调整提示条(diet.food.healthAdjustUi · B2):blocked 红条 / warning 黄条 / boost 绿条,normal 或缺失不渲染 -->
  127. <view class="adjustment-tip" v-if="item.adjustment === 'blocked'">
  128. <text class="adjustment-tip-text adjustment-tip-blocked">⚠ 健康问卷不建议:{{ item.adjustmentReason }}</text>
  129. </view>
  130. <view class="adjustment-tip" v-if="item.adjustment === 'warning'">
  131. <text class="adjustment-tip-text adjustment-tip-warning">注意:{{ item.adjustmentReason }}</text>
  132. </view>
  133. <view class="adjustment-tip" v-if="item.adjustment === 'boost'">
  134. <text class="adjustment-tip-text adjustment-tip-boost">✓ 符合饮食习惯偏好</text>
  135. </view>
  136. </view>
  137. </view>
  138. <view class="food-empty-state" v-if="!foodLoading && filteredFoods.length === 0 && currentView === 'personal'">
  139. <text class="food-empty-icon">🥗</text>
  140. <text class="food-empty-text">暂无匹配食材</text>
  141. </view>
  142. <view class="loading-state" v-if="foodLoading">
  143. <text class="loading-text">加载中...</text>
  144. </view>
  145. </view>
  146. <!-- 今日食谱区(recipe Tab 内容) -->
  147. <view v-if="currentTab === 'recipe'">
  148. <!-- 局部加载态:切换视角 / 刷新期间先清空旧数据,不残留上一视角食谱(AC-36,不整页遮罩) -->
  149. <view class="recipe-loading" v-if="recipeLoading">
  150. <text class="recipe-loading-text">正在加载今日食谱...</text>
  151. </view>
  152. <!-- 失败态:接口异常 → 明确提示 + 重试入口,文案与空态区分(AC-16 / AC-38);只读分享模式下文案改分享语义 -->
  153. <view class="empty-state" v-else-if="recipeError">
  154. <view class="empty-icon-wrap"><text class="empty-icon">⚠️</text></view>
  155. <text class="empty-title">{{ shareMode ? '菜谱加载失败' : '今日食谱加载失败' }}</text>
  156. <text class="empty-sub">{{ recipeError }}</text>
  157. <view class="generate-btn" @tap="retryRecommendation">
  158. <text>点击重试</text>
  159. </view>
  160. </view>
  161. <!-- 无推荐状态 / 视角级空态(AC-04;不回退展示其它视角食谱) -->
  162. <view class="empty-state" v-else-if="!recommendation">
  163. <view class="empty-icon-wrap"><text class="empty-icon">🍽️</text></view>
  164. <block v-if="shareMode">
  165. <text class="empty-title">菜谱不存在或已失效</text>
  166. <text class="empty-sub">分享链接可能已过期</text>
  167. </block>
  168. <block v-else>
  169. <text class="empty-title">今日菜单空着</text>
  170. <text class="empty-sub">点击生成今日三餐食谱</text>
  171. <view class="generate-btn" @tap="generateRecipe">
  172. <text>生成食谱</text>
  173. </view>
  174. </block>
  175. </view>
  176. <!-- 整份空态:所有餐次菜数为 0(删除后可能出现,AC-35);只读分享模式下隐藏重新生成入口 -->
  177. <view class="empty-state" v-else-if="allMealsEmpty">
  178. <view class="empty-icon-wrap"><text class="empty-icon">🍽️</text></view>
  179. <text class="empty-title">今天的菜品都删完啦</text>
  180. <text class="empty-sub" v-if="!shareMode">点击重新生成今日三餐食谱</text>
  181. <view class="generate-btn" @tap="regenerate" v-if="!shareMode">
  182. <text>重新生成</text>
  183. </view>
  184. </view>
  185. <!-- 有推荐状态 -->
  186. <view v-else>
  187. <!-- 日期和状态 -->
  188. <view class="card header-card">
  189. <view class="card-accent"></view>
  190. <view class="card-body">
  191. <text class="date-text">{{ recommendation.date }}</text>
  192. <view class="status-badge" :class="'status-' + recommendation.status">
  193. <text>{{ statusText }}</text>
  194. </view>
  195. </view>
  196. </view>
  197. <!-- 分享操作区:只读分享模式显示"这是朋友分享的菜谱",本人模式显示分享按钮 -->
  198. <view class="share-bar">
  199. <text v-if="shareMode" class="share-mode-tip">📤 朋友分享的今日食谱</text>
  200. <view v-else class="share-btn-wrap">
  201. <button class="share-btn" open-type="share">
  202. <text class="share-btn-text">📤 分享菜谱</text>
  203. </button>
  204. </view>
  205. </view>
  206. <!-- 菜品列表 -->
  207. <view class="meal-section" v-for="(meal, index) in meals" :key="index">
  208. <view class="meal-header">
  209. <view class="meal-icon-wrap" :class="'meal-icon-' + meal.type">
  210. <text class="meal-icon">{{ meal.icon }}</text>
  211. </view>
  212. <text class="meal-name">{{ meal.name }}</text>
  213. <text class="meal-count">{{ meal.participants }} 人份</text>
  214. <!-- D2① 只读状态提示:当前 N 菜 1 汤 / 未达标准,不静默补菜 -->
  215. <text class="meal-standard" v-if="dishStandard(meal)">{{ dishStandard(meal) }}</text>
  216. </view>
  217. <view class="dish-list">
  218. <!-- 餐次级空态:某餐菜数删至 0(AC-34),提供「重新生成」入口 -->
  219. <view class="meal-empty" v-if="meal.dishes.length === 0">
  220. <text class="meal-empty-text">本餐暂无菜品</text>
  221. <view class="meal-empty-btn" @tap="regenerate"><text>重新生成</text></view>
  222. </view>
  223. <view class="dish-item" v-for="(dish, dIndex) in meal.dishes" :key="dIndex">
  224. <view class="dish-header">
  225. <text class="dish-name">{{ dish.name }}</text>
  226. <text class="dish-cal">{{ dish.calories }} kcal</text>
  227. </view>
  228. <view class="dish-ingredients">
  229. <text class="ingredient-tag" v-for="(ing, iIndex) in dish.ingredients" :key="iIndex">
  230. {{ ing.name }} {{ ing.amount }}g
  231. </text>
  232. </view>
  233. <view class="dish-method">
  234. <text class="method-text">🍳 {{ dish.method }}</text>
  235. </view>
  236. <!-- D1①:收敛为单一「🗑 删除」;按钮组合由 dishActions 数据位驱动,便于回退 -->
  237. <view class="dish-actions" v-if="dishActions === 'delete-only' && !shareMode">
  238. <view class="action-btn delete-btn"
  239. :class="{'action-btn-disabled': isDeleting(meal.name, dIndex)}"
  240. @tap="deleteDish(meal.name, dIndex)">🗑 删除</view>
  241. </view>
  242. </view>
  243. </view>
  244. </view>
  245. <!-- 营养汇总 -->
  246. <view class="card nutrition-card">
  247. <view class="card-accent"></view>
  248. <view class="card-body">
  249. <text class="card-title">今日营养汇总</text>
  250. <view class="nutrition-grid">
  251. <view class="nutrition-item">
  252. <text class="nutrition-value">{{ summary.calories }}</text>
  253. <text class="nutrition-unit">kcal</text>
  254. <text class="nutrition-label">热量</text>
  255. </view>
  256. <view class="nutrition-item">
  257. <text class="nutrition-value">{{ summary.protein }}</text>
  258. <text class="nutrition-unit">g</text>
  259. <text class="nutrition-label">蛋白质</text>
  260. </view>
  261. <view class="nutrition-item">
  262. <text class="nutrition-value">{{ summary.carbs }}</text>
  263. <text class="nutrition-unit">g</text>
  264. <text class="nutrition-label">碳水</text>
  265. </view>
  266. <view class="nutrition-item">
  267. <text class="nutrition-value">{{ summary.fat }}</text>
  268. <text class="nutrition-unit">g</text>
  269. <text class="nutrition-label">脂肪</text>
  270. </view>
  271. </view>
  272. </view>
  273. </view>
  274. <!-- 操作按钮:只读分享模式下隐藏本人操作 -->
  275. <view class="action-area" v-if="!shareMode">
  276. <view class="btn-row">
  277. <view class="btn-secondary" @tap="regenerate">重新生成</view>
  278. <view class="btn-primary" @tap="completeRecipe" v-if="recommendation.status !== 'completed'">
  279. 标记完成
  280. </view>
  281. </view>
  282. </view>
  283. </view>
  284. </view>
  285. </scroll-view>
  286. <!-- 共餐人选择弹层(需求7:家庭总览「生成食谱」先选共餐人,确认后生成) -->
  287. <view class="participant-mask" v-if="showParticipantPicker" @tap="cancelParticipants">
  288. <view class="participant-sheet" @tap.stop>
  289. <view class="participant-sheet-header">
  290. <text class="participant-sheet-title">选择共餐人</text>
  291. <text class="participant-sheet-sub">为今天的食谱挑选一起用餐的家庭成员</text>
  292. </view>
  293. <view class="participant-list">
  294. <view class="participant-item" v-for="member in pendingParticipantOptions" :key="member.id"
  295. :class="{'participant-item-selected': member.selected}"
  296. @tap="toggleParticipant(member)">
  297. <view class="participant-check" v-if="member.selected">
  298. <text class="participant-check-icon">✓</text>
  299. </view>
  300. <text class="participant-name">{{ member.nickname }}</text>
  301. </view>
  302. <view class="participant-empty" v-if="pendingParticipantOptions.length === 0">
  303. <text class="participant-empty-text">暂无家庭成员可选</text>
  304. </view>
  305. </view>
  306. <view class="participant-actions">
  307. <view class="participant-btn participant-btn-cancel" @tap="cancelParticipants">
  308. <text>取消</text>
  309. </view>
  310. <view class="participant-btn participant-btn-confirm" @tap="confirmParticipants">
  311. <text>确认生成({{ pendingParticipantIds.length }} 人)</text>
  312. </view>
  313. </view>
  314. </view>
  315. </view>
  316. </view>
  317. </template>
  318. <script>
  319. import { getDietRecommendation, generateDietRecommendation, completeDietRecommendation, regenerateDietRecommendation, updateDietRecommendation, getShareDietRecommendation } from '@/utils/api.js'
  320. import config from '@/config.js'
  321. import MemberSelector from '@/components/MemberSelector.vue'
  322. import { memberIdOf } from '@/utils/memberNormalize.js'
  323. import shareMixin from '@/components/share-mixin.js'
  324. import fontScaleMixin from '@/mixins/font-scale.js'
  325. export default {
  326. mixins: [fontScaleMixin, shareMixin],
  327. components: { MemberSelector },
  328. data() {
  329. return {
  330. recommendation: null,
  331. meals: [],
  332. summary: {},
  333. loading: false,
  334. // ===== 推荐食材(原「食材查询」页迁移)=====
  335. searchQuery: '',
  336. activeCategory: 'all',
  337. filterType: 'suitable',
  338. sortType: 'desc',
  339. currentView: 'personal',
  340. currentTab: 'recipe',
  341. visibleCount: 20,
  342. memberSelectLocked: false,
  343. allFoods: [],
  344. familyData: null,
  345. familyMembers: [],
  346. familyOverview: [],
  347. currentMemberId: null,
  348. memberList: [],
  349. foodLoading: false,
  350. refreshing: false,
  351. // ===== 共餐人选择(需求7:家庭总览生成食谱先选共餐人)=====
  352. showParticipantPicker: false,
  353. pendingParticipantIds: [],
  354. // ===== 今日食谱视角隔离 / 删除交互 / 空·加载·失败三态(本轮增量)=====
  355. recipeLoading: false,
  356. recipeError: '',
  357. deleting: false,
  358. deletingKey: '',
  359. // D1① 可回退数据位:'delete-only'(当前)/ 'replace-and-delete'(备选,改此值 + 模板分支即可)
  360. dishActions: 'delete-only',
  361. // ===== 菜谱分享(id 参数进入只读模式,跨家庭可看,跳过本人成员/家庭/食材数据加载)=====
  362. shareMode: false,
  363. sharedId: null
  364. }
  365. },
  366. computed: {
  367. statusText: function() {
  368. var map = {
  369. 'pending': '待确认',
  370. 'accepted': '已接受',
  371. 'completed': '已完成'
  372. }
  373. return map[this.recommendation && this.recommendation.status] || '待确认'
  374. },
  375. familyMode: function() {
  376. return this.currentView === 'family'
  377. },
  378. filteredFoods: function() {
  379. var self = this
  380. var result = self.currentView === 'family'
  381. ? self.familyOverview
  382. : self.allFoods
  383. // 分类筛选(食材分类为中文,用关键词集合匹配不同数据源的分类命名)
  384. if (self.activeCategory !== 'all') {
  385. var keywords = self.getCategoryKeywords(self.activeCategory)
  386. result = result.filter(function(f) {
  387. if (!f.category) return false
  388. for (var ki = 0; ki < keywords.length; ki++) {
  389. if (f.category.indexOf(keywords[ki]) !== -1) return true
  390. }
  391. return false
  392. })
  393. }
  394. // 搜索筛选
  395. if (self.searchQuery) {
  396. result = result.filter(function(f) {
  397. return (f.name && f.name.indexOf(self.searchQuery) !== -1) ||
  398. (f.category && f.category.indexOf(self.searchQuery) !== -1)
  399. })
  400. }
  401. // 适合/戒备筛选(戒备 = 推荐指数 < 0)
  402. if (self.filterType === 'suitable') {
  403. result = result.filter(function(f) {
  404. return f.score >= 0
  405. })
  406. } else if (self.filterType === 'unsuitable') {
  407. result = result.filter(function(f) {
  408. return f.score < 0
  409. })
  410. }
  411. // 排序(戒备模式默认升序,见 setFilter)
  412. var sortFn = self.sortType === 'asc'
  413. ? function(a, b) { return (a.score || 0) - (b.score || 0) }
  414. : function(a, b) { return (b.score || 0) - (a.score || 0) }
  415. // 健康问卷个性化调整(B3):suitable Tab 中 blocked 项整体排到列表末尾(保持可见不置顶;组内各按既有分值序)
  416. if (self.filterType === 'suitable') {
  417. var nonBlocked = []
  418. var blocked = []
  419. result.forEach(function(f) {
  420. if (f.adjustment === 'blocked') {
  421. blocked.push(f)
  422. } else {
  423. nonBlocked.push(f)
  424. }
  425. })
  426. result = nonBlocked.slice().sort(sortFn).concat(blocked.slice().sort(sortFn))
  427. } else {
  428. result = result.slice().sort(sortFn)
  429. }
  430. // 健康问卷个性化调整分组(diet.food.healthAdjustUi · B3):suitable Tab 中 blocked 项整体排到列表末尾
  431. // (保持可见但不置顶,组内仍按既有分值排序,stable 分组;unsuitable / all 位置不变、仅带提示条)
  432. if (self.filterType === 'suitable') {
  433. result = result.filter(function(f) { return f.adjustment !== 'blocked' })
  434. .concat(result.filter(function(f) { return f.adjustment === 'blocked' }))
  435. }
  436. return result
  437. },
  438. pagedFoods: function() {
  439. return this.filteredFoods.slice(0, this.visibleCount)
  440. },
  441. // 整份食谱空态:所有餐次菜数为 0(AC-35)
  442. allMealsEmpty: function() {
  443. var meals = this.meals || []
  444. if (meals.length === 0) return true
  445. for (var i = 0; i < meals.length; i++) {
  446. if (meals[i].dishes && meals[i].dishes.length > 0) return false
  447. }
  448. return true
  449. },
  450. // 共餐人选择弹层列表(原始 memberList 归一化为 {id, nickname, selected},避免模板内方法调用)
  451. pendingParticipantOptions: function() {
  452. var self = this
  453. var ids = self.pendingParticipantIds || []
  454. return (self.memberList || []).map(function(m) {
  455. var id = memberIdOf(m)
  456. return {
  457. id: id,
  458. nickname: m.nickname || m.roleLabel || '成员',
  459. selected: ids.indexOf(id) >= 0
  460. }
  461. })
  462. }
  463. },
  464. onLoad: function(options) {
  465. var opts = options || {}
  466. this.currentMemberId = opts.memberId ? parseInt(opts.memberId) : null
  467. // 菜谱分享只读模式:带 id 进入 → 按 id 加载该份菜谱(跨家庭可看),跳过本人成员/家庭/食材数据加载
  468. this.shareMode = !!(opts.id && !opts.memberId)
  469. if (this.shareMode) {
  470. this.sharedId = parseInt(opts.id)
  471. this.loadSharedRecommendation(this.sharedId)
  472. return
  473. }
  474. this.loadRecommendation()
  475. this.loadMembers()
  476. this.loadFamilyData()
  477. this.loadFoods()
  478. },
  479. onShow: function() {
  480. if (this.shareMode) return
  481. this.loadRecommendation()
  482. },
  483. methods: {
  484. goBack: function() {
  485. uni.navigateBack()
  486. },
  487. // 按当前视角加载今日食谱:view_key 同源、局部 loading 先清空防串数据(AC-01/03/09/36)
  488. loadRecommendation: function() {
  489. var self = this
  490. var viewKey = self.buildViewKey()
  491. self.recipeError = ''
  492. // 视角尚未就绪(首次 onLoad 时 loadRecommendation 先于异步 loadMembers,personal 且无 currentMemberId):
  493. // 不发请求、清空残留,由 loadMembers 成功回调补发一次
  494. if (!viewKey) {
  495. self.recipeLoading = false
  496. self.recommendation = null
  497. self.meals = []
  498. self.summary = {}
  499. return Promise.resolve()
  500. }
  501. var today = self.formatDate(new Date())
  502. self.recipeLoading = true
  503. self.recommendation = null
  504. self.meals = []
  505. self.summary = {}
  506. return getDietRecommendation({ date: today, view_key: viewKey }).then(function(res) {
  507. self.recipeLoading = false
  508. var d = res && res.data
  509. if (d && d.id) {
  510. self.recommendation = d
  511. self.parseMenu(d.menu)
  512. var ns = d.nutritionSummary
  513. self.summary = ns ? (typeof ns === 'string' ? JSON.parse(ns) : ns) : {}
  514. self.setShareInfo('今日食谱 ' + (d.date || today), '/pages/diet/recommendation?id=' + d.id)
  515. } else {
  516. self.recommendation = null
  517. self.meals = []
  518. self.summary = {}
  519. }
  520. }).catch(function(err) {
  521. self.recipeLoading = false
  522. self.recommendation = null
  523. self.meals = []
  524. self.summary = {}
  525. self.recipeError = (err && err.message) || '加载失败,请重试'
  526. })
  527. },
  528. // 视角键生成(K1 可回退的唯一落点):家庭总览固定 'family';个人/成员 'member:<id>';
  529. // loadMembers 未完成、memberList 为空且无 currentMemberId 时返回 null 且不发请求。
  530. // 后端把 view_key 当不透明字符串,语义全在此方法一处。
  531. buildViewKey: function() {
  532. if (this.currentView === 'family') return 'family'
  533. if (this.currentView === 'personal') {
  534. if (this.currentMemberId !== null && this.currentMemberId !== undefined) {
  535. return 'member:' + this.currentMemberId
  536. }
  537. return null
  538. }
  539. return null
  540. },
  541. // 失败态重试:按当前视角重新加载,不重置用户当前视角
  542. retryRecommendation: function() {
  543. if (this.shareMode) {
  544. this.loadSharedRecommendation(this.sharedId)
  545. return
  546. }
  547. this.loadRecommendation()
  548. },
  549. // 分享只读模式:按 id 加载该份菜谱(后端 getShareDetail,跨家庭可看,无 familyId 归属校验)
  550. loadSharedRecommendation: function(id) {
  551. var self = this
  552. if (!id) return
  553. self.recipeLoading = true
  554. getShareDietRecommendation({ id: id }).then(function(res) {
  555. self.recipeLoading = false
  556. var d = res && res.data
  557. if (d && d.id) {
  558. self.recommendation = d
  559. self.parseMenu(d.menu)
  560. var ns = d.nutritionSummary
  561. self.summary = ns ? (typeof ns === 'string' ? JSON.parse(ns) : ns) : {}
  562. self.setShareInfo('今日食谱 ' + (d.date || ''), '/pages/diet/recommendation?id=' + id)
  563. } else {
  564. self.recipeLoading = false
  565. self.recommendation = null
  566. self.meals = []
  567. self.summary = {}
  568. uni.showToast({ title: (d && d.message) || '菜谱不存在或已失效', icon: 'none' })
  569. }
  570. }).catch(function() {
  571. self.recipeLoading = false
  572. uni.showToast({ title: '加载分享菜谱失败', icon: 'none' })
  573. })
  574. },
  575. parseMenu: function(menuJson) {
  576. try {
  577. var menu = (typeof menuJson === 'string') ? JSON.parse(menuJson || '{}') : (menuJson || {})
  578. this.meals = []
  579. var mealMap = {
  580. 'breakfast': { name: '早餐', icon: '🌅' },
  581. 'lunch': { name: '午餐', icon: '☀️' },
  582. 'dinner': { name: '晚餐', icon: '🌙' }
  583. }
  584. if (menu.meals) {
  585. var self = this
  586. menu.meals.forEach(function(meal) {
  587. var config = mealMap[meal.type] || { name: meal.name || meal.type, icon: '🍽️' }
  588. var dishes = (meal.dishes || []).map(function(dish) {
  589. var ing = (dish.ingredients || []).map(function(item) {
  590. return { name: item.name, amount: item.amount || item.grams || 0 }
  591. })
  592. return {
  593. name: dish.name,
  594. // 汤/菜可识别:dish.type = dish|soup,存量无 type 时默认 'dish'(AC-25)
  595. type: dish.type || 'dish',
  596. calories: dish.calories || (dish.nutrition && dish.nutrition.calories) || 0,
  597. ingredients: ing,
  598. method: dish.method || dish.cooking_method || ''
  599. }
  600. })
  601. self.meals.push({
  602. name: config.name,
  603. icon: config.icon,
  604. type: meal.type,
  605. participants: meal.participants || 1,
  606. dishes: dishes
  607. })
  608. })
  609. }
  610. } catch (e) {
  611. console.error('解析菜单失败', e)
  612. }
  613. },
  614. generateRecipe: function() {
  615. var self = this
  616. // 家庭总览:先弹共餐人多选,确认后再生成(需求7)
  617. if (self.currentView === 'family') {
  618. self.openParticipantPicker()
  619. return
  620. }
  621. // 个人/成员:只对当前选中人生成(participant_member_ids 只传当前成员)
  622. self.loading = true
  623. var participantIds = self.currentMemberId ? [self.currentMemberId] : []
  624. uni.showLoading({ title: '正在生成食谱...' })
  625. return generateDietRecommendation({
  626. date: self.formatDate(new Date()),
  627. meal_type: 'all',
  628. participant_member_ids: JSON.stringify(participantIds),
  629. view_key: self.buildViewKey()
  630. }).then(function(res) {
  631. self.loading = false
  632. uni.hideLoading()
  633. if (res && res.data && res.data.id) {
  634. uni.showToast({ title: '食谱生成成功', icon: 'success' })
  635. self.loadRecommendation()
  636. } else {
  637. uni.showToast({ title: (res && res.message) || '生成失败', icon: 'none' })
  638. }
  639. }).catch(function() {
  640. self.loading = false
  641. uni.hideLoading()
  642. uni.showToast({ title: '生成失败', icon: 'none' })
  643. })
  644. },
  645. // 打开共餐人多选弹层(默认勾选全部家庭成员)
  646. openParticipantPicker: function() {
  647. var self = this
  648. var ids = []
  649. var members = self.memberList || []
  650. for (var i = 0; i < members.length; i++) {
  651. var id = memberIdOf(members[i])
  652. if (id !== null && id !== undefined && ids.indexOf(id) < 0) ids.push(id)
  653. }
  654. self.pendingParticipantIds = ids
  655. self.showParticipantPicker = true
  656. },
  657. // 多选切换共餐人
  658. toggleParticipant: function(member) {
  659. var self = this
  660. if (!member) return
  661. var id = (member.id !== null && member.id !== undefined) ? member.id : memberIdOf(member)
  662. if (id === null || id === undefined) return
  663. var ids = (self.pendingParticipantIds || []).slice()
  664. var idx = ids.indexOf(id)
  665. if (idx >= 0) {
  666. ids.splice(idx, 1)
  667. } else {
  668. ids.push(id)
  669. }
  670. self.pendingParticipantIds = ids
  671. },
  672. // 确认共餐人 → 生成食谱(participant_member_ids = 所选共餐人)
  673. confirmParticipants: function() {
  674. var self = this
  675. self.showParticipantPicker = false
  676. self.loading = true
  677. generateDietRecommendation({
  678. date: self.formatDate(new Date()),
  679. meal_type: 'all',
  680. participant_member_ids: JSON.stringify(self.pendingParticipantIds || []),
  681. view_key: self.buildViewKey()
  682. }).then(function(res) {
  683. self.loading = false
  684. if (res && res.data && res.data.id) {
  685. uni.showToast({ title: '食谱生成成功', icon: 'success' })
  686. self.loadRecommendation()
  687. } else {
  688. uni.showToast({ title: (res && res.message) || '生成失败', icon: 'none' })
  689. }
  690. }).catch(function() {
  691. self.loading = false
  692. uni.showToast({ title: '生成失败', icon: 'none' })
  693. })
  694. },
  695. // 取消共餐人选择
  696. cancelParticipants: function() {
  697. this.showParticipantPicker = false
  698. this.pendingParticipantIds = []
  699. },
  700. // D2① 只读菜数状态:当前 X 菜 Y 汤 / 未达标准;与删除逻辑解耦,绝不触发补菜请求
  701. dishStandard: function(meal) {
  702. if (!meal || (meal.type !== 'lunch' && meal.type !== 'dinner')) return ''
  703. var dishes = meal.dishes || []
  704. var mainCount = 0
  705. var soupCount = 0
  706. for (var i = 0; i < dishes.length; i++) {
  707. if (dishes[i].type === 'soup') soupCount += 1
  708. else mainCount += 1
  709. }
  710. var n = meal.participants || 1
  711. var expected = 4 + Math.max(0, n - 3)
  712. var reached = mainCount >= expected && soupCount >= 1
  713. var text = '当前 ' + mainCount + ' 菜 ' + soupCount + ' 汤'
  714. return reached ? (text + ' · 达标') : (text + ' / 未达标准')
  715. },
  716. // 防重复点击:删除中的那一道菜按钮禁用(AC-37)
  717. isDeleting: function(mealName, dishIndex) {
  718. return this.deleting && this.deletingKey === (mealName + ':' + dishIndex)
  719. },
  720. // 从 this.meals 组装「移除目标菜」后的整份 menu_json(不含 icon 等纯展示字段,避免结构漂移)
  721. buildMenuPayload: function(mealName, dishIndex) {
  722. var payloadMeals = []
  723. var meals = this.meals || []
  724. for (var i = 0; i < meals.length; i++) {
  725. var meal = meals[i]
  726. var dishes = []
  727. var src = meal.dishes || []
  728. for (var j = 0; j < src.length; j++) {
  729. if (meal.name === mealName && j === dishIndex) continue
  730. var d = src[j]
  731. var ings = []
  732. var srcIng = d.ingredients || []
  733. for (var k = 0; k < srcIng.length; k++) {
  734. ings.push({ name: srcIng[k].name, amount: srcIng[k].amount || 0 })
  735. }
  736. dishes.push({
  737. name: d.name,
  738. type: d.type || 'dish',
  739. calories: d.calories || 0,
  740. ingredients: ings,
  741. method: d.method || ''
  742. })
  743. }
  744. payloadMeals.push({
  745. type: meal.type,
  746. name: meal.name,
  747. participants: meal.participants || 1,
  748. dishes: dishes
  749. })
  750. }
  751. return JSON.stringify({ meals: payloadMeals })
  752. },
  753. // D1① 单一主操作「🗑 删除」:复用 POST /api/diet/recommendation/update 整份覆盖。
  754. // 删除与补菜完全解耦(不调任何补菜 / 重新生成接口);失败保留原数据可重试(AC-13/15/16/18)
  755. deleteDish: function(mealName, dishIndex) {
  756. var self = this
  757. if (self.deleting) return
  758. if (!self.recommendation || !self.recommendation.id) return
  759. var targetMeal = null
  760. for (var i = 0; i < (self.meals || []).length; i++) {
  761. if (self.meals[i].name === mealName) {
  762. targetMeal = self.meals[i]
  763. break
  764. }
  765. }
  766. if (!targetMeal || !targetMeal.dishes || dishIndex < 0 || dishIndex >= targetMeal.dishes.length) return
  767. self.deleting = true
  768. self.deletingKey = mealName + ':' + dishIndex
  769. uni.showLoading({ title: '删除中...' })
  770. var payload = self.buildMenuPayload(mealName, dishIndex)
  771. return updateDietRecommendation({ id: self.recommendation.id, menu_json: payload }).then(function(res) {
  772. self.deleting = false
  773. self.deletingKey = ''
  774. uni.hideLoading()
  775. if (!res) {
  776. uni.showToast({ title: '删除失败,请重试', icon: 'none' })
  777. return
  778. }
  779. targetMeal.dishes.splice(dishIndex, 1)
  780. uni.showToast({ title: '已删除', icon: 'success' })
  781. }).catch(function(err) {
  782. self.deleting = false
  783. self.deletingKey = ''
  784. uni.hideLoading()
  785. uni.showToast({ title: (err && err.message) || '删除失败,请重试', icon: 'none' })
  786. })
  787. },
  788. // D1 可回退入口:当前 dishActions='delete-only' 时模板不渲染,与 deleteDish 完全独立、互不引用。
  789. // 若产品改选「双按钮」,只需把 dishActions 切为 'replace-and-delete' 并在模板补分支。
  790. replaceDish: function(mealName, dishIndex) {
  791. uni.showToast({ title: '该功能已下线,请用「删除」或「重新生成」', icon: 'none' })
  792. },
  793. regenerate: function() {
  794. var self = this
  795. if (!self.recommendation || !self.recommendation.id) return
  796. var regData = { id: self.recommendation.id }
  797. uni.showLoading({ title: '重新生成中...' })
  798. regenerateDietRecommendation(regData).then(function(res) {
  799. uni.hideLoading()
  800. if (res && res.data && res.data.id) {
  801. self.loadRecommendation()
  802. } else {
  803. uni.showToast({ title: (res && res.message) || '重新生成失败', icon: 'none' })
  804. }
  805. }).catch(function() {
  806. uni.hideLoading()
  807. uni.showToast({ title: '重新生成失败', icon: 'none' })
  808. })
  809. },
  810. completeRecipe: function() {
  811. var self = this
  812. if (!self.recommendation) return
  813. completeDietRecommendation({ id: self.recommendation.id }).then(function() {
  814. uni.showToast({ title: '已标记完成', icon: 'success' })
  815. self.loadRecommendation()
  816. })
  817. },
  818. formatDate: function(date) {
  819. var d = date
  820. var m = (d.getMonth() + 1).toString().padStart(2, '0')
  821. var day = d.getDate().toString().padStart(2, '0')
  822. return d.getFullYear() + '-' + m + '-' + day
  823. },
  824. // ===== 推荐食材(原「食材查询」页迁移)=====
  825. getFoodKey: function(item, idx) {
  826. return item.id || idx
  827. },
  828. loadMembers: function() {
  829. var self = this
  830. var token = uni.getStorageSync('token')
  831. if (!token) return
  832. uni.request({
  833. // config 在契约测试桩下可能为 undefined(stub 仅提供 default 键),防御性取址
  834. url: ((config && config.API_BASE_URL) || '') + '/api/food/recommendation/members',
  835. method: 'POST',
  836. header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
  837. success: function(res) {
  838. if (res.data && res.data.code === 200 && res.data.data) {
  839. self.memberList = res.data.data
  840. // 默认选中「个人」= isSelf 行(统一身份键 familyMemberId,不再用 userId)。
  841. // 仅限首次 onLoad:切到家庭总览(switchView('family') 置 memberSelectLocked)后,
  842. // loadMembers 不得再自动默认选「个人」,个人/成员 chip 保持不高亮。
  843. if (!self.memberSelectLocked && !self.currentMemberId && self.memberList.length > 0) {
  844. var defaultMember = self.getSelfRow() || self.memberList[0]
  845. self.currentMemberId = memberIdOf(defaultMember)
  846. }
  847. // onLoad 先 loadRecommendation 后异步 loadMembers:此时个人视角键才就绪,补发一次(AC-01/10)
  848. self.loadRecommendation()
  849. }
  850. }
  851. })
  852. },
  853. loadFoods: function() {
  854. var self = this
  855. var token = uni.getStorageSync('token')
  856. if (!token) return
  857. self.foodLoading = true
  858. var url = config.API_BASE_URL + '/api/health/foods'
  859. var data = {}
  860. if (self.currentMemberId) {
  861. data.memberId = self.currentMemberId
  862. }
  863. uni.request({
  864. url: url,
  865. method: 'POST',
  866. data: data,
  867. header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
  868. success: function(res) {
  869. self.foodLoading = false
  870. if (res.data && res.data.code === 200 && res.data.data) {
  871. self.allFoods = res.data.data.map(function(f) {
  872. f.scoreClass = self.getScoreClass(f.score)
  873. f.statusText = self.getStatusText(f.score)
  874. f.status = f.score >= 0 ? 'suitable' : 'unsuitable'
  875. return f
  876. })
  877. }
  878. },
  879. fail: function() {
  880. self.foodLoading = false
  881. }
  882. })
  883. },
  884. loadFamilyData: function() {
  885. var self = this
  886. var token = uni.getStorageSync('token')
  887. if (!token) return
  888. var familyId = uni.getStorageSync('familyId')
  889. if (!familyId) return
  890. uni.request({
  891. url: config.API_BASE_URL + '/api/health/foods/by-family',
  892. method: 'POST',
  893. header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
  894. success: function(res) {
  895. if (res.data && res.data.code === 200 && res.data.data) {
  896. self.familyData = res.data.data
  897. self.familyMembers = Object.keys(res.data.data.byMember || {}).map(function(key) {
  898. return { userId: key, nickname: res.data.data.memberNames[key] || '成员' }
  899. })
  900. // 优先使用后端持久化总览(overview):overviewScore = 分段聚合展示值
  901. // (有成员<0取全员最低值、全员>=0取平均值);旧版后端无该字段时回退 minIndexScore
  902. if (res.data.data.overview && res.data.data.overview.length > 0) {
  903. self.familyOverview = res.data.data.overview.map(function(o) {
  904. var score = (o.overviewScore !== undefined && o.overviewScore !== null)
  905. ? o.overviewScore : o.minIndexScore
  906. return {
  907. id: o.foodId,
  908. name: o.foodName,
  909. category: o.category,
  910. score: score,
  911. scoreClass: self.getScoreClass(score),
  912. color: self.getScoreClass(score),
  913. statusText: self.getStatusText(score),
  914. status: score >= 0 ? 'suitable' : 'unsuitable',
  915. aggregateRule: o.aggregateRule || '',
  916. minScore: o.minIndexScore,
  917. memberCount: o.memberCount || 0,
  918. memberScores: (o.memberScores || []).map(function(s) {
  919. return { name: s.nickname || '', score: s.score }
  920. })
  921. }
  922. })
  923. } else {
  924. // 后端未返回 overview 时的降级路径:前端按同一分段聚合口径计算
  925. self.buildFamilyOverview(res.data.data.total || res.data.data.totalList, res.data.data.byMember, res.data.data.memberNames)
  926. }
  927. }
  928. }
  929. })
  930. },
  931. buildFamilyOverview: function(totalList, byMember, memberNames) {
  932. var self = this
  933. var overview = []
  934. var list = totalList || []
  935. for (var i = 0; i < list.length; i++) {
  936. var food = list[i]
  937. var memberScores = []
  938. for (var j = 0; j < self.familyMembers.length; j++) {
  939. var member = self.familyMembers[j]
  940. var memberFoods = byMember[member.userId]
  941. if (memberFoods) {
  942. for (var k = 0; k < memberFoods.length; k++) {
  943. if (memberFoods[k].foodId === food.id) {
  944. var score = memberFoods[k].indexScore || 0
  945. memberScores.push({ name: member.nickname, score: score })
  946. break
  947. }
  948. }
  949. }
  950. }
  951. // 降级路径:与后端同口径 —— 有人 < 0 取全员最低值,全员 >= 0 取平均值(四舍五入)
  952. if (memberScores.length > 0) {
  953. var minScore = memberScores[0].score
  954. var sum = 0
  955. var hasNegative = false
  956. for (var mi = 0; mi < memberScores.length; mi++) {
  957. var s = memberScores[mi].score
  958. if (s < minScore) minScore = s
  959. sum += s
  960. if (s < 0) hasNegative = true
  961. }
  962. var score = hasNegative ? minScore : Math.round(sum / memberScores.length)
  963. overview.push({
  964. id: food.id,
  965. name: food.name,
  966. category: food.category,
  967. score: score,
  968. scoreClass: self.getScoreClass(score),
  969. color: self.getScoreClass(score),
  970. statusText: self.getStatusText(score),
  971. status: score >= 0 ? 'suitable' : 'unsuitable',
  972. aggregateRule: hasNegative ? 'MIN_NEGATIVE' : 'AVG_POSITIVE',
  973. minScore: minScore,
  974. memberCount: memberScores.length,
  975. memberScores: memberScores
  976. })
  977. }
  978. }
  979. // 按总览展示值排序(从高到低)
  980. overview.sort(function(a, b) {
  981. return b.score - a.score
  982. })
  983. self.familyOverview = overview
  984. },
  985. getScoreClass: function(score) {
  986. if (score === undefined || score === null) return 'neutral'
  987. if (score >= 0) return 'good'
  988. return 'bad'
  989. },
  990. getStatusText: function(score) {
  991. if (score === undefined || score === null) return '未知'
  992. if (score >= 0) return '适合'
  993. return '戒备'
  994. },
  995. searchFood: function() {
  996. // 搜索由 computed 自动处理
  997. },
  998. switchCategory: function(category) {
  999. this.activeCategory = category
  1000. this.visibleCount = 20
  1001. },
  1002. getCategoryKeywords: function(category) {
  1003. var map = {
  1004. '蔬菜': ['蔬菜'],
  1005. '水果': ['水果'],
  1006. '肉禽': ['肉类', '肉禽'],
  1007. '水产': ['水产', '水产品'],
  1008. '谷物': ['谷物', '主食', '全谷物'],
  1009. '蛋奶': ['蛋类', '蛋奶', '乳制品']
  1010. }
  1011. return map[category] || []
  1012. },
  1013. setFilter: function(type) {
  1014. this.filterType = type
  1015. // 适合/全部:倒序,推荐值大的排前面;戒备:升序,推荐值小的排前面
  1016. if (type === 'unsuitable') {
  1017. this.sortType = 'asc'
  1018. } else {
  1019. this.sortType = 'desc'
  1020. }
  1021. this.visibleCount = 20
  1022. },
  1023. setSort: function(type) {
  1024. this.sortType = type
  1025. },
  1026. switchTab: function(tab) {
  1027. // 4 Tab:今日食谱 | 适合 | 戒备 | 全部;切 Tab 重置分页(请求式上滑加载从首批重新开始)
  1028. this.currentTab = tab
  1029. this.visibleCount = 20
  1030. if (tab !== 'recipe') {
  1031. this.filterType = tab
  1032. this.sortType = tab === 'unsuitable' ? 'asc' : 'desc'
  1033. } else {
  1034. // 切回「今日食谱」按当前视角重载,避免展示切换前残留(AC-09)
  1035. this.loadRecommendation()
  1036. }
  1037. },
  1038. loadMore: function() {
  1039. // 上滑触底加载更多:未达全量末尾时每批追加 20 条,到达末尾自动停止
  1040. if (this.visibleCount < this.filteredFoods.length) {
  1041. this.visibleCount += 20
  1042. }
  1043. },
  1044. switchView: function(view) {
  1045. this.currentView = view
  1046. if (view === 'family') {
  1047. // 家庭总览 ↔ 个人/成员互斥:清空成员选中态(个人/成员 chip 不高亮);
  1048. // 并锁定「不再自动默认选个人」,loadMembers 再次加载时不回灌默认选中
  1049. this.currentMemberId = null
  1050. this.memberSelectLocked = true
  1051. }
  1052. // 视角切换后按新 buildViewKey() 重载今日食谱(AC-03)
  1053. this.loadRecommendation()
  1054. },
  1055. // 取「本人」行(isSelf):后端已按 user_id 折叠,此处仅取第一行 isSelf
  1056. getSelfRow: function() {
  1057. var members = this.memberList || []
  1058. for (var i = 0; i < members.length; i++) {
  1059. if (members[i] && members[i].isSelf) return members[i]
  1060. }
  1061. return null
  1062. },
  1063. switchMember: function(member) {
  1064. // 统一身份键:familyMemberId(= family_members.id);userId 仅用于折叠,不再作主键
  1065. this.currentMemberId = memberIdOf(member)
  1066. this.currentView = 'personal'
  1067. this.visibleCount = 20
  1068. this.loadFoods()
  1069. // 成员切换联动今日食谱(AC-01/02),仍保留 loadFoods + visibleCount=20 既有行为
  1070. this.loadRecommendation()
  1071. },
  1072. onRefresh: function() {
  1073. var self = this
  1074. self.refreshing = true
  1075. self.loadFoods()
  1076. self.loadFamilyData()
  1077. // 下拉刷新按当前视角重载今日食谱(AC-09)
  1078. self.loadRecommendation()
  1079. setTimeout(function() {
  1080. self.refreshing = false
  1081. }, 500)
  1082. }
  1083. }
  1084. }
  1085. </script>
  1086. <style scoped lang="scss">
  1087. .recommendation-page {
  1088. /* 翻页失效根因修复:父容器必须是「确定高度」而不是由内容撑开的 min-height。
  1089. 原 min-height:100vh 下 scroll-view 会随内容一起长高,退化为页面级滚动,
  1090. @scrolltolower 永不触发 → visibleCount 卡在 20 → 下滑不追加食材。
  1091. 页面内内容全部在 scroll-view 内部,弹层为 position:fixed,故固定 100vh 安全。 */
  1092. height: 100vh;
  1093. background-color: $app-bg;
  1094. display: flex;
  1095. flex-direction: column;
  1096. }
  1097. .nav-placeholder {
  1098. width: 80rpx;
  1099. }
  1100. .content {
  1101. /* 保留既有 flex 布局;height:0 给出确定基准,min-height:0 阻止 min-content 把
  1102. 滚动容器撑高。配合父级 height:100vh,flex:1 才能算出确定高度,让
  1103. scroll-y 形成内部滚动视口并派发 @scrolltolower(H5 / 小程序通用)。 */
  1104. flex: 1;
  1105. height: 0;
  1106. min-height: 0;
  1107. padding: $uni-space-page;
  1108. box-sizing: border-box;
  1109. width: 100%;
  1110. overflow: hidden;
  1111. }
  1112. .empty-state { display: flex; flex-direction: column; align-items: center; padding: 120rpx 40rpx; }
  1113. .empty-icon-wrap {
  1114. width: 160rpx; height: 160rpx; border-radius: 50%;
  1115. background: linear-gradient(135deg, $dim-body, $dim-body-light);
  1116. display: flex; align-items: center; justify-content: center;
  1117. box-shadow: 0 10rpx 30rpx rgba(255, 140, 66, 0.3);
  1118. margin-bottom: 40rpx;
  1119. }
  1120. .empty-icon { font-size: calc($uni-font-size-5xl * var(--font-scale, 1)); }
  1121. .empty-title { font-size: calc(34rpx * var(--font-scale, 1)); font-weight: 700; color: $facade-text-strong; display: block; margin-bottom: 16rpx; }
  1122. .empty-sub { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-muted; display: block; margin-bottom: 48rpx; }
  1123. .generate-btn {
  1124. background: linear-gradient(135deg, $dim-body, $dim-body-light);
  1125. color: $app-surface; padding: 28rpx 60rpx; border-radius: 999rpx;
  1126. font-size: calc(30rpx * var(--font-scale, 1)); font-weight: 600;
  1127. box-shadow: 0 6rpx 20rpx rgba(255, 140, 66, 0.25);
  1128. }
  1129. .card {
  1130. display: flex;
  1131. background-color: $app-surface;
  1132. border-radius: 24rpx;
  1133. margin-bottom: $uni-space-lg;
  1134. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  1135. overflow: hidden;
  1136. }
  1137. .card-accent { width: 8rpx; background: linear-gradient(180deg, $dim-body, $dim-body-light); flex-shrink: 0; }
  1138. .card-body {
  1139. flex: 1;
  1140. padding: $uni-space-page;
  1141. }
  1142. .card-title {
  1143. font-size: calc(30rpx * var(--font-scale, 1));
  1144. font-weight: 600;
  1145. color: $facade-text-strong;
  1146. margin-bottom: 20rpx;
  1147. display: block;
  1148. }
  1149. .header-card .card-body {
  1150. display: flex;
  1151. justify-content: space-between;
  1152. align-items: center;
  1153. }
  1154. .date-text {
  1155. font-size: calc(28rpx * var(--font-scale, 1));
  1156. color: $facade-text-strong;
  1157. font-weight: 500;
  1158. }
  1159. .status-badge {
  1160. padding: 8rpx 20rpx;
  1161. border-radius: 24rpx;
  1162. font-size: calc(24rpx * var(--font-scale, 1));
  1163. }
  1164. .status-pending { background: $tint-warm-soft; color: $brand-primary-deep; }
  1165. .status-accepted {
  1166. background: #E8F1FB;
  1167. color: $mat-blue-base;
  1168. }
  1169. .status-completed {
  1170. background-color: $mat-green-tint;
  1171. color: $mat-green;
  1172. }
  1173. .meal-section {
  1174. background-color: $app-surface;
  1175. border-radius: 24rpx;
  1176. margin-bottom: $uni-space-lg;
  1177. overflow: hidden;
  1178. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  1179. }
  1180. .meal-header { display: flex; flex-wrap: wrap; align-items: center; padding: 24rpx $uni-space-page; border-bottom: 1rpx solid #FDE8D0; }
  1181. .meal-icon-wrap { width: 64rpx; height: 64rpx; border-radius: 24rpx; display: flex; align-items: center; justify-content: center; margin-right: 16rpx; }
  1182. .meal-icon-breakfast { background: linear-gradient(135deg, $dim-body-light, #FFD48A); }
  1183. .meal-icon-lunch { background: linear-gradient(135deg, $status-warning, $accent-amber-light); }
  1184. .meal-icon-dinner { background: linear-gradient(135deg, $facade-violet-light, $accent-violet-300); }
  1185. .meal-icon {
  1186. font-size: calc(36rpx * var(--font-scale, 1));
  1187. margin-right: 12rpx;
  1188. }
  1189. .meal-name {
  1190. font-size: calc(28rpx * var(--font-scale, 1));
  1191. font-weight: 600;
  1192. color: $facade-text-strong;
  1193. flex: 1;
  1194. }
  1195. .meal-count {
  1196. font-size: calc(24rpx * var(--font-scale, 1));
  1197. color: $facade-text-muted;
  1198. }
  1199. .dish-list {
  1200. padding: 20rpx $uni-space-page;
  1201. }
  1202. .dish-item { padding: 24rpx; border-radius: 24rpx; background: $flat-bg; margin-bottom: 16rpx; }
  1203. .dish-item:last-child { margin-bottom: 0; }
  1204. .dish-header {
  1205. display: flex;
  1206. justify-content: space-between;
  1207. margin-bottom: 12rpx;
  1208. }
  1209. .dish-name { font-size: calc(28rpx * var(--font-scale, 1)); font-weight: 600; color: $facade-text-strong; }
  1210. .dish-cal { font-size: calc(24rpx * var(--font-scale, 1)); color: $brand-primary-deep; font-weight: 600; }
  1211. .dish-ingredients {
  1212. display: flex;
  1213. flex-wrap: wrap;
  1214. gap: 12rpx;
  1215. margin-bottom: 12rpx;
  1216. }
  1217. .ingredient-tag {
  1218. padding: 6rpx 16rpx;
  1219. background-color: $facade-fill-2;
  1220. border-radius: 24rpx;
  1221. font-size: calc(22rpx * var(--font-scale, 1));
  1222. color: $facade-text-body;
  1223. }
  1224. .dish-method {
  1225. margin-bottom: 16rpx;
  1226. }
  1227. .method-text {
  1228. font-size: calc(24rpx * var(--font-scale, 1));
  1229. color: $facade-text-muted;
  1230. }
  1231. .dish-actions { display: flex; gap: 16rpx; margin-top: 8rpx; }
  1232. .action-btn { padding: 12rpx 26rpx; border-radius: 999rpx; font-size: calc(24rpx * var(--font-scale, 1)); }
  1233. /* 既有按钮样式保留备用,便于 D1 回退到双按钮组合(当前 dishActions='delete-only' 不渲染) */
  1234. .like-btn { background: $mat-green-tint; color: $mat-green; }
  1235. .swap-btn { background: #E8F1FB; color: $mat-blue-base; }
  1236. .skip-btn { background: $fortune-0-tint; color: $mat-red; }
  1237. /* 本轮增量:删除主操作 / 防重复点击 / 菜数只读状态 / 空·加载态 */
  1238. .delete-btn { background: $fortune-0-tint; color: $mat-red; }
  1239. .action-btn-disabled { opacity: 0.5; }
  1240. .meal-standard {
  1241. flex-basis: 100%;
  1242. text-align: right;
  1243. font-size: calc(22rpx * var(--font-scale, 1));
  1244. color: $facade-text-muted;
  1245. margin-top: 8rpx;
  1246. }
  1247. .meal-empty {
  1248. padding: 40rpx 0;
  1249. display: flex;
  1250. flex-direction: column;
  1251. align-items: center;
  1252. }
  1253. .meal-empty-text {
  1254. font-size: calc(26rpx * var(--font-scale, 1));
  1255. color: $facade-text-muted;
  1256. margin-bottom: 20rpx;
  1257. }
  1258. .meal-empty-btn {
  1259. padding: 12rpx 40rpx;
  1260. border-radius: 999rpx;
  1261. background: $tint-warm-soft;
  1262. color: $brand-primary-deep;
  1263. font-size: calc(24rpx * var(--font-scale, 1));
  1264. }
  1265. .recipe-loading {
  1266. display: flex;
  1267. align-items: center;
  1268. justify-content: center;
  1269. padding: 60rpx 0;
  1270. }
  1271. .recipe-loading-text {
  1272. font-size: calc(26rpx * var(--font-scale, 1));
  1273. color: $facade-text-muted;
  1274. }
  1275. .nutrition-grid {
  1276. display: flex;
  1277. justify-content: space-around;
  1278. }
  1279. .nutrition-item {
  1280. text-align: center;
  1281. }
  1282. .nutrition-card .card-body { background: $flat-bg; border-radius: 0 0 24rpx 24rpx; }
  1283. .nutrition-value { font-size: calc(40rpx * var(--font-scale, 1)); font-weight: 700; color: $brand-primary-deep; display: block; }
  1284. .nutrition-unit {
  1285. font-size: calc(22rpx * var(--font-scale, 1));
  1286. color: $facade-text-muted;
  1287. }
  1288. .nutrition-label {
  1289. font-size: calc(22rpx * var(--font-scale, 1));
  1290. color: $facade-text-body;
  1291. display: block;
  1292. margin-top: 4rpx;
  1293. }
  1294. /* ===== 菜谱分享栏(本人模式分享按钮 / 只读模式提示条)===== */
  1295. .share-bar {
  1296. padding: 24rpx $uni-space-page 0;
  1297. }
  1298. .share-btn-wrap {
  1299. display: flex;
  1300. justify-content: center;
  1301. }
  1302. .share-btn {
  1303. width: 320rpx;
  1304. padding: 18rpx 0;
  1305. background: linear-gradient(135deg, #ff8c42, #ffb26b);
  1306. border-radius: 999rpx;
  1307. border: none;
  1308. line-height: 1.4;
  1309. font-size: calc(28rpx * var(--font-scale, 1));
  1310. color: #fff;
  1311. font-weight: 600;
  1312. box-shadow: 0 6rpx 20rpx rgba(255, 140, 66, 0.25);
  1313. }
  1314. .share-btn::after {
  1315. border: none;
  1316. }
  1317. .share-btn-text {
  1318. color: #fff;
  1319. }
  1320. .share-mode-tip {
  1321. display: block;
  1322. text-align: center;
  1323. font-size: calc(26rpx * var(--font-scale, 1));
  1324. color: $brand-primary-deep;
  1325. background: rgba(255, 140, 66, 0.08);
  1326. border-radius: 16rpx;
  1327. padding: 20rpx 0;
  1328. }
  1329. .action-area {
  1330. padding: 40rpx $uni-space-page;
  1331. }
  1332. .btn-row {
  1333. display: flex;
  1334. gap: 20rpx;
  1335. }
  1336. .btn-secondary {
  1337. flex: 1; padding: 28rpx 0; background: $app-surface;
  1338. border: 2rpx solid $dim-body; border-radius: 999rpx;
  1339. text-align: center; font-size: calc(28rpx * var(--font-scale, 1)); color: $brand-primary-deep;
  1340. }
  1341. .btn-primary {
  1342. flex: 1; padding: 28rpx 0;
  1343. background: linear-gradient(135deg, $dim-body, $dim-body-light);
  1344. border-radius: 999rpx; text-align: center;
  1345. font-size: calc(28rpx * var(--font-scale, 1)); color: $app-surface; font-weight: 600;
  1346. box-shadow: 0 6rpx 20rpx rgba(255, 140, 66, 0.25);
  1347. }
  1348. /* ===== 推荐食材(原「食材查询」页迁移)===== */
  1349. .section-title-bar {
  1350. display: flex;
  1351. flex-direction: column;
  1352. padding: 8rpx 0 16rpx;
  1353. }
  1354. .section-title {
  1355. font-size: calc(34rpx * var(--font-scale, 1));
  1356. font-weight: 700;
  1357. color: $facade-text-strong;
  1358. }
  1359. .section-subtitle {
  1360. font-size: calc(24rpx * var(--font-scale, 1));
  1361. color: $facade-text-muted;
  1362. margin-top: 6rpx;
  1363. }
  1364. .food-section {
  1365. background-color: $app-surface;
  1366. border-radius: 24rpx;
  1367. padding: 20rpx;
  1368. margin-bottom: 32rpx;
  1369. }
  1370. /* 模式切换(排序) */
  1371. .mode-bar {
  1372. display: flex;
  1373. padding: 16rpx 0;
  1374. gap: 20rpx;
  1375. }
  1376. .mode-btn {
  1377. flex: 1;
  1378. padding: 12rpx 0;
  1379. text-align: center;
  1380. border-radius: 24rpx;
  1381. background: $facade-fill-2;
  1382. color: $facade-text-body;
  1383. font-size: calc(26rpx * var(--font-scale, 1));
  1384. }
  1385. .mode-btn.active {
  1386. background: linear-gradient(135deg, $status-success, $status-success-light-3);
  1387. color: $app-surface;
  1388. }
  1389. /* 搜索栏 */
  1390. .search-bar {
  1391. display: flex;
  1392. padding: 20rpx 0;
  1393. }
  1394. .search-input {
  1395. flex: 1;
  1396. border: 1rpx solid $facade-border-soft;
  1397. border-radius: 24rpx;
  1398. padding: 16rpx 24rpx;
  1399. font-size: calc(26rpx * var(--font-scale, 1));
  1400. background-color: $facade-fill-ghost;
  1401. }
  1402. .search-btn {
  1403. margin-left: 20rpx;
  1404. padding: 16rpx 32rpx;
  1405. background-color: $dim-body;
  1406. color: $app-surface;
  1407. border-radius: 24rpx;
  1408. font-size: calc(26rpx * var(--font-scale, 1));
  1409. }
  1410. /* 分类标签 */
  1411. .category-tabs {
  1412. display: flex;
  1413. flex-wrap: wrap;
  1414. gap: 16rpx;
  1415. margin-bottom: 20rpx;
  1416. }
  1417. .tab-item {
  1418. padding: 12rpx 24rpx;
  1419. border: 1rpx solid $facade-border-soft;
  1420. border-radius: 24rpx;
  1421. font-size: calc(24rpx * var(--font-scale, 1));
  1422. color: $facade-text-body;
  1423. background-color: $app-surface;
  1424. }
  1425. .tab-active {
  1426. border-color: $dim-body;
  1427. color: $dim-body;
  1428. background-color: $flat-card;
  1429. }
  1430. /* 筛选栏 */
  1431. .filter-bar {
  1432. display: flex;
  1433. gap: 20rpx;
  1434. margin-bottom: 20rpx;
  1435. }
  1436. .filter-item {
  1437. flex: 1;
  1438. text-align: center;
  1439. padding: 12rpx 8rpx;
  1440. border: 1rpx solid $facade-border-soft;
  1441. border-radius: 24rpx;
  1442. font-size: calc(24rpx * var(--font-scale, 1));
  1443. color: $facade-text-body;
  1444. background-color: $app-surface;
  1445. }
  1446. .filter-active {
  1447. border-color: $mat-green;
  1448. color: $mat-green;
  1449. background-color: $mat-green-tint;
  1450. }
  1451. /* 家庭总览 */
  1452. .family-overview {
  1453. background: $facade-fill-ghost-2;
  1454. border-radius: 16rpx;
  1455. padding: 20rpx;
  1456. margin-bottom: 20rpx;
  1457. }
  1458. .overview-title {
  1459. font-size: calc(28rpx * var(--font-scale, 1));
  1460. font-weight: 600;
  1461. color: $facade-text-strong;
  1462. margin-bottom: 16rpx;
  1463. padding-bottom: 16rpx;
  1464. border-bottom: 1rpx solid $facade-fill;
  1465. }
  1466. .overview-item {
  1467. padding: 16rpx 0;
  1468. border-bottom: 1rpx solid $facade-fill-2;
  1469. }
  1470. .overview-item:last-child {
  1471. border-bottom: none;
  1472. }
  1473. .overview-header {
  1474. display: flex;
  1475. align-items: center;
  1476. justify-content: space-between;
  1477. margin-bottom: 8rpx;
  1478. }
  1479. .overview-detail {
  1480. display: flex;
  1481. flex-direction: column;
  1482. gap: 8rpx;
  1483. }
  1484. .category-label {
  1485. font-size: calc(22rpx * var(--font-scale, 1));
  1486. color: $facade-text-muted;
  1487. }
  1488. .member-scores {
  1489. display: flex;
  1490. flex-wrap: wrap;
  1491. gap: 12rpx;
  1492. }
  1493. .member-score {
  1494. font-size: calc(20rpx * var(--font-scale, 1));
  1495. padding: 4rpx 12rpx;
  1496. border-radius: 16rpx;
  1497. background: $facade-fill-2;
  1498. }
  1499. .score-green {
  1500. color: $status-success;
  1501. background: $mat-green-tint;
  1502. }
  1503. .score-red {
  1504. color: $status-danger;
  1505. background: $status-danger-soft;
  1506. }
  1507. .score-badge {
  1508. min-width: 72rpx;
  1509. text-align: center;
  1510. padding: 4rpx 14rpx;
  1511. border-radius: 16rpx;
  1512. font-size: calc(24rpx * var(--font-scale, 1));
  1513. font-weight: 700;
  1514. color: $app-surface;
  1515. background: linear-gradient(135deg, $dim-body, $dim-body-light);
  1516. }
  1517. .score-badge.good {
  1518. background: linear-gradient(135deg, $status-success, $status-success-light-3);
  1519. }
  1520. .score-badge.bad {
  1521. background: linear-gradient(135deg, $status-danger, $status-danger-deep);
  1522. }
  1523. /* 食材列表 */
  1524. .food-list {
  1525. display: flex;
  1526. flex-direction: column;
  1527. gap: 16rpx;
  1528. }
  1529. .food-card {
  1530. background: $facade-fill-ghost-2;
  1531. border-radius: 16rpx;
  1532. padding: 18rpx 20rpx;
  1533. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.06);
  1534. display: flex;
  1535. flex-wrap: wrap;
  1536. align-items: center;
  1537. justify-content: space-between;
  1538. width: 100%;
  1539. box-sizing: border-box;
  1540. }
  1541. /* 健康问卷个性化调整提示条(blocked 红 / warning 黄 / boost 绿;normal/空不渲染) */
  1542. .health-adjust-bar {
  1543. width: 100%;
  1544. margin-bottom: 12rpx;
  1545. }
  1546. .health-adjust-text {
  1547. display: block;
  1548. padding: 8rpx 16rpx;
  1549. border-radius: 8rpx;
  1550. font-size: calc(22rpx * var(--font-scale, 1));
  1551. line-height: 1.4;
  1552. }
  1553. .health-adjust-blocked {
  1554. background: $fortune-0-tint;
  1555. color: $mat-red;
  1556. }
  1557. .health-adjust-warning {
  1558. background: rgba(245, 158, 11, 0.14);
  1559. color: #b45309;
  1560. }
  1561. .health-adjust-boost {
  1562. background: $mat-green-tint;
  1563. color: $mat-green;
  1564. }
  1565. .food-left {
  1566. display: flex;
  1567. align-items: center;
  1568. flex: 1;
  1569. min-width: 0;
  1570. }
  1571. .ingredient-badge {
  1572. width: 36rpx;
  1573. height: 36rpx;
  1574. border-radius: 8rpx;
  1575. background: linear-gradient(135deg, $dim-body, $dim-body-light);
  1576. display: flex;
  1577. align-items: center;
  1578. justify-content: center;
  1579. margin-right: 16rpx;
  1580. flex-shrink: 0;
  1581. }
  1582. .ingredient-badge.good {
  1583. background: linear-gradient(135deg, $status-success, $status-success-light-3);
  1584. }
  1585. .ingredient-badge.bad {
  1586. background: linear-gradient(135deg, $status-danger, $status-danger-deep);
  1587. }
  1588. .ingredient-badge-text {
  1589. font-size: calc(18rpx * var(--font-scale, 1));
  1590. color: $app-surface;
  1591. font-weight: 600;
  1592. }
  1593. .food-info {
  1594. display: flex;
  1595. flex-direction: column;
  1596. flex: 1;
  1597. min-width: 0;
  1598. overflow: hidden;
  1599. }
  1600. .food-name {
  1601. font-size: calc(28rpx * var(--font-scale, 1));
  1602. font-weight: 600;
  1603. color: $text-charcoal;
  1604. display: block;
  1605. white-space: nowrap;
  1606. overflow: hidden;
  1607. text-overflow: ellipsis;
  1608. }
  1609. .food-meta {
  1610. display: flex;
  1611. flex-wrap: wrap;
  1612. gap: 8rpx;
  1613. margin-top: 6rpx;
  1614. }
  1615. .meta-item {
  1616. flex-shrink: 0;
  1617. font-size: calc(20rpx * var(--font-scale, 1));
  1618. color: $facade-text-faint;
  1619. background: $facade-fill-2;
  1620. padding: 4rpx 14rpx;
  1621. border-radius: 8rpx;
  1622. }
  1623. .food-right {
  1624. display: flex;
  1625. align-items: center;
  1626. gap: 12rpx;
  1627. flex-shrink: 0;
  1628. }
  1629. .score-value {
  1630. font-size: calc(28rpx * var(--font-scale, 1));
  1631. font-weight: 700;
  1632. min-width: 60rpx;
  1633. text-align: right;
  1634. }
  1635. .score-value.good { color: $status-success; }
  1636. .score-value.bad { color: $status-danger; }
  1637. .food-status-badge {
  1638. padding: 6rpx 16rpx;
  1639. border-radius: 24rpx;
  1640. font-size: calc(22rpx * var(--font-scale, 1));
  1641. font-weight: 500;
  1642. }
  1643. .badge-suitable {
  1644. background: $mat-green-tint;
  1645. color: $mat-green;
  1646. }
  1647. .badge-unsuitable {
  1648. background: $fortune-0-tint;
  1649. color: $mat-red;
  1650. }
  1651. /* 健康问卷个性化调整提示条(diet.food.healthAdjustUi · B2) */
  1652. .adjustment-tip {
  1653. margin-top: 12rpx;
  1654. align-self: flex-start;
  1655. max-width: 100%;
  1656. }
  1657. .adjustment-tip-text {
  1658. display: inline-flex;
  1659. align-items: center;
  1660. padding: 6rpx 16rpx;
  1661. border-radius: 10rpx;
  1662. font-size: calc(22rpx * var(--font-scale, 1));
  1663. line-height: 1.5;
  1664. }
  1665. .adjustment-tip-blocked {
  1666. background: $status-danger-soft;
  1667. color: $status-danger;
  1668. }
  1669. .adjustment-tip-warning {
  1670. background: $status-warning-soft;
  1671. color: $status-warning;
  1672. }
  1673. .adjustment-tip-boost {
  1674. background: $status-success-soft;
  1675. color: $status-success;
  1676. }
  1677. /* 空状态 */
  1678. .food-empty-state {
  1679. text-align: center;
  1680. padding: 60rpx 40rpx;
  1681. }
  1682. .food-empty-icon {
  1683. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  1684. display: block;
  1685. margin-bottom: 20rpx;
  1686. }
  1687. .food-empty-text {
  1688. font-size: calc(30rpx * var(--font-scale, 1));
  1689. color: $facade-text-strong;
  1690. font-weight: 500;
  1691. display: block;
  1692. margin-bottom: 12rpx;
  1693. }
  1694. .loading-state {
  1695. text-align: center;
  1696. padding: 60rpx 0;
  1697. }
  1698. .loading-text {
  1699. font-size: calc(26rpx * var(--font-scale, 1));
  1700. color: $facade-text-muted;
  1701. }
  1702. /* ===== 共餐人选择弹层(需求7)===== */
  1703. .participant-mask {
  1704. position: fixed;
  1705. left: 0;
  1706. top: 0;
  1707. right: 0;
  1708. bottom: 0;
  1709. background: rgba(0, 0, 0, 0.45);
  1710. z-index: 999;
  1711. display: flex;
  1712. align-items: flex-end;
  1713. }
  1714. .participant-sheet {
  1715. box-sizing: border-box;
  1716. width: 100%;
  1717. background: $app-surface;
  1718. border-radius: 24rpx 24rpx 0 0;
  1719. padding: 32rpx 32rpx 40rpx;
  1720. }
  1721. .participant-sheet-header {
  1722. padding-bottom: 24rpx;
  1723. }
  1724. .participant-sheet-title {
  1725. font-size: calc(32rpx * var(--font-scale, 1));
  1726. font-weight: 600;
  1727. color: $facade-text-strong;
  1728. display: block;
  1729. }
  1730. .participant-sheet-sub {
  1731. font-size: calc(24rpx * var(--font-scale, 1));
  1732. color: $facade-text-muted;
  1733. display: block;
  1734. margin-top: 8rpx;
  1735. }
  1736. .participant-list {
  1737. display: flex;
  1738. flex-wrap: wrap;
  1739. gap: 20rpx;
  1740. padding: 16rpx 0 24rpx;
  1741. max-height: 60vh;
  1742. overflow-y: auto;
  1743. }
  1744. .participant-item {
  1745. box-sizing: border-box;
  1746. position: relative;
  1747. display: flex;
  1748. align-items: center;
  1749. padding: 16rpx 24rpx;
  1750. border: 2rpx solid $facade-fill-2;
  1751. border-radius: 24rpx;
  1752. background: $app-surface;
  1753. min-width: 160rpx;
  1754. }
  1755. .participant-item-selected {
  1756. border-color: $dim-body;
  1757. background: linear-gradient(135deg, $dim-body, $dim-body-light);
  1758. }
  1759. .participant-name {
  1760. font-size: calc(26rpx * var(--font-scale, 1));
  1761. color: $facade-text-body;
  1762. }
  1763. .participant-item-selected .participant-name {
  1764. color: $app-surface;
  1765. font-weight: 600;
  1766. }
  1767. .participant-check {
  1768. position: absolute;
  1769. top: -8rpx;
  1770. right: -8rpx;
  1771. width: 32rpx;
  1772. height: 32rpx;
  1773. border-radius: 50%;
  1774. background-color: $app-surface;
  1775. color: $dim-body;
  1776. display: flex;
  1777. align-items: center;
  1778. justify-content: center;
  1779. z-index: 2;
  1780. }
  1781. .participant-check-icon {
  1782. font-size: calc(20rpx * var(--font-scale, 1));
  1783. font-weight: 700;
  1784. }
  1785. .participant-empty {
  1786. width: 100%;
  1787. padding: 20rpx 0;
  1788. text-align: center;
  1789. }
  1790. .participant-empty-text {
  1791. font-size: calc(24rpx * var(--font-scale, 1));
  1792. color: $facade-text-muted;
  1793. }
  1794. .participant-actions {
  1795. display: flex;
  1796. gap: 20rpx;
  1797. }
  1798. .participant-btn {
  1799. flex: 1;
  1800. padding: 26rpx 0;
  1801. border-radius: 999rpx;
  1802. text-align: center;
  1803. font-size: calc(28rpx * var(--font-scale, 1));
  1804. }
  1805. .participant-btn-cancel {
  1806. background: $facade-fill-2;
  1807. color: $facade-text-body;
  1808. }
  1809. .participant-btn-confirm {
  1810. background: linear-gradient(135deg, $dim-body, $dim-body-light);
  1811. color: $app-surface;
  1812. font-weight: 600;
  1813. }
  1814. </style>