Explorar o código

feat(小程序): 新增方案删除入口(弹窗确认后级联删除任务,任务4/6)

iwt hai 1 semana
pai
achega
a391f33096
Modificáronse 2 ficheiros con 35 adicións e 1 borrados
  1. 34 1
      cfc-frontend/pages/health/plan-list.vue
  2. 1 0
      cfc-frontend/utils/api.js

+ 34 - 1
cfc-frontend/pages/health/plan-list.vue

@@ -32,6 +32,7 @@
       >
         <view class="card-top">
           <text class="plan-title">{{ plan.goal || plan.memberName || '健康方案' }}</text>
+          <text class="plan-delete" @click.stop="onDeletePlan(plan)">删除</text>
           <view class="plan-status" :class="'status-' + plan.status">
             <text>{{ statusText(plan.status) }}</text>
           </view>
@@ -47,7 +48,7 @@
 </template>
 
 <script>
-import { getHealthPlanList } from '@/utils/api.js'
+import { getHealthPlanList, deleteHealthPlan } from '@/utils/api.js'
 
 export default {
   data() {
@@ -91,6 +92,30 @@ export default {
     goCreatePlan() {
       uni.navigateTo({ url: '/pages/health/health-plan-summary' })
     },
+    onDeletePlan(plan) {
+      var self = this
+      uni.showModal({
+        title: '删除方案',
+        content: '删除后不可恢复:该方案及其已生成的所有任务(含每日生成的实例)将一并删除。确认删除?',
+        confirmText: '删除',
+        confirmColor: '#C62828',
+        success: function(res) {
+          if (!res.confirm) return
+          deleteHealthPlan({ planId: plan.id }).then(function(r) {
+            if (r && r.code === 200) {
+              var count = (r.data && r.data.taskCount) || 0
+              uni.showToast({ title: '已删除方案及 ' + count + ' 条任务', icon: 'none' })
+              self.loadPlans()
+            } else {
+              uni.showToast({ title: (r && r.message) || '删除失败', icon: 'none' })
+            }
+          }).catch(function(err) {
+            console.error('删除方案失败', err)
+            uni.showToast({ title: '删除失败', icon: 'none' })
+          })
+        }
+      })
+    },
     statusText(status) {
       var map = {
         'draft': '待确认',
@@ -209,6 +234,14 @@ export default {
   flex: 1;
 }
 
+.plan-delete {
+  font-size: 24rpx;
+  color: #C62828;
+  padding: 8rpx 16rpx;
+  margin-right: 16rpx;
+  flex-shrink: 0;
+}
+
 .plan-status {
   font-size: 22rpx;
   padding: 4rpx 16rpx;

+ 1 - 0
cfc-frontend/utils/api.js

@@ -2581,6 +2581,7 @@ export const rejectPlan = (data) => request('/api/health/plan/pending-review/rej
 export const getHealthPlanList = (data) => request('/api/health/plan/list', 'POST', data)
 export const getHealthPlanDetail = (data) => request('/api/health/plan/detail', 'POST', data)
 export const getHealthPlanTasks = (data) => request('/api/health/plan/tasks', 'POST', data)
+export const deleteHealthPlan = (data) => request('/api/health/plan/delete', 'POST', data)
 
 // ===== 閭€璇烽噷绋嬬 =====
 export const getInviteMilestones = () => {