<template>
  <view class="wk-field wk-field-location" @click.stop="handleToLocation">
    <view v-if="_label" class="wk-field__label">
      <view v-if="field.isNull === 1" class="line" />
      {{ _label }}
    </view>
    <view class="wk-field__body">
      <view class="wk-field__body-core">
        {{ valueStr }}
      </view>
      <text class="wk wk-position icon-right" />
    </view>
  </view>
</template>

<script>
  import mixins from './mixins'
  import {
    bMapTransQQMap,
    qqMapTransBMap,
    getLocation
  } from '@/utils/map.js'
	
  export default {
    name: 'WkFieldLocation',
    mixins: [mixins],
    data() {
      return {
        guid: null,
        locationPoint: {}
      }
    },
    computed: {
      valueStr() {
        return this.formValue ? (this.formValue.address || '') : ''
      }
    },
    created() {
      this.guid = this.$guid()
    },
    methods: {
      handleToLocation() {
        if (this.field.disabled) {
          if (this.config && this.config.disabledMsg) {
            this.$toast(this.config.disabledMsg)
          }
          return
        }

        uni.$once('choose-address', this.chooseAddress)
        this.$Router.navigateTo({
          url: '/pages_common/map/chooseAddress'
        })
      },

      chooseAddress(data) {
        const point = qqMapTransBMap(data.longitude, data.latitude)
        this.formValue = {
          lng: point.longitude,
          lat: point.latitude,
          address: data.addr || data.address || '',
        }
        console.log(this.formValue)
				
        this.$emit('input', this.formValue)
        this.$emit('change', {
          index: this.index,
          field: this.field,
          value: this.formValue
        })
      }
    }
  }
</script>

<style scoped lang="scss">
	@import './wkField.scss';
	.wk-field-location {
		.wk-field__body {
			.icon-right {
				font-size: $wk-font-large;
			}
		}
	}
</style>
