// pages/index/policy/list/list.js
import * as UTIL from '../../../utils/util.js';
import * as API from '../../../utils/API.js';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //自定义导航栏
    isIPX: app.globalData.isIPX,
    value:'',
    total:0,
    list:[],
    pageNums:1,
    title:'',
    entityName:'',
    option1: [
      { text: '专业合作社', value: 1 },
      { text: '家庭农场', value: 2 },
      { text: '龙头企业', value: 3 },
      { text: '农业庄园', value: 4 },
      { text: '专业大户', value: 5 }
    ],
    value1: 0,
    statisticsTypeId: 1
  },

  goDetail(e) {
    wx.navigateTo({
      url: '/pages/mainBody/detail/detail?id='+e.currentTarget.dataset.id,
    })
  },
  changeTab(e){
    var that = this ;
    console.log(e.detail);
    that.setData({statisticsTypeId:e.detail});
    this.getList();
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

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

  },

  /** 
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getList();
  },
  paging(){
    this.setData({
      pageNums:this.data.pageNums+1,
    })
    this.getList();
  },
  getList(){
    let data = {
      pageNum:this.data.pageNums,
      pageSize:10,
      translate_dict:true,
      entityName:this.data.entityName,
      statisticsTypeId:this.data.statisticsTypeId,
      method: 'GET'
    }
    UTIL.httpRequest(API.URL_GET_ENTITYLIST,data,{
      success: (res) => {
        if (res.code == API.SUCCESS_CODE) {
          let arr = this.data.list;
          if (arr.length>=res.total){return;}
          res.rows.map(rr=>{
            rr.releaseTime = rr.releaseTime == null?'':rr.releaseTime.substr(0,10);
            arr.push(rr)
          })
          this.setData({
            total:res.total,
            list:arr
          })
        }
      }
    })
  },
  goSearch(e){
    this.setData({
      pageNums:1,
      entityName:e.detail,
      list:[]
    })
    this.getList();
  },

  back:function(){
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

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

  },

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

  },

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

  },

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

  }
})