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.4 KiB
356 lines
7.4 KiB
import http from '../../utils/api'
|
|
const baseUrl = require('../../utils/baseUrl')
|
|
Page({
|
|
data: {
|
|
// 轮播图数据
|
|
currentSwiper: 0,
|
|
baseUrl: baseUrl,
|
|
swiperList: [],
|
|
// 通知公告数据
|
|
currentNotice: 0,
|
|
noticeList: [],
|
|
forum: [],
|
|
suffer: [],
|
|
// 添加用户数据
|
|
user: {},
|
|
county: ''
|
|
},
|
|
|
|
// 查询用户信息
|
|
getUserInfo() {
|
|
http.UserInfo({
|
|
data: {},
|
|
success: res => {
|
|
this.setData({
|
|
user: res.data.area
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
// 在线问答列表
|
|
getforumList() {
|
|
http.forumList({
|
|
data: {},
|
|
success: res => {
|
|
const zxwd = []
|
|
zxwd.push(res.rows[0])
|
|
this.setData({
|
|
forum: zxwd
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
// 经验分享列表
|
|
getexperience() {
|
|
http.experience({
|
|
data: {},
|
|
success: res => {
|
|
console.log(111, res);
|
|
const zyfx = []
|
|
zyfx.push(res.rows[0])
|
|
this.setData({
|
|
suffer: zyfx
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
// 轮播
|
|
getCarousel() {
|
|
http.carousel({
|
|
data: {},
|
|
success: res => {
|
|
this.setData({
|
|
swiperList: res.rows
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
// 灾害/通知公告
|
|
getDisaster() {
|
|
http.disaster({
|
|
data: {},
|
|
success: res => {
|
|
// 处理通知数据,添加时间戳
|
|
const notices = res.rows.map(item => {
|
|
return {
|
|
...item,
|
|
// // 判断是否是24小时内的通知
|
|
// isNew: this.isNewNotification(item.createdTime)
|
|
}
|
|
})
|
|
this.setData({
|
|
noticeList: notices
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
// // 判断通知是否在24小时内
|
|
// isNewNotification(createdTime) {
|
|
// if (!createdTime) return false
|
|
// const noticeTime = new Date(createdTime.replace(/-/g, '/')).getTime()
|
|
// const now = new Date().getTime()
|
|
// const twentyFourHours = 24 * 60 * 60 * 1000
|
|
// return now - noticeTime < twentyFourHours
|
|
// },
|
|
|
|
// 区域划分跳转
|
|
bindXzqh() {
|
|
wx.navigateTo({
|
|
url: '/pagesB/pages/administrativeDivision/administrativeDivision',
|
|
})
|
|
},
|
|
|
|
// AI问诊
|
|
bindAI() {
|
|
wx.navigateTo({
|
|
url: '/pagesA/pages/wzai/wzai',
|
|
})
|
|
},
|
|
|
|
// 问兽医
|
|
bindWsy() {
|
|
wx.navigateTo({
|
|
url: '/pagesA/pages/askingSy/askingSy',
|
|
})
|
|
},
|
|
|
|
// 找专家
|
|
bindZj() {
|
|
wx.navigateTo({
|
|
url: '/pagesA/pages/expert/expert',
|
|
})
|
|
},
|
|
|
|
// 去买药
|
|
bindYao() {
|
|
wx.navigateTo({
|
|
url: '/pagesA/pages/medicine/medicine',
|
|
})
|
|
},
|
|
|
|
// 养殖知识库
|
|
bindZsk() {
|
|
wx.navigateTo({
|
|
url: '/pagesB/pages/repository/repository',
|
|
})
|
|
},
|
|
|
|
// 在线培训
|
|
bindPx() {
|
|
wx.navigateTo({
|
|
url: '/pagesB/pages/training/training',
|
|
})
|
|
},
|
|
|
|
// 政策解读
|
|
bindJd() {
|
|
wx.navigateTo({
|
|
url: '/pagesB/pages/policyElucidation/policyElucidation',
|
|
})
|
|
},
|
|
|
|
// 问答列表
|
|
bindwdlist() {
|
|
wx.navigateTo({
|
|
url: '/pagesB/pages/forumlist/forumlist',
|
|
})
|
|
},
|
|
|
|
// 问答详情
|
|
bindTw(e) {
|
|
console.log(e);
|
|
const id = e.currentTarget.dataset.id
|
|
wx.navigateTo({
|
|
url: `/pagesB/pages/onlineAsk/onlineAsk?id=${id}`,
|
|
})
|
|
},
|
|
|
|
// 经验分享列表
|
|
viewexperience() {
|
|
wx.navigateTo({
|
|
url: '/pagesB/pages/experienceList/experienceList',
|
|
})
|
|
},
|
|
|
|
// 经验分享详情
|
|
bindfx(e) {
|
|
const id = e.currentTarget.dataset.id
|
|
wx.navigateTo({
|
|
url: `/pagesB/pages/experienceDetails/experienceDetails?id=${id}`,
|
|
})
|
|
},
|
|
|
|
// 查看所有通知
|
|
viewAllNotices() {
|
|
wx.navigateTo({
|
|
url: '/pagesB/pages/noticeList/noticeList',
|
|
})
|
|
},
|
|
|
|
// 查看所有问题
|
|
viewAllQuestions() {
|
|
this.bindwdlist()
|
|
},
|
|
|
|
// 获取当前位置信息
|
|
getLocation() {
|
|
let that = this;
|
|
// 腾讯获取的密钥
|
|
let key = 'AOBBZ-6LUK7-WXGXX-HJUXS-HHUM5-FWFPJ'
|
|
wx.getLocation({
|
|
isHighAccuracy: true,
|
|
type: 'gcj02',
|
|
success: function (res) {
|
|
let latitude = res.latitude;
|
|
let longitude = res.longitude;
|
|
wx.request({
|
|
url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${key}`,
|
|
success: res => {
|
|
that.setData({
|
|
county: res.data.result.address_component.district //城市
|
|
});
|
|
}
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
onLoad() {
|
|
this.getUserInfo()
|
|
this.getDisaster()
|
|
this.getCarousel()
|
|
this.getLocation()
|
|
this.getforumList()
|
|
this.getexperience()
|
|
},
|
|
|
|
onShow() {
|
|
// 页面显示时重置轮播图(解决某些手机上的轮播问题)
|
|
this.resetSwiper()
|
|
},
|
|
|
|
// 重置轮播图(解决轮播不自动播放的问题)
|
|
resetSwiper() {
|
|
setTimeout(() => {
|
|
if (this.data.swiperList.length > 0) {
|
|
this.setData({
|
|
currentSwiper: this.data.currentSwiper
|
|
})
|
|
}
|
|
}, 300)
|
|
},
|
|
|
|
// 轮播图变化事件
|
|
onSwiperChange(e) {
|
|
const current = e.detail.current;
|
|
this.setData({
|
|
currentSwiper: current
|
|
});
|
|
},
|
|
|
|
// 轮播图指示器点击
|
|
onIndicatorTap(e) {
|
|
const index = e.currentTarget.dataset.index;
|
|
this.setData({
|
|
currentSwiper: index
|
|
});
|
|
},
|
|
|
|
// 通知轮播变化事件
|
|
onNoticeSwiperChange(e) {
|
|
const current = e.detail.current;
|
|
this.setData({
|
|
currentNotice: current
|
|
});
|
|
},
|
|
|
|
// 轮播图点击
|
|
onSwiperTap(e) {
|
|
console.log(1111, e);
|
|
var item = e.currentTarget.dataset.value
|
|
wx.showToast({
|
|
title: `进入${item.adsType}`,
|
|
icon: 'none',
|
|
duration: 1000
|
|
});
|
|
},
|
|
|
|
// 通知点击
|
|
onNoticeTap(e) {
|
|
const id = e.currentTarget.dataset.id;
|
|
console.log('通知点击:', id);
|
|
|
|
// 显示当前点击的通知内容
|
|
const notice = this.data.noticeList.find(item => item.id === id);
|
|
if (notice) {
|
|
wx.showModal({
|
|
title: notice.warningLevel || '通知详情',
|
|
content: notice.title,
|
|
showCancel: true,
|
|
cancelText: '关闭',
|
|
confirmText: '查看详情',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
wx.navigateTo({
|
|
url: '/pagesB/pages/noticeDetail/noticeDetail?id=' + id
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
onReady() {
|
|
// 当前网络状态
|
|
wx.getNetworkType({
|
|
success: function (res) {
|
|
// 返回网络类型, 有效值:
|
|
// wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
|
|
console.log(res);
|
|
var networkType = res.networkType
|
|
if (networkType !== 'unknown') {
|
|
wx.showToast({
|
|
title: '当前使用"' + networkType + '"网络',
|
|
icon: 'none',
|
|
duration: 1000
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
// 下拉刷新
|
|
onPullDownRefresh() {
|
|
wx.showNavigationBarLoading()
|
|
|
|
// 重新加载所有数据
|
|
Promise.all([
|
|
new Promise(resolve => this.getUserInfo(resolve)),
|
|
new Promise(resolve => this.getDisaster(resolve)),
|
|
new Promise(resolve => this.getCarousel(resolve)),
|
|
new Promise(resolve => this.getforumList(resolve)),
|
|
new Promise(resolve => this.getexperience(resolve))
|
|
]).then(() => {
|
|
wx.showToast({
|
|
title: '刷新成功',
|
|
icon: 'none',
|
|
duration: 1000
|
|
})
|
|
wx.hideNavigationBarLoading()
|
|
wx.stopPullDownRefresh()
|
|
}).catch(() => {
|
|
wx.hideNavigationBarLoading()
|
|
wx.stopPullDownRefresh()
|
|
})
|
|
},
|
|
|
|
// 页面滚动
|
|
onPageScroll(e) {
|
|
// 可以根据需要添加滚动效果
|
|
}
|
|
});
|