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

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