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

192 lines
3.6 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. getLocation() {
  50. let that = this;
  51. // 腾讯获取的密钥
  52. let key = 'AOBBZ-6LUK7-WXGXX-HJUXS-HHUM5-FWFPJ'
  53. wx.getLocation({
  54. isHighAccuracy: true,
  55. type: 'gcj02',
  56. success: function (res) {
  57. console.log(res);
  58. let latitude = res.latitude;
  59. let longitude = res.longitude;
  60. wx.request({
  61. url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}`,
  62. success: res => {
  63. console.log(res);
  64. that.setData({
  65. county: res.data.result.address_component.district //城市
  66. });
  67. }
  68. })
  69. }
  70. })
  71. },
  72. onLoad() {
  73. this.getDisaster()
  74. this.getCarousel()
  75. this.getLocation()
  76. },
  77. onShow() {
  78. },
  79. // 轮播图变化事件
  80. onSwiperChange(e) {
  81. const current = e.detail.current;
  82. const swiperList = this.data.swiperList.map((item, index) => ({
  83. ...item,
  84. }));
  85. this.setData({
  86. currentSwiper: current,
  87. swiperList
  88. });
  89. },
  90. // 轮播图点击
  91. onSwiperTap(e) {
  92. console.log(1111, e);
  93. var item = e.currentTarget.dataset.value
  94. wx.showToast({
  95. title: `进入${item.adsType}`,
  96. icon: 'none',
  97. duration: 1000
  98. });
  99. },
  100. // 通知点击 - 使用catchtap防止事件冒泡
  101. onNoticeTap(e) {
  102. const id = e.currentTarget.dataset.id;
  103. console.log('通知点击:', id);
  104. // 显示当前点击的通知内容
  105. const notice = this.data.noticeList.find(item => item.id === id);
  106. if (notice) {
  107. wx.showModal({
  108. title: notice.typeName,
  109. content: notice.content,
  110. showCancel: true,
  111. cancelText: '关闭',
  112. confirmText: '查看详情',
  113. success: (res) => {
  114. if (res.confirm) {
  115. wx.navigateTo({
  116. url: '/pages/notice/detail?id=' + id
  117. });
  118. }
  119. }
  120. });
  121. }
  122. },
  123. // 更多通知
  124. gotoNotices() {
  125. wx.navigateTo({
  126. url: ''
  127. });
  128. },
  129. onReady() {
  130. //当前网络状态
  131. wx.getNetworkType({
  132. success: function (res) { // 返回网络类型, 有效值:// wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
  133. console.log(res);
  134. var networkType = res.networkType
  135. if (networkType !== 'unknown') {
  136. wx.showToast({
  137. title: '当前使用"' + networkType + '"网络',
  138. icon: 'none',
  139. duration: 1000
  140. })
  141. }
  142. }
  143. })
  144. },
  145. // 下拉刷新
  146. onPullDownRefresh() {
  147. wx.showNavigationBarLoading()
  148. setTimeout(function () {
  149. wx.showToast({
  150. title: '刷新成功',
  151. icon: 'none',
  152. duration: 1000
  153. })
  154. wx.hideNavigationBarLoading()
  155. wx.stopPullDownRefresh()
  156. }, 1000)
  157. },
  158. // 页面滚动
  159. onPageScroll(e) {
  160. }
  161. });