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

257 lines
4.7 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. bindwdlist(){
  97. wx.navigateTo({
  98. url: '/pagesB/pages/forumlist/forumlist',
  99. })
  100. },
  101. // 问答详情
  102. bindTw() {
  103. wx.navigateTo({
  104. url: '/pagesB/pages/onlineAsk/onlineAsk',
  105. })
  106. },
  107. //获取当前位置信息
  108. getLocation() {
  109. let that = this;
  110. // 腾讯获取的密钥
  111. let key = 'AOBBZ-6LUK7-WXGXX-HJUXS-HHUM5-FWFPJ'
  112. wx.getLocation({
  113. isHighAccuracy: true,
  114. type: 'gcj02',
  115. success: function (res) {
  116. let latitude = res.latitude;
  117. let longitude = res.longitude;
  118. wx.request({
  119. url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}`,
  120. success: res => {
  121. that.setData({
  122. county: res.data.result.address_component.district //城市
  123. });
  124. }
  125. })
  126. }
  127. })
  128. },
  129. onLoad() {
  130. this.getUserInfo()
  131. this.getDisaster()
  132. this.getCarousel()
  133. this.getLocation()
  134. },
  135. onShow() {
  136. },
  137. // 轮播图变化事件
  138. onSwiperChange(e) {
  139. const current = e.detail.current;
  140. const swiperList = this.data.swiperList.map((item, index) => ({
  141. ...item,
  142. }));
  143. this.setData({
  144. currentSwiper: current,
  145. swiperList
  146. });
  147. },
  148. // 轮播图点击
  149. onSwiperTap(e) {
  150. console.log(1111, e);
  151. var item = e.currentTarget.dataset.value
  152. wx.showToast({
  153. title: `进入${item.adsType}`,
  154. icon: 'none',
  155. duration: 1000
  156. });
  157. },
  158. // 通知点击 - 使用catchtap防止事件冒泡
  159. onNoticeTap(e) {
  160. const id = e.currentTarget.dataset.id;
  161. console.log('通知点击:', id);
  162. // 显示当前点击的通知内容
  163. const notice = this.data.noticeList.find(item => item.id === id);
  164. if (notice) {
  165. wx.showModal({
  166. title: notice.typeName,
  167. content: notice.content,
  168. showCancel: true,
  169. cancelText: '关闭',
  170. confirmText: '查看详情',
  171. success: (res) => {
  172. if (res.confirm) {
  173. wx.navigateTo({
  174. url: '/pages/notice/detail?id=' + id
  175. });
  176. }
  177. }
  178. });
  179. }
  180. },
  181. // 更多通知
  182. gotoNotices() {
  183. wx.navigateTo({
  184. url: ''
  185. });
  186. },
  187. onReady() {
  188. //当前网络状态
  189. wx.getNetworkType({
  190. success: function (res) { // 返回网络类型, 有效值:// wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
  191. console.log(res);
  192. var networkType = res.networkType
  193. if (networkType !== 'unknown') {
  194. wx.showToast({
  195. title: '当前使用"' + networkType + '"网络',
  196. icon: 'none',
  197. duration: 1000
  198. })
  199. }
  200. }
  201. })
  202. },
  203. // 下拉刷新
  204. onPullDownRefresh() {
  205. wx.showNavigationBarLoading()
  206. setTimeout(function () {
  207. wx.showToast({
  208. title: '刷新成功',
  209. icon: 'none',
  210. duration: 1000
  211. })
  212. wx.hideNavigationBarLoading()
  213. wx.stopPullDownRefresh()
  214. }, 1000)
  215. },
  216. // 页面滚动
  217. onPageScroll(e) {
  218. }
  219. });