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

252 lines
5.6 KiB

Page({
data: {
// 轮播图数据
currentSwiper: 0,
swiperList: [{
id: 1,
image: '/pages/images/banner1.png',
tag: '疫病防治',
title: '春季牛羊常见病预防指南',
desc: '专业兽医教你科学预防',
isActive: false
},
{
id: 2,
image: '/pages/images/banner2.png',
tag: '专家直播',
title: '畜牧养殖新技术分享会',
desc: '今晚8点准时开播',
isActive: false
},
{
id: 3,
image: '/pages/images/banner3.png',
tag: '市场动态',
title: '最新牛羊肉价格行情',
desc: '实时掌握市场变化',
isActive: false
},
{
id: 4,
image: '/pages/images/banner4.png',
tag: '在线问诊',
title: 'AI智能诊断上线',
desc: '24小时在线解答',
isActive: false
}
],
// 通知公告数据
currentNotice: 0,
noticeList: [{
id: 1,
type: 'urgent',
typeName: '紧急',
content: '关于春季动物疫病防控的重要通知,请各位牧民及时查看并做好预防工作',
time: '03-15 14:30'
},
{
id: 2,
type: 'important',
typeName: '重要',
content: '兽药购买资质审核流程更新,请相关商家及时上传最新资质文件',
time: '03-14 09:15'
},
{
id: 3,
type: 'normal',
typeName: '通知',
content: '平台将于3月20日进行系统升级,升级期间部分功能可能无法正常使用',
time: '03-13 16:45'
}
],
},
//获取当前位置信息
getLocation() {
let that = this;
// 腾讯获取的密钥
let key = 'AOBBZ-6LUK7-WXGXX-HJUXS-HHUM5-FWFPJ'
wx.getLocation({
isHighAccuracy: true,
type: 'gcj02',
success: function (res) {
console.log(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 => {
console.log(res);
that.setData({
county: res.data.result.address_component.district //城市
});
}
})
}
})
},
onLoad() {
// 初始化数据
this.initSwiperActiveState();
this.getLocation()
},
onShow() {
},
// 初始化轮播图激活状态
initSwiperActiveState() {
const swiperList = this.data.swiperList.map((item, index) => ({
...item,
isActive: index === this.data.currentSwiper
}));
this.setData({
swiperList
});
},
// 轮播图变化事件
onSwiperChange(e) {
const current = e.detail.current;
const swiperList = this.data.swiperList.map((item, index) => ({
...item,
isActive: index === current
}));
this.setData({
currentSwiper: current,
swiperList
});
},
// 轮播图指示器点击
onIndicatorTap(e) {
const index = e.currentTarget.dataset.index;
this.setData({
currentSwiper: index
});
},
// 轮播图点击
onSwiperTap(e) {
const id = e.currentTarget.dataset.id;
const item = this.data.swiperList.find(item => item.id === id);
if (!item) return;
console.log('轮播图点击:', item);
wx.showToast({
title: `进入${item.tag}`,
icon: 'none',
duration: 1000
});
// 根据不同类型跳转不同页面
switch (id) {
case 1:
wx.navigateTo({
url: '/pages/knowledge/detail?id=' + id
});
break;
case 2:
wx.navigateTo({
url: '/pages/live/detail?id=' + id
});
break;
case 3:
wx.navigateTo({
url: '/pages/market/detail?id=' + id
});
break;
case 4:
wx.navigateTo({
url: '/pages/consult/ai'
});
break;
default:
// 默认跳转到详情页
wx.navigateTo({
url: '/pages/detail/index?id=' + id
});
}
},
// 通知点击 - 使用catchtap防止事件冒泡
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.typeName,
content: notice.content,
showCancel: true,
cancelText: '关闭',
confirmText: '查看详情',
success: (res) => {
if (res.confirm) {
wx.navigateTo({
url: '/pages/notice/detail?id=' + id
});
}
}
});
}
},
// 更多通知
gotoNotices() {
wx.navigateTo({
url: ''
});
},
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()
setTimeout(function () {
wx.showToast({
title: '刷新成功',
icon: 'none',
duration: 1000
})
wx.hideNavigationBarLoading()
wx.stopPullDownRefresh()
}, 1000)
},
// 页面滚动
onPageScroll(e) {
}
});