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

185 lines
3.5 KiB

import http from '../../utils/api'
const baseUr = require('../../utils/baseUrl')
Page({
data: {
// 轮播图数据
currentSwiper: 0,
baseUr: baseUr,
swiperList: [],
// 通知公告数据
currentNotice: 0,
noticeList: [],
},
// 轮播
getCarousel() {
http.carousel({
data: {},
success: res => {
this.setData({
swiperList: res.rows
})
}
})
},
// 灾害
getDisaster() {
http.disaster({
data: {},
success: res => {
console.log(222, res);
this.setData({
noticeList:res.rows
})
}
})
},
// AI问诊
bindAI() {
wx.navigateTo({
url: '/pagesA/pages/wzai/wzai',
})
},
//获取当前位置信息
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.getDisaster()
this.getCarousel()
this.getLocation()
},
onShow() {
},
// 轮播图变化事件
onSwiperChange(e) {
const current = e.detail.current;
const swiperList = this.data.swiperList.map((item, index) => ({
...item,
}));
this.setData({
currentSwiper: current,
swiperList
});
},
// 轮播图点击
onSwiperTap(e) {
console.log(1111, e);
var item = e.currentTarget.dataset.value
wx.showToast({
title: `进入${item.adsType}`,
icon: 'none',
duration: 1000
});
},
// 通知点击 - 使用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) {
}
});