<template>
<view id="pusher">
    <block v-for="(items, idx) in twitterList" :key="idx"  >
        <view class="vipManage-item" v-for="(item, index) in items" :key="index" >
            <image :src="item.user.avatar"></image>
            <view class="item-right">
                <view class="username">
                    <span class="nickname">{{item.user.nick_name}}</span>
                    <!--<span class="grade">Vitem.grade</span>-->
                </view>
                <view class="vipdate">
                    <span class="vipnum">会员号：{{item.user_id}}</span>
                    <span>加入日期：{{item.user.created_at}}</span>
                </view>
            </view>
        </view>
    </block>
    <block v-if="twitterList && twitterList[0] && twitterList[0].length == 0 && init">
        <view class="no-data">暂无数据</view>
    </block>

</view>
</template>
<script>

import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';

export default {
  data() {
    return {
      twitterList: [],
      //推客列表
      page: 1,
      more: true,
      init: false
    };
  },

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

  onLoad() {
    this.queryTwitterList(1);
  },

  components: {},
  props: {},
  methods: {
    //请求推客列表
    queryTwitterList(page) {
      wx.showLoading({
        title: "加载中",
        mask: true
      });
      var token = this.$cookieStorage.get('user_token');
      this.$http.get({
        api: 'api/distribution/twitter/list',
        header: {
          Authorization: token
        },
        data: {
          page: page
        }
      }).then(res => {
        if (res.statusCode == 200) {
          res = res.data;

          if (res.status) {
            var pages = res.meta.pagination;
            var current_page = pages.current_page;
            var total_pages = pages.total_pages;
            // this.setData({
            //   [`twitterList[${page - 1}]`]: res.data,
            //   more: current_page < total_pages,
            //   page: current_page,
            //   init: true
            // });
			
			this.$set(this.twitterList, page -1, res.data);
			this.init=true;
			this.page=current_page;
			this.more=current_page < total_pages;
			
          } else {
            wx.showModal({
              content: res.message || '请求失败',
              showCancel: false
            });
          }
        } else {
          wx.showModal({
            content: res.message || '请求失败',
            showCancel: false
          });
        }

        wx.hideLoading();
      }).catch(rej => {
        wx.hideLoading();
        wx.showModal({
          content: res.message || '请求失败',
          showCancel: false
        });
      });
    },

    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 "pusher";
</style>
