2024-07-17 20:15:41 +08:00
|
|
|
|
<!-- 目录是不是叫 member 好点。然后这个组件是 MemberInfo,里面有浏览足迹 -->
|
2024-07-17 16:43:20 +08:00
|
|
|
|
<template>
|
2024-11-04 15:25:43 +08:00
|
|
|
|
<el-container class="kefu">
|
|
|
|
|
<el-header class="kefu-header">
|
|
|
|
|
<el-tabs v-model="activeName" class="kefu-tabs" @tab-click="handleClick">
|
|
|
|
|
<el-tab-pane label="最近浏览" name="a" />
|
|
|
|
|
<el-tab-pane label="订单列表" name="b" />
|
|
|
|
|
</el-tabs>
|
|
|
|
|
</el-header>
|
|
|
|
|
<el-main class="kefu-content">
|
|
|
|
|
<div v-show="!isEmpty(conversation)">
|
|
|
|
|
<el-scrollbar ref="scrollbarRef" always @scroll="handleScroll">
|
|
|
|
|
<!-- 最近浏览 -->
|
|
|
|
|
<ProductBrowsingHistory v-if="activeName === 'a'" ref="productBrowsingHistoryRef" />
|
|
|
|
|
<!-- 订单列表 -->
|
|
|
|
|
<OrderBrowsingHistory v-if="activeName === 'b'" ref="orderBrowsingHistoryRef" />
|
|
|
|
|
</el-scrollbar>
|
|
|
|
|
</div>
|
|
|
|
|
<el-empty v-show="isEmpty(conversation)" description="请选择左侧的一个会话后开始" />
|
|
|
|
|
</el-main>
|
|
|
|
|
</el-container>
|
2024-07-17 16:43:20 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import type { TabsPaneContext } from 'element-plus'
|
|
|
|
|
import ProductBrowsingHistory from './ProductBrowsingHistory.vue'
|
2024-07-17 18:03:34 +08:00
|
|
|
|
import OrderBrowsingHistory from './OrderBrowsingHistory.vue'
|
2024-07-17 16:43:20 +08:00
|
|
|
|
import { KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
|
|
|
|
|
import { isEmpty } from '@/utils/is'
|
2024-07-17 18:03:34 +08:00
|
|
|
|
import { debounce } from 'lodash-es'
|
2024-08-13 16:31:45 +08:00
|
|
|
|
import { ElScrollbar as ElScrollbarType } from 'element-plus/es/components/scrollbar/index'
|
2024-07-17 16:43:20 +08:00
|
|
|
|
|
|
|
|
|
defineOptions({ name: 'MemberBrowsingHistory' })
|
|
|
|
|
|
|
|
|
|
const activeName = ref('a')
|
2024-07-17 20:15:41 +08:00
|
|
|
|
|
2024-07-17 16:43:20 +08:00
|
|
|
|
/** tab 切换 */
|
|
|
|
|
const productBrowsingHistoryRef = ref<InstanceType<typeof ProductBrowsingHistory>>()
|
2024-07-17 18:03:34 +08:00
|
|
|
|
const orderBrowsingHistoryRef = ref<InstanceType<typeof OrderBrowsingHistory>>()
|
|
|
|
|
const handleClick = async (tab: TabsPaneContext) => {
|
2024-07-17 16:43:20 +08:00
|
|
|
|
activeName.value = tab.paneName as string
|
2024-07-17 18:03:34 +08:00
|
|
|
|
await nextTick()
|
|
|
|
|
await getHistoryList()
|
2024-07-17 16:43:20 +08:00
|
|
|
|
}
|
2024-07-17 20:15:41 +08:00
|
|
|
|
|
2024-07-17 16:43:20 +08:00
|
|
|
|
/** 获得历史数据 */
|
2024-07-17 20:15:41 +08:00
|
|
|
|
// TODO @puhui:不要用 a、b 哈。就订单列表、浏览列表这种噶
|
2024-07-17 16:43:20 +08:00
|
|
|
|
const getHistoryList = async () => {
|
|
|
|
|
switch (activeName.value) {
|
|
|
|
|
case 'a':
|
|
|
|
|
await productBrowsingHistoryRef.value?.getHistoryList(conversation.value)
|
|
|
|
|
break
|
|
|
|
|
case 'b':
|
2024-07-17 18:03:34 +08:00
|
|
|
|
await orderBrowsingHistoryRef.value?.getHistoryList(conversation.value)
|
|
|
|
|
break
|
|
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-17 20:15:41 +08:00
|
|
|
|
|
2024-07-17 18:03:34 +08:00
|
|
|
|
/** 加载下一页数据 */
|
|
|
|
|
const loadMore = async () => {
|
|
|
|
|
switch (activeName.value) {
|
|
|
|
|
case 'a':
|
|
|
|
|
await productBrowsingHistoryRef.value?.loadMore()
|
|
|
|
|
break
|
|
|
|
|
case 'b':
|
|
|
|
|
await orderBrowsingHistoryRef.value?.loadMore()
|
2024-07-17 16:43:20 +08:00
|
|
|
|
break
|
|
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-17 20:15:41 +08:00
|
|
|
|
|
2024-07-17 16:43:20 +08:00
|
|
|
|
/** 浏览历史初始化 */
|
|
|
|
|
const conversation = ref<KeFuConversationRespVO>({} as KeFuConversationRespVO) // 用户会话
|
|
|
|
|
const initHistory = async (val: KeFuConversationRespVO) => {
|
|
|
|
|
activeName.value = 'a'
|
|
|
|
|
conversation.value = val
|
2024-07-17 18:03:34 +08:00
|
|
|
|
await nextTick()
|
2024-07-17 16:43:20 +08:00
|
|
|
|
await getHistoryList()
|
|
|
|
|
}
|
|
|
|
|
defineExpose({ initHistory })
|
2024-07-17 18:03:34 +08:00
|
|
|
|
|
|
|
|
|
/** 处理消息列表滚动事件(debounce 限流) */
|
|
|
|
|
const scrollbarRef = ref<InstanceType<typeof ElScrollbarType>>()
|
|
|
|
|
const handleScroll = debounce(() => {
|
|
|
|
|
const wrap = scrollbarRef.value?.wrapRef
|
|
|
|
|
// 触底重置
|
|
|
|
|
if (Math.abs(wrap!.scrollHeight - wrap!.clientHeight - wrap!.scrollTop) < 1) {
|
|
|
|
|
loadMore()
|
|
|
|
|
}
|
|
|
|
|
}, 200)
|
2024-07-17 16:43:20 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2024-11-04 15:25:43 +08:00
|
|
|
|
.kefu {
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
height: 100%;
|
|
|
|
|
width: 300px !important;
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
border-left: var(--el-border-color) solid 1px;
|
|
|
|
|
|
|
|
|
|
&-header {
|
|
|
|
|
background: #fbfbfb;
|
|
|
|
|
box-shadow: 0 0 0 0 #dcdfe6;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
|
|
|
|
&-title {
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&-content {
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
position: relative;
|
|
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&-tabs {
|
|
|
|
|
height: 100%;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-17 16:43:20 +08:00
|
|
|
|
.header-title {
|
|
|
|
|
border-bottom: #e4e0e0 solid 1px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|