// pages/detailInfo/detailinfo.js
import http from '../../utils/http'
import util from '../../utils/util'
import api from '../../utils/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    min_date: "",
    max_date: "",
    date: 0,
    all: 0,
    selectIndex: 2,
    list: [{
        name: "全部",
        value: 2
      },
      {
        name: "已解决",
        value: 1
      },
      {
        name: "未解决",
        value: 0
      }
    ],
    years: [],
    project_id: "",
    project_list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.getDateInfo()
    this.setData({
      project_id: options.id - 0
    })
  },

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

  },
  // getDateInfo() {
  //   var that = this
  //   http({
  //     url: 'data/getDateInfo',
  //     data: {},
  //     success: function (res) {
  //       if (res.code == 0) {
  //         that.setData(res.data)
  //       }
  //     }
  //   })
  // },
  detailDatainfo(e) {
    let date = this.data.project_list[e.currentTarget.dataset.index].date
    let dates = this.data.project_list[e.currentTarget.dataset.index].dates
    let order_sn = this.data.project_list[e.currentTarget.dataset.index].order_sn
    wx.navigateTo({
      url: '../detailInfo/detailData?id=' + this.data.project_id + '&date=' + date + '&dates=' + dates + '&order_sn=' + order_sn,
    })
  },
  onstatusChange(e) {
    this.setData({
      all: e.detail.value,
      selectIndex: this.data.list[e.detail.value].value,
      project_list: []
    })
    this.getMonthData()
  },
  onChange(e) {
    this.setData({
      date: e.detail.value,
      project_list: []
    })
    this.getMonthData()
  },
  getMonthData() {
    http({
      url: 'orders/getOrderview',
      data: {
        year: this.data.years[this.data.date],
        status: this.data.selectIndex,
        project_id: this.data.project_id
      },
      success: (res) => {
        if (res.code == 0) {
          this.setData({
            project_list: res.data
          })
        }
      }
    })
  },
  getYears() {
    http({
      url: 'orders/getYears',
      data: {},
      success: (res) => {
        if (res.code == 0) {
          this.setData({
            years: res.data
          })
          this.getMonthData()
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getYears()
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})