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

430 lines
12 KiB

  1. import http from '../../../utils/api'
  2. Page({
  3. data: {
  4. // 搜索关键词
  5. searchKeyword: '',
  6. // 当前筛选条件
  7. currentFilter: 'all',
  8. // 所有专家数据
  9. allExperts: [
  10. {
  11. id: 1,
  12. name: '张建国',
  13. title: '畜牧学博士',
  14. expertise: '牛类养殖与疾病防治',
  15. experience: 15,
  16. online: true,
  17. senior: true,
  18. phone: '138-0013-8001',
  19. email: 'zhangjg@agri-expert.com',
  20. institution: '国家畜牧业研究所',
  21. address: '北京市朝阳区农业科技大厦',
  22. bio: '15年牛类养殖研究经验,发表SCI论文20余篇,擅长规模化养殖场管理与疾病防控。',
  23. tags: ['肉牛养殖', '疾病预防', '饲料配方', '规模化养殖'],
  24. successRate: 98,
  25. responseTime: '15分钟内响应',
  26. avatar: '/pagesA/images/1.png'
  27. },
  28. {
  29. id: 2,
  30. name: '李秀英',
  31. title: '兽医学硕士',
  32. expertise: '猪病诊断与治疗',
  33. experience: 12,
  34. online: true,
  35. senior: true,
  36. phone: '139-0013-9002',
  37. email: 'lixy@vet-hospital.cn',
  38. institution: '农业大学动物医学院',
  39. address: '上海市徐汇区农业路58号',
  40. bio: '资深猪病防治专家,参与多项国家级科研项目,成功解决多个大规模猪场疫情。',
  41. tags: ['猪病诊疗', '疫苗管理', '养殖场规划', '传染病防治'],
  42. successRate: 96,
  43. responseTime: '20分钟内响应',
  44. avatar: '/pagesA/images/2.png'
  45. },
  46. {
  47. id: 3,
  48. name: '王伟民',
  49. title: '高级畜牧师',
  50. expertise: '羊类繁殖与饲养管理',
  51. experience: 20,
  52. online: false,
  53. senior: true,
  54. phone: '137-0013-7003',
  55. email: 'wangwm@livestock.cn',
  56. institution: '草原畜牧业研究中心',
  57. address: '内蒙古呼和浩特市牧业科技园',
  58. bio: '羊类养殖领域权威专家,拥有20年草原牧区养殖经验,精通各类羊只繁殖技术。',
  59. tags: ['绵羊养殖', '山羊繁殖', '牧草种植', '草原管理'],
  60. successRate: 95,
  61. responseTime: '1小时内响应',
  62. avatar: '/pagesA/images/3.png'
  63. },
  64. {
  65. id: 4,
  66. name: '陈秀兰',
  67. title: '家禽养殖专家',
  68. expertise: '鸡鸭养殖技术',
  69. experience: 18,
  70. online: true,
  71. senior: false,
  72. phone: '136-0013-6004',
  73. email: 'chenxl@poultry-expert.com',
  74. institution: '家禽养殖技术中心',
  75. address: '广东省广州市禽业科技园',
  76. bio: '家禽养殖技术推广专家,帮助300+养殖户实现科学化、标准化养殖管理。',
  77. tags: ['蛋鸡养殖', '肉鸭饲养', '疾病防控', '禽舍设计'],
  78. successRate: 94,
  79. responseTime: '30分钟内响应',
  80. avatar: '/pagesA/images/1.png'
  81. },
  82. {
  83. id: 5,
  84. name: '刘志强',
  85. title: '特种养殖专家',
  86. expertise: '鹿、兔等特种动物养殖',
  87. experience: 10,
  88. online: false,
  89. senior: false,
  90. phone: '135-0013-5005',
  91. email: 'liuzq@special-livestock.cn',
  92. institution: '特种动物养殖研究所',
  93. address: '四川省成都市农业科技园',
  94. bio: '特种动物养殖新兴力量,专注于梅花鹿、肉兔等特种动物的现代化养殖技术。',
  95. tags: ['梅花鹿养殖', '肉兔饲养', '市场分析', '特色养殖'],
  96. successRate: 92,
  97. responseTime: '2小时内响应',
  98. avatar: '/pagesA/images/2.png'
  99. },
  100. {
  101. id: 6,
  102. name: '赵雪梅',
  103. title: '畜牧营养学博士',
  104. expertise: '牲畜饲料配方与营养',
  105. experience: 14,
  106. online: true,
  107. senior: true,
  108. phone: '134-0013-4006',
  109. email: 'zhaoxm@feed-research.cn',
  110. institution: '农业科学院饲料研究所',
  111. address: '江苏省南京市科研路88号',
  112. bio: '饲料营养学专家,研发多个高效饲料配方,帮助养殖户降低30%饲料成本。',
  113. tags: ['饲料配方', '营养管理', '成本控制', '饲料安全'],
  114. successRate: 97,
  115. responseTime: '25分钟内响应',
  116. avatar: '/pagesA/images/3.png'
  117. },
  118. {
  119. id: 7,
  120. name: '孙建国',
  121. title: '养殖场管理专家',
  122. expertise: '现代化养殖场设计与运营',
  123. experience: 22,
  124. online: true,
  125. senior: true,
  126. phone: '133-0013-3007',
  127. email: 'sunjg@farm-management.com',
  128. institution: '现代农业发展中心',
  129. address: '浙江省杭州市创新产业园',
  130. bio: '养殖场规划设计专家,参与设计200+现代化养殖场,精通自动化养殖设备应用。',
  131. tags: ['场舍设计', '设备管理', '成本核算', '环保处理'],
  132. successRate: 99,
  133. responseTime: '10分钟内响应',
  134. avatar: '/pagesA/images/2.png'
  135. },
  136. {
  137. id: 8,
  138. name: '周小芳',
  139. title: '兽医病理学硕士',
  140. expertise: '牲畜常见病与传染病防治',
  141. experience: 11,
  142. online: false,
  143. senior: false,
  144. phone: '132-0013-2008',
  145. email: 'zhouxf@vet-pathology.cn',
  146. institution: '动物疫病防控中心',
  147. address: '湖北省武汉市动物防疫站',
  148. bio: '专攻牲畜病理诊断与传染病防控,在快速诊断和精准治疗方面有丰富经验。',
  149. tags: ['传染病防治', '病理诊断', '用药指导', '疫情处理'],
  150. successRate: 93,
  151. responseTime: '1.5小时内响应',
  152. avatar: '/pagesA/images/3.png'
  153. }
  154. ],
  155. // 筛选后的专家列表
  156. filteredExperts: [],
  157. // 在线专家数量
  158. onlineCount: 0,
  159. // 当前选中的专家
  160. currentExpert: null,
  161. // 是否显示联系方式弹窗
  162. showContactDialog: false
  163. },
  164. onLoad() {
  165. this.sortAndFilterExperts()
  166. this.getexpertsList()
  167. },
  168. onShow() {
  169. // 页面显示时随机更新一些专家的在线状态(模拟实时状态)
  170. this.updateOnlineStatus();
  171. },
  172. // 专家列表
  173. getexpertsList(){
  174. http.expertsList({
  175. data:{},
  176. success:res=>{
  177. console.log(111,res);
  178. }
  179. })
  180. },
  181. // 更新在线状态
  182. updateOnlineStatus() {
  183. const experts = this.data.allExperts.map(expert => ({
  184. ...expert,
  185. online: Math.random() > 0.4 // 60%的概率在线
  186. }));
  187. this.setData({
  188. allExperts: experts
  189. }, () => {
  190. this.sortAndFilterExperts();
  191. });
  192. },
  193. // 处理搜索输入
  194. onSearchInput(e) {
  195. this.setData({
  196. searchKeyword: e.detail.value
  197. });
  198. this.sortAndFilterExperts();
  199. },
  200. // 清空搜索
  201. clearSearch() {
  202. this.setData({
  203. searchKeyword: '',
  204. currentFilter: 'all'
  205. });
  206. this.sortAndFilterExperts();
  207. },
  208. // 更改筛选条件
  209. changeFilter(e) {
  210. const filter = e.currentTarget.dataset.filter;
  211. this.setData({
  212. currentFilter: filter
  213. });
  214. this.sortAndFilterExperts();
  215. },
  216. // 排序和筛选专家
  217. sortAndFilterExperts() {
  218. const { allExperts, searchKeyword, currentFilter } = this.data;
  219. let filtered = [...allExperts];
  220. // 关键词搜索
  221. if (searchKeyword.trim()) {
  222. const keyword = searchKeyword.toLowerCase();
  223. filtered = filtered.filter(expert =>
  224. expert.name.toLowerCase().includes(keyword) ||
  225. expert.expertise.toLowerCase().includes(keyword) ||
  226. expert.tags.some(tag => tag.toLowerCase().includes(keyword)) ||
  227. expert.institution.toLowerCase().includes(keyword)
  228. );
  229. }
  230. // 筛选条件
  231. switch (currentFilter) {
  232. case 'online':
  233. filtered = filtered.filter(expert => expert.online);
  234. break;
  235. case 'offline':
  236. filtered = filtered.filter(expert => !expert.online);
  237. break;
  238. case 'senior':
  239. filtered = filtered.filter(expert => expert.senior);
  240. break;
  241. case 'veterinary':
  242. filtered = filtered.filter(expert =>
  243. expert.expertise.includes('病') ||
  244. expert.tags.some(tag => tag.includes('病') || tag.includes('医'))
  245. );
  246. break;
  247. }
  248. // 排序:在线优先 > 资深专家 > 经验丰富 > 解决率高
  249. filtered.sort((a, b) => {
  250. // 在线状态优先
  251. if (a.online !== b.online) {
  252. return a.online ? -1 : 1;
  253. }
  254. // 资深专家优先
  255. if (a.senior !== b.senior) {
  256. return a.senior ? -1 : 1;
  257. }
  258. // 经验丰富优先
  259. if (a.experience !== b.experience) {
  260. return b.experience - a.experience;
  261. }
  262. // 解决率高优先
  263. return (b.successRate || 0) - (a.successRate || 0);
  264. });
  265. // 计算在线人数
  266. const onlineCount = filtered.filter(expert => expert.online).length;
  267. this.setData({
  268. filteredExperts: filtered,
  269. onlineCount: onlineCount
  270. });
  271. },
  272. // 显示专家联系方式
  273. showContactInfo(e) {
  274. const index = e.currentTarget.dataset.index;
  275. const expert = this.data.filteredExperts[index];
  276. this.setData({
  277. currentExpert: expert,
  278. showContactDialog: true
  279. });
  280. },
  281. // 隐藏联系方式弹窗
  282. hideContactDialog() {
  283. this.setData({
  284. showContactDialog: false
  285. });
  286. },
  287. // 阻止事件冒泡
  288. stopPropagation() {
  289. // 阻止事件冒泡
  290. },
  291. // 拨打电话
  292. makePhoneCall(e) {
  293. const phone = e.currentTarget.dataset.phone;
  294. const cleanPhone = phone.replace(/-/g, '');
  295. wx.showModal({
  296. title: '拨打电话',
  297. content: `确定要拨打 ${phone} 吗?`,
  298. success: (res) => {
  299. if (res.confirm) {
  300. wx.makePhoneCall({
  301. phoneNumber: cleanPhone,
  302. success: () => {
  303. wx.showToast({
  304. title: '拨号成功',
  305. icon: 'success'
  306. });
  307. },
  308. fail: (err) => {
  309. console.error('拨打电话失败:', err);
  310. wx.showToast({
  311. title: '拨号失败',
  312. icon: 'none'
  313. });
  314. }
  315. });
  316. }
  317. }
  318. });
  319. },
  320. // 复制邮箱
  321. copyEmail(e) {
  322. const email = e.currentTarget.dataset.email;
  323. wx.setClipboardData({
  324. data: email,
  325. success: () => {
  326. wx.showToast({
  327. title: '邮箱已复制',
  328. icon: 'success'
  329. });
  330. },
  331. fail: () => {
  332. wx.showToast({
  333. title: '复制失败',
  334. icon: 'none'
  335. });
  336. }
  337. });
  338. },
  339. // 查看位置
  340. viewLocation(e) {
  341. const address = e.currentTarget.dataset.address
  342. wx.showModal({
  343. title: '单位地址',
  344. content: address,
  345. showCancel: false,
  346. confirmText: '知道了'
  347. });
  348. },
  349. // 开始咨询
  350. startConsultation() {
  351. const expert = this.data.currentExpert;
  352. wx.showModal({
  353. title: '咨询确认',
  354. content: expert.online
  355. ? `确定要立即咨询 ${expert.name} 专家吗?`
  356. : `确定要预约咨询 ${expert.name} 专家吗?`,
  357. success: (res) => {
  358. if (res.confirm) {
  359. if (expert.online) {
  360. wx.showToast({
  361. title: '正在为您连接专家...',
  362. icon: 'loading',
  363. duration: 2000
  364. });
  365. setTimeout(() => {
  366. // 跳转一对一咨询专家
  367. wx.navigateTo({
  368. url: '/pagesA/pages/expertChat/expertChat',
  369. })
  370. this.hideContactDialog();
  371. }, 2000);
  372. } else {
  373. wx.showToast({
  374. title: '预约成功,专家将尽快回复',
  375. icon: 'success'
  376. });
  377. this.hideContactDialog();
  378. }
  379. }
  380. }
  381. });
  382. },
  383. // 分享专家
  384. onShareAppMessage() {
  385. return {
  386. title: '牲畜专家咨询平台',
  387. path: '/pages/expert/expert',
  388. imageUrl: '/images/share-cover.jpg'
  389. };
  390. }
  391. });