Skip to content

Commit eeb76bb

Browse files
author
puhui999
committed
【新增】客服会话所属会员足迹展示组件
1 parent fe48f87 commit eeb76bb

File tree

5 files changed

+109
-12
lines changed

5 files changed

+109
-12
lines changed

src/views/mall/promotion/kefu/components/KeFuMessageList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
</MessageItem>
7979
<!-- 订单消息 -->
8080
<MessageItem :content-type="KeFuMessageContentTypeEnum.ORDER" :message="item">
81-
<OrderItem :message="item" />
81+
<OrderItem :message="item" class="max-w-70%" />
8282
</MessageItem>
8383
</div>
8484
<el-avatar

src/views/mall/promotion/kefu/components/history/MemberBrowsingHistory.vue

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,37 @@
55
<el-tab-pane label="最近浏览" name="a" />
66
<el-tab-pane label="订单列表" name="b" />
77
</el-tabs>
8-
<!-- 最近浏览 -->
9-
<ProductBrowsingHistory v-if="activeName === 'a'" ref="productBrowsingHistoryRef" />
10-
<!-- 订单列表 -->
11-
<template v-if="activeName === 'b'"></template>
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>
1216
</div>
1317
<el-empty v-show="isEmpty(conversation)" description="请选择左侧的一个会话后开始" />
1418
</template>
1519

1620
<script lang="ts" setup>
1721
import type { TabsPaneContext } from 'element-plus'
1822
import ProductBrowsingHistory from './ProductBrowsingHistory.vue'
23+
import OrderBrowsingHistory from './OrderBrowsingHistory.vue'
1924
import { KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
2025
import { isEmpty } from '@/utils/is'
26+
import { debounce } from 'lodash-es'
27+
import { ElScrollbar as ElScrollbarType } from 'element-plus/es/components/scrollbar'
2128
2229
defineOptions({ name: 'MemberBrowsingHistory' })
2330
2431
const activeName = ref('a')
2532
/** tab 切换 */
2633
const productBrowsingHistoryRef = ref<InstanceType<typeof ProductBrowsingHistory>>()
27-
const handleClick = (tab: TabsPaneContext) => {
34+
const orderBrowsingHistoryRef = ref<InstanceType<typeof OrderBrowsingHistory>>()
35+
const handleClick = async (tab: TabsPaneContext) => {
2836
activeName.value = tab.paneName as string
29-
getHistoryList()
37+
await nextTick()
38+
await getHistoryList()
3039
}
3140
/** 获得历史数据 */
3241
const getHistoryList = async () => {
@@ -35,6 +44,20 @@ const getHistoryList = async () => {
3544
await productBrowsingHistoryRef.value?.getHistoryList(conversation.value)
3645
break
3746
case 'b':
47+
await orderBrowsingHistoryRef.value?.getHistoryList(conversation.value)
48+
break
49+
default:
50+
break
51+
}
52+
}
53+
/** 加载下一页数据 */
54+
const loadMore = async () => {
55+
switch (activeName.value) {
56+
case 'a':
57+
await productBrowsingHistoryRef.value?.loadMore()
58+
break
59+
case 'b':
60+
await orderBrowsingHistoryRef.value?.loadMore()
3861
break
3962
default:
4063
break
@@ -45,9 +68,20 @@ const conversation = ref<KeFuConversationRespVO>({} as KeFuConversationRespVO) /
4568
const initHistory = async (val: KeFuConversationRespVO) => {
4669
activeName.value = 'a'
4770
conversation.value = val
71+
await nextTick()
4872
await getHistoryList()
4973
}
5074
defineExpose({ initHistory })
75+
76+
/** 处理消息列表滚动事件(debounce 限流) */
77+
const scrollbarRef = ref<InstanceType<typeof ElScrollbarType>>()
78+
const handleScroll = debounce(() => {
79+
const wrap = scrollbarRef.value?.wrapRef
80+
// 触底重置
81+
if (Math.abs(wrap!.scrollHeight - wrap!.clientHeight - wrap!.scrollTop) < 1) {
82+
loadMore()
83+
}
84+
}, 200)
5185
</script>
5286

5387
<style lang="scss" scoped>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<template>
2+
<OrderItem v-for="item in list" :key="item.id" :order="item" class="mb-10px" />
3+
</template>
4+
5+
<script lang="ts" setup>
6+
import OrderItem from '@/views/mall/promotion/kefu/components/message/OrderItem.vue'
7+
import { KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
8+
import { getOrderPage } from '@/api/mall/trade/order'
9+
import { concat } from 'lodash-es'
10+
11+
defineOptions({ name: 'OrderBrowsingHistory' })
12+
13+
const list = ref<any>([]) // 列表
14+
const total = ref(0) // 总数
15+
const queryParams = reactive({
16+
pageNo: 1,
17+
pageSize: 10,
18+
userId: 0
19+
})
20+
const skipGetMessageList = computed(() => {
21+
// 已加载到最后一页的话则不触发新的消息获取
22+
return total.value > 0 && Math.ceil(total.value / queryParams.pageSize) === queryParams.pageNo
23+
}) // 跳过消息获取
24+
/** 获得浏览记录 */
25+
const getHistoryList = async (val: KeFuConversationRespVO) => {
26+
queryParams.userId = val.userId
27+
const res = await getOrderPage(queryParams)
28+
total.value = res.total
29+
list.value = res.list
30+
}
31+
/** 加载下一页数据 */
32+
const loadMore = async () => {
33+
if (skipGetMessageList.value) {
34+
return
35+
}
36+
queryParams.pageNo += 1
37+
const res = await getOrderPage(queryParams)
38+
total.value = res.total
39+
concat(list.value, res.list)
40+
}
41+
defineExpose({ getHistoryList, loadMore })
42+
</script>

src/views/mall/promotion/kefu/components/history/ProductBrowsingHistory.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,40 @@
1616
import { getBrowseHistoryPage } from '@/api/mall/product/history'
1717
import ProductItem from '@/views/mall/promotion/kefu/components/message/ProductItem.vue'
1818
import { KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
19+
import { concat } from 'lodash-es'
1920
2021
defineOptions({ name: 'ProductBrowsingHistory' })
2122
2223
const list = ref<any>([]) // 列表
24+
const total = ref(0) // 总数
2325
const queryParams = reactive({
24-
pageNum: 1,
26+
pageNo: 1,
2527
pageSize: 10,
2628
userId: 0,
2729
userDeleted: false
2830
})
31+
const skipGetMessageList = computed(() => {
32+
// 已加载到最后一页的话则不触发新的消息获取
33+
return total.value > 0 && Math.ceil(total.value / queryParams.pageSize) === queryParams.pageNo
34+
}) // 跳过消息获取
2935
/** 获得浏览记录 */
3036
const getHistoryList = async (val: KeFuConversationRespVO) => {
3137
queryParams.userId = val.userId
3238
const res = await getBrowseHistoryPage(queryParams)
39+
total.value = res.total
3340
list.value = res.list
3441
}
35-
defineExpose({ getHistoryList })
42+
/** 加载下一页数据 */
43+
const loadMore = async () => {
44+
if (skipGetMessageList.value) {
45+
return
46+
}
47+
queryParams.pageNo += 1
48+
const res = await getBrowseHistoryPage(queryParams)
49+
total.value = res.total
50+
concat(list.value, res.list)
51+
}
52+
defineExpose({ getHistoryList, loadMore })
3653
</script>
3754

3855
<style lang="scss" scoped></style>

src/views/mall/promotion/kefu/components/message/OrderItem.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div :key="getMessageContent.id" class="order-list-card-box mt-14px max-w-70%">
2+
<div :key="getMessageContent.id" class="order-list-card-box mt-14px">
33
<div class="order-card-header flex items-center justify-between p-x-20px">
44
<div class="order-no">订单号:{{ getMessageContent.no }}</div>
55
<div :class="formatOrderColor(getMessageContent)" class="order-state font-16">
@@ -32,13 +32,17 @@
3232
import { fenToYuan } from '@/utils'
3333
import ProductItem from './ProductItem.vue'
3434
import { KeFuMessageRespVO } from '@/api/mall/promotion/kefu/message'
35+
import { isEmpty } from '@/utils/is'
3536
3637
defineOptions({ name: 'OrderItem' })
3738
const props = defineProps<{
38-
message: KeFuMessageRespVO
39+
message?: KeFuMessageRespVO
40+
order?: any
3941
}>()
4042
41-
const getMessageContent = computed(() => JSON.parse(props.message.content))
43+
const getMessageContent = computed(() =>
44+
isEmpty(props.order) ? JSON.parse(props!.message!.content) : props.order
45+
)
4246
4347
/**
4448
* 格式化订单状态的颜色

0 commit comments

Comments
 (0)