const util = require('../../../utils/util.js');
const app = getApp();
Page({
  data: {
    datas:[],
    friendDatas:[]
  },
  onLoad(options) {
    if(options.aid && options.groupid){//团内同行伙伴
      wx.setNavigationBarTitle({
        title: '拼团成员列表'
      })
      this.groupFriend(options.aid,options.groupid)
    }else{//全部同行伙伴
      this.getData(options.aid)
    }
    
  },
  getData(aid){
    let that = this;
    util.ajax({
      func:"v2/article/partners",
      data:{"aid":aid}
    },function(res){
      if(res.code == 0){
        let datas = res.data;
        for(let i in datas){
          let users = datas[i].users
          for(let l in users){
            if(users[l].avatar == ''){
              users[l].avatar = '/images/default_logo.jpg';
            }
          }
        }
        that.setData({datas});
      }
    });
  },
  groupFriend(aid,groupid){
    let that = this;
    util.ajax({
      func:"article/groupusers",
      data: { "aid": aid, "groupid":groupid || ""}
    },function(res){
      if(res.code == 0){
        let friendDatas = res.data;
        for(let i in friendDatas){
          if(!friendDatas[i].avatar){
            friendDatas[i].avatar = util.config.imgUrl+'img/default_logo.jpg';
          }
          if(!friendDatas[i].nickname){
            friendDatas[i].nickname = '无名宝贝'
          }
        }
        that.setData({friendDatas});
      }
    })
  }
})