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

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