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

251 lines
5.6 KiB

6 days ago
  1. Page({
  2. data: {
  3. // 轮播图数据
  4. currentSwiper: 0,
  5. swiperList: [{
  6. id: 1,
  7. image: '/pages/images/banner1.png',
  8. tag: '疫病防治',
  9. title: '春季牛羊常见病预防指南',
  10. desc: '专业兽医教你科学预防',
  11. isActive: false
  12. },
  13. {
  14. id: 2,
  15. image: '/pages/images/banner2.png',
  16. tag: '专家直播',
  17. title: '畜牧养殖新技术分享会',
  18. desc: '今晚8点准时开播',
  19. isActive: false
  20. },
  21. {
  22. id: 3,
  23. image: '/pages/images/banner3.png',
  24. tag: '市场动态',
  25. title: '最新牛羊肉价格行情',
  26. desc: '实时掌握市场变化',
  27. isActive: false
  28. },
  29. {
  30. id: 4,
  31. image: '/pages/images/banner4.png',
  32. tag: '在线问诊',
  33. title: 'AI智能诊断上线',
  34. desc: '24小时在线解答',
  35. isActive: false
  36. }
  37. ],
  38. // 通知公告数据
  39. currentNotice: 0,
  40. noticeList: [{
  41. id: 1,
  42. type: 'urgent',
  43. typeName: '紧急',
  44. content: '关于春季动物疫病防控的重要通知,请各位牧民及时查看并做好预防工作',
  45. time: '03-15 14:30'
  46. },
  47. {
  48. id: 2,
  49. type: 'important',
  50. typeName: '重要',
  51. content: '兽药购买资质审核流程更新,请相关商家及时上传最新资质文件',
  52. time: '03-14 09:15'
  53. },
  54. {
  55. id: 3,
  56. type: 'normal',
  57. typeName: '通知',
  58. content: '平台将于3月20日进行系统升级,升级期间部分功能可能无法正常使用',
  59. time: '03-13 16:45'
  60. }
  61. ],
  62. },
  63. //获取当前位置信息
  64. getLocation() {
  65. let that = this;
  66. // 腾讯获取的密钥
  67. let key = 'AOBBZ-6LUK7-WXGXX-HJUXS-HHUM5-FWFPJ'
  68. wx.getLocation({
  69. isHighAccuracy: true,
  70. type: 'gcj02',
  71. success: function (res) {
  72. console.log(res);
  73. let latitude = res.latitude;
  74. let longitude = res.longitude;
  75. wx.request({
  76. url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}`,
  77. success: res => {
  78. console.log(res);
  79. that.setData({
  80. county: res.data.result.address_component.district //城市
  81. });
  82. }
  83. })
  84. }
  85. })
  86. },
  87. onLoad() {
  88. // 初始化数据
  89. this.initSwiperActiveState();
  90. this.getLocation()
  91. },
  92. onShow() {
  93. },
  94. // 初始化轮播图激活状态
  95. initSwiperActiveState() {
  96. const swiperList = this.data.swiperList.map((item, index) => ({
  97. ...item,
  98. isActive: index === this.data.currentSwiper
  99. }));
  100. this.setData({
  101. swiperList
  102. });
  103. },
  104. // 轮播图变化事件
  105. onSwiperChange(e) {
  106. const current = e.detail.current;
  107. const swiperList = this.data.swiperList.map((item, index) => ({
  108. ...item,
  109. isActive: index === current
  110. }));
  111. this.setData({
  112. currentSwiper: current,
  113. swiperList
  114. });
  115. },
  116. // 轮播图指示器点击
  117. onIndicatorTap(e) {
  118. const index = e.currentTarget.dataset.index;
  119. this.setData({
  120. currentSwiper: index
  121. });
  122. },
  123. // 轮播图点击
  124. onSwiperTap(e) {
  125. const id = e.currentTarget.dataset.id;
  126. const item = this.data.swiperList.find(item => item.id === id);
  127. if (!item) return;
  128. console.log('轮播图点击:', item);
  129. wx.showToast({
  130. title: `进入${item.tag}`,
  131. icon: 'none',
  132. duration: 1000
  133. });
  134. // 根据不同类型跳转不同页面
  135. switch (id) {
  136. case 1:
  137. wx.navigateTo({
  138. url: '/pages/knowledge/detail?id=' + id
  139. });
  140. break;
  141. case 2:
  142. wx.navigateTo({
  143. url: '/pages/live/detail?id=' + id
  144. });
  145. break;
  146. case 3:
  147. wx.navigateTo({
  148. url: '/pages/market/detail?id=' + id
  149. });
  150. break;
  151. case 4:
  152. wx.navigateTo({
  153. url: '/pages/consult/ai'
  154. });
  155. break;
  156. default:
  157. // 默认跳转到详情页
  158. wx.navigateTo({
  159. url: '/pages/detail/index?id=' + id
  160. });
  161. }
  162. },
  163. // 通知点击 - 使用catchtap防止事件冒泡
  164. onNoticeTap(e) {
  165. const id = e.currentTarget.dataset.id;
  166. console.log('通知点击:', id);
  167. // 显示当前点击的通知内容
  168. const notice = this.data.noticeList.find(item => item.id === id);
  169. if (notice) {
  170. wx.showModal({
  171. title: notice.typeName,
  172. content: notice.content,
  173. showCancel: true,
  174. cancelText: '关闭',
  175. confirmText: '查看详情',
  176. success: (res) => {
  177. if (res.confirm) {
  178. wx.navigateTo({
  179. url: '/pages/notice/detail?id=' + id
  180. });
  181. }
  182. }
  183. });
  184. }
  185. },
  186. // 更多通知
  187. gotoNotices() {
  188. wx.navigateTo({
  189. url: ''
  190. });
  191. },
  192. onReady(){
  193. //当前网络状态
  194. wx.getNetworkType({
  195. success: function (res) { // 返回网络类型, 有效值:// wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
  196. console.log(res);
  197. var networkType = res.networkType
  198. if (networkType !== 'unknown') {
  199. wx.showToast({
  200. title: '当前使用"' + networkType + '"网络',
  201. icon: 'none',
  202. duration: 1000
  203. })
  204. }
  205. }
  206. })
  207. },
  208. // 下拉刷新
  209. onPullDownRefresh() {
  210. wx.showNavigationBarLoading()
  211. setTimeout(function () {
  212. wx.showToast({
  213. title: '刷新成功',
  214. icon: 'none',
  215. duration: 1000
  216. })
  217. wx.hideNavigationBarLoading()
  218. wx.stopPullDownRefresh()
  219. }, 1000)
  220. },
  221. // 页面滚动
  222. onPageScroll(e) {
  223. }
  224. });