// pages/myCars/creatNewCar/creatNewCar.js
const app = getApp();
var network = require("../../../utils/net.js");
var insert = "/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/CarRpc/Insert";
var carNum = null;
var driverName = null;
var driverPhone = null;

Page({

  // 车牌号
  getCarNum: function(event) {
    carNum = event.detail.value;
  },

  // 司机姓名
  getDriverName: function(event) {
    driverName = event.detail.value;
  },

  // 司机电话
  getDriverPhoneNum: function(event) {
    driverPhone = event.detail.value;
  },

  // 确认按钮
  submitNewCarsInfo: function(event) {
    if (!carNum) {
      wx.showToast({
        title: '车牌号不能为空',
      })
      return false;
    }
    if (!driverName) {
      wx.showToast({
        title: '司机姓名不能为空',
      })
      return false;
    }
    if (driverPhone == "") {
      wx.showToast({
        title: '请输入手机号码',
      })
      return false;
    } else if (!(/^1[34578]\d{9}$/.test(driverPhone))){
      wx.showToast({
        title: '号码不正确',
      })
      return false;
    }

    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1]; //当前页面
    var prevPage = pages[pages.length - 2]; //上一个页面

    prevPage.setData({
      carNumber: carNum,
      driverName: driverName,
      driverPhone: driverPhone,
      isNewCar: true,
    });

    wx.showToast({
      title: '创建成功',
      success: function(res) {
        wx.navigateBack({
          delta: 1
        })
      }
    })


  },

})