123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- // pages/home/map/map.js
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- location:{},
- mapworkelist:[],
- inputValue:"",
- workelist:[],
- hasMarkers:true,
- workedesc:"",
- status:"",
- show:false
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var that = this
- that.setData({
- location:{
- 'latitude':wx.getStorageSync('latitude'),
- 'longitude':wx.getStorageSync('longitude')
- }
- })
- that.workDesc();
- that.setData({
- status:app.globalData.status
- })
-
- },
- onHide(){
- wx.stopLocationUpdate({
- success: (res) => {
- console.log(res);
- },
- })
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- wx.stopLocationUpdate({
- success: (res) => {
- console.log(res);
- },
- })
- },
- //网点列表
- workDesc:function(e){
- var that=this;
- var keyword=that.data.inputValue;
- console.log(keyword);
- var latitude=wx.getStorageSync('latitude');
- var longitude=wx.getStorageSync('longitude');
-
- app.api.useApi(app.globalData.baseAppUrl + "api", {
- lat: latitude,
- lng: longitude,
- keyword: keyword,
- }, "get").then(function (res) {
- if (res.code != 200) {
- wx.showLoading({
- title: '网点加载失败'+res.status,
- })
- } else {
- var data=res.message.data.data
-
- that.setData({
- workelist:res.message.data.data
- })
- var maplist=[];
- var workelist=[];
- for (var i = 0; i < data.length; ++i) {
- maplist[i]={
- 'id':data[i]['id'],
- 'latitude':data[i]['lat'],
- 'longitude':data[i]['lng'],
- 'iconPath': '/image/address/location.png',
- 'width':60,
- 'height':60,
- }
- workelist[data[i]['id']]={
- 'id':data[i]['id'],
- 'latitude':data[i]['lat'],
- 'longitude':data[i]['lng'],
- 'title':data[i]['title'],
- 'address':data[i]['address'],
- 'name':data[i]['name'],
- 'signing_status':data[i]['signing_status'],
- 'distance':data[i]['distance']
- }
-
- if((keyword!='' || keyword!=null)&& i==0){
-
- that.setData({
- workedesc: workelist[data[i]['id']],
- show:true
- })
- }
- }
-
- console.log(data);
- if(data=="" || data ==null || data==[]){
- console.log(33333);
- var workedesc={
- 'id':0,
- 'latitude':0,
- 'longitude':0,
- 'title':'暂无数据',
- 'address':'暂无数据',
- 'name':'暂无数据',
- 'signing_status':0,
- 'distance':0
- }
- that.setData({
- workedesc: workedesc,
- show:true
- })
- }
-
- that.setData({
- mapworkelist:maplist,
- hasMarkers:true,
- workelist:workelist
- })
- console.log(that.data.mapworkelist)
- }
- wx.hideLoading();
- }).catch(function (err) {
- var workedesc={
- 'id':0,
- 'latitude':0,
- 'longitude':0,
- 'title':'暂无数据!',
- 'address':'暂无数据!',
- 'name':'暂无数据!',
- 'signing_status':12,
- 'distance':0
- }
- that.setData({
- workedesc: workedesc,
- show:true
- })})
- },
- bindKeyInput: function (e) {
- this.setData({
- inputValue: e.detail.value
- })
- },
- markertap(e) {
- console.log('@@@ markertap', e)
- var workelist=this.data.workelist;
- var markerId=e.detail.markerId;
- var workedesc=workelist[markerId];
- this.setData({
- workedesc: workedesc,
- show:true
- })
- },
- //设置网点
- setworke(e){
- app.api.useApi(app.globalData.baseAppUrl+"api/user",{
- network_id:e.target.dataset.id,
- },"get").then(function(res){
- if (res.code == 200) {
- wx.showLoading({
- title: '网点设置成功',
- })
- }
- }).catch(function(err){
- console.log(222);
- })
- }
- })
|