// index.js // 获取应用实例 import { getbuddyList } from "../../utils/api" const app = getApp() import { getindex, submitAddr, getAround, addFirends, getUserByOpenid } from "../../utils/api" const restapi = getApp().globalData.restapi Page({ data: { longitude: "117.1200", latitude: "36.65184", map: '', markes: [ { id: 'a789', longitude: "117.85", latitude: "36.3850", iconPath: "../../images/定位.png", width:50, height: 60 } ], show: false }, showPopup() { this.setData({ show: true }); }, onClose() { this.setData({ show: false }); }, onShow() { // console.log("load") // this.setData({ // map: wx.createMapContext('map') // }) // console.log(this.data.map) // getindex().then((res)=>{ // console.log(res) // }) // restapi.setUserList([{ // "uuid": "08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a", // "name": "Mattie", // "avatar": '/static/images/Avatar-1.png' // }, // { // "uuid": "3bb179af-bcc5-4fe0-9dac-c05688484649", // "name": "Wallace", // "avatar": '/static/images/Avatar-2.png' // }, // { // "uuid": "fdee46b0-4b01-4590-bdba-6586d7617f95", // "name": "Tracy", // "avatar": '/static/images/Avatar-3.png' // }, // { // "uuid": "33c3693b-dbb0-4bc9-99c6-fa77b9eb763f", // "name": "Juanita", // "avatar": '/static/images/Avatar-4.png' // }]) let that = this // let openid = wx.getStorageSync('currentUser').openid // if(!openid){ // return ; // } this.init() // wx.getSetting({ // success(res) { // console.log(res) // if (!res.authSetting['scope.userLocation']) { // wx.authorize({ // scope: 'scope.userLocation', // success() { // that.init() // }, // fail() { // that.setData({ // show: true // }) // } // }) // } else { // that.init() // } // } // }) // this.init() }, shouquan() { console.log("diaoyong") wx.openSetting({ success (res) { console.log(res.authSetting) // res.authSetting = { // "scope.userInfo": true, // "scope.userLocation": true // } }, fail(err){ console.log(err) } }) }, init() { let that = this wx.getLocation({ success(loacl) { console.log(loacl) that.setData({ longitude: loacl.longitude, latitude: loacl.latitude }) submitAddr({ longitude: loacl.longitude, latitude: loacl.latitude }).then((res) => { console.log(res) let list = [] getAround({ longitude: loacl.longitude, latitude: loacl.latitude }).then((res) => { console.log(res) for (let i of res.data) { // { // id: 1, // longitude: "117.85", // latitude: "36.3850", // iconPath: "../../images/定位.png", // width:50, // height: 60 // } let info = { id: 1, longitude: "117.85", latitude: "36.3850", iconPath: "../../images/定位.png", width: 50, height: 60 } info.id = i.openid; info.longitude = i.longitude; info.latitude = i.latitude; list.push(info) } // that.setData({ // markes: list // }) console.log(that.data.markes) }) }) } }) }, addf(data) { let openid = wx.getStorageSync('currentUser').openid if(!openid){ wx.navigateTo({ url:"/pages/login/login" }) return ; } console.log(data.markerId) getUserByOpenid({ openid: data.markerId }).then((res) => { console.log(res) if (res.code == 1) { wx.showToast({ title: res.msg, icon: 'none', duration: 2000 }) return; } this.setData({ show: true }) // wx.showModal({ // title: '添加好友', // content: '是否添加' + res.data.name + '为好友?', // success(res) { // if (res.confirm) { // addFirends({ // friend_openid: data.markerId // }).then((res) => { // console.log(res) // if (res.code == 1) { // wx.showToast({ // title: res.msg, // icon: 'none', // duration: 2000 // }) // } else { // getbuddyList().then((res) => { // console.log(res) // app.globalData.restapi.setUserList(res.data) // if (res.code == 0) { // wx.showToast({ // title: "添加成功", // icon: 'none', // duration: 2000 // }) // } else { // wx.showToast({ // title: res.msg, // icon: 'none', // duration: 2000 // }) // } // }) // } // }) // } else if (res.cancel) { // console.log('用户点击取消') // } // } // }) }) } })