list.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { onLoad, onShow, onReachBottom } from '@dcloudio/uni-app'
  4. import {
  5. listPendingReimburse,
  6. listPendingAdvance,
  7. approveReimburse,
  8. rejectReimburse,
  9. approveAdvance,
  10. rejectAdvance
  11. } from '@/api/bx'
  12. import { bxStatusLabel, formatMoney, dash } from '@/utils/bxLabels'
  13. import { PAGE_PATHS } from '@/config/api'
  14. /** type: reimburse | advance */
  15. const bizType = ref('reimburse')
  16. const list = ref([])
  17. const page = ref(1)
  18. const total = ref(0)
  19. const loading = ref(false)
  20. const finished = ref(false)
  21. const pageSize = 20
  22. const titleText = ref('报销审批')
  23. const goBack = () => {
  24. uni.navigateBack({
  25. fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
  26. })
  27. }
  28. const goDetail = (row) => {
  29. if (bizType.value === 'advance') {
  30. uni.navigateTo({ url: `${PAGE_PATHS.bxAdvanceDetail}?id=${row.id}` })
  31. } else {
  32. uni.navigateTo({ url: `${PAGE_PATHS.bxReimburseDetail}?id=${row.id}` })
  33. }
  34. }
  35. const loadList = async (reset = false) => {
  36. if (loading.value) return
  37. if (reset) {
  38. page.value = 1
  39. finished.value = false
  40. list.value = []
  41. }
  42. if (finished.value) return
  43. loading.value = true
  44. try {
  45. const q = { page: page.value, pageSize }
  46. const res =
  47. bizType.value === 'advance'
  48. ? await listPendingAdvance(q)
  49. : await listPendingReimburse(q)
  50. const rows = res.rows || []
  51. list.value = reset ? rows : list.value.concat(rows)
  52. total.value = res.total || 0
  53. if (list.value.length >= total.value || rows.length < pageSize) finished.value = true
  54. else page.value += 1
  55. } catch (e) {
  56. uni.showToast({ title: e.message || '加载失败', icon: 'none' })
  57. } finally {
  58. loading.value = false
  59. }
  60. }
  61. const doApprove = (row, pass) => {
  62. uni.showModal({
  63. title: pass ? '通过' : '驳回',
  64. editable: !pass,
  65. placeholderText: '驳回意见',
  66. success: async (r) => {
  67. if (!r.confirm) return
  68. try {
  69. const op = r.content || (pass ? '同意' : '驳回')
  70. if (bizType.value === 'advance') {
  71. if (pass) await approveAdvance(row.id, op)
  72. else await rejectAdvance(row.id, op)
  73. } else if (pass) await approveReimburse(row.id, op)
  74. else await rejectReimburse(row.id, op)
  75. uni.showToast({ title: '操作成功', icon: 'success' })
  76. loadList(true)
  77. } catch (e) {
  78. uni.showToast({ title: e.message || '操作失败', icon: 'none' })
  79. }
  80. }
  81. })
  82. }
  83. onLoad((q) => {
  84. bizType.value = q?.type === 'advance' ? 'advance' : 'reimburse'
  85. titleText.value = bizType.value === 'advance' ? '借款审批' : '报销审批'
  86. })
  87. onShow(() => loadList(true))
  88. onReachBottom(() => loadList(false))
  89. </script>
  90. <template>
  91. <view class="mp-page mp-page--sub">
  92. <view class="mp-header mp-header--bx">
  93. <text class="mp-subpage-back" @click="goBack">← 工作台</text>
  94. <text class="mp-header__title" style="margin-top: 16rpx">{{ titleText }}</text>
  95. </view>
  96. <view class="mp-section">
  97. <mp-empty v-if="!list.length && !loading" title="暂无待审批" />
  98. <view v-else class="mp-list">
  99. <view v-for="row in list" :key="row.id" class="mp-card" @click="goDetail(row)">
  100. <view class="mp-card__head">
  101. <view>
  102. <text class="mp-card__title">{{ dash(row.applyCode) }}</text>
  103. <text class="mp-card__sub">
  104. {{ bizType === 'advance' ? dash(row.reason) : dash(row.expenseName || row.title) }}
  105. </text>
  106. </view>
  107. <text class="mp-tag" :class="'mp-tag--' + bxStatusLabel(row.status).tag">
  108. {{ bxStatusLabel(row.status).text }}
  109. </text>
  110. </view>
  111. <view class="mp-card__row">
  112. <text>申请人</text>
  113. <text class="mp-card__row-val">{{ dash(row.applicantName) }}</text>
  114. </view>
  115. <view class="mp-card__foot">
  116. <text class="mp-card__amount">{{ formatMoney(row.amount) }}</text>
  117. <view style="display: flex; gap: 16rpx" @click.stop>
  118. <view class="mp-btn mp-btn--danger mp-btn--sm" @click="doApprove(row, false)">驳回</view>
  119. <view class="mp-btn mp-btn--primary mp-btn--sm" @click="doApprove(row, true)">通过</view>
  120. </view>
  121. </view>
  122. </view>
  123. </view>
  124. <view v-if="loading" class="mp-list-loading">加载中…</view>
  125. <view v-else-if="finished && list.length" class="mp-list-end">已加载全部</view>
  126. </view>
  127. </view>
  128. </template>