list.vue 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { onShow, onReachBottom } from '@dcloudio/uni-app'
  4. import { listMyAdvance } from '@/api/bx'
  5. import { bxStatusLabel, formatMoney, dash } from '@/utils/bxLabels'
  6. import { PAGE_PATHS } from '@/config/api'
  7. const list = ref([])
  8. const page = ref(1)
  9. const total = ref(0)
  10. const loading = ref(false)
  11. const finished = ref(false)
  12. const pageSize = 20
  13. const goBack = () => {
  14. uni.navigateBack({
  15. fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
  16. })
  17. }
  18. const goForm = () => uni.navigateTo({ url: PAGE_PATHS.bxAdvanceForm })
  19. const goDetail = (row) =>
  20. uni.navigateTo({ url: `${PAGE_PATHS.bxAdvanceDetail}?id=${row.id}` })
  21. const loadList = async (reset = false) => {
  22. if (loading.value) return
  23. if (reset) {
  24. page.value = 1
  25. finished.value = false
  26. list.value = []
  27. }
  28. if (finished.value) return
  29. loading.value = true
  30. try {
  31. const res = await listMyAdvance({ page: page.value, pageSize })
  32. const rows = res.rows || []
  33. list.value = reset ? rows : list.value.concat(rows)
  34. total.value = res.total || 0
  35. if (list.value.length >= total.value || rows.length < pageSize) finished.value = true
  36. else page.value += 1
  37. } catch (e) {
  38. uni.showToast({ title: e.message || '加载失败', icon: 'none' })
  39. } finally {
  40. loading.value = false
  41. }
  42. }
  43. onShow(() => loadList(true))
  44. onReachBottom(() => loadList(false))
  45. </script>
  46. <template>
  47. <view class="mp-page mp-page--sub">
  48. <view class="mp-header mp-header--bx">
  49. <view class="mp-header__row">
  50. <text class="mp-subpage-back" @click="goBack">← 工作台</text>
  51. <view class="mp-header__action" @click="goForm">+ 申请</view>
  52. </view>
  53. <text class="mp-header__title" style="margin-top: 16rpx">借款申请</text>
  54. </view>
  55. <view class="mp-section">
  56. <mp-empty v-if="!list.length && !loading" title="暂无借款单" />
  57. <view v-else class="mp-list">
  58. <view v-for="row in list" :key="row.id" class="mp-card" @click="goDetail(row)">
  59. <view class="mp-card__head">
  60. <view>
  61. <text class="mp-card__title">{{ dash(row.applyCode) }}</text>
  62. <text class="mp-card__sub">{{ dash(row.reason) }}</text>
  63. </view>
  64. <text class="mp-tag" :class="'mp-tag--' + bxStatusLabel(row.status).tag">
  65. {{ bxStatusLabel(row.status).text }}
  66. </text>
  67. </view>
  68. <view class="mp-card__row">
  69. <text>申请时间</text>
  70. <text class="mp-card__row-val">{{ dash(row.applyTime) }}</text>
  71. </view>
  72. <view class="mp-card__foot">
  73. <text class="mp-card__amount">{{ formatMoney(row.amount) }}</text>
  74. </view>
  75. </view>
  76. </view>
  77. <view v-if="loading" class="mp-list-loading">加载中…</view>
  78. <view v-else-if="finished && list.length" class="mp-list-end">已加载全部</view>
  79. </view>
  80. </view>
  81. </template>