list.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { onShow, onReachBottom } from '@dcloudio/uni-app'
  4. import { listQuote } from '@/api/crm'
  5. import { labelOf, dash, formatMoney } from '@/utils/crmLabels'
  6. import { PAGE_PATHS } from '@/config/api'
  7. const tabs = [
  8. { key: 'all', label: '全部' },
  9. { key: 'draft', label: '草稿', status: 'draft' },
  10. { key: 'pending', label: '待审批', status: 'pending' },
  11. { key: 'approved', label: '已通过', status: 'approved' }
  12. ]
  13. const activeTab = ref('all')
  14. const keyword = ref('')
  15. const list = ref([])
  16. const page = ref(1)
  17. const total = ref(0)
  18. const loading = ref(false)
  19. const finished = ref(false)
  20. const pageSize = 20
  21. const goBack = () => {
  22. uni.navigateBack({
  23. fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
  24. })
  25. }
  26. const goDetail = (row) => {
  27. uni.navigateTo({ url: `${PAGE_PATHS.crmQuoteDetail}?id=${row.id}` })
  28. }
  29. const statusLabel = (s) => labelOf('quoteStatus', s)
  30. const loadList = async (reset = false) => {
  31. if (loading.value) return
  32. if (reset) {
  33. page.value = 1
  34. finished.value = false
  35. list.value = []
  36. }
  37. if (finished.value) return
  38. loading.value = true
  39. try {
  40. const tab = tabs.find((t) => t.key === activeTab.value)
  41. const query = {
  42. pageNum: page.value,
  43. pageSize,
  44. keyword: keyword.value.trim() || undefined
  45. }
  46. if (tab?.status) query.status = tab.status
  47. const res = await listQuote(query)
  48. const rows = res.rows || []
  49. list.value = reset ? rows : list.value.concat(rows)
  50. total.value = res.total || 0
  51. if (list.value.length >= total.value || rows.length < pageSize) finished.value = true
  52. else page.value += 1
  53. } catch (e) {
  54. uni.showToast({ title: e.message || '加载失败', icon: 'none' })
  55. } finally {
  56. loading.value = false
  57. }
  58. }
  59. const switchTab = (key) => {
  60. if (activeTab.value === key) return
  61. activeTab.value = key
  62. loadList(true)
  63. }
  64. onShow(() => loadList(true))
  65. onReachBottom(() => loadList(false))
  66. </script>
  67. <template>
  68. <view class="mp-page mp-page--sub">
  69. <view class="mp-header">
  70. <text class="mp-subpage-back" @click="goBack">← 工作台</text>
  71. <text class="mp-header__title" style="margin-top: 16rpx">报价管理</text>
  72. <view class="mp-header__search">
  73. <view class="mp-header__search-dot" />
  74. <input
  75. v-model="keyword"
  76. class="mp-header__search-input"
  77. placeholder="搜索报价单号 / 客户"
  78. confirm-type="search"
  79. @confirm="loadList(true)"
  80. />
  81. </view>
  82. </view>
  83. <view class="mp-section" style="padding-bottom: 0">
  84. <scroll-view scroll-x class="mp-tabs">
  85. <view
  86. v-for="t in tabs"
  87. :key="t.key"
  88. class="mp-tab"
  89. :class="{ 'mp-tab--active': activeTab === t.key }"
  90. @click="switchTab(t.key)"
  91. >
  92. {{ t.label }}
  93. </view>
  94. </scroll-view>
  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.quoteTitle || row.quoteNo) }}</text>
  103. <text class="mp-card__sub">{{ dash(row.quoteNo) }} · {{ dash(row.customerName) }}</text>
  104. </view>
  105. <text class="mp-tag" :class="'mp-tag--' + statusLabel(row.status).tag">
  106. {{ statusLabel(row.status).text }}
  107. </text>
  108. </view>
  109. <view class="mp-card__row">
  110. <text>金额</text>
  111. <text class="mp-card__row-val">{{ formatMoney(row.totalAmount ?? row.amount) }}</text>
  112. </view>
  113. <view class="mp-card__row">
  114. <text>负责人</text>
  115. <text class="mp-card__row-val">{{ dash(row.ownerUserName) }}</text>
  116. </view>
  117. <view class="mp-card__row">
  118. <text>报价日期</text>
  119. <text class="mp-card__row-val">{{ dash(row.quoteDate || row.createTime) }}</text>
  120. </view>
  121. </view>
  122. </view>
  123. <view v-if="loading" class="mp-list-loading">加载中…</view>
  124. <view v-else-if="finished && list.length" class="mp-list-end">已加载全部</view>
  125. </view>
  126. </view>
  127. </template>