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

206 lines
3.9 KiB

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