<template>
  <view class="collect">
    <view class="text">以下是您收藏的商品服务</view>

    <!-- 收藏的服务 -->
   <serviceItem :item='init_list' :skipType='1'></serviceItem>
   <u-empty v-if="init_list.length == 0" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" > </u-empty>
  </view>
</template>

<script>
  import serviceItem from '@/components/service/index.vue';
  import { maintainFavoritePaging } from "@/api/mine.js"
  import { getCurrentLocation } from '@/api/home';

  export default {
    components: {
      serviceItem,
    },
    data() {
      return {
        queryParams:{
          size:10,
          type:'MERCHANT',
          region:null,//地区编码
          longitude:null,//经度
          latitude:null,//纬度
        },
        init_list:[]
      };
    },
    onLoad() {
      this.handlerInitLocation()
    },
    methods: {
      // 获取当前经纬度
      handlerInitLocation(){
        uni.getLocation({
        	type: 'gcj02',
        	success: res => {
        		this.queryParams.longitude = res.longitude;
        		this.queryParams.latitude = res.latitude;
            let point = {
              latitude: res.latitude,
              longitude: res.longitude
            }
            getCurrentLocation(point).then(rc=>{
              this.queryParams.region = rc.data.id
              this.handlerInitList()
            })
        	},
        	fail: (rs) => {
            uni.showToast({
              title:rs,
              icon:'none'
            })
        	}
        });
      },
      // 初始化列表信息
      handlerInitList(){
        maintainFavoritePaging(this.queryParams).then(res=>{
          res.data.map(rs=>{
            this.init_list.push(rs.simpleMerchantVO)
          })
          console.log('getHomePageApi',this.init_list);
        })
      }
    },
  };
</script>

<style lang="scss" scoped>
  .collect {
    height: 100vh;
    background-color: #efefef;

    .text {
      text-align: center;
      padding: 40rpx;
      color: #999;
    }
  }
</style>
