与牧同行-兽医端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

142 lines
4.1 KiB

Page({
data: {
// 专家信息(新增在线状态)
expertInfo: {
avatar: 'https://api.dicebear.com/7.x/avataaars/png?seed=expert_pro&size=140',
name: '张振农',
specialty: '作物栽培 · 土壤改良',
experience: 15,
online: true // 在线状态
},
// 聊天申请列表数据
applyList: [],
// 分页相关
page: 1,
pageSize: 10,
hasMore: true,
total: 0,
},
onLoad() {
this.loadApplyList(1);
},
// 加载申请列表(增强模拟数据)
loadApplyList(page) {
const { pageSize } = this.data;
wx.showLoading({ title: '加载中...', mask: true });
setTimeout(() => {
const mockData = this.generateMockData(page, pageSize);
if (page === 1) {
this.setData({
applyList: mockData.list,
total: mockData.total,
hasMore: mockData.hasMore,
page: page
});
} else {
this.setData({
applyList: this.data.applyList.concat(mockData.list),
total: mockData.total,
hasMore: mockData.hasMore,
page: page
});
}
wx.hideLoading();
}, 600);
},
// 生成更丰富的模拟数据(含标签)
generateMockData(page, pageSize) {
const total = 23;
const start = (page - 1) * pageSize;
const end = start + pageSize;
const hasMore = end < total;
const list = [];
const seeds = ['farmer1', 'sheep', 'cattle', 'wheat', 'tractor', 'green', 'sun', 'rain', 'soil', 'seed'];
const firstNames = ['李', '王', '张', '刘', '赵', '陈', '杨', '周', '吴', '黄'];
const farmTypes = ['水稻种植', '牛羊养殖', '果树栽培', '蔬菜大棚', '有机农场', '蜂蜜养殖', '食用菌', '药材种植'];
const tagPool = [
['玉米', '虫害'],
['羊羔', '腹泻'],
['施肥', '建议'],
['土壤', '检测'],
['大棚', '温度'],
['猪病', '防治'],
['果树', '修剪'],
['蜂蜜', '取蜜']
];
for (let i = start; i < Math.min(end, total); i++) {
const id = `apply_${i + 1}`;
const userId = `user_${(i % 10) + 1}`;
const seedIndex = i % seeds.length;
const nameIndex = i % firstNames.length;
const typeIndex = (i * 3) % farmTypes.length;
const unread = i % 4 === 0 ? 2 : (i % 7 === 0 ? 1 : 0);
const statuses = ['pending', 'accepted', 'completed'];
const status = statuses[i % 3];
// 随机标签
const tags = tagPool[(i * 2) % tagPool.length];
const time = new Date(Date.now() - (i * 7200000) - Math.floor(Math.random() * 5000000));
const timeStr = `${time.getMonth()+1}.${time.getDate()} ${time.getHours()}:${time.getMinutes().toString().padStart(2,'0')}`;
// 更真实的预览消息
let lastMessage = '';
if (i % 5 === 0) lastMessage = '专家您好,我家玉米出现黄叶,能帮看看吗?';
else if (i % 3 === 0) lastMessage = '咨询一下羊羔腹泻的问题,急!';
else if (i % 4 === 0) lastMessage = '请问什么时候方便通话?';
else lastMessage = '请求添加您为咨询顾问';
list.push({
id: id,
user: {
id: userId,
name: firstNames[nameIndex] + (i % 2 === 0 ? '建国' : '秀英') + (i + 1),
avatar: `https://api.dicebear.com/7.x/avataaars/png?seed=${seeds[seedIndex]}_${i}&size=96`,
farmType: farmTypes[typeIndex],
},
applyTime: timeStr,
lastMessage: lastMessage,
unreadCount: unread,
status: status,
tags: tags,
});
}
return {
list,
total,
hasMore,
};
},
// 处理点击申请项
handleApply(e) {
console.log(111,e);
const id = e.currentTarget.dataset.id
wx.navigateTo({
url: `/pagesA/pages/expertChat/expertChat?id=${id}`,
})
},
loadMore() {
const { hasMore, page } = this.data;
if (hasMore) {
this.loadApplyList(page + 1);
}
},
onPullDownRefresh() {
this.setData({ page: 1, hasMore: true });
this.loadApplyList(1);
wx.stopPullDownRefresh();
}
});