Просмотр исходного кода

feat(miniprogram): add withdraw button on reimburse and advance lists

Co-authored-by: Cursor <cursoragent@cursor.com>
wuzilong 1 месяц назад
Родитель
Сommit
31d3a044cf

+ 43 - 0
miniprogram/pages/bx/advance/list.vue

@@ -117,6 +117,14 @@
           </view>
           <view v-else class="op-actions">
             <button class="btn btn-sm btn-primary" @click="goDetail(item.id)">查看</button>
+            <button
+              v-if="canWithdraw(item)"
+              class="btn btn-sm btn-ghost"
+              :disabled="withdrawingId === item.id"
+              @click="handleWithdraw(item)"
+            >
+              撤回
+            </button>
           </view>
         </view>
       </view>
@@ -140,8 +148,21 @@ import {
   formatApplyDate
 } from '@/utils/bxFormat'
 import { getSafeAreaStyle } from '@/utils/safeArea'
+import { useUserStore } from '@/stores/user'
 
 const safeAreaStyle = getSafeAreaStyle()
+const userStore = useUserStore()
+const withdrawingId = ref('')
+
+function currentUserId() {
+  const u = userStore.userInfo || {}
+  return String(u.id || u.userId || '')
+}
+
+function canWithdraw(item) {
+  if (!item) return false
+  return item.status === 'pending' && String(item.applicantId || '') === currentUserId()
+}
 
 const tabs = [
   { label: '全部', value: '' },
@@ -286,6 +307,28 @@ function handleDelete(item) {
   })
 }
 
+function handleWithdraw(item) {
+  if (!item?.id || !canWithdraw(item)) return
+  uni.showModal({
+    title: '确认撤回',
+    content: '确定撤回该备用金申请?撤回后可修改再提交。',
+    confirmText: '确定撤回',
+    success: async (res) => {
+      if (!res.confirm) return
+      withdrawingId.value = String(item.id)
+      try {
+        await advanceApi.withdraw(item.id)
+        uni.showToast({ title: '已撤回', icon: 'success' })
+      } catch (e) {
+        // toasted by bxRequest
+      } finally {
+        withdrawingId.value = ''
+        onRefresh()
+      }
+    }
+  })
+}
+
 onShow(() => {
   computeListHeight()
   onRefresh()

+ 43 - 0
miniprogram/pages/bx/reimburse/list.vue

@@ -132,6 +132,14 @@
           </view>
           <view v-else class="op-actions">
             <button class="btn btn-sm btn-primary" @click="goDetail(item.id)">查看</button>
+            <button
+              v-if="canWithdraw(item)"
+              class="btn btn-sm btn-ghost"
+              :disabled="withdrawingId === item.id"
+              @click="handleWithdraw(item)"
+            >
+              撤回
+            </button>
           </view>
         </view>
       </view>
@@ -158,8 +166,21 @@ import {
   resolveExpenseDisplay
 } from '@/utils/bxFormat'
 import { getSafeAreaStyle } from '@/utils/safeArea'
+import { useUserStore } from '@/stores/user'
 
 const safeAreaStyle = getSafeAreaStyle()
+const userStore = useUserStore()
+const withdrawingId = ref('')
+
+function currentUserId() {
+  const u = userStore.userInfo || {}
+  return String(u.id || u.userId || '')
+}
+
+function canWithdraw(item) {
+  if (!item) return false
+  return item.status === 'pending' && String(item.applicantId || '') === currentUserId()
+}
 
 const tabs = [
   { label: '全部', value: '' },
@@ -315,6 +336,28 @@ function handleDelete(item) {
   })
 }
 
+function handleWithdraw(item) {
+  if (!item?.id || !canWithdraw(item)) return
+  uni.showModal({
+    title: '确认撤回',
+    content: '确定撤回该报销单?撤回后将退回发票额度。',
+    confirmText: '确定撤回',
+    success: async (res) => {
+      if (!res.confirm) return
+      withdrawingId.value = String(item.id)
+      try {
+        await reimburseApi.withdraw(item.id)
+        uni.showToast({ title: '已撤回', icon: 'success' })
+      } catch (e) {
+        // toasted by bxRequest
+      } finally {
+        withdrawingId.value = ''
+        onRefresh()
+      }
+    }
+  })
+}
+
 onShow(() => {
   computeListHeight()
   loadExpenseFlat()

+ 6 - 0
miniprogram/styles/bx-theme.scss

@@ -455,6 +455,12 @@
   border-color: var(--text-sec);
 }
 
+.bx-page .btn-ghost {
+  background: #fff !important;
+  color: var(--text) !important;
+  border-color: var(--border, #e2e8f0);
+}
+
 .bx-page .btn-block {
   width: 100%;
 }