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

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