// pages/Highlight-photos/index.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        //人员信息页面
        show: false,
        //页面跳转参数
        loginName:'',
        userName:'',
        projectId:'',
        projectName:'' ,
        initData:{},
        loadShow:false,
        //记录列表
        recordList:[],
        //查看图片
        picShow:false,
        imageUrl:''

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that = this
        //获取项目缓存数据
        wx.getStorage({
            key: 'userinfo',
            success:function(res){
            that.setData({
                loginName:res.data.loginName,
                userName:res.data.userName,
                projectId:app.globalData.projectId,
                projectName:app.globalData.projectName,
                initData:{text:app.globalData.projectName,id:app.globalData.projectId}
            })  
            }
        })
        that.getProjectCorrespondence(app.globalData.projectId)
    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    },
     /**
      * 返回到更多功能页面
      */
    goBeforPage: function () {
        wx.redirectTo({
            url: '../newAddPage/safetyManagement/index'
        })
    },
    showPopup() {
        this.setData({
            show: true,
        });

    },
    onClose() {
        this.setData({
            show: false
        });
    },
     //项目切换 返回值
    onProjectSelect(e) {
        var that = this;
        this.onClickShow();
        let projectId = e.detail.id;
        let projectName = e.detail.text;
        app.globalData.projectId = projectId;
        app.globalData.projectName = projectName;
        that.setData({
            projectId: projectId,
            projectName: projectName
        })
        this.onLoad()
    },


    /**
   * 项目对应关系
   */
  getProjectCorrespondence(projectId) {
    var that = this;
    wx.request({
      url: app.globalData.reqUrl + '/weixin/training/getProjectCorrespondence',
      data: {
        "projectId": projectId,
      },
      method: "get",
      success: function (res) {
        console.log(res.data);
        that.setData({
          projectData: res.data,
          projectId:res.data.szh
        })
        that.getURLList()
      }
    })
  },
    /**
     * 
     */
    getURLList() {
        var that = this
        wx.request({
          url: app.globalData.szhUrl+'/api/wei/getHighlightPhotos',
          data:{
              projectId:that.data.projectId
          },
          method:"POST",
          header: {
            'content-type': 'application/x-www-form-urlencoded' //修改此处即可
          },
          success:(res)=>{
                if(res.data.code == 0) {
                    that.setData({
                        recordList:res.data.data
                    })
                } else {
                    that.setData({
                        recordList:[]
                    })
                }
          }

        })
    },
    showPic(e) {
      this.setData({
          picShow:true,
          imageUrl:e.currentTarget.dataset.id
      })
    },
    closePic() {
        this.setData({
            picShow:false,
            imageUrl:''
        
        })
    }

})