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

184 lines
3.5 KiB

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