<template>
  <view class="container">
    <serviceItem :item="init_list" :skipType="0"/>
    <view v-if='init_list.length == 0' style="margin-top: 40rpx">
      <u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" />
    </view>
  </view>
</template>

<script>
  import {
    getHomePageApi,
    indexMerchantPaging
  } from '@/api/client/home';
  import serviceItem from '@/components/service/serviceItem.vue';
  import {
    mapGetters
  } from "vuex"
  export default {
    data() {
      return {
        queryParams: {
          region: null, //地区编码
          longitude: null, //经度
          latitude: null, //纬度
          paging:'1,10',
          queryType:1, //查询类型 0-附近商家 1- 推荐商家
        },
        init_list: [],
      };
    },
    components: {
      serviceItem,
    },
    computed: {
      ...mapGetters(['location'])
    },
    // 上滑刷新
    onReachBottom(){
      let { paging } = this.queryParams
      let pageNum = paging.split(',')[0]
      let pageSize = paging.split(',')[1]
      if( pageNum * pageSize > this.total ){
        uni.showToast({
          title:'没有更多啦~',
          icon:'none'
        })
        return
      }else{
        pageNum ++
        this.queryParams.paging = `${pageNum},${pageSize}`
        this.handlerInitList()
      }
    },
    mounted() {
      let {
        latitude,
        longitude,
        region
      } = this.location
      this.queryParams.latitude = latitude
      this.queryParams.longitude = longitude
      this.queryParams.region = region
      this.handlerInitList();
    },
    methods: {
      // 初始化列表信息
      handlerInitList() {
        indexMerchantPaging(this.queryParams).then(res => {
          let { records , total } = res.data
          this.init_list = [...this.init_list , ...records]
          this.total = total
        });
      },
    },
  };
</script>
