list.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { onShow, onReachBottom } from '@dcloudio/uni-app'
  4. import { listClue, listMyClue } from '@/api/crm'
  5. import { labelOf, dash } from '@/utils/crmLabels'
  6. import { PAGE_PATHS } from '@/config/api'
  7. const tabs = [
  8. { key: 'all', label: '全部' },
  9. { key: 'mine', label: '我的' },
  10. { key: 'new', label: '新线索', status: 'new' },
  11. { key: 'follow', label: '跟进中', status: 'follow' },
  12. { key: 'converted', label: '已转化', status: 'converted' }
  13. ]
  14. const activeTab = ref('all')
  15. const keyword = ref('')
  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 goBack = () => {
  23. uni.navigateBack({
  24. fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
  25. })
  26. }
  27. const goForm = () => {
  28. uni.navigateTo({ url: PAGE_PATHS.crmClueForm })
  29. }
  30. const goDetail = (row) => {
  31. uni.navigateTo({ url: `${PAGE_PATHS.crmClueDetail}?id=${row.id}` })
  32. }
  33. const statusLabel = (status) => labelOf('clueStatus', status)
  34. const loadList = async (reset = false) => {
  35. if (loading.value) return
  36. if (reset) {
  37. page.value = 1
  38. finished.value = false
  39. list.value = []
  40. }
  41. if (finished.value) return
  42. loading.value = true
  43. try {
  44. const tab = tabs.find((t) => t.key === activeTab.value)
  45. const query = {
  46. pageNum: page.value,
  47. pageSize,
  48. keyword: keyword.value.trim() || undefined
  49. }
  50. if (tab?.status) query.status = tab.status
  51. if (activeTab.value === 'converted') query.viewType = 'converted'
  52. const res = activeTab.value === 'mine' ? await listMyClue(query) : await listClue(query)
  53. const rows = res.rows || []
  54. list.value = reset ? rows : list.value.concat(rows)
  55. total.value = res.total || 0
  56. if (list.value.length >= total.value || rows.length < pageSize) {
  57. finished.value = true
  58. } else {
  59. page.value += 1
  60. }
  61. } catch (e) {
  62. uni.showToast({ title: e.message || '加载失败', icon: 'none' })
  63. } finally {
  64. loading.value = false
  65. }
  66. }
  67. const switchTab = (key) => {
  68. if (activeTab.value === key) return
  69. activeTab.value = key
  70. loadList(true)
  71. }
  72. const onSearch = () => loadList(true)
  73. onShow(() => loadList(true))
  74. onReachBottom(() => loadList(false))
  75. </script>
  76. <template>
  77. <view class="mp-page mp-page--sub">
  78. <view class="mp-header">
  79. <view class="mp-header__row">
  80. <text class="mp-subpage-back" @click="goBack">← 工作台</text>
  81. <view class="mp-header__action" @click="goForm">新增</view>
  82. </view>
  83. <text class="mp-header__title" style="margin-top: 16rpx">线索管理</text>
  84. <view class="mp-header__search">
  85. <view class="mp-header__search-dot" />
  86. <input
  87. v-model="keyword"
  88. class="mp-header__search-input"
  89. placeholder="搜索姓名 / 公司 / 手机"
  90. confirm-type="search"
  91. @confirm="onSearch"
  92. />
  93. </view>
  94. </view>
  95. <view class="mp-section" style="padding-bottom: 0">
  96. <scroll-view scroll-x class="mp-tabs">
  97. <view
  98. v-for="t in tabs"
  99. :key="t.key"
  100. class="mp-tab"
  101. :class="{ 'mp-tab--active': activeTab === t.key }"
  102. @click="switchTab(t.key)"
  103. >
  104. {{ t.label }}
  105. </view>
  106. </scroll-view>
  107. </view>
  108. <view class="mp-section">
  109. <mp-empty v-if="!list.length && !loading" title="暂无线索" />
  110. <view v-else class="mp-list">
  111. <view v-for="row in list" :key="row.id" class="mp-card" @click="goDetail(row)">
  112. <view class="mp-card__head">
  113. <view>
  114. <text class="mp-card__title">{{ dash(row.clueName) }}</text>
  115. <text class="mp-card__sub">{{ dash(row.company) }}</text>
  116. </view>
  117. <text class="mp-tag" :class="'mp-tag--' + statusLabel(row.status).tag">
  118. {{ statusLabel(row.status).text }}
  119. </text>
  120. </view>
  121. <view class="mp-card__row">
  122. <text>手机</text>
  123. <text class="mp-card__row-val">{{ dash(row.mobile) }}</text>
  124. </view>
  125. <view class="mp-card__row">
  126. <text>负责人</text>
  127. <text class="mp-card__row-val">{{ dash(row.ownerUserName) }}</text>
  128. </view>
  129. <view class="mp-card__row">
  130. <text>来源</text>
  131. <text class="mp-card__row-val">{{ dash(row.source) }}</text>
  132. </view>
  133. </view>
  134. </view>
  135. <view v-if="loading" class="mp-list-loading">加载中…</view>
  136. <view v-else-if="finished && list.length" class="mp-list-end">已加载全部</view>
  137. </view>
  138. </view>
  139. </template>