init project

This commit is contained in:
limqhz
2020-06-21 16:27:58 +08:00
commit e8fe10b5fb
178 changed files with 9964 additions and 0 deletions

View File

@@ -0,0 +1,178 @@
// pages/sportsGroundList/index.js
const app = getApp();
let latitude = 0; // 纬度
let longitude = 0; // 经度
let page = 1;
Page({
/**
* 页面的初始数据
*/
data: {
state: 1,
venues: [],
isShowAuth: false,
isShowNewplot: false,
isGoHome: false,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
let that = this;
this.setData({
state: options.state
})
this.getLocation();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
let pages = getCurrentPages();
this.setData({
isGoHome: pages.length == 1
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
this.getData();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
this.getData(++page);
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
return {
title: '智慧云馆'
}
},
// 切换列表
changeTip(e) {
let state = e.currentTarget.dataset.state;
this.setData({
state: state
})
this.getData();
},
// 点击cell
clickCell(e) {
let id = e.currentTarget.dataset.id;
if (this.data.state == 1) {
wx.navigateTo({
url: `/pages/basketballGym/index?id=${id}`,
})
}
if (this.data.state == 2) {
wx.navigateTo({
url: `/pages/gymnasium/index?id=${id}`,
})
}
},
// 获取数据
getData(e) {
wx.showLoading({
title: '加载中...',
mask: true,
})
app.$api.venues({
latitude: latitude,
longitude: longitude,
page: e ? e : 1,
pageSize: 10,
type: this.data.state
}).then(res => {
page = res.page.data.length > 0 ? res.page.page : page--;
let list = [];
if (e) {
list = this.data.venues
}
for (let i = 0; i < res.page.data.length; i++) {
list.push(res.page.data[i]);
}
this.setData({
venues: list,
isShowNewplot: true
})
if (this.data.state == 3) {
wx.showToast({
title: '暂未开放,敬请期待',
icon: 'none',
})
}
wx.stopPullDownRefresh();
}, err => {
wx.stopPullDownRefresh();
this.setData({
isShowNewplot: true
})
})
},
// 活动当前坐标
getLocation() {
let that = this;
wx.getLocation({
type: 'gcj02',
success: function(res) {
latitude = res.latitude;
longitude = res.longitude;
that.getData()
},
fail: function(res) {
if (res.errMsg == 'getLocation:fail auth deny' || res.errMsg == 'getLocation:fail:auth denied') {
that.setData({
isShowAuth: true
})
}
},
})
},
// 获取授权
setAuthSuccess(e) {
if (e.detail.authSetting['scope.userLocation']) {
this.getLocation();
this.setData({
isShowAuth: false
})
}
},
})