123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- //index.js
- //获取应用实例
- const app = getApp()
- const QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
- const qqmapsdk = new QQMapWX({
- key: '36IBZ-VI53O-FJHW2-SV2NP-USSAE-GFBUS'
- })
- Page({
- data: {
- userInfo: {},
- list: []
- },
- onLoad: function () {
- if (app.globalData.userInfo) {
- this.setData({
- userInfo: app.globalData.userInfo
- });
- this.getList();
- } else {
- // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
- // 所以此处加入 callback 以防止这种情况
- app.userInfoReadyCallback = res => {
- this.setData({
- userInfo: res
- })
- this.getList();
- };
- }
- },
- goDetail(e) {
- let id = e.currentTarget.dataset.id;
- let currentActivity = this.data.list.filter(v => {
- return v.id == id;
- });
- app.globalData.currentActivity = currentActivity[0];
- wx.navigateTo({
- url: '/pages/detail/index',
- })
- },
- async getList() {
- try {
- let result = await app.globalData.api.activity_list_mine(app.globalData.userInfo.phone || '');
- const lngArr = [];
- result.data.forEach(v => {
- v.shareMember = 0;
- if (v.images) {
- v.imgList = v.images.split(';').filter(v=>{
- return v != '';
- })
- }
- if(v.members){
- v.membersList = v.members.split(';').filter(v=>{
- return v != '';
- })
- if(v.membersList.indexOf(app.globalData.userInfo.phone || '0') > -1){
- v.shareMember = 1;
- }
- }
- if (v.lat && v.lng) {
- lngArr.push({
- latitude: v.lat,
- longitude: v.lng
- })
- }
- });
- this.setData({
- list: result.data
- })
- if (lngArr.length) {
- this.getDistance(lngArr);
- }
- } catch (error) {
- console.log(error)
- }
- },
- getDistance(localresult) {
- qqmapsdk.calculateDistance({
- to: localresult, //终点坐标
- success: function (res) { //成功后的回调
- console.log(res,8888)
- //判断经纬度,获取具体门店,付值 distance
- // resolve(res.result.elements[0].distance);
- },
- fail: function (error) {
- console.error(error);
- },
- complete: function (res) {}
- });
- },
- goEdit() {
- console.log('edit')
- },
- userInfoHandler(e) {
- const that = this;
- if (e.detail.errMsg == "getUserInfo:ok") {
- let userInfo = e.detail.userInfo;
- let params = Object.assign({}, {
- openid: app.globalData.userInfo.openid,
- nickName: userInfo.nickName,
- gender: userInfo.gender,
- avatarUrl: userInfo.avatarUrl
- });
- app.globalData.api.binduserinfo(params).then(res => {
- console.log(res);
- let newUserInfo = Object.assign({}, app.globalData.userInfo, {
- nickName: userInfo.nickName,
- gender: userInfo.gender,
- avatarUrl: userInfo.avatarUrl
- });
- app.globalData.userInfo = newUserInfo;
- that.setData({
- userInfo: newUserInfo
- })
- })
- }
- },
- })
|