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

354 lines
7.4 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
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. 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: '/pagesB/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 item = e.currentTarget.dataset.value
  247. wx.showToast({
  248. title: `进入${item.adsType}`,
  249. icon: 'none',
  250. duration: 1000
  251. });
  252. },
  253. // 通知点击
  254. onNoticeTap(e) {
  255. const id = e.currentTarget.dataset.id;
  256. console.log('通知点击:', id);
  257. // 显示当前点击的通知内容
  258. const notice = this.data.noticeList.find(item => item.id === id);
  259. if (notice) {
  260. wx.showModal({
  261. title: notice.warningLevel || '通知详情',
  262. content: notice.title,
  263. showCancel: true,
  264. cancelText: '关闭',
  265. confirmText: '查看详情',
  266. success: (res) => {
  267. if (res.confirm) {
  268. wx.navigateTo({
  269. url: '/pagesB/pages/noticeDetail/noticeDetail?id=' + id
  270. });
  271. }
  272. }
  273. });
  274. }
  275. },
  276. onReady() {
  277. // 当前网络状态
  278. wx.getNetworkType({
  279. success: function (res) {
  280. // 返回网络类型, 有效值:
  281. // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
  282. console.log(res);
  283. var networkType = res.networkType
  284. if (networkType !== 'unknown') {
  285. wx.showToast({
  286. title: '当前使用"' + networkType + '"网络',
  287. icon: 'none',
  288. duration: 1000
  289. })
  290. }
  291. }
  292. })
  293. },
  294. // 下拉刷新
  295. onPullDownRefresh() {
  296. wx.showNavigationBarLoading()
  297. // 重新加载所有数据
  298. Promise.all([
  299. new Promise(resolve => this.getUserInfo(resolve)),
  300. new Promise(resolve => this.getDisaster(resolve)),
  301. new Promise(resolve => this.getCarousel(resolve)),
  302. new Promise(resolve => this.getforumList(resolve)),
  303. new Promise(resolve => this.getexperience(resolve))
  304. ]).then(() => {
  305. wx.showToast({
  306. title: '刷新成功',
  307. icon: 'none',
  308. duration: 1000
  309. })
  310. wx.hideNavigationBarLoading()
  311. wx.stopPullDownRefresh()
  312. }).catch(() => {
  313. wx.hideNavigationBarLoading()
  314. wx.stopPullDownRefresh()
  315. })
  316. },
  317. // 页面滚动
  318. onPageScroll(e) {
  319. // 可以根据需要添加滚动效果
  320. }
  321. });