MemberBrowsingHistory.vue 3.2 KB

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