import http from '../../../utils/api' const baseUrl = require('../../../utils/baseUrl') Page({ data: { // 搜索关键词 searchKeyword: '', // 当前筛选条件 currentFilter: '全部', // 所有专家数据 allExperts: [], baseUrl: baseUrl, formzj: { isOnline: null, realName: null, expert: null, expertiseArea: null }, // 筛选后的专家列表 filteredExperts: [], // 当前选中的专家 currentExpert: null, // 是否显示联系方式弹窗 showContactDialog: false }, onLoad() { this.getexpertsList() }, onShow() { }, // 专家列表 getexpertsList() { http.expertsList({ data: this.data.formzj, success: res => { console.log(111, res); this.setData({ allExperts: res.rows }) } }) }, // 处理搜索输入 onSearchInput(e) { this.setData({ searchKeyword: e.detail.value }); this.sortAndFilterExperts(); }, // 清空搜索 clearSearch() { this.setData({ searchKeyword: '', currentFilter: 'all' }); this.sortAndFilterExperts(); }, // 更改筛选条件 changeFilter(e) { console.log(2222, e); const filter = e.currentTarget.dataset.filter; this.setData({ currentFilter: filter }); if (filter == '全部') { this.data.formzj.isOnline = null this.getexpertsList() } else { this.data.formzj.isOnline = filter this.getexpertsList() } }, // 显示专家联系方式 showContactInfo(e) { const index = e.currentTarget.dataset.index; const expert = this.data.allExperts[index]; console.log(33333,expert); this.setData({ currentExpert: expert, showContactDialog: true }); }, // 隐藏联系方式弹窗 hideContactDialog() { this.setData({ showContactDialog: false }); }, // 阻止事件冒泡 stopPropagation() { // 阻止事件冒泡 }, // 拨打电话 makePhoneCall(e) { const phone = e.currentTarget.dataset.phone; const cleanPhone = phone.replace(/-/g, ''); wx.showModal({ title: '拨打电话', content: `确定要拨打 ${phone} 吗?`, success: (res) => { if (res.confirm) { wx.makePhoneCall({ phoneNumber: cleanPhone, success: () => { wx.showToast({ title: '拨号成功', icon: 'success' }); }, fail: (err) => { console.error('拨打电话失败:', err); wx.showToast({ title: '拨号失败', icon: 'none' }); } }); } } }); }, // 复制邮箱 copyEmail(e) { const email = e.currentTarget.dataset.email; wx.setClipboardData({ data: email, success: () => { wx.showToast({ title: '邮箱已复制', icon: 'success' }); }, fail: () => { wx.showToast({ title: '复制失败', icon: 'none' }); } }); }, // 查看位置 viewLocation(e) { const address = e.currentTarget.dataset.address wx.showModal({ title: '单位地址', content: address, showCancel: false, confirmText: '知道了' }); }, // 开始咨询 startConsultation() { const expert = this.data.currentExpert; console.log(1111,expert); wx.showModal({ title: '咨询确认', content: `确定要立即咨询 ${expert.realName} 专家吗?`, success: (res) => { if (res.confirm) { wx.showToast({ title: '正在为您连接', icon: 'loading', duration: 2000 }); setTimeout(() => { // 跳转一对一咨询专家 wx.navigateTo({ url: `/pagesA/pages/expertChat/expertChat?id=${expert.userId}`, }) this.hideContactDialog(); }, 2000); } } }); }, // 分享专家 onShareAppMessage() { return { title: '牲畜专家咨询平台', path: '/pages/expert/expert', imageUrl: '/images/share-cover.jpg' } } });