text: import Http from '../../utils/http';
  import config from '../../utils/config';
  import cache from '../../utils/cache';
  import fang from '../../models/Fang';
  
  const http = new Http;
  
  Page({
    data: {
      userInfo: {},
      show: false,
      // 房源列表
      fanglists: [],
      // 分页
      page: 1,
    },
  
    onLoad(options) {
      if (cache.has('userInfo')) {
        this.setData({
          userInfo: cache.get('userInfo'),
          show: true
        });
      }
      // 加载更多 房源列表
      this.getMore();
    },
  
    // 加载更多
    getMore() {
      fang.getFangList(this.data.page).then(res => {
        let page = this.data.page;
        if (res.data.length > 0) {
          this.setData({
            fanglists: [...this.data.fanglists, ...res.data],
            page: ++page
          });
        }
      })
    },
  
    getUserInfo() {
      wx.getUserInfo({
        timeout: 10000,
        success: ({ userInfo }) => {
          this.setData({
            userInfo,
            show: true
          });
          cache.set('userInfo', userInfo);
          http.axios({
            url: config.userinfo,
            method: 'POST',
            data: {
              openid: cache.get('openid'),
              nickname: userInfo.nickName,
              sex: userInfo.gender == 1 ? '男' : '女',
              avatar: userInfo.avatarUrl
            }
          });
        }
      });
    }
  })