|
|
|
|
// pages/chat/index.js
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
chatList: [],
|
|
|
|
|
searchKeyword: '',
|
|
|
|
|
filteredChatList: []
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
this.loadChatList();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
loadChatList: function () {
|
|
|
|
|
// 模拟加载消息列表
|
|
|
|
|
const chatList = [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
|
|
|
|
name: '系统消息',
|
|
|
|
|
avatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
|
|
|
|
|
content: '欢迎使用消息中心功能',
|
|
|
|
|
time: '刚刚',
|
|
|
|
|
unread: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
|
name: '客服小王',
|
|
|
|
|
avatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
|
|
|
|
|
content: '您好,有什么可以帮助您的吗?',
|
|
|
|
|
time: '10分钟前',
|
|
|
|
|
unread: false
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 3,
|
|
|
|
|
name: '供应商小李',
|
|
|
|
|
avatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
|
|
|
|
|
content: '您的订单已经发货,请注意查收',
|
|
|
|
|
time: '1小时前',
|
|
|
|
|
unread: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 4,
|
|
|
|
|
name: '采购部门',
|
|
|
|
|
avatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
|
|
|
|
|
content: '关于下个月的采购计划,请查收附件',
|
|
|
|
|
time: '昨天',
|
|
|
|
|
unread: false
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 5,
|
|
|
|
|
name: '技术支持',
|
|
|
|
|
avatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
|
|
|
|
|
content: '系统升级已完成,新增了多项功能',
|
|
|
|
|
time: '2天前',
|
|
|
|
|
unread: true
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
chatList: chatList,
|
|
|
|
|
filteredChatList: chatList
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 搜索功能
|
|
|
|
|
onSearchInput: function (e) {
|
|
|
|
|
const keyword = e.detail.value;
|
|
|
|
|
this.setData({
|
|
|
|
|
searchKeyword: keyword
|
|
|
|
|
});
|
|
|
|
|
this.filterChatList(keyword);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 过滤聊天列表
|
|
|
|
|
filterChatList: function (keyword) {
|
|
|
|
|
if (!keyword) {
|
|
|
|
|
this.setData({
|
|
|
|
|
filteredChatList: this.data.chatList
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const filteredList = this.data.chatList.filter(item => {
|
|
|
|
|
return item.name.includes(keyword) || item.content.includes(keyword);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
filteredChatList: filteredList
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 聊天项点击事件
|
|
|
|
|
onChatItemTap: function (e) {
|
|
|
|
|
const chatId = e.currentTarget.dataset.id;
|
|
|
|
|
|
|
|
|
|
// 跳转到聊天详情页
|
|
|
|
|
wx.navigateTo({
|
|
|
|
|
url: '/pages/chat-detail/index?id=' + chatId,
|
|
|
|
|
success: function () {
|
|
|
|
|
console.log('成功跳转到聊天详情页');
|
|
|
|
|
},
|
|
|
|
|
fail: function (error) {
|
|
|
|
|
console.error('跳转到聊天详情页失败:', error);
|
|
|
|
|
wx.showToast({
|
|
|
|
|
title: '聊天功能开发中',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
this.loadChatList();
|
|
|
|
|
wx.stopPullDownRefresh();
|
|
|
|
|
}
|
|
|
|
|
});
|