import { Component } from 'react'
import Taro from '@tarojs/taro'
import { connect } from 'react-redux'
import {View, Map, Button} from '@tarojs/components'
import dayjs from 'dayjs';

import { add, minus, asyncAdd } from '../../actions/counter'

import './index.less'


@connect(({ counter }) => ({
  counter
}), (dispatch) => ({
  add () {
    dispatch(add())
  },
  dec () {
    dispatch(minus())
  },
  asyncAdd () {
    dispatch(asyncAdd())
  }
}))
class Index extends Component {
  constructor(props) {
    super(props);
    this.state={
      data:[],
      newArrder:{},
      newList:[
        {
          longitude: 112.9513,
          latitude: 28.23529,
          title:'营销员1',
          label:{
            content:'营销员1'
          }
        },
        {
          longitude: 112.9613,
          latitude: 28.23529,
          title:'营销员2',
        },
        {
          longitude: 112.9713,
          latitude: 28.23529,
          title:'营销员3',
        }
      ],
    }
  }

  componentDidShow () {

  }

  componentDidMount() {
    //获得当前位置
    Taro.getLocation({
      type: 'gcj02',
      isHighAccuracy:true,
      success: (res)=> {
        const latitude = res.latitude
        const longitude = res.longitude
        this.setState({
          newArrder:{
            latitude,
            longitude
          },
        })
      }
    })
  }

  render () {
    return (
      <View>
        <Map
          id="allmap"
          {...this.state.newArrder}
          markers={this.state.newList}
        />
      </View>
    )
  }
}

export default Index

