10 changed files with 2117 additions and 1280 deletions
-
7app.json
-
BINpages/images/xx.png
-
BINpages/images/xx1.png
-
199pagesA/pages/advisory/advisory.js
-
26pagesA/pages/advisory/advisory.wxml
-
5pagesA/pages/advisory/advisory.wxss
-
1613pagesA/pages/expertChat/expertChat.js
-
155pagesA/pages/expertChat/expertChat.wxml
-
505pagesA/pages/expertChat/expertChat.wxss
-
15utils/api.js
|
Before Width: 200 | Height: 200 | Size: 4.3 KiB |
|
Before Width: 200 | Height: 200 | Size: 4.3 KiB |
@ -1,142 +1,129 @@ |
|||||
|
import http from '../../../utils/api' |
||||
|
const baseUrl = require('../../../utils/baseUrl') |
||||
|
|
||||
Page({ |
Page({ |
||||
data: { |
data: { |
||||
// 专家信息(新增在线状态)
|
|
||||
expertInfo: { |
|
||||
avatar: 'https://api.dicebear.com/7.x/avataaars/png?seed=expert_pro&size=140', |
|
||||
name: '张振农', |
|
||||
specialty: '作物栽培 · 土壤改良', |
|
||||
experience: 15, |
|
||||
online: true // 在线状态
|
|
||||
}, |
|
||||
|
baseUrl: baseUrl, |
||||
|
user: {}, |
||||
// 聊天申请列表数据
|
// 聊天申请列表数据
|
||||
applyList: [], |
applyList: [], |
||||
// 分页相关
|
// 分页相关
|
||||
page: 1, |
page: 1, |
||||
pageSize: 10, |
pageSize: 10, |
||||
hasMore: true, |
|
||||
total: 0, |
total: 0, |
||||
|
hasMore: true, // 是否还有更多数据
|
||||
|
isLoading: false, // 是否正在加载
|
||||
|
isFirstLoad: true, // 是否首次加载
|
||||
}, |
}, |
||||
|
|
||||
onLoad() { |
onLoad() { |
||||
this.loadApplyList(1); |
|
||||
|
this.getzj() |
||||
|
this.getsessions(true) // true 表示首次加载(重置列表)
|
||||
}, |
}, |
||||
|
|
||||
// 加载申请列表(增强模拟数据)
|
|
||||
loadApplyList(page) { |
|
||||
const { pageSize } = this.data; |
|
||||
wx.showLoading({ title: '加载中...', mask: true }); |
|
||||
|
|
||||
setTimeout(() => { |
|
||||
const mockData = this.generateMockData(page, pageSize); |
|
||||
|
|
||||
if (page === 1) { |
|
||||
|
// 个人专家信息
|
||||
|
getzj() { |
||||
|
const user = wx.getStorageSync('userInfo') |
||||
|
console.log(222, user) |
||||
this.setData({ |
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); |
|
||||
|
user: user |
||||
|
}) |
||||
}, |
}, |
||||
|
|
||||
// 生成更丰富的模拟数据(含标签)
|
|
||||
generateMockData(page, pageSize) { |
|
||||
const total = 23; |
|
||||
const start = (page - 1) * pageSize; |
|
||||
const end = start + pageSize; |
|
||||
const hasMore = end < total; |
|
||||
const list = []; |
|
||||
|
// 咨询列表 - 支持分页加载
|
||||
|
getsessions(isRefresh = false) { |
||||
|
// 防止重复请求
|
||||
|
if (this.data.isLoading) return |
||||
|
// 如果是加载更多但已无更多数据,直接返回
|
||||
|
if (!isRefresh && !this.data.hasMore) return |
||||
|
|
||||
const seeds = ['farmer1', 'sheep', 'cattle', 'wheat', 'tractor', 'green', 'sun', 'rain', 'soil', 'seed']; |
|
||||
const firstNames = ['李', '王', '张', '刘', '赵', '陈', '杨', '周', '吴', '黄']; |
|
||||
const farmTypes = ['水稻种植', '牛羊养殖', '果树栽培', '蔬菜大棚', '有机农场', '蜂蜜养殖', '食用菌', '药材种植']; |
|
||||
const tagPool = [ |
|
||||
['玉米', '虫害'], |
|
||||
['羊羔', '腹泻'], |
|
||||
['施肥', '建议'], |
|
||||
['土壤', '检测'], |
|
||||
['大棚', '温度'], |
|
||||
['猪病', '防治'], |
|
||||
['果树', '修剪'], |
|
||||
['蜂蜜', '取蜜'] |
|
||||
]; |
|
||||
|
this.setData({ isLoading: true }) |
||||
|
|
||||
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 params = { |
||||
|
page: isRefresh ? 1 : this.data.page, |
||||
|
pageSize: this.data.pageSize |
||||
|
} |
||||
|
|
||||
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')}`; |
|
||||
|
http.sessions({ |
||||
|
data: params, |
||||
|
success: (res) => { |
||||
|
console.log('接口返回数据:', res) |
||||
|
|
||||
|
let newList = [] |
||||
|
let total = 0 |
||||
|
|
||||
|
if (Array.isArray(res)) { |
||||
|
// 如果直接返回数组
|
||||
|
newList = res |
||||
|
total = res.length |
||||
|
} else if (res.data && Array.isArray(res.data)) { |
||||
|
// 如果返回 { data: [], total: 100 }
|
||||
|
newList = res.data |
||||
|
total = res.total || res.data.length |
||||
|
} else if (res.list && Array.isArray(res.list)) { |
||||
|
// 如果返回 { list: [], total: 100 }
|
||||
|
newList = res.list |
||||
|
total = res.total || res.list.length |
||||
|
} else { |
||||
|
console.error('接口返回格式不正确', res) |
||||
|
newList = [] |
||||
|
total = 0 |
||||
|
} |
||||
|
|
||||
// 更真实的预览消息
|
|
||||
let lastMessage = ''; |
|
||||
if (i % 5 === 0) lastMessage = '专家您好,我家玉米出现黄叶,能帮看看吗?'; |
|
||||
else if (i % 3 === 0) lastMessage = '咨询一下羊羔腹泻的问题,急!'; |
|
||||
else if (i % 4 === 0) lastMessage = '请问什么时候方便通话?'; |
|
||||
else lastMessage = '请求添加您为咨询顾问'; |
|
||||
|
// 计算是否有更多数据
|
||||
|
const currentPage = isRefresh ? 1 : this.data.page |
||||
|
const pageSize = this.data.pageSize |
||||
|
const hasMore = currentPage * pageSize < total |
||||
|
|
||||
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], |
|
||||
|
this.setData({ |
||||
|
applyList: isRefresh ? newList : [...this.data.applyList, ...newList], |
||||
|
total: total, |
||||
|
page: isRefresh ? 2 : this.data.page + 1, // 下次请求的页码
|
||||
|
hasMore: hasMore, |
||||
|
isLoading: false, |
||||
|
isFirstLoad: false |
||||
|
}) |
||||
}, |
}, |
||||
applyTime: timeStr, |
|
||||
lastMessage: lastMessage, |
|
||||
unreadCount: unread, |
|
||||
status: status, |
|
||||
tags: tags, |
|
||||
}); |
|
||||
|
fail: (err) => { |
||||
|
console.error('加载失败:', err) |
||||
|
wx.showToast({ |
||||
|
title: '加载失败', |
||||
|
icon: 'none' |
||||
|
}) |
||||
|
this.setData({ |
||||
|
isLoading: false, |
||||
|
isFirstLoad: false |
||||
|
}) |
||||
} |
} |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
return { |
|
||||
list, |
|
||||
total, |
|
||||
hasMore, |
|
||||
}; |
|
||||
|
// 加载更多(上拉触底触发)
|
||||
|
loadMore() { |
||||
|
// 如果有更多数据且不在加载中,则加载下一页
|
||||
|
if (this.data.hasMore && !this.data.isLoading) { |
||||
|
this.getsessions(false) |
||||
|
} |
||||
}, |
}, |
||||
|
|
||||
// 处理点击申请项
|
// 处理点击申请项
|
||||
handleApply(e) { |
handleApply(e) { |
||||
console.log(111,e); |
|
||||
|
console.log(111, e) |
||||
const id = e.currentTarget.dataset.id |
const id = e.currentTarget.dataset.id |
||||
wx.navigateTo({ |
wx.navigateTo({ |
||||
url: `/pagesA/pages/expertChat/expertChat?id=${id}`, |
url: `/pagesA/pages/expertChat/expertChat?id=${id}`, |
||||
}) |
}) |
||||
}, |
}, |
||||
|
|
||||
|
|
||||
|
|
||||
loadMore() { |
|
||||
const { hasMore, page } = this.data; |
|
||||
if (hasMore) { |
|
||||
this.loadApplyList(page + 1); |
|
||||
} |
|
||||
}, |
|
||||
|
|
||||
|
// 可选:下拉刷新功能
|
||||
onPullDownRefresh() { |
onPullDownRefresh() { |
||||
this.setData({ page: 1, hasMore: true }); |
|
||||
this.loadApplyList(1); |
|
||||
wx.stopPullDownRefresh(); |
|
||||
|
this.setData({ |
||||
|
page: 1, |
||||
|
hasMore: true |
||||
|
}) |
||||
|
this.getsessions(true) |
||||
|
// 停止下拉刷新
|
||||
|
wx.stopPullDownRefresh() |
||||
} |
} |
||||
}); |
|
||||
|
}) |
||||
1613
pagesA/pages/expertChat/expertChat.js
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue