tanzhongheY/pages/footprint/footprint.js

107 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// pages/footprint/footprint.js
var urlPath = require('../../config.js');
Page({
/**
* 页面的初始数据
*/
data: {
host:urlPath.host,
data_list: [
// {
// name:'低碳婚礼',
// icon:'/img/nav/huaindex.png',
// time:'2020年12月12日',
// img:'/img/001.png',
// num1:'300KG',
// num2:'300KG',
// num3:'300元',
// num4:'油松',
// address:'北京一环碳中和林(妍清洁的)',
// },{
// name:'低碳婚礼',
// icon:'/img/nav/time.png',
// time:'2020年12月12日',
// img:'/img/001.png',
// num1:'300KG',
// num2:'300KG',
// num3:'300元',
// num4:'油松',
// address:'北京一环碳中和林(妍清洁的)',
// },{
// name:'低碳婚礼',
// icon:'/img/nav/cheindex.png',
// time:'2020年12月12日',
// img:'/img/001.png',
// num1:'300KG',
// num2:'300KG',
// num3:'300元',
// num4:'油松',
// address:'北京一环碳中和林(妍清洁的)',
// }
],
page: 1,
},
timestampToTime: function(timestamp) {
var date = new Date(timestamp * 1000); //时间戳为10位需*1000时间戳为13位的话不需乘1000
var Y = date.getFullYear() ;
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) ;
var D = date.getDate() ;
var h = date.getHours() + ':';
var m = date.getMinutes() + ':';
var s = date.getSeconds();
return Y+'年' + M+'月' + D+'日' ;//+ h + m + s;
},
onLoad: function(options) {
this.getData(options)
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
this.setData({
page: this.data.page + 1
})
this.getData()
},
getData: function(openid) {
var that = this
wx.request({
url: urlPath.markList,
header: {
'content-type': 'application/x-www-form-urlencoded' // 改变默认值为这个配置
},
dataType: 'json', // 添加这个配置
method: 'post',
data: {
openid: wx.getStorageSync('openid'),
page: that.data.page,
size: '10'
},
success(res) {
if (res.data.result == 'success') {
let data_list = JSON.parse(res.data.data)
.list; // that.data.data_list.concat(JSON.parse(res.data.data).list)
data_list.forEach(function(item) {
item.created_time = that.timestampToTime(item.created_time);
item.start_date_time = that.timestampToTime(item.start_date_time);
item.end_date_time = that.timestampToTime(item.end_date_time);
})
console.log(data_list,'data_list')
that.setData({
data_list: that.data.data_list.concat(data_list),
})
} else {
console.log(res.msg); //失败
}
}
});
},
})