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

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