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

211 lines
4.2 KiB

3 months ago
3 months ago
3 months ago
  1. import http from '../../../utils/api'
  2. const baseUrl = require('../../../utils/baseUrl')
  3. Page({
  4. data: {
  5. // 搜索关键词
  6. searchKeyword: '',
  7. // 当前筛选条件
  8. currentFilter: '全部',
  9. // 所有专家数据
  10. allExperts: [],
  11. baseUrl: baseUrl,
  12. formzj: {
  13. isOnline: null,
  14. realName: null,
  15. expert: null,
  16. expertiseArea: null
  17. },
  18. // 筛选后的专家列表
  19. filteredExperts: [],
  20. // 当前选中的专家
  21. currentExpert: null,
  22. // 是否显示联系方式弹窗
  23. showContactDialog: false
  24. },
  25. onLoad() {
  26. this.getexpertsList()
  27. },
  28. onShow() {
  29. },
  30. // 专家列表
  31. getexpertsList() {
  32. http.expertsList({
  33. data: this.data.formzj,
  34. success: res => {
  35. console.log(111, res);
  36. this.setData({
  37. allExperts: res.rows
  38. })
  39. }
  40. })
  41. },
  42. // 处理搜索输入
  43. onSearchInput(e) {
  44. this.setData({
  45. searchKeyword: e.detail.value
  46. });
  47. this.sortAndFilterExperts();
  48. },
  49. // 清空搜索
  50. clearSearch() {
  51. this.setData({
  52. searchKeyword: '',
  53. currentFilter: 'all'
  54. });
  55. this.sortAndFilterExperts();
  56. },
  57. // 更改筛选条件
  58. changeFilter(e) {
  59. console.log(2222, e);
  60. const filter = e.currentTarget.dataset.filter;
  61. this.setData({
  62. currentFilter: filter
  63. });
  64. if (filter == '全部') {
  65. this.data.formzj.isOnline = null
  66. this.getexpertsList()
  67. } else {
  68. this.data.formzj.isOnline = filter
  69. this.getexpertsList()
  70. }
  71. },
  72. // 显示专家联系方式
  73. showContactInfo(e) {
  74. const index = e.currentTarget.dataset.index;
  75. const expert = this.data.allExperts[index];
  76. console.log(33333,expert);
  77. this.setData({
  78. currentExpert: expert,
  79. showContactDialog: true
  80. });
  81. },
  82. // 隐藏联系方式弹窗
  83. hideContactDialog() {
  84. this.setData({
  85. showContactDialog: false
  86. });
  87. },
  88. // 阻止事件冒泡
  89. stopPropagation() {
  90. // 阻止事件冒泡
  91. },
  92. // 拨打电话
  93. makePhoneCall(e) {
  94. const phone = e.currentTarget.dataset.phone;
  95. const cleanPhone = phone.replace(/-/g, '');
  96. wx.showModal({
  97. title: '拨打电话',
  98. content: `确定要拨打 ${phone} 吗?`,
  99. success: (res) => {
  100. if (res.confirm) {
  101. wx.makePhoneCall({
  102. phoneNumber: cleanPhone,
  103. success: () => {
  104. wx.showToast({
  105. title: '拨号成功',
  106. icon: 'success'
  107. });
  108. },
  109. fail: (err) => {
  110. console.error('拨打电话失败:', err);
  111. wx.showToast({
  112. title: '拨号失败',
  113. icon: 'none'
  114. });
  115. }
  116. });
  117. }
  118. }
  119. });
  120. },
  121. // 复制邮箱
  122. copyEmail(e) {
  123. const email = e.currentTarget.dataset.email;
  124. wx.setClipboardData({
  125. data: email,
  126. success: () => {
  127. wx.showToast({
  128. title: '邮箱已复制',
  129. icon: 'success'
  130. });
  131. },
  132. fail: () => {
  133. wx.showToast({
  134. title: '复制失败',
  135. icon: 'none'
  136. });
  137. }
  138. });
  139. },
  140. // 查看位置
  141. viewLocation(e) {
  142. const address = e.currentTarget.dataset.address
  143. wx.showModal({
  144. title: '单位地址',
  145. content: address,
  146. showCancel: false,
  147. confirmText: '知道了'
  148. });
  149. },
  150. // 开始咨询
  151. startConsultation() {
  152. const expert = this.data.currentExpert;
  153. console.log(1111,expert);
  154. wx.showModal({
  155. title: '咨询确认',
  156. content: `确定要立即咨询 ${expert.realName} 专家吗?`,
  157. success: (res) => {
  158. if (res.confirm) {
  159. wx.showToast({
  160. title: '正在为您连接',
  161. icon: 'loading',
  162. duration: 2000
  163. });
  164. setTimeout(() => {
  165. // 跳转一对一咨询专家
  166. wx.navigateTo({
  167. url: `/pagesA/pages/expertChat/expertChat?id=${expert.userId}`,
  168. })
  169. this.hideContactDialog();
  170. }, 2000);
  171. }
  172. }
  173. });
  174. },
  175. // 分享专家
  176. onShareAppMessage() {
  177. return {
  178. title: '牲畜专家咨询平台',
  179. path: '/pages/expert/expert',
  180. imageUrl: '/images/share-cover.jpg'
  181. }
  182. }
  183. });