// pages/project/project.js
import * as UTIL from '../../utils/util.js';
import * as API from '../../utils/API.js';
let EVN_CONFIG = require('../../env/env');

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isIPX: app.globalData.isIPX,
    name:"",
    value:'',
    pageNums:1,
    showUpload:false,
    uploadOptions:[],
    voteTypeOptions:[],
    fileList:[],
    itemId:"",
    itemIndex:"",
    list:[],
    fileEvent:{},
    projectList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var _this = this;
    let qu = wx.createSelectorQuery()
    qu.select("#top_view").boundingClientRect()
    qu.exec(res => {
      _this.setData({
        scrollHeight:wx.getSystemInfoSync().windowHeight-res[0].height-res[0].top
      })
    })
  },
  goDetail(e){
    console.log('aaaaaaaaa');
    wx.navigateTo({
      url: 'detail/detail?id='+e.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.onShow();
  },
   goSearch(e){
    this.setData({name:e.detail})
    this.onShow();
  },
  back:function(){
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var that = this;
    //获取附件字典
    UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'vote_status', {method:'GET'}, {
     success: (res) => {
       this.setData({
         voteStatusOptions:res.data,
       })
       UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'vote_type', {method:'GET'}, {
        success: (res) => {
          this.setData({
           voteTypeOptions:res.data,
          })
          let params= {
            itemName:this.data.name,
            method:'GET'
          }
          UTIL.httpRequest(API.URL_GET_VOTELIST, params,{
            success: (response) => {
              if (response.code == API.SUCCESS_CODE) {
                response.rows.map(rr=>{
                  rr.voteStatusText = UTIL.getTransform(rr.voteStatus,that.data.voteStatusOptions);
                  rr.voteTypeText = UTIL.getTransform(rr.voteType,that.data.voteTypeOptions);
                })
                that.setData({
                  projectList:response.rows
                })
              }
            }
          })
        }
       })
     }
   })
   
    
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

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

  },

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

  },

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

  },

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

  }
})