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

199 lines
3.7 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. import http from '../../utils/api'
  2. const baseUr = require('../../utils/baseUrl')
  3. Page({
  4. data: {
  5. // 轮播图数据
  6. currentSwiper: 0,
  7. baseUr: baseUr,
  8. swiperList: [],
  9. // 通知公告数据
  10. currentNotice: 0,
  11. noticeList: [],
  12. },
  13. // 轮播
  14. getCarousel() {
  15. http.carousel({
  16. data: {},
  17. success: res => {
  18. this.setData({
  19. swiperList: res.rows
  20. })
  21. }
  22. })
  23. },
  24. // 灾害
  25. getDisaster() {
  26. http.disaster({
  27. data: {},
  28. success: res => {
  29. console.log(222, res);
  30. this.setData({
  31. noticeList:res.rows
  32. })
  33. }
  34. })
  35. },
  36. // AI问诊
  37. bindAI() {
  38. wx.navigateTo({
  39. url: '/pagesA/pages/wzai/wzai',
  40. })
  41. },
  42. // 问兽医
  43. bindWsy(){
  44. wx.navigateTo({
  45. url: '/pagesA/pages/askingSy/askingSy',
  46. })
  47. },
  48. // 找专家
  49. bindZj(){
  50. wx.navigateTo({
  51. url: '/pagesA/pages/expert/expert',
  52. })
  53. },
  54. //获取当前位置信息
  55. getLocation() {
  56. let that = this;
  57. // 腾讯获取的密钥
  58. let key = 'AOBBZ-6LUK7-WXGXX-HJUXS-HHUM5-FWFPJ'
  59. wx.getLocation({
  60. isHighAccuracy: true,
  61. type: 'gcj02',
  62. success: function (res) {
  63. console.log(res);
  64. let latitude = res.latitude;
  65. let longitude = res.longitude;
  66. wx.request({
  67. url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}`,
  68. success: res => {
  69. console.log(res);
  70. that.setData({
  71. county: res.data.result.address_component.district //城市
  72. });
  73. }
  74. })
  75. }
  76. })
  77. },
  78. onLoad() {
  79. this.getDisaster()
  80. this.getCarousel()
  81. this.getLocation()
  82. },
  83. onShow() {
  84. },
  85. // 轮播图变化事件
  86. onSwiperChange(e) {
  87. const current = e.detail.current;
  88. const swiperList = this.data.swiperList.map((item, index) => ({
  89. ...item,
  90. }));
  91. this.setData({
  92. currentSwiper: current,
  93. swiperList
  94. });
  95. },
  96. // 轮播图点击
  97. onSwiperTap(e) {
  98. console.log(1111, e);
  99. var item = e.currentTarget.dataset.value
  100. wx.showToast({
  101. title: `进入${item.adsType}`,
  102. icon: 'none',
  103. duration: 1000
  104. });
  105. },
  106. // 通知点击 - 使用catchtap防止事件冒泡
  107. onNoticeTap(e) {
  108. const id = e.currentTarget.dataset.id;
  109. console.log('通知点击:', id);
  110. // 显示当前点击的通知内容
  111. const notice = this.data.noticeList.find(item => item.id === id);
  112. if (notice) {
  113. wx.showModal({
  114. title: notice.typeName,
  115. content: notice.content,
  116. showCancel: true,
  117. cancelText: '关闭',
  118. confirmText: '查看详情',
  119. success: (res) => {
  120. if (res.confirm) {
  121. wx.navigateTo({
  122. url: '/pages/notice/detail?id=' + id
  123. });
  124. }
  125. }
  126. });
  127. }
  128. },
  129. // 更多通知
  130. gotoNotices() {
  131. wx.navigateTo({
  132. url: ''
  133. });
  134. },
  135. onReady() {
  136. //当前网络状态
  137. wx.getNetworkType({
  138. success: function (res) { // 返回网络类型, 有效值:// wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
  139. console.log(res);
  140. var networkType = res.networkType
  141. if (networkType !== 'unknown') {
  142. wx.showToast({
  143. title: '当前使用"' + networkType + '"网络',
  144. icon: 'none',
  145. duration: 1000
  146. })
  147. }
  148. }
  149. })
  150. },
  151. // 下拉刷新
  152. onPullDownRefresh() {
  153. wx.showNavigationBarLoading()
  154. setTimeout(function () {
  155. wx.showToast({
  156. title: '刷新成功',
  157. icon: 'none',
  158. duration: 1000
  159. })
  160. wx.hideNavigationBarLoading()
  161. wx.stopPullDownRefresh()
  162. }, 1000)
  163. },
  164. // 页面滚动
  165. onPageScroll(e) {
  166. }
  167. });