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

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