list.vue 4.1 KB

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