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

250 lines
4.6 KiB

2 months ago
2 months ago
2 months ago
2 months ago
1 month ago
1 month 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 baseUrl = require('../../utils/baseUrl')
  3. Page({
  4. data: {
  5. // 轮播图数据
  6. currentSwiper: 0,
  7. baseUrl: baseUrl,
  8. swiperList: [],
  9. // 通知公告数据
  10. currentNotice: 0,
  11. noticeList: [],
  12. },
  13. // 查询用户信息
  14. getUserInfo(){
  15. http.UserInfo({
  16. data:{},
  17. success:res=>{
  18. console.log(789,res);
  19. this.setData({
  20. user:res.data.area
  21. })
  22. }
  23. })
  24. },
  25. // 轮播
  26. getCarousel() {
  27. http.carousel({
  28. data: {},
  29. success: res => {
  30. this.setData({
  31. swiperList: res.rows
  32. })
  33. }
  34. })
  35. },
  36. // 灾害
  37. getDisaster() {
  38. http.disaster({
  39. data: {},
  40. success: res => {
  41. this.setData({
  42. noticeList: res.rows
  43. })
  44. }
  45. })
  46. },
  47. // 区域划分跳转
  48. bindXzqh() {
  49. wx.navigateTo({
  50. url: '/pagesB/pages/administrativeDivision/administrativeDivision',
  51. })
  52. },
  53. // AI问诊
  54. bindAI() {
  55. wx.navigateTo({
  56. url: '/pagesA/pages/wzai/wzai',
  57. })
  58. },
  59. // 问兽医
  60. bindWsy() {
  61. wx.navigateTo({
  62. url: '/pagesA/pages/askingSy/askingSy',
  63. })
  64. },
  65. // 找专家
  66. bindZj() {
  67. wx.navigateTo({
  68. url: '/pagesA/pages/expert/expert',
  69. })
  70. },
  71. // 去买药
  72. bindYao() {
  73. wx.navigateTo({
  74. url: '/pagesA/pages/medicine/medicine',
  75. })
  76. },
  77. // 养殖知识库
  78. bindZsk() {
  79. wx.navigateTo({
  80. url: '/pagesB/pages/repository/repository',
  81. })
  82. },
  83. // 在线培训
  84. bindPx() {
  85. wx.navigateTo({
  86. url: '/pagesB/pages/training/training',
  87. })
  88. },
  89. // 政策解读
  90. bindJd() {
  91. wx.navigateTo({
  92. url: '/pagesB/pages/policyElucidation/policyElucidation',
  93. })
  94. },
  95. // 用户提问
  96. bindTw() {
  97. wx.navigateTo({
  98. url: '/pagesB/pages/onlineAsk/onlineAsk',
  99. })
  100. },
  101. //获取当前位置信息
  102. getLocation() {
  103. let that = this;
  104. // 腾讯获取的密钥
  105. let key = 'AOBBZ-6LUK7-WXGXX-HJUXS-HHUM5-FWFPJ'
  106. wx.getLocation({
  107. isHighAccuracy: true,
  108. type: 'gcj02',
  109. success: function (res) {
  110. let latitude = res.latitude;
  111. let longitude = res.longitude;
  112. wx.request({
  113. url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}`,
  114. success: res => {
  115. that.setData({
  116. county: res.data.result.address_component.district //城市
  117. });
  118. }
  119. })
  120. }
  121. })
  122. },
  123. onLoad() {
  124. this.getUserInfo()
  125. this.getDisaster()
  126. this.getCarousel()
  127. this.getLocation()
  128. },
  129. onShow() {
  130. },
  131. // 轮播图变化事件
  132. onSwiperChange(e) {
  133. const current = e.detail.current;
  134. const swiperList = this.data.swiperList.map((item, index) => ({
  135. ...item,
  136. }));
  137. this.setData({
  138. currentSwiper: current,
  139. swiperList
  140. });
  141. },
  142. // 轮播图点击
  143. onSwiperTap(e) {
  144. console.log(1111, e);
  145. var item = e.currentTarget.dataset.value
  146. wx.showToast({
  147. title: `进入${item.adsType}`,
  148. icon: 'none',
  149. duration: 1000
  150. });
  151. },
  152. // 通知点击 - 使用catchtap防止事件冒泡
  153. onNoticeTap(e) {
  154. const id = e.currentTarget.dataset.id;
  155. console.log('通知点击:', id);
  156. // 显示当前点击的通知内容
  157. const notice = this.data.noticeList.find(item => item.id === id);
  158. if (notice) {
  159. wx.showModal({
  160. title: notice.typeName,
  161. content: notice.content,
  162. showCancel: true,
  163. cancelText: '关闭',
  164. confirmText: '查看详情',
  165. success: (res) => {
  166. if (res.confirm) {
  167. wx.navigateTo({
  168. url: '/pages/notice/detail?id=' + id
  169. });
  170. }
  171. }
  172. });
  173. }
  174. },
  175. // 更多通知
  176. gotoNotices() {
  177. wx.navigateTo({
  178. url: ''
  179. });
  180. },
  181. onReady() {
  182. //当前网络状态
  183. wx.getNetworkType({
  184. success: function (res) { // 返回网络类型, 有效值:// wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
  185. console.log(res);
  186. var networkType = res.networkType
  187. if (networkType !== 'unknown') {
  188. wx.showToast({
  189. title: '当前使用"' + networkType + '"网络',
  190. icon: 'none',
  191. duration: 1000
  192. })
  193. }
  194. }
  195. })
  196. },
  197. // 下拉刷新
  198. onPullDownRefresh() {
  199. wx.showNavigationBarLoading()
  200. setTimeout(function () {
  201. wx.showToast({
  202. title: '刷新成功',
  203. icon: 'none',
  204. duration: 1000
  205. })
  206. wx.hideNavigationBarLoading()
  207. wx.stopPullDownRefresh()
  208. }, 1000)
  209. },
  210. // 页面滚动
  211. onPageScroll(e) {
  212. }
  213. });