473 lines
9.2 KiB
JavaScript
Raw Normal View History

2025-07-10 16:27:08 +08:00
let App = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
step:0,
userStep:0,
licheng:0,
day:0,
paiming:12143,
position:'江西瑞金',
nextPosition:'宜章',
mubiao:50,
showModel:0,
showStep:0,
polyline:[],
markers:[],
canyuNum:0,
topicInfo:[],
stepToday:0,
zdStep:0,
zgStep:0,
time:0
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log('onLoad');
this.getStepNew();
this.setData({
// 仅设置的属性会生效,其它的不受影响
setting: {
enableZoom: false,
enableScroll: false,
},
})
this.getImageData();
this.getAddress();
this.getStepCountToday();
this.getTopicInfo();
this.getStepConfig();
this.getStepJl();
this.mapContext = wx.createMapContext('map');
let _this = this;
App._post_form('topic/getLicheng', {
user_id: wx.getStorageSync('user_id')
}, function(result) {
var rdata = result.data.data;
if( rdata ){
var a = _this.data.showModel;
_this.setData({
showModel: !a
})
_this.getData();
}
});
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
console.log('onShow');
this.getStepNew();
this.getStepJl();
},
//获取用户微信运动步数
getUserStep:function(){
let _this = this;
App._post_form('topic/getUserStep', {
user_id: wx.getStorageSync('user_id')
}, function(result) {
var userStep = result.data.data;
console.log('userStep',userStep);
_this.setData({
userStep: userStep
})
});
},
getStepCountToday:function(){
let _this = this;
App._post_form('topic/getStepCountToday', {
user_id: wx.getStorageSync('user_id'),
}, function(result) {
var stepToday = result.data.data;
_this.setData({stepToday:stepToday});
});
},
getStepJl:function(){
let _this = this;
App._post_form('topic/getStepJl', {
user_id: wx.getStorageSync('user_id'),
}, function(result) {
var time = result.data.data;
console.log('time',time);
_this.setData({time:time});
});
},
getStepNew:function(){
let _this = this;
App._post_form('topic/getStep', {
user_id: wx.getStorageSync('user_id'),
}, function(result) {
var stepNew = result.data.data;
_this.setData({step:stepNew});
});
},
/**
* 获取长征路路线
*/
getAddress: function() {
let _this = this;
App._post_form('topic/getAddress', {
user_id: wx.getStorageSync('user_id')
}, function(result) {
var rdata = result.data.data.address;
var dangqianInfo = result.data.data.dangqianData;
var rdata2 = result.data.data.result3;
let markers = [] ,polyline = [] ,points = [], points2 = [],dataPoint = [];
for (var i=0;i<rdata.length;i++)
{
let iconPath = "/images/fabulous.png",width = 8 ,height = 8;
if(rdata[i]['sort'] < dangqianInfo['sort']){
iconPath = "/images/qi_on.png";width = 19 ;height = 23;
}
if(rdata[i]['sort'] == dangqianInfo['sort']){
iconPath = dangqianInfo['avatarUrl'];width = 40 ;height = 40;
}
markers[i] = {
id:i,
latitude:rdata[i]['latitude'],
longitude:rdata[i]['longitude'],
iconPath: iconPath,
width:width,
height:height,
anchor:{x: .3, y: 1},
callout: {
content:rdata[i]['name'],
fontSize: 12,
bgColor: "#FFF",
borderWidth: 1,
borderColor: "#CCC",
padding: 4,
display: "ALWAYS",
textAlign: "center",
borderRadius:12
}
}
points[i] = {
latitude:rdata[i]['latitude'],
longitude:rdata[i]['longitude'],
}
}
polyline = [{
points: points,
color:"#A2A5AD",//线条的颜色
width: 5,//宽度
}];
for (var i=0;i<rdata2.length;i++)
{
points2[i] = {
latitude:rdata2[i]['latitude'],
longitude:rdata2[i]['longitude'],
}
}
if(rdata2.length > 1){
polyline.push({
points:points2,
color:"#D03020",//线条的颜色
width: 5,//宽度
})
}
_this.setData({
markers: markers,
polyline:polyline
})
});
},
goLicheng:function(){
let _this = this;
App._post_form('topic/goLicheng', {
user_id: wx.getStorageSync('user_id')
}, function(result) {
var rdata = result.data.data;
if( rdata ){
var a = _this.data.showModel;
wx.showToast({
title: '加入成功',
icon: 'none',
duration: 2000
})
_this.setData({
showModel: !a
})
_this.getData();
}
});
},
goDuiHuanW:function(e){
console.log('goDuiHuanW');
let _this = this;
_this.getStepJl();
let zdStep = _this.data.zdStep;
let zgStep = _this.data.zgStep;
let stepToday = _this.data.stepToday;
let time = _this.data.time;
let step = e.target.dataset.step;
let dhnum = e.target.dataset.dhnum;
let dhnumc = e.target.dataset.dhnumc;
console.log('_this.data.time',time);
if(stepToday >= zgStep ){
wx.showToast({
title: '今日兑换步数已达上限'+zgStep+'步',
icon: 'none',
duration: 4000
})
return false;
}
if(dhnum == dhnumc ){
wx.showToast({
title: '今日兑换次数已用完',
icon: 'none',
duration: 4000
})
return false;
}
if(0 < time && time <= 3600 ){
wx.showToast({
title: '再走走看吧',
icon: 'none',
duration: 4000
})
return false;
}
if(step <= zdStep ){
wx.showToast({
title: '步数不能低于'+zdStep+'步',
icon: 'none',
duration: 4000
})
return false;
}
},
goDuiHuan:function(e){
let _this = this;
_this.getStepJl();
let zdStep = _this.data.zdStep;
let zgStep = _this.data.zgStep;
let stepToday = _this.data.stepToday;
let step = e.target.dataset.step;
let time = _this.data.time;
let dhnum = e.target.dataset.dhnum;
let dhnumc = e.target.dataset.dhnumc;
if(stepToday >= zgStep ){
wx.showToast({
title: '今日兑换步数已达上限'+zgStep+'步',
icon: 'none',
duration: 4000
})
return false;
}
if(dhnum == dhnumc ){
wx.showToast({
title: '今日兑换次数已用完',
icon: 'none',
duration: 4000
})
return false;
}
if(0 < time && time <= 3600 ){
wx.showToast({
title: '再走走看吧',
icon: 'none',
duration: 4000
})
return false;
}
if(step < zdStep ){
wx.showToast({
title: '步数不能低于'+zdStep+'步',
icon: 'none',
duration: 4000
})
return false;
}
if(dhnum == 0 && step > zgStep){
step = zgStep; //首次兑换 兑换步数 > 每日最高兑换步数 兑换步数 = 每日最高兑换步数
}
if( ( dhnum > 0 && dhnum < dhnumc ) && (step + stepToday) > zgStep){
step = zgStep - stepToday; //第二次 或者 第三次兑换 可兑换步数 = 最高兑换步数 - 已兑换步数
}
App._post_form('topic/goDuiHuan', {
user_id: wx.getStorageSync('user_id'),
step:step
}, function(result) {
var rdata = result.data.data;
if( rdata.status ){
_this.getData();
_this.getStepCountToday();
_this.setData({step:rdata.step});
wx.showToast({
title: '兑换成功',
icon: 'none',
duration: 2000
})
}
});
},
getTopicInfo:function(){
let _this = this;
App._get('topic/getTopicDetail', {}, function(result) {
var rdata = result.data.data;
_this.setData({topicInfo:rdata});
});
},
/**
* 获取图片设置数据
*/
getImageData: function() {
let _this = this;
App._get('wxapp/imageSet', {}, function(result) {
_this.setData({imageSet:result.data.new_values});
});
},
/**
* 获取基础设置
*/
getStepConfig: function() {
let _this = this;
App._get('wxapp/store', {}, function(result) {
console.log('result.data.values',result.data.values);
_this.setData({
zdStep:result.data.values.zdstep,
zgStep:result.data.values.zgstep,
});
});
},
getData:function(){
let _this = this;
App._post_form('topic/getTopicData', {
user_id: wx.getStorageSync('user_id'),
}, function(result) {
var rdata = result.data.data;
_this.setData({
licheng:rdata.mileage,
day:rdata.days,
paiming:rdata.sort,
position:rdata.next.dangqianAddress,
nextPosition:rdata.next.nextMubiao,
mubiao:rdata.next.mubiaoJuLi,
info:rdata.next.dangqianData,
canyuNum:rdata.canyuNum,
dhnum:rdata.dhnum,
dhnumC:rdata.config.dhnum,
});
});
},
goInfo: function () {
wx.navigateTo({
url: "/pages/topic/address"
});
},
goXunzhang: function () {
wx.navigateTo({
url: "/pages/topic/xunzhang"
});
},
goDetail: function () {
wx.navigateTo({
url: "/pages/topic/detail"
});
},
goJiLu :function () {
wx.navigateTo({
url: "/pages/topic/addList"
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
console.log('onHide');
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
console.log('onUnload');
},
onPullDownRefresh: function () {
wx.stopPullDownRefresh()
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})