list.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { onShow, onReachBottom } from '@dcloudio/uni-app'
  4. import { listPoolCustomer, claimCustomer, getCustomer } from '@/api/crm'
  5. import { labelOf, dash } from '@/utils/crmLabels'
  6. import { PAGE_PATHS } from '@/config/api'
  7. const keyword = ref('')
  8. const list = ref([])
  9. const page = ref(1)
  10. const total = ref(0)
  11. const loading = ref(false)
  12. const finished = ref(false)
  13. const claimingId = ref('')
  14. const pageSize = 20
  15. const goBack = () => {
  16. uni.navigateBack({
  17. fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
  18. })
  19. }
  20. const levelLabel = (s) => labelOf('level', s)
  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 query = {
  32. pageNum: page.value,
  33. pageSize,
  34. customerName: keyword.value.trim() || undefined,
  35. keyword: keyword.value.trim() || undefined
  36. }
  37. const res = await listPoolCustomer(query)
  38. const rows = res.rows || []
  39. list.value = reset ? rows : list.value.concat(rows)
  40. total.value = res.total || 0
  41. if (list.value.length >= total.value || rows.length < pageSize) finished.value = true
  42. else page.value += 1
  43. } catch (e) {
  44. uni.showToast({ title: e.message || '加载失败', icon: 'none' })
  45. } finally {
  46. loading.value = false
  47. }
  48. }
  49. const onClaim = (row) => {
  50. uni.showModal({
  51. title: '领取客户',
  52. content: `确认领取「${row.customerName || ''}」?`,
  53. success: async (r) => {
  54. if (!r.confirm) return
  55. claimingId.value = row.id
  56. try {
  57. await claimCustomer(row.id)
  58. uni.showToast({ title: '领取成功', icon: 'success' })
  59. loadList(true)
  60. } catch (e) {
  61. uni.showToast({ title: e.message || '领取失败', icon: 'none' })
  62. } finally {
  63. claimingId.value = ''
  64. }
  65. }
  66. })
  67. }
  68. const goDetail = async (row) => {
  69. try {
  70. await getCustomer(row.id)
  71. uni.navigateTo({ url: `${PAGE_PATHS.crmCustomerDetail}?id=${row.id}` })
  72. } catch (e) {
  73. uni.showToast({ title: e.message || '暂无法查看详情', icon: 'none' })
  74. }
  75. }
  76. onShow(() => loadList(true))
  77. onReachBottom(() => loadList(false))
  78. </script>
  79. <template>
  80. <view class="mp-page mp-page--sub">
  81. <view class="mp-header">
  82. <text class="mp-subpage-back" @click="goBack">← 工作台</text>
  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="loadList(true)"
  92. />
  93. </view>
  94. </view>
  95. <view class="mp-section">
  96. <mp-empty v-if="!list.length && !loading" title="公海暂无客户" />
  97. <view v-else class="mp-list">
  98. <view v-for="row in list" :key="row.id" class="mp-card">
  99. <view class="mp-card__head" @click="goDetail(row)">
  100. <view>
  101. <text class="mp-card__title">{{ dash(row.customerName) }}</text>
  102. <text class="mp-card__sub">入池:{{ dash(row.poolTime || row.updateTime) }}</text>
  103. </view>
  104. <text class="mp-tag mp-tag--muted">{{ levelLabel(row.level).text }}</text>
  105. </view>
  106. <view class="mp-card__row">
  107. <text>来源</text>
  108. <text class="mp-card__row-val">{{ dash(row.source) }}</text>
  109. </view>
  110. <view class="mp-card__row">
  111. <text>原负责人</text>
  112. <text class="mp-card__row-val">{{ dash(row.ownerUserName || row.prevOwnerName) }}</text>
  113. </view>
  114. <view class="mp-card__foot">
  115. <view
  116. class="mp-btn mp-btn--primary mp-btn--sm"
  117. @click.stop="onClaim(row)"
  118. >
  119. {{ claimingId === row.id ? '领取中…' : '领取' }}
  120. </view>
  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>