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

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