<template>
  <view class="demos">
    <web-view @bindmessage="onMessageHandler" :src="webViewSrc"></web-view>
  </view>
</template>

<script>
import httpAjax from '@/utils/https.js';
import config from '@/utils/config.js';

const _cDate = new Date();
export default {
  components: {},
  data() {
    return {
      time: null,
      webViewSrc: config.webViewUrl +
		'?v='+_cDate.getTime()+'&objs=' +
		JSON.stringify(uni.getStorageSync('userInfo'))
    };
  },
  onReady(){
	wx.setNavigationBarTitle(({
		title: config.webViewUrl === config.webViewUrl2 ? '要素一本账' : '地块管护'
	}))  
  },
  mounted() {
    this.time = setInterval(() => {
      this.initGetLocation();
    }, 3000);
  },
  methods: {
    initGetLocation() {
      let that = this;
      let citys = {
        longitude: '',
        latitude: '',
      };
      uni.getLocation({
        success: function (res) {
          citys.longitude = res.longitude;
          citys.latitude = res.latitude;
          that.webViewSrc =
            config.webViewUrl +
            '?objs=' +
            JSON.stringify(uni.getStorageSync('userInfo')) +
            '&city=' +
            JSON.stringify(citys);
        },
      });
    },
    onMessageHandler(event) {
      console.log(event);
      let res = event.detail.data;
      console.log('小程序接收到H5传递过了的message:', JSON.stringify(res));

      uni.showToast({
        title: '小程序接收到H5传递过了的message:' + JSON.stringify(res),
        icon: 'none',
      });
    },
  },
};
</script>

<style lang="scss"></style>
