Selaa lähdekoodia

feat(patient): 新增解除绑定医生功能及相关逻辑

mcbaiyun 1 kuukausi sitten
vanhempi
commit
d17390e58d
1 muutettua tiedostoa jossa 61 lisäystä ja 2 poistoa
  1. 61 2
      src/pages/patient/index/my-doctor.vue

+ 61 - 2
src/pages/patient/index/my-doctor.vue

@@ -16,7 +16,9 @@
         </view>
       </view>
 
-
+      <view class="action-buttons">
+        <button class="action-btn danger" @click="unbindDoctor">解除绑定</button>
+      </view>
 
     </view>
 
@@ -32,7 +34,7 @@
 import { ref, computed, onMounted } from 'vue'
 import { onLoad, onShow } from '@dcloudio/uni-app'
 import CustomNav from '@/components/custom-nav.vue'
-import { listUserBindingsByPatient, type UserBindingResponse, type UserBindingPageResponse } from '@/api/userBinding'
+import { listUserBindingsByPatient, deleteUserBinding, type UserBindingResponse, type UserBindingPageResponse } from '@/api/userBinding'
 import { downloadAvatar } from '@/api/user'
 import { formatDate } from '@/utils/date'
 import { avatarCache } from '@/utils/avatarCache'
@@ -46,6 +48,7 @@ interface LocalDoctorInfo {
 }
 
 const doctorInfo = ref<LocalDoctorInfo | null>(null)
+const currentBinding = ref<UserBindingResponse | null>(null)
 const userBindings = ref<UserBindingResponse[]>([])
 const pageData = ref({
   pageNum: 1,
@@ -124,6 +127,7 @@ const fetchDoctorInfo = async () => {
       // 如果有绑定的医生,获取第一个医生的详细信息
       if (pageResult.records && pageResult.records.length > 0) {
         const boundDoctor = pageResult.records[0]
+        currentBinding.value = boundDoctor
 
         // 直接使用绑定接口返回的信息,不再调用额外的用户详情接口
         doctorInfo.value = {
@@ -176,6 +180,56 @@ const bindDoctor = () => {
   })
 }
 
+// 解除绑定医生
+const unbindDoctor = () => {
+  if (!currentBinding.value) return
+
+  uni.showModal({
+    title: '确认解除绑定',
+    content: `确定要解除与 ${doctorInfo.value?.name} 的绑定关系吗?`,
+    success: async (res) => {
+      if (res.confirm) {
+        try {
+          uni.showLoading({ title: '正在解除绑定...' })
+          
+          // 调用解除绑定接口
+          const response = await deleteUserBinding({
+            patientUserId: currentBinding.value!.patientUserId,
+            boundUserId: currentBinding.value!.boundUserId
+          })
+          
+          uni.hideLoading()
+          
+          const resp = response.data as any
+          if (resp && resp.code === 200) {
+            uni.showToast({
+              title: '解除绑定成功',
+              icon: 'success'
+            })
+            
+            // 清空医生信息
+            doctorInfo.value = null
+            currentBinding.value = null
+            downloadedAvatar.value = null
+          } else {
+            uni.showToast({
+              title: resp?.message || '解除绑定失败',
+              icon: 'none'
+            })
+          }
+        } catch (error) {
+          uni.hideLoading()
+          console.error('解除绑定失败:', error)
+          uni.showToast({
+            title: '解除绑定失败',
+            icon: 'none'
+          })
+        }
+      }
+    }
+  })
+}
+
 onLoad(() => {
   fetchDoctorInfo()
 })
@@ -270,6 +324,11 @@ onShow(() => {
   color: #333;
 }
 
+.danger {
+  background-color: #ff4757;
+  color: #fff;
+}
+
 .empty-state {
   display: flex;
   flex-direction: column;