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

  /**
   * 页面的初始数据
   */
  data: {
    isIPX: app.globalData.isIPX,
    active:"",
    pageTitle:"",
    // 待办列表
    todoList:[],
    // 已办列表
    doneList:[],
    // 已发起
    yfqList:[],
    // 已制单
    yzdList:[],
    //待办数量
    todoNum:0,
    //已办数量
    doneNum:0,
    //已发起数量
    yfqNum:0,
    //已制单数量
    yzdNum:0,
    index:0,
    array:["未提交","待审核","已审核","已挂起"],
    //字典
    transferType:[
      {"dictVale":1,"dictLabel":"村账户转账"},
      {"dictVale":2,"dictLabel":"公务卡转账"},
      {"dictVale":3,"dictLabel":"虚拟挂账"},
      {"dictVale":4,"dictLabel":"代管账户转账"},
      {"dictVale":5,"dictLabel":"母子转账"},
      {"dictVale":10,"dictLabel":"现金提现"},
      {"dictVale":11,"dictLabel":"现金使用"},
      {"dictVale":12,"dictLabel":"汇票支出"}
  ],
  userInfoObj:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({active:options.active})
    if(options.active==1||options.active==2){
      this.setData({pageTitle:"待办/已办"})
    }else{
      this.setData({pageTitle:"发起/制单"})
    }
    //获取用户信息
    this.getUserInfo()
    
  },
  /* 获取用户信息*/
  getUserInfo(){
    UTIL.httpRequest(API.URL_GET_GETINFO, {method:'GET'}, {
      success: (res) => {
        if (res.code == API.SUCCESS_CODE) {
          this.setData({userInfoObj:res.user})
          this.setData({region:res.user.deptName})
          this.setData({item:JSON.stringify(res.user)})
          //查询待办
          this.getTaskList();
          //查询已办
          this.getTaskDoneList();
          //查询已发起
          this.getTransferList();
          //查询已制单
          this.getTransferList2();
        }
      }
    })
  },
  bindPickerChange:function(e){zhibob
    this.setData({index:e.detail.value});
  },
  switchTab:function(e){
    this.setData({
      active:e.currentTarget.dataset.gid
    })
},

  dictTranslate(d,value){
    let val = ""
    for(var index in d){
        if(d[index].dictVale==value){
          return val = d[index].dictLabel
        }
    } 
},
  getTaskList:function(e){
    let data = {
      pageNum:1,
      pageSize:10,
      orderByColumn:"A.ID_",
      isAsc:"desc",
      systemType:4,
      method:"GET",
      taskName:'相关人员审批'
    }
    UTIL.httpRequest(API.URL_GET_TASKLIST,data, {
      success: (res) => {
        if (res.code == API.SUCCESS_CODE) {
          this.setData({todoNum:res.total})
          if(res.rows!=null&&res.rows!=""){
            for(let i = 0;i<res.total;i++){
              let d = this.dictTranslate(this.data.transferType,res.rows[i].formData.transferType)
              res.rows[i].formData.transferType =  d
            }
            this.setData({todoList:res.rows})
          }
        }
      },	fail: (res) => {
        console.log(res);
      },
      complete: (res) => {
      }
    })
  },
  getTaskDoneList:function(e){
    let data = {
      pageNum:1,
      pageSize:10,
      orderByColumn:"A.ID_",
      isAsc:"desc",
      systemType:4,
      method:"GET",
      taskName:'相关人员审批'
    }
    UTIL.httpRequest(API.URL_GET_TASKDONELIST,data, {
      success: (res) => {
        if (res.code == API.SUCCESS_CODE) {
          this.setData({doneNum:res.total})
          if(res.rows!=null&&res.rows!=""){
            for(var index in res.rows){
              let d = this.dictTranslate(this.data.transferType,res.rows[index].formData.transferType)
              res.rows[index].formData.transferType =  d
          } 
            this.setData({doneList:res.rows})
          }
        }
      },	fail: (res) => {
        console.log(res);
      },
      complete: (res) => {
      }
    })
  },
  getTransferList:function(e){
    let data = {
      // pageNum:1,
      // pageSize:10,
      transferType:"1",
      status:"5",
      method:"GET",
      applyUserName:this.data.userInfoObj.nickName
    }
    UTIL.httpRequest(API.URL_GET_TRANSFERLIST,data, {
      success: (res) => {
        console.log(res);
        if (res.code == API.SUCCESS_CODE) {
          let a = this.data.yfqNum+res.total
          this.setData({yfqNum:a})
          let b = this.data.yfqList
          this.setData({yfqList:res.rows.concat(b)})
        }
      },	fail: (res) => {
      },
      complete: (res) => {
      }
    })
  },
  getTransferList1:function(e){
    let data = {
      // pageNum:1,
      // pageSize:10,
      transferType:"1",
      auditStatus:"3",
      method:"GET"
    }
    UTIL.httpRequest(API.URL_GET_TRANSFERLIST,data, {
      success: (res) => {
        console.log(res);
        if (res.code == API.SUCCESS_CODE) {
          let a = this.data.yfqNum+res.total
          this.setData({yfqNum:a})
          let b = this.data.yfqList
          this.setData({yfqList:res.rows.concat(b)})
        }
      },	fail: (res) => {
      },
      complete: (res) => {
      }
    })
  },
  getTransferList1:function(e){
    let data = {
      // pageNum:1,
      // pageSize:10,
      transferType:"1",
      auditStatus:"3",
      method:"GET"
    }
    UTIL.httpRequest(API.URL_GET_TRANSFERLIST,data, {
      success: (res) => {
        if (res.code == API.SUCCESS_CODE) {
          console.log();
          let a = this.data.yfqNum+res.total
          this.setData({yfqNum:a})
          this.setData({yfqList:res.rows})
        }
      },	fail: (res) => {
        console.log(res);
      },
      complete: (res) => {
        console.log(res);
      }
    })
  },
  //已制单
  getTransferList2:function(e){
    console.log(this.data.userInfoObj)
    let data = {
      // pageNum:1,
      // pageSize:10,
      transferType:"1",
      status:"0",
      method:"GET",
      submitter:this.data.userInfoObj.nickName
    }
    UTIL.httpRequest(API.URL_GET_TRANSFERLIST,data, {
      success: (res) => {
        if (res.code == API.SUCCESS_CODE) {
          this.setData({yzdNum:res.total})
          this.setData({yzdList:res.rows})
        }
      },	fail: (res) => {
        console.log(res);
      },
      complete: (res) => {
        console.log(res);
      }
    })
  },
  back:function(){
    wx.navigateBack({
      delta: 1
    })
  },
  godetail:function(e){
    wx.navigateTo({
      url: '/pages/apply/paymentTemplate/add/add?id='+e.currentTarget.dataset.id,
    })
  },
  gosee:function(e){
    wx.navigateTo({
      url: '/pages/handle/expenditureAudit/expenditureAudit?id='+e.currentTarget.dataset.id+'&taskId='+e.currentTarget.dataset.taskid+'&type='+e.currentTarget.dataset.type,
    })
  },
  goUpdate(e){
    wx.navigateTo({
      url: '/pages/apply/paymentTemplate/add/add?id='+e.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})