与牧同行-兽医端小程序
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.

141 lines
4.1 KiB

  1. Page({
  2. data: {
  3. // 专家信息(新增在线状态)
  4. expertInfo: {
  5. avatar: 'https://api.dicebear.com/7.x/avataaars/png?seed=expert_pro&size=140',
  6. name: '张振农',
  7. specialty: '作物栽培 · 土壤改良',
  8. experience: 15,
  9. online: true // 在线状态
  10. },
  11. // 聊天申请列表数据
  12. applyList: [],
  13. // 分页相关
  14. page: 1,
  15. pageSize: 10,
  16. hasMore: true,
  17. total: 0,
  18. },
  19. onLoad() {
  20. this.loadApplyList(1);
  21. },
  22. // 加载申请列表(增强模拟数据)
  23. loadApplyList(page) {
  24. const { pageSize } = this.data;
  25. wx.showLoading({ title: '加载中...', mask: true });
  26. setTimeout(() => {
  27. const mockData = this.generateMockData(page, pageSize);
  28. if (page === 1) {
  29. this.setData({
  30. applyList: mockData.list,
  31. total: mockData.total,
  32. hasMore: mockData.hasMore,
  33. page: page
  34. });
  35. } else {
  36. this.setData({
  37. applyList: this.data.applyList.concat(mockData.list),
  38. total: mockData.total,
  39. hasMore: mockData.hasMore,
  40. page: page
  41. });
  42. }
  43. wx.hideLoading();
  44. }, 600);
  45. },
  46. // 生成更丰富的模拟数据(含标签)
  47. generateMockData(page, pageSize) {
  48. const total = 23;
  49. const start = (page - 1) * pageSize;
  50. const end = start + pageSize;
  51. const hasMore = end < total;
  52. const list = [];
  53. const seeds = ['farmer1', 'sheep', 'cattle', 'wheat', 'tractor', 'green', 'sun', 'rain', 'soil', 'seed'];
  54. const firstNames = ['李', '王', '张', '刘', '赵', '陈', '杨', '周', '吴', '黄'];
  55. const farmTypes = ['水稻种植', '牛羊养殖', '果树栽培', '蔬菜大棚', '有机农场', '蜂蜜养殖', '食用菌', '药材种植'];
  56. const tagPool = [
  57. ['玉米', '虫害'],
  58. ['羊羔', '腹泻'],
  59. ['施肥', '建议'],
  60. ['土壤', '检测'],
  61. ['大棚', '温度'],
  62. ['猪病', '防治'],
  63. ['果树', '修剪'],
  64. ['蜂蜜', '取蜜']
  65. ];
  66. for (let i = start; i < Math.min(end, total); i++) {
  67. const id = `apply_${i + 1}`;
  68. const userId = `user_${(i % 10) + 1}`;
  69. const seedIndex = i % seeds.length;
  70. const nameIndex = i % firstNames.length;
  71. const typeIndex = (i * 3) % farmTypes.length;
  72. const unread = i % 4 === 0 ? 2 : (i % 7 === 0 ? 1 : 0);
  73. const statuses = ['pending', 'accepted', 'completed'];
  74. const status = statuses[i % 3];
  75. // 随机标签
  76. const tags = tagPool[(i * 2) % tagPool.length];
  77. const time = new Date(Date.now() - (i * 7200000) - Math.floor(Math.random() * 5000000));
  78. const timeStr = `${time.getMonth()+1}.${time.getDate()} ${time.getHours()}:${time.getMinutes().toString().padStart(2,'0')}`;
  79. // 更真实的预览消息
  80. let lastMessage = '';
  81. if (i % 5 === 0) lastMessage = '专家您好,我家玉米出现黄叶,能帮看看吗?';
  82. else if (i % 3 === 0) lastMessage = '咨询一下羊羔腹泻的问题,急!';
  83. else if (i % 4 === 0) lastMessage = '请问什么时候方便通话?';
  84. else lastMessage = '请求添加您为咨询顾问';
  85. list.push({
  86. id: id,
  87. user: {
  88. id: userId,
  89. name: firstNames[nameIndex] + (i % 2 === 0 ? '建国' : '秀英') + (i + 1),
  90. avatar: `https://api.dicebear.com/7.x/avataaars/png?seed=${seeds[seedIndex]}_${i}&size=96`,
  91. farmType: farmTypes[typeIndex],
  92. },
  93. applyTime: timeStr,
  94. lastMessage: lastMessage,
  95. unreadCount: unread,
  96. status: status,
  97. tags: tags,
  98. });
  99. }
  100. return {
  101. list,
  102. total,
  103. hasMore,
  104. };
  105. },
  106. // 处理点击申请项
  107. handleApply(e) {
  108. console.log(111,e);
  109. const id = e.currentTarget.dataset.id
  110. wx.navigateTo({
  111. url: `/pagesA/pages/expertChat/expertChat?id=${id}`,
  112. })
  113. },
  114. loadMore() {
  115. const { hasMore, page } = this.data;
  116. if (hasMore) {
  117. this.loadApplyList(page + 1);
  118. }
  119. },
  120. onPullDownRefresh() {
  121. this.setData({ page: 1, hasMore: true });
  122. this.loadApplyList(1);
  123. wx.stopPullDownRefresh();
  124. }
  125. });