const api = require('../../api/index.js');
Page({

  data: {
    visible:false,
    tabsindex:"1,2",
    workorderName:'',
    datestart:'',
    dateend:'',
    array:['日常','故障','其他'],
    priority:'',
    index:'',
    reviewdata:[],
    examineType:0
  },
  onLoad() {
  },
  // 选项卡
  onTabsChange(e){
  console.log(e.detail.value);
  this.setData({
    tabsindex:e.detail.value
  })
  this.gitreview()
  },
  // 输入工单名称
  onPeakprice(e){
console.log(e.detail.value);
this.setData({
  workorderName:e.detail.value
})
  },
    // 事件
    bindeventChange(e){
      console.log(e.detail.value);
      this.setData({
        index:e.detail.value
      })
        },
  // 开始事件
  bindstartChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      datestart: e.detail.value
    })
  },
  // 结束时间
  bindendChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      dateend: e.detail.value
    })
  },
    // 工单优先级
    onradio(e){
      console.log(e.detail.value); 
      this.setData({
        priority:e.detail.value
      })
        },
          // 工单审核状态
          onexamineType(e){
      console.log(e.detail.value); 
      this.setData({
        examineType:e.detail.value
      })
        },
        
        onworkorder(){
         this.setData({
          visible:false
         })
        this.gitreview()
        },
        onreset(){
          this.setData({
            workorderName:'',
            tabsindex:"1,2",
            datestart:'',
            dateend:'',
            index:'',
            priority:'',
            examineType:0
          })
          this.gitreview()

        },
  gitreview(){
    
    let data = {
      workorderName:this.data.workorderName,
      workorderType:this.data.tabsindex==0?'':this.data.tabsindex,
      workorderAddress:'',
      starttime:this.data.datestart,
      endtime:this.data.dateend,
      type:this.data.index==''?'':this.data.index*1+1,
      examineType:this.data.examineType==0?'':this.data.examineType
    }
  
    api.request(`/workoder/selectworkoder`, 'POST',data)
    .then((res) => {
  if (res.data) {
    this.setData({
      reviewdata:res.data
    })
  }else{
    this.setData({
      reviewdata:[]
    })
  }
    })
    .catch((err) => {
      console.error('请求失败：', err);
    
      // 在这里处理请求失败的情况
    });
  },
  onfilter(){
    this.setData({
      visible:true
    })
  },
  onVisibleChange(){
    this.setData({
      visible:false
    })
  },
  ondetails(e){
    console.log(e.currentTarget.dataset);
wx.navigateTo({
  url: `/pages/workorderdetails/index?id=${e.currentTarget.dataset.id}&workorderId=${e.currentTarget.dataset.workorderid}`,
})
  },
  onShow() {
    // this.setData({
    //   workorderName:'',
    //   tabsindex:"1,2",
    //   datestart:'',
    //   dateend:'',
    //   index:''
    // })
    this.gitreview()

  },
   /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  async onPullDownRefresh() {
   await this.gitreview()
   await wx.stopPullDownRefresh();

  }
});
