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

355 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. this.setData({
  24. user: res.data.area
  25. })
  26. }
  27. })
  28. },
  29. // 在线问答列表
  30. getforumList() {
  31. http.forumList({
  32. data: {},
  33. success: res => {
  34. const zxwd = []
  35. zxwd.push(res.rows[0])
  36. this.setData({
  37. forum: zxwd
  38. })
  39. }
  40. })
  41. },
  42. // 经验分享列表
  43. getexperience() {
  44. http.experience({
  45. data: {},
  46. success: res => {
  47. console.log(111, 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.getUserInfo()
  203. this.getDisaster()
  204. this.getCarousel()
  205. this.getLocation()
  206. this.getforumList()
  207. this.getexperience()
  208. },
  209. onShow() {
  210. // 页面显示时重置轮播图(解决某些手机上的轮播问题)
  211. this.resetSwiper()
  212. },
  213. // 重置轮播图(解决轮播不自动播放的问题)
  214. resetSwiper() {
  215. setTimeout(() => {
  216. if (this.data.swiperList.length > 0) {
  217. this.setData({
  218. currentSwiper: this.data.currentSwiper
  219. })
  220. }
  221. }, 300)
  222. },
  223. // 轮播图变化事件
  224. onSwiperChange(e) {
  225. const current = e.detail.current;
  226. this.setData({
  227. currentSwiper: current
  228. });
  229. },
  230. // 轮播图指示器点击
  231. onIndicatorTap(e) {
  232. const index = e.currentTarget.dataset.index;
  233. this.setData({
  234. currentSwiper: index
  235. });
  236. },
  237. // 通知轮播变化事件
  238. onNoticeSwiperChange(e) {
  239. const current = e.detail.current;
  240. this.setData({
  241. currentNotice: current
  242. });
  243. },
  244. // 轮播图点击
  245. onSwiperTap(e) {
  246. console.log(1111, e);
  247. var item = e.currentTarget.dataset.value
  248. wx.showToast({
  249. title: `进入${item.adsType}`,
  250. icon: 'none',
  251. duration: 1000
  252. });
  253. },
  254. // 通知点击
  255. onNoticeTap(e) {
  256. const id = e.currentTarget.dataset.id;
  257. console.log('通知点击:', id);
  258. // 显示当前点击的通知内容
  259. const notice = this.data.noticeList.find(item => item.id === id);
  260. if (notice) {
  261. wx.showModal({
  262. title: notice.warningLevel || '通知详情',
  263. content: notice.title,
  264. showCancel: true,
  265. cancelText: '关闭',
  266. confirmText: '查看详情',
  267. success: (res) => {
  268. if (res.confirm) {
  269. wx.navigateTo({
  270. url: '/pagesB/pages/noticeDetail/noticeDetail?id=' + id
  271. });
  272. }
  273. }
  274. });
  275. }
  276. },
  277. onReady() {
  278. // 当前网络状态
  279. wx.getNetworkType({
  280. success: function (res) {
  281. // 返回网络类型, 有效值:
  282. // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
  283. console.log(res);
  284. var networkType = res.networkType
  285. if (networkType !== 'unknown') {
  286. wx.showToast({
  287. title: '当前使用"' + networkType + '"网络',
  288. icon: 'none',
  289. duration: 1000
  290. })
  291. }
  292. }
  293. })
  294. },
  295. // 下拉刷新
  296. onPullDownRefresh() {
  297. wx.showNavigationBarLoading()
  298. // 重新加载所有数据
  299. Promise.all([
  300. new Promise(resolve => this.getUserInfo(resolve)),
  301. new Promise(resolve => this.getDisaster(resolve)),
  302. new Promise(resolve => this.getCarousel(resolve)),
  303. new Promise(resolve => this.getforumList(resolve)),
  304. new Promise(resolve => this.getexperience(resolve))
  305. ]).then(() => {
  306. wx.showToast({
  307. title: '刷新成功',
  308. icon: 'none',
  309. duration: 1000
  310. })
  311. wx.hideNavigationBarLoading()
  312. wx.stopPullDownRefresh()
  313. }).catch(() => {
  314. wx.hideNavigationBarLoading()
  315. wx.stopPullDownRefresh()
  316. })
  317. },
  318. // 页面滚动
  319. onPageScroll(e) {
  320. // 可以根据需要添加滚动效果
  321. }
  322. });