123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- // pages/ucenter/mychargestation/mychargestation.js
- let Util = require('../../../utils/util');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- markers: []
- },
- goIndex(e) {
- //console.log(e);
- let markerId = e.currentTarget.id;
- let pages = getCurrentPages();
- let prevPage = pages[pages.length - 3]; //上一个页面
- this.data.markers.forEach((item, index) => {
- if (markerId && markerId == item.id) {
- let {
- latitude,
- longitude
- } = item;
- prevPage.setData({
- markerId,
- latitude,
- longitude,
- textData: item
- });
- wx.navigateBack({
- delta: 3
- });
- }
- });
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- let that = this;
- //console.log(12345);
- if (userInfo && isLogin) {
- wx.getLocation({
- success: function(res) {
- //console.log(res);
- let {
- latitude,
- longitude,
- } = res;
- wx.request({
- url: getApp().globalData.postHeadAgreement +'/restapi/wechat/userChargStations',
- data: {
- userId: userInfo.userId,
- lat: latitude,
- lon: longitude
- },
- method: 'POST',
- success(res) {
- console.log(res);
- let {
- data
- } = res;
- let markers = [];
- data.forEach((item, index) => {
- //item.callout = {
- // content: item.name, //文本 String 1.2.0
- // display: 'BYCLICK', //'BYCLICK': 点击显示; 'ALWAYS': 常显 String 1.2.0
- // textAlign: 'center' //文本对齐方式。有效值: left, right, center String 1.6.0
- // };
- //console.log(Util.distance(latitude, longitude, item.lat, item.lon));
- var marker = {
- name: item.chargStationName,
- address: item.address,
- width: "88rpx",
- height: "112rpx",
- iconPath: "/images/marker.png",
- id: item.id,
- callout: {},
- latitude: item.lat,
- longitude: item.lon,
- distance: Math.round(item.distance) / 1000,
- //distance: Util.distance(latitude, longitude, item.lat, item.lon),
- chargPileNum: item.fastCharg + item.slowCharg,
- fastCharg: item.fastCharg,
- slowCharg: item.slowCharg,
- freenum: item.freenum,
- fastfreenum: item.fastfreenum,
- slowfreenum: item.slowfreenum,
- breaknum: item.breaknum,
- /** 电费 */
- chargprice: item.chargprice,
- /** 服务费 */
- serviceprice: item.serviceprice,
- /** 停车费 */
- stopprice: item.stopprice,
- operationState: item.operationState
- };
- markers[index] = marker;
- });
- that.setData({
- markers
- });
- }
- });
- }
- });
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|