<template>
<view id="self-shop">
<!--    搜索框-->
    <view class="search-box">
        <view class="item">
            <input type="text" @input="changeInput" placeholder="店铺名"></input>
            <view class="iconfont icon--sousuo" @tap="searchName"></view>
        </view>
    </view>
<!--    门店列表-->
    <view class="shop-list">
        <radio-group class="radio-group">
            <block v-for="(items, idx) in list" :key="idx"  >
                <view class="item" v-for="(item, index) in items" :key="index" :data-id="item.id" :data-name="item.name" @tap="changeShop">
                    <view class="left-box">
                        <label class="radio">
                            <radio :value="String(item.id)" color="#FF2741"></radio>
                        </label>
                    </view>
                    <view class="right-box mx-1px-left">
                        <view class="name">
                            {{item.name}}
                        </view>
                        <view class="adress">
                            地址：{{item.address}}
                        </view>
                       <!-- <view class="time adress">
                            营业时间：周一到周日 10:00-22:00
                        </view>-->
                        <view class="mobile">
                            联系电话：{{item.phone}}
                        </view>
                    </view>
                </view>
            </block>
        </radio-group>
    </view>


</view>
</template>
<script>
import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';

export default {
  data() {
    return {
      list: [],
      page: 1,
      more: true,
      init: false,
      seleckValue: '',
      name: ''
    };
  },

  onReachBottom() {
    if (this.more) {
      let page = this.page + 1;
      // this.queryShopList(page);
    } else {
      wx.showToast({
        image: '../../../static/error.png',
        title: '再拉也没有啦'
      });
    }
  },

  onShow() {
    /* this.queryShopList(1); */
  },
  methods: {
    //查询自提门店列表
    queryShopList(page, name) {
      this.$http.get({
        api: 'api/pick/self/store',
        data: {
          page: page,
          name: name || ''
        }
      }).then(res => {
        if (res.statusCode == 200) {
          res = res.data;

          if (res.status) {
            let pages = res.meta.pagination;
            let current_page = pages.current_page;
            let total_pages = pages.total_pages;
            this.setData({
              //[`list[${page - 1}]`]: res.data,
              page: current_page,
              more: current_page < total_pages,
              init: true
            });
			
			this.$set(this.list, page -1, res.data);
			
			
          } else {
            wx.showToast({
              title: res.message,
              image: '../../../static/error.png'
            });
          }
        } else {
          wx.showToast({
            title: '获取信息失败',
            image: '../../../static/error.png'
          });
        }
      });
    },

    changeShop(e) {
        let name = e.currentTarget.dataset.name;
        let id = e.currentTarget.dataset.id;
        let data = {
            name,
            id
        }
      this.$cookieStorage.set('selfShop', data);
      wx.navigateBack({
        delta: 1
      });
    },

    changeInput(e) {
      this.setData({
        name: e.detail.value
      });
    },

    searchName() {
      let name = this.name;
      /* this.queryShopList(1, name); */
    },

    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  },
  computed: {},
  watch: {}
};
</script>
<style rel="stylesheet/less" lang="less">
    @import "selfShop";
</style>