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

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