// packageI/donation_project/donation_project_index/donation_project_index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    latest_list: [],
    picture_list: [],
    video_list: [],

    pic_src_list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  getData(){
    let urlStr = app.getNetAddresss("plugin.present-project.frontend.project.index");
    app._getNetWork({
      url: urlStr,
      data: {},
      success: (resdata) => {
        var res = resdata.data;
        if (res.result != 1) return app.tips(res.msg);
        
        let picture_list = [],
          video_list = [],
          pic_src_list = [];
        res.data.project_img_list.forEach(element => {
          if (picture_list.length == 10) return;
          element.change_img.forEach(item => {
            if (picture_list.length == 10) return;
            let o = { name: element.title, url: item };
            picture_list.push(o);
            pic_src_list.push(item);
          });
        });
        res.data.project_video_list.forEach(element => {
          if (video_list.length == 10) return;
          element.change_video.forEach(item => {
            if (video_list.length == 10) return;
            let o = { name: element.title, url: item };
            video_list.push(o);
          });
        });

        this.setData({
          latest_list:res.data.latest_list,
          picture_list,video_list,pic_src_list
        });

      }
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  gotoPage(evt){
    let name = evt.currentTarget.dataset.name;
    let url = `/packageI/donation_project/${name}/${name}`;
    wx.navigateTo({url});
  },
  getDetails(evt){
    let id = evt.currentTarget.dataset.id;
    let url = `/packageI/donation_project/donationProjectDetails/donationProjectDetails?id=${id}`;
    wx.navigateTo({url});
  },
  handImagePreview(evt){
    let src = evt.currentTarget.dataset.src;
    wx.previewImage({
      urls:[src]
    });
  },
  handPictureImagePreview(evt){
    let src = evt.currentTarget.dataset.src;
    console.log(src);
    wx.previewImage({
      urls:this.data.pic_src_list,
      current:src
    });
  }
});