const app = getApp();
var baseUrl = app.globalData.baseUrl;
var network = require("../../utils/net.js");
var timechage = require("../../utils/dateTimeUtil.js");
var ID = 0;
var ID1;
var LoadTime1;
var Number;
var SecondNumber;
var Phone;
var ID4;

Page({
  data: {
    name1: [],
    countsArraydrug: [],
    index: null,
    btnnum: 1
  },

  phoneNum: function(e) {
    Phone = e.detail.value
    var that = this;
    var method2 = '/MainSystem/B3MiniProgramRpc/Rpcs/BaseInfoRpc/GetDriver';
    var params2 = [{
      "InputValue": Phone,
      "PageIndex": 0,
      "PageSize": 100
    }];

    network.transfer_request(method2, params2, function(res) {
      that.setData({
        name1: res.result,
      })
    })
  },

  onLoad: function(options) {
    var that = this;
    ID = parseInt(options.ID);
    var num = this.data.btnnum;
    this.setData({
      btnnum: num,
      obj: {
        1: {
          "yaopin": "请选择司机",
          num: num,
          countsArraydrug: [],
        }
      },
    })
  
    var method1 = '/MainSystem/B3MiniProgramRpc/XuRpcs/Customer/OrderRpc/LoadForDriver';
    var params1 = [ID];

    network.transfer_request(method1, params1, function(res) {
      that.setData({
        ID1: res.result.ID,
        LoadTime1: timechage.formatTimeTwo(res.result.LoadTime.substring(6, 19), "Y/M/D"),

        Number: res.result.Number,
        SecondNumber: res.result.SecondNumber,

      })
    })
  },

  powerDrawer1: function(e) {
    var that = this;
    var method2 = '/MainSystem/B3MiniProgramRpc/Rpcs/BaseInfoRpc/GetDriver';
    var params2 = [{
      "InputValue": Phone,
      "PageIndex": 0,
      "PageSize": 100
    }];

    network.transfer_request(method2, params2, function(res) {
      //res就是我们请求接口返回的数据
      that.setData({
        name1: res.result,

        countsArraydrug: res.result,
        obj: {
          1: {
            "yaopin": "请选择司机",
          }
        }

      })
    })
    var currentStatu = e.currentTarget.dataset.statu;
    var i = e.currentTarget.dataset.index;
    this.util(currentStatu)
    this.setData({
      thatIndex: i
    })
  },

  a: function(event) {
    var ID3;
    var that = this;
    var index = event.currentTarget.dataset.index

    let indexNum = this.data.thatIndex;
    let obj = this.data.obj;
    ID3 = that.data.name1[index].ID
    ID4 = ID3;
    obj[indexNum] = {

      "yaopin": that.data.name1[index].Name,
      
      indexNum: indexNum,

    }

    that.setData({
      obj: obj,
      showModalStatus: false,
    })
  
  },


  paiche: function(event) {
    var that = this;
  that.setData({
    ID4:ID4,
  })
    if (ID4 == null) {
      wx.showModal({
        title: '提示',
        content: '不能为空',
      })
    } else {
      var method = '/MainSystem/B3MiniProgramRpc/XuRpcs/Customer/OrderRpc/SetDriverToOrder';
      var params = [ID, ID4];
      network.transfer_request(method, params, function(res) {
        if (ID4 != null) {
          wx.navigateBack({
            delta: "/pages/theDriverSend/theDriverSend"
          })
        }
      })
    }
  },

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

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    var that = this
    var ID5=ID;
    return {
      title: '',
      path: "/pages/fenxiang/fenxiang?ID=" + ID5,
      //分享成功后执行
      success: function(res) {
        wx.showModal({
          showCancel : false,
          title: '转发成功',
        })
      },
      fail: function(res) {
      }
    }
  },

  powerDrawer: function(e) {
    var currentStatu = e.currentTarget.dataset.statu;
    this.util(currentStatu)
  },
  util: function(currentStatu) {
    /* 动画部分 */
    // 第1步：创建动画实例   
    var animation = wx.createAnimation({
      duration: 200, //动画时长  
      timingFunction: "linear", //线性  
      delay: 0 //0则不延迟  
    });

    // 第2步：这个动画实例赋给当前的动画实例  
    this.animation = animation;

    // 第3步：执行第一组动画  
    animation.opacity(0).rotateX(-100).step();

    // 第4步：导出动画对象赋给数据对象储存  
    this.setData({
      animationData: animation.export()
    })

    // 第5步：设置定时器到指定时候后，执行第二组动画  
    setTimeout(function() {
      // 执行第二组动画  
      animation.opacity(1).rotateX(0).step();
      // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象  
      this.setData({
        animationData: animation
      })

      //关闭  
      if (currentStatu == "close") {
        this.setData({
          showModalStatus: false
        });
      }
    }.bind(this), 200)

    // 显示  
    if (currentStatu == "open") {
      this.setData({
        showModalStatus: true
      });
    }
  },


})