// pages/signReview/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    str:'&emsp;',
    loginStatus: wx.getStorageSync('loginStatus') ? wx.getStorageSync('loginStatus') : false,
    roleCodeList: wx.getStorageSync('roleCodeList') ? wx.getStorageSync('roleCodeList') : '',
    searchVal: '',
    //分页
    limit: 10,
    requestStatu: '加载中...',
    page: 1,
    totalPages: 1,
    more: false,
    nomore: '',

    resData:[],

    show: false,
    auditFlag:'false',
    auditReason:'',//审核备注
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const roleCodeList = wx.getStorageSync('roleCodeList')
    let loginStatus = wx.getStorageSync('loginStatus')
    this.setData({
      searchVal: '',
      roleCodeList: roleCodeList ? roleCodeList : '',
      loginStatus: loginStatus ? loginStatus : false
    })
    //动态tabbar
    // if (roleCodeList == 'bizAdmin') {
    //   this.getTabBar().setData({
    //     list: app.globalData.allList[0].list2,
    //   })
    // } else if(roleCodeList == 'send') {
    //   this.getTabBar().setData({
    //     list: app.globalData.allList[0].list3,
    //   })
    // } else if(roleCodeList == 'sale') {
    //   this.getTabBar().setData({
    //     list: app.globalData.allList[0].list4,
    //   })
    // }else if(roleCodeList == 'customer') {
    //   this.getTabBar().setData({
    //     list: app.globalData.allList[0].list5,
    //   })
    // } else if (roleCodeList=='driver'||roleCodeList==''){
    //   this.getTabBar().setData({
    //     list: app.globalData.allList[0].list1,
    //   })
    // }
    // if (typeof this.getTabBar === 'function' && this.getTabBar()) {
    //   this.getTabBar().setData({
    //     selected: 1
    //   })
    // }
    
    if(wx.getStorageSync('loginStatus')){
      this.getListFun();
    }
  },

  //搜索框请求S
  onChange(e) {
    this.setData({
      searchVal: e.detail,
    });
  },
  onSearch: function (event) {
    this.setData({
      searchVal: event.detail
    })
    this.getListFun();
  },
  onCancel: function () {
    this.setData({})
  },
  toSearch: function (event) {
    this.getListFun();
  },
  //搜索框请求E

  //列表
  getListFun: function () {
    this.setData({
      page: 1
    })
    let params = {
      current: this.data.page,
      size: this.data.limit,
      signFlag:'1',
      licensePlate:this.data.searchVal
    }
    app.request.pageFirst({
      url: app.API.sendGoodsList,
      page: this,
      params: params,
    })
  },

  //页面跳转
  toLink: function (e) {
    let { url } = e.currentTarget.dataset
    wx.navigateTo({
      url: url
    })
  },

  // 审核S
  showPopup(e) {
    let { id } = e.currentTarget.dataset
    this.setData({
      show: true,
      auditReason: '',
      id: id
    });
  },
  onClose() {
    this.setData({
      show: false,
      auditFlag:'false',
      auditReason:'',
      id: ''
    });
  },
  // 单选
  dangerStatusChange: function (e) {
    this.setData({
      [e.currentTarget.dataset.radiotype]: e.detail.value
    })
  },
  //审核
  formSubmit: function (e) {
    let formData = e.detail.value;
    var warn = ""; //弹框时提示的内容
    if (formData.auditFlag == '') {
      warn = "选择审核结果！";
    } else if (formData.auditFlag == 'false' && formData.auditReason == '') {
      warn = "审核不通过时备注不能为空！";
    }
    formData.auditFlag = formData.auditFlag=='true'
    if (warn != '') {
      app.util.checkForm(warn);
    } else {
      app.request.POST({
        url: app.API.auditRecord,
        params: formData,
        page: this,
        isLoadingTxt: '审核中...',
        successFun: true
      }).then(res => {
        wx.showToast({
          title: '审核成功',
          icon: 'success',
          duration: 1000,
          mask: true
        })
        this.onClose()
        this.getListFun(); //刷新列表
      })
    }
  },
  // 审核E

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

  },

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

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({
      searchVal: ''
    })
    if (wx.getStorageSync('loginStatus')) {
      this.getListFun();
    } else {
      wx.stopPullDownRefresh();
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.data.page++;
    let params = {
      current: this.data.page,
      size: this.data.limit,
      signFlag:'1',
      licensePlate:this.data.searchVal
    }
    app.request.pageOther({
      url: app.API.sendGoodsList,
      page: this,
      params: params,
      loadType: true //加载类型，是否是下拉加载
    });
  },

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

  }
})