MemberBrowsingHistory.vue 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div v-show="!isEmpty(conversation)" class="kefu">
  3. <div class="header-title h-60px flex justify-center items-center">他的足迹</div>
  4. <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
  5. <el-tab-pane label="最近浏览" name="a" />
  6. <el-tab-pane label="订单列表" name="b" />
  7. </el-tabs>
  8. <div>
  9. <el-scrollbar ref="scrollbarRef" always height="calc(100vh - 400px)" @scroll="handleScroll">
  10. <!-- 最近浏览 -->
  11. <ProductBrowsingHistory v-if="activeName === 'a'" ref="productBrowsingHistoryRef" />
  12. <!-- 订单列表 -->
  13. <OrderBrowsingHistory v-if="activeName === 'b'" ref="orderBrowsingHistoryRef" />
  14. </el-scrollbar>
  15. </div>
  16. </div>
  17. <el-empty v-show="isEmpty(conversation)" description="请选择左侧的一个会话后开始" />
  18. </template>
  19. <script lang="ts" setup>
  20. import type { TabsPaneContext } from 'element-plus'
  21. import ProductBrowsingHistory from './ProductBrowsingHistory.vue'
  22. import OrderBrowsingHistory from './OrderBrowsingHistory.vue'
  23. import { KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
  24. import { isEmpty } from '@/utils/is'
  25. import { debounce } from 'lodash-es'
  26. import { ElScrollbar as ElScrollbarType } from 'element-plus/es/components/scrollbar'
  27. defineOptions({ name: 'MemberBrowsingHistory' })
  28. const activeName = ref('a')
  29. /** tab 切换 */
  30. const productBrowsingHistoryRef = ref<InstanceType<typeof ProductBrowsingHistory>>()
  31. const orderBrowsingHistoryRef = ref<InstanceType<typeof OrderBrowsingHistory>>()
  32. const handleClick = async (tab: TabsPaneContext) => {
  33. activeName.value = tab.paneName as string
  34. await nextTick()
  35. await getHistoryList()
  36. }
  37. /** 获得历史数据 */
  38. const getHistoryList = async () => {
  39. switch (activeName.value) {
  40. case 'a':
  41. await productBrowsingHistoryRef.value?.getHistoryList(conversation.value)
  42. break
  43. case 'b':
  44. await orderBrowsingHistoryRef.value?.getHistoryList(conversation.value)
  45. break
  46. default:
  47. break
  48. }
  49. }
  50. /** 加载下一页数据 */
  51. const loadMore = async () => {
  52. switch (activeName.value) {
  53. case 'a':
  54. await productBrowsingHistoryRef.value?.loadMore()
  55. break
  56. case 'b':
  57. await orderBrowsingHistoryRef.value?.loadMore()
  58. break
  59. default:
  60. break
  61. }
  62. }
  63. /** 浏览历史初始化 */
  64. const conversation = ref<KeFuConversationRespVO>({} as KeFuConversationRespVO) // 用户会话
  65. const initHistory = async (val: KeFuConversationRespVO) => {
  66. activeName.value = 'a'
  67. conversation.value = val
  68. await nextTick()
  69. await getHistoryList()
  70. }
  71. defineExpose({ initHistory })
  72. /** 处理消息列表滚动事件(debounce 限流) */
  73. const scrollbarRef = ref<InstanceType<typeof ElScrollbarType>>()
  74. const handleScroll = debounce(() => {
  75. const wrap = scrollbarRef.value?.wrapRef
  76. // 触底重置
  77. if (Math.abs(wrap!.scrollHeight - wrap!.clientHeight - wrap!.scrollTop) < 1) {
  78. loadMore()
  79. }
  80. }, 200)
  81. </script>
  82. <style lang="scss" scoped>
  83. .header-title {
  84. border-bottom: #e4e0e0 solid 1px;
  85. }
  86. </style>