list.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { onShow, onReachBottom } from '@dcloudio/uni-app'
  4. import { listOpportunity } 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: 'following', label: '跟进中', status: 'following' },
  10. { key: 'won', label: '赢单', status: 'won' },
  11. { key: 'lost', label: '输单', status: 'lost' }
  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.crmOpportunityDetail}?id=${row.id}` })
  28. }
  29. const stageLabel = (s) => labelOf('opportunityStage', s)
  30. const statusLabel = (s) => labelOf('opportunityStatus', s)
  31. const loadList = async (reset = false) => {
  32. if (loading.value) return
  33. if (reset) {
  34. page.value = 1
  35. finished.value = false
  36. list.value = []
  37. }
  38. if (finished.value) return
  39. loading.value = true
  40. try {
  41. const tab = tabs.find((t) => t.key === activeTab.value)
  42. const query = {
  43. pageNum: page.value,
  44. pageSize,
  45. keyword: keyword.value.trim() || undefined
  46. }
  47. if (tab?.status) query.status = tab.status
  48. const res = await listOpportunity(query)
  49. const rows = res.rows || []
  50. list.value = reset ? rows : list.value.concat(rows)
  51. total.value = res.total || 0
  52. if (list.value.length >= total.value || rows.length < pageSize) finished.value = true
  53. else page.value += 1
  54. } catch (e) {
  55. uni.showToast({ title: e.message || '加载失败', icon: 'none' })
  56. } finally {
  57. loading.value = false
  58. }
  59. }
  60. const switchTab = (key) => {
  61. if (activeTab.value === key) return
  62. activeTab.value = key
  63. loadList(true)
  64. }
  65. onShow(() => loadList(true))
  66. onReachBottom(() => loadList(false))
  67. </script>
  68. <template>
  69. <view class="mp-page mp-page--sub">
  70. <view class="mp-header">
  71. <text class="mp-subpage-back" @click="goBack">← 工作台</text>
  72. <text class="mp-header__title" style="margin-top: 16rpx">商机管理</text>
  73. <view class="mp-header__search">
  74. <view class="mp-header__search-dot" />
  75. <input
  76. v-model="keyword"
  77. class="mp-header__search-input"
  78. placeholder="搜索商机 / 客户"
  79. confirm-type="search"
  80. @confirm="loadList(true)"
  81. />
  82. </view>
  83. </view>
  84. <view class="mp-section" style="padding-bottom: 0">
  85. <scroll-view scroll-x class="mp-tabs">
  86. <view
  87. v-for="t in tabs"
  88. :key="t.key"
  89. class="mp-tab"
  90. :class="{ 'mp-tab--active': activeTab === t.key }"
  91. @click="switchTab(t.key)"
  92. >
  93. {{ t.label }}
  94. </view>
  95. </scroll-view>
  96. </view>
  97. <view class="mp-section">
  98. <mp-empty v-if="!list.length && !loading" title="暂无商机" />
  99. <view v-else class="mp-list">
  100. <view v-for="row in list" :key="row.id" class="mp-card" @click="goDetail(row)">
  101. <view class="mp-card__head">
  102. <view>
  103. <text class="mp-card__title">{{ dash(row.opportunityName) }}</text>
  104. <text class="mp-card__sub">{{ dash(row.customerName) }}</text>
  105. </view>
  106. <text class="mp-tag" :class="'mp-tag--' + statusLabel(row.status).tag">
  107. {{ statusLabel(row.status).text }}
  108. </text>
  109. </view>
  110. <view class="mp-card__row">
  111. <text>阶段</text>
  112. <text class="mp-card__row-val">{{ stageLabel(row.stage).text }}</text>
  113. </view>
  114. <view class="mp-card__row">
  115. <text>金额</text>
  116. <text class="mp-card__row-val">{{ formatMoney(row.amount ?? row.expectedAmount) }}</text>
  117. </view>
  118. <view class="mp-card__row">
  119. <text>负责人</text>
  120. <text class="mp-card__row-val">{{ dash(row.ownerUserName) }}</text>
  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>