list.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <script setup>
  2. import { ref, computed } from 'vue'
  3. import { onShow } from '@dcloudio/uni-app'
  4. import { listPlans } from '@/api/pl'
  5. import { archiveStatusLabel, planCardSub, dash, planTypeLabel } from '@/utils/plLabels'
  6. import { PAGE_PATHS } from '@/config/api'
  7. const keyword = ref('')
  8. const rows = ref([])
  9. const total = ref(0)
  10. const loading = ref(false)
  11. const page = ref(1)
  12. const finished = ref(false)
  13. const list = computed(() => {
  14. const kw = String(keyword.value || '')
  15. .trim()
  16. .toLowerCase()
  17. if (!kw) return rows.value
  18. return rows.value.filter((row) => {
  19. const blob = [row.planNo, row.customerName, planCardSub(row)].join(' ').toLowerCase()
  20. return blob.includes(kw)
  21. })
  22. })
  23. const goBack = () => {
  24. uni.navigateBack({
  25. fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
  26. })
  27. }
  28. const goDetail = (row) =>
  29. uni.navigateTo({ url: `${PAGE_PATHS.plPlanDetail}?id=${row.id}&readonly=1` })
  30. const load = async (reset = true) => {
  31. if (loading.value) return
  32. if (reset) {
  33. page.value = 1
  34. finished.value = false
  35. rows.value = []
  36. }
  37. if (finished.value) return
  38. loading.value = true
  39. try {
  40. const res = await listPlans({
  41. archiveStatus: 'archived',
  42. q: keyword.value.trim() || undefined,
  43. page: page.value,
  44. pageSize: 20
  45. })
  46. const next = res.rows || []
  47. rows.value = reset ? next : rows.value.concat(next)
  48. total.value = res.total || 0
  49. if (!next.length || rows.value.length >= total.value) finished.value = true
  50. else page.value += 1
  51. } catch (e) {
  52. uni.showToast({ title: e.message || '加载失败', icon: 'none' })
  53. } finally {
  54. loading.value = false
  55. }
  56. }
  57. onShow(() => load(true))
  58. </script>
  59. <template>
  60. <view class="mp-page mp-page--sub">
  61. <view class="mp-header mp-header--pl">
  62. <text class="mp-subpage-back" @click="goBack">← 工作台</text>
  63. <text class="mp-header__title" style="margin-top: 16rpx">计划归档</text>
  64. <view class="mp-header__search">
  65. <view class="mp-header__search-dot" />
  66. <input
  67. v-model="keyword"
  68. class="mp-header__search-input"
  69. placeholder="计划号 / 客户"
  70. confirm-type="search"
  71. @confirm="load(true)"
  72. />
  73. </view>
  74. </view>
  75. <view class="mp-section">
  76. <mp-empty v-if="!list.length && !loading" title="暂无已归档计划" />
  77. <view v-else class="mp-list">
  78. <view v-for="row in list" :key="row.id" class="mp-card" @click="goDetail(row)">
  79. <view class="mp-card__head">
  80. <view>
  81. <text class="mp-card__title">{{ dash(row.planNo) }}</text>
  82. <text class="mp-card__sub">{{ planCardSub(row) }}</text>
  83. </view>
  84. <text class="mp-tag" :class="'mp-tag--' + archiveStatusLabel(row.archiveStatus).tag">
  85. {{ archiveStatusLabel(row.archiveStatus).text }}
  86. </text>
  87. </view>
  88. <view class="mp-card__row">
  89. <text>{{ planTypeLabel(row.planType) }}</text>
  90. <text>{{ dash(row.planDate) }}</text>
  91. </view>
  92. </view>
  93. </view>
  94. <view v-if="!finished && list.length" class="mp-load-more" @click="load(false)">
  95. {{ loading ? '加载中…' : '加载更多' }}
  96. </view>
  97. </view>
  98. </view>
  99. </template>