const app = getApp();
Page({

  data: {
    information: '',   //个人信息
    optioninfo: '',    //择偶信息
    adopticon: '',  //认证信息
    geifabulous:'',  //获取点赞
    Fabulous:'',  // 点赞
    optionsuid: '', //用户uid
    collection: '',  //收藏
    options_img: '',  //头像
    uploadImages:[], //相册放大图集
    albumimg:'', // 相册
    albumimgurl: '',// 相册url
    watermark: '',
    to_id:'',
  },



  onLoad: function (options) {
    var that = this;

 

    app.postRequest('my/images/headurl', {}, function (res) {
      if (res.code == 201) {
        that.myheadurl = res.data.img
        // console.log(res);
        // that.setData({
        //   myheadurl: res.data.img,
        //   // optioninfocode: res,
        // })
      }
    })

    that.to_id = options.uid;
    that.setData({
      options_img: options.img,  //头像
      to_id: options.uid
    })

    // 同步传参
    try {
      wx.setStorageSync('optionsuid', options.uid)
    } catch (e) {

    }

    var _optionsuid = wx.getStorageSync('optionsuid');
    // console.log(_optionsuid)
    that.setData({
      optionsuid: _optionsuid
    })
 


    //    个人相册
    let albumimg_url = 'circle/frienddetails/albumimg';
    let albumimg_data = {
      uid: _optionsuid,
    };
    app.postRequest(albumimg_url, albumimg_data, function (res) {
      // console.log(res.data.url);
      console.log(res.data.data);
      if (res.code == 201) {



        //  对象转数组
        var itemList = res.data.data;
        //声明一个空的数组
        var items = [];
        //遍历数据
        for (let i in itemList) {
          //push到空数组里
          items.push(res.data.url + itemList[i].img + res.data.watermark);
        }
        console.log(items);
        that.setData({
          uploadImages: items,
          albumimg: res.data.data,
          albumimgurl: res.data.url,
          watermark: res.data.watermark,
        })
      }
    })


    //  个人信息
    let information_url = 'circle/frienddetails/details';
    let information_data = {
      uid: this.data.optionsuid,
    };
    app.postRequest(information_url, information_data, function (res) {
      if (res.code == 201) {
        // console.log(res.data);
        that.setData({
          information: res.data
        })
      }
    })


    //  择偶信息
    let optioninfo_url = 'circle/frienddetails/optiondetails';
    let optioninfo_data = {
      uid: this.data.optionsuid,
    };
    app.postRequest(optioninfo_url, optioninfo_data, function (res) {
      // console.log(res.data);
      if (res.code == 201) {

        that.setData({
          optioninfo: res.data,
          optioninfocode: res,
        })
      }
    })


    //  认证信息
    let adopticon_url = 'circle/frienddetails/authdetails';
    let adopticon_data = {
      uid: this.data.optionsuid,
    };
    app.postRequest(adopticon_url, adopticon_data, function (res) {
      // console.log(res.data);
      // console.log(res);
      if (res.code == 201) {
        that.setData({
          adopticon: res.data,
          adopticoncode: res,
        })
      }
    })


    //  获取点赞
    let appreciate_url = 'circle/adore/appreciate';
    let appreciate_data = {
      uuid: this.data.optionsuid,
    };
    app.postRequest(appreciate_url, appreciate_data, function (res) {
      // console.log(res.data);
      
      if (res.code == 201) {

        that.setData({
          geifabulous: res.data,
          // optioninfocode: res,
        })
      }else{
        that.setData({
          geifabulous: res.data,
          // optioninfocode: res,
        })
      }
    })



    //  获取收藏
    let collection_url = 'circle/adore/collection';
    let collection_data = {
      uuid: this.data.optionsuid,
    };
    app.postRequest(collection_url, collection_data, function (res) {
      // console.log(res.data);

      if (res.code == 201) {

        that.setData({
          collection: res.data,
          // optioninfocode: res,
        })
      } else {
        that.setData({
          collection: res.data,
          // optioninfocode: res,
        })
      }
    })


  },


// 相册点击放大
  enlarge: function (e) {
    var that = this;
console.log(that.data.uploadImages)
    wx.previewImage({
      urls: that.data.uploadImages ,
      current: e.currentTarget.dataset.src
    })

  },




  fabulousclick: function(e){
    var that = this ;
    //  点赞
    let appreciateform_url = 'circle/adore/appreciateform';
    let appreciateform_data = {
      uuid: this.data.optionsuid,
    };
    app.postRequest(appreciateform_url, appreciateform_data, function (res) {
              if (res.code == 201) {

                that.setData({
                  geifabulous: res.data,
                  // optioninfocode: res,
                })
              } else {
                that.setData({
                  geifabulous: res.data,
                  // optioninfocode: res,
                })
              }  
    })

  },

  collectionformclick: function (e) {
    var that = this;
    //  点赞
    let collectionform_url = 'circle/adore/collectionform';
    let collectionform_data = {
      uuid: this.data.optionsuid,
    };
    app.postRequest(collectionform_url, collectionform_data, function (res) {
      if (res.code == 201) {
        that.setData({
          collection: res.data,
          // optioninfocode: res,
        })
      } else {
        that.setData({
          collection: res.data,
          // optioninfocode: res,
        })
      }
    })

  },
  toChat(e) { //跳转进入聊天页面
  let that = this;

    app.postRequest('circle/dialogue/validate', {to_id:that.data.to_id}, function (res) {
        // console.log(res);

        // return ;
      if (res.code == 201) {

        wx.navigateTo({
          url: '../information/chat/chat?to_id=' + that.data.to_id + '&headUrl=' + that.data.options_img + '&myheadurl=' + res.data.myHeadImg
        });

        // wx.navigateTo({
        //   url: '../chat/chat?to_id=' +  + '&myheadurl=' + that.myheadurl + '&headUrl=' + that.data.options_img
        // });
       return;
      } 

      if (res.data.location == 'shiming') {
    
            wx.showModal({
              title: '实名认证',
              content: res.msg,
              success(res) {
                if (res.confirm) {
                    // console.log('用户点击确定');
                      wx.navigateTo({
                        url: '/pages/personal_core/home_list/home_list'
                      });
                } else if (res.cancel) {
                  // console.log('用户点击取消')
                }
              }
            })
        return;
      }

      if (res.data.location == 'huiyuan') {
        wx.showModal({
          title: '开通会员',
          content: res.msg,
          success(res) {
            if (res.confirm) {
              // console.log('用户点击确定');
              wx.navigateTo({
                url: '/pages/payment/Member/Member'
              });
            } else if (res.cancel) {
              // console.log('用户点击取消')
            }
          }
        })
        return;
      }

      // if (res.data.location == shiming) {
      //   wx.navigateTo({
      //     url: '../chat/chat?to_id=' + that.to_id + '&myheadurl=' + that.myheadurl + '&headUrl=' + that.data.options_img
      //   });
      // }


      app.Tips(res.msg);

    })

  }



})



