plan-list.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <view class="page">
  3. <view class="header">
  4. <text class="title">我的健康方案</text>
  5. <text class="subtitle">查看和管理健康计划</text>
  6. </view>
  7. <!-- 新建方案按钮 -->
  8. <view class="action-bar">
  9. <button class="btn-create" @click="goCreatePlan">+ 新建方案</button>
  10. </view>
  11. <!-- 加载状态 -->
  12. <view class="loading" v-if="loading">
  13. <text class="loading-text">加载中...</text>
  14. </view>
  15. <!-- 空状态 -->
  16. <view class="empty" v-else-if="plans.length === 0">
  17. <text class="empty-icon">📋</text>
  18. <text class="empty-title">暂无健康方案</text>
  19. <text class="empty-desc">点击下方按钮创建第一个健康方案</text>
  20. </view>
  21. <!-- 方案列表 -->
  22. <view class="plan-list" v-else>
  23. <view
  24. class="plan-card"
  25. v-for="plan in plans"
  26. :key="plan.id"
  27. @click="goDetail(plan.id)"
  28. >
  29. <view class="card-top">
  30. <text class="plan-title">{{ plan.goal || plan.memberName || '健康方案' }}</text>
  31. <text class="plan-delete" @click.stop="onDeletePlan(plan)">删除</text>
  32. <view class="plan-status" :class="'status-' + plan.status">
  33. <text>{{ statusText(plan.status) }}</text>
  34. </view>
  35. </view>
  36. <view class="card-meta">
  37. <text class="meta-item" v-if="plan.memberName">成员:{{ plan.memberName }}</text>
  38. <text class="meta-item">创建时间:{{ formatTime(plan.createdAt) }}</text>
  39. </view>
  40. <view class="plan-arrow">›</view>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import { getHealthPlanList, deleteHealthPlan } from '@/utils/api.js'
  47. export default {
  48. data() {
  49. return {
  50. loading: false,
  51. plans: []
  52. }
  53. },
  54. onLoad() {
  55. this.loadPlans()
  56. this._onLoadFired = true
  57. },
  58. onShow() {
  59. if (this._onLoadFired) {
  60. this._onLoadFired = false // 首次进入:onLoad 已加载,跳过避免双发
  61. } else {
  62. this.loadPlans() // 从子页面返回时刷新
  63. }
  64. },
  65. methods: {
  66. loadPlans() {
  67. this.loading = true
  68. var self = this
  69. getHealthPlanList({}).then(function(res) {
  70. self.loading = false
  71. if (res && res.code === 200 && res.data) {
  72. var list = res.data.list || res.data
  73. self.plans = Array.isArray(list) ? list : []
  74. } else {
  75. self.plans = []
  76. }
  77. }).catch(function(err) {
  78. self.loading = false
  79. console.error('加载方案列表失败', err)
  80. self.plans = []
  81. })
  82. },
  83. goDetail(planId) {
  84. uni.navigateTo({ url: '/pages/health/health-plan-summary?planId=' + planId })
  85. },
  86. goCreatePlan() {
  87. uni.navigateTo({ url: '/pages/health/health-plan-summary' })
  88. },
  89. onDeletePlan(plan) {
  90. var self = this
  91. uni.showModal({
  92. title: '删除方案',
  93. content: '删除后不可恢复:该方案及其已生成的所有任务(含每日生成的实例)将一并删除。确认删除?',
  94. confirmText: '删除',
  95. confirmColor: '#C62828',
  96. success: function(res) {
  97. if (!res.confirm) return
  98. deleteHealthPlan({ planId: plan.id }).then(function(r) {
  99. if (r && r.code === 200) {
  100. var count = (r.data && r.data.taskCount) || 0
  101. uni.showToast({ title: '已删除方案及 ' + count + ' 条任务', icon: 'none' })
  102. self.loadPlans()
  103. } else {
  104. uni.showToast({ title: (r && r.message) || '删除失败', icon: 'none' })
  105. }
  106. }).catch(function(err) {
  107. console.error('删除方案失败', err)
  108. uni.showToast({ title: '删除失败', icon: 'none' })
  109. })
  110. }
  111. })
  112. },
  113. statusText(status) {
  114. var map = {
  115. 'draft': '待确认',
  116. 'pending_review': '待审核',
  117. 'confirmed': '已确认',
  118. 'published': '已发布',
  119. 'rejected': '已驳回'
  120. }
  121. return map[status] || '未知'
  122. },
  123. formatTime(t) {
  124. if (!t) return '-'
  125. return String(t).substring(0, 19).replace('T', ' ')
  126. }
  127. }
  128. }
  129. </script>
  130. <style scoped lang="scss">
  131. .page {
  132. min-height: 100vh;
  133. background: #F5FAFE;
  134. padding-bottom: 30rpx;
  135. }
  136. .header {
  137. padding: 40rpx 30rpx 20rpx;
  138. }
  139. .title {
  140. font-size: 36rpx;
  141. font-weight: bold;
  142. color: #1F2D3D;
  143. display: block;
  144. }
  145. .subtitle {
  146. font-size: 26rpx;
  147. color: #8A94A6;
  148. margin-top: 8rpx;
  149. display: block;
  150. }
  151. .action-bar {
  152. padding: 0 30rpx 20rpx;
  153. }
  154. .btn-create {
  155. width: 100%;
  156. background: $brand-primary;
  157. color: #fff;
  158. font-size: 30rpx;
  159. font-weight: 600;
  160. padding: 24rpx 0;
  161. border-radius: 12rpx;
  162. border: none;
  163. }
  164. .loading, .empty {
  165. display: flex;
  166. flex-direction: column;
  167. align-items: center;
  168. padding: 100rpx 0;
  169. }
  170. .loading-text {
  171. font-size: 28rpx;
  172. color: #8A94A6;
  173. }
  174. .empty-icon {
  175. font-size: 80rpx;
  176. }
  177. .empty-title {
  178. font-size: 32rpx;
  179. font-weight: bold;
  180. color: #333;
  181. margin-top: 20rpx;
  182. }
  183. .empty-desc {
  184. font-size: 26rpx;
  185. color: #999;
  186. margin-top: 10rpx;
  187. text-align: center;
  188. }
  189. .plan-list {
  190. padding: 0 30rpx;
  191. }
  192. .plan-card {
  193. background: #fff;
  194. border-radius: 16rpx;
  195. padding: 30rpx;
  196. margin-bottom: 20rpx;
  197. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  198. position: relative;
  199. }
  200. .plan-card:active {
  201. opacity: 0.8;
  202. }
  203. .card-top {
  204. display: flex;
  205. justify-content: space-between;
  206. align-items: center;
  207. }
  208. .plan-title {
  209. font-size: 30rpx;
  210. font-weight: bold;
  211. color: #333;
  212. flex: 1;
  213. }
  214. .plan-delete {
  215. font-size: 24rpx;
  216. color: #C62828;
  217. padding: 8rpx 16rpx;
  218. margin-right: 16rpx;
  219. flex-shrink: 0;
  220. }
  221. .plan-status {
  222. font-size: 22rpx;
  223. padding: 4rpx 16rpx;
  224. border-radius: 20rpx;
  225. }
  226. .status-draft { background: #FFF3E0; color: #F97316; }
  227. .status-pending_review { background: #E3F2FD; color: #2196F3; }
  228. .status-confirmed { background: #E8F5E9; color: #4CAF50; }
  229. .status-published { background: #E8F5E9; color: #4CAF50; }
  230. .status-rejected { background: #FDE8E8; color: #C62828; }
  231. .card-meta {
  232. display: flex;
  233. flex-direction: column;
  234. margin-top: 16rpx;
  235. gap: 6rpx;
  236. }
  237. .meta-item {
  238. font-size: 24rpx;
  239. color: #bbb;
  240. }
  241. .plan-arrow {
  242. position: absolute;
  243. right: 24rpx;
  244. top: 50%;
  245. transform: translateY(-50%);
  246. font-size: 36rpx;
  247. color: #CCC;
  248. }
  249. </style>