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

300 lines
6.3 KiB

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