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

337 lines
7.0 KiB

4 months ago
4 months ago
4 months ago
4 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 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. suffer: [],
  14. // 添加用户数据
  15. user: {},
  16. county: ''
  17. },
  18. // 查询用户信息
  19. getUserInfo() {
  20. http.UserInfo({
  21. data: {},
  22. success: res => {
  23. console.log(111,res);
  24. this.setData({
  25. user: res.data.user.area
  26. })
  27. }
  28. })
  29. },
  30. // 在线问答列表
  31. getforumList() {
  32. http.forumList({
  33. data: {},
  34. success: res => {
  35. const zxwd = []
  36. zxwd.push(res.rows[0])
  37. this.setData({
  38. forum: zxwd
  39. })
  40. }
  41. })
  42. },
  43. // 经验分享列表
  44. getexperience() {
  45. http.experience({
  46. data: {},
  47. success: res => {
  48. const zyfx = []
  49. zyfx.push(res.rows[0])
  50. this.setData({
  51. suffer: zyfx
  52. })
  53. }
  54. })
  55. },
  56. // 轮播
  57. getCarousel() {
  58. http.carousel({
  59. data: {},
  60. success: res => {
  61. this.setData({
  62. swiperList: res.rows
  63. })
  64. }
  65. })
  66. },
  67. // 灾害/通知公告
  68. getDisaster() {
  69. http.disaster({
  70. data: {},
  71. success: res => {
  72. // 处理通知数据,添加时间戳
  73. const notices = res.rows.map(item => {
  74. return {
  75. ...item,
  76. // // 判断是否是24小时内的通知
  77. // isNew: this.isNewNotification(item.createdTime)
  78. }
  79. })
  80. this.setData({
  81. noticeList: notices
  82. })
  83. }
  84. })
  85. },
  86. // // 判断通知是否在24小时内
  87. // isNewNotification(createdTime) {
  88. // if (!createdTime) return false
  89. // const noticeTime = new Date(createdTime.replace(/-/g, '/')).getTime()
  90. // const now = new Date().getTime()
  91. // const twentyFourHours = 24 * 60 * 60 * 1000
  92. // return now - noticeTime < twentyFourHours
  93. // },
  94. // 区域划分跳转
  95. bindXzqh() {
  96. wx.navigateTo({
  97. url: '/pagesB/pages/administrativeDivision/administrativeDivision',
  98. })
  99. },
  100. // AI问诊
  101. bindAI() {
  102. wx.navigateTo({
  103. url: '/pagesA/pages/wzai/wzai',
  104. })
  105. },
  106. // 问兽医
  107. bindWsy() {
  108. wx.navigateTo({
  109. url: '/pagesA/pages/askingSy/askingSy',
  110. })
  111. },
  112. // 找专家
  113. bindZj() {
  114. wx.navigateTo({
  115. url: '/pagesA/pages/expert/expert',
  116. })
  117. },
  118. // 去买药
  119. bindYao() {
  120. wx.navigateTo({
  121. url: '/pagesA/pages/medicine/medicine',
  122. })
  123. },
  124. // 养殖知识库
  125. bindZsk() {
  126. wx.navigateTo({
  127. url: '/pagesB/pages/repository/repository',
  128. })
  129. },
  130. // 在线培训
  131. bindPx() {
  132. wx.navigateTo({
  133. url: '/pagesB/pages/training/training',
  134. })
  135. },
  136. // 政策解读
  137. bindJd() {
  138. wx.navigateTo({
  139. url: '/pagesB/pages/policyElucidation/policyElucidation',
  140. })
  141. },
  142. // 问答列表
  143. bindwdlist() {
  144. wx.navigateTo({
  145. url: '/pagesB/pages/forumlist/forumlist',
  146. })
  147. },
  148. // 问答详情
  149. bindTw(e) {
  150. console.log(e);
  151. const id = e.currentTarget.dataset.id
  152. wx.navigateTo({
  153. url: `/pagesB/pages/onlineAsk/onlineAsk?id=${id}`,
  154. })
  155. },
  156. // 经验分享列表
  157. viewexperience() {
  158. wx.navigateTo({
  159. url: '/pagesB/pages/experienceList/experienceList',
  160. })
  161. },
  162. // 经验分享详情
  163. bindfx(e) {
  164. const id = e.currentTarget.dataset.id
  165. wx.navigateTo({
  166. url: `/pagesB/pages/experienceDetails/experienceDetails?id=${id}`,
  167. })
  168. },
  169. // 查看所有通知
  170. viewAllNotices() {
  171. wx.navigateTo({
  172. url: '/pagesA/pages/noticeList/noticeList',
  173. })
  174. },
  175. // 查看所有问题
  176. viewAllQuestions() {
  177. this.bindwdlist()
  178. },
  179. // 获取当前位置信息
  180. getLocation() {
  181. let that = this;
  182. // 腾讯获取的密钥
  183. let key = 'AOBBZ-6LUK7-WXGXX-HJUXS-HHUM5-FWFPJ'
  184. wx.getLocation({
  185. isHighAccuracy: true,
  186. type: 'gcj02',
  187. success: function (res) {
  188. let latitude = res.latitude;
  189. let longitude = res.longitude;
  190. wx.request({
  191. url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}`,
  192. success: res => {
  193. that.setData({
  194. county: res.data.result.address_component.district //城市
  195. });
  196. }
  197. })
  198. }
  199. })
  200. },
  201. onLoad() {
  202. this.getDisaster()
  203. this.getCarousel()
  204. this.getLocation()
  205. this.getforumList()
  206. this.getexperience()
  207. },
  208. onShow() {
  209. this.resetSwiper()
  210. this.getUserInfo()
  211. },
  212. // 重置轮播图(解决轮播不自动播放的问题)
  213. resetSwiper() {
  214. setTimeout(() => {
  215. if (this.data.swiperList.length > 0) {
  216. this.setData({
  217. currentSwiper: this.data.currentSwiper
  218. })
  219. }
  220. }, 300)
  221. },
  222. // 轮播图变化事件
  223. onSwiperChange(e) {
  224. const current = e.detail.current;
  225. this.setData({
  226. currentSwiper: current
  227. });
  228. },
  229. // 轮播图指示器点击
  230. onIndicatorTap(e) {
  231. const index = e.currentTarget.dataset.index;
  232. this.setData({
  233. currentSwiper: index
  234. });
  235. },
  236. // 通知轮播变化事件
  237. onNoticeSwiperChange(e) {
  238. const current = e.detail.current;
  239. this.setData({
  240. currentNotice: current
  241. });
  242. },
  243. // 轮播图点击
  244. onSwiperTap(e) {
  245. console.log(1111, e);
  246. var id = e.currentTarget.dataset.value.carouselId
  247. wx.navigateTo({
  248. url: `/pagesA/pages/carouselDetail/carouselDetail?id=${id}`,
  249. })
  250. },
  251. // 通知点击
  252. onNoticeTap(e) {
  253. console.log(111,e);
  254. const id = e.currentTarget.dataset.id;
  255. console.log('通知点击:', id);
  256. wx.navigateTo({
  257. url: '/pagesA/pages/noticeListDetails/noticeListDetails?id=' + id,
  258. })
  259. },
  260. onReady() {
  261. // 当前网络状态
  262. wx.getNetworkType({
  263. success: function (res) {
  264. // 返回网络类型, 有效值:
  265. // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
  266. console.log(res);
  267. var networkType = res.networkType
  268. if (networkType !== 'unknown') {
  269. wx.showToast({
  270. title: '当前使用"' + networkType + '"网络',
  271. icon: 'none',
  272. duration: 1000
  273. })
  274. }
  275. }
  276. })
  277. },
  278. // 下拉刷新
  279. onPullDownRefresh() {
  280. wx.showNavigationBarLoading()
  281. // 重新加载所有数据
  282. Promise.all([
  283. new Promise(resolve => this.getUserInfo(resolve)),
  284. new Promise(resolve => this.getDisaster(resolve)),
  285. new Promise(resolve => this.getCarousel(resolve)),
  286. new Promise(resolve => this.getforumList(resolve)),
  287. new Promise(resolve => this.getexperience(resolve))
  288. ]).then(() => {
  289. wx.showToast({
  290. title: '刷新成功',
  291. icon: 'none',
  292. duration: 1000
  293. })
  294. wx.hideNavigationBarLoading()
  295. wx.stopPullDownRefresh()
  296. }).catch(() => {
  297. wx.hideNavigationBarLoading()
  298. wx.stopPullDownRefresh()
  299. })
  300. },
  301. // 页面滚动
  302. onPageScroll(e) {
  303. // 可以根据需要添加滚动效果
  304. }
  305. });