123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- // pages/ucenter/car/bindCar.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- carNum: '',
- carId: '',
- updateFlag: false,
- isDef: false,
- },
- inputPlateNumber(e){
- console.info(e.detail.value)
- console.info(e)
- this.setData({
- carNum: e.detail.value
- });
- },
- saveCarNum(){
- let carNum = this.data.carNum;
- if (!this.checkCarNum(carNum)) {
- wx.showModal({
- title: '提示',
- showCancel:false,
- content: '车牌号输入有误,请重新输入',
- confirmColor:'#00AADD',
- });
- return;
- } else {
- this.setData({
- carNum: carNum,
- errorMsg: ''
- });
- }
- this.bindUpdateCarNum(carNum);
- },
- checkCarNum(carNum){
- if (carNum){
- // if (!(/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/.test(this.data.carNum))) {
- // if (!/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领].*$/.test(carNum)) {
- // return false;
- // }
- if(carNum.length<1 || carNum.length>10){
- return false;
- }
- }else{
- return false;
- }
- return true;
- },
- bindUpdateCarNum(carNum) {
- let that = this;
- let userInfo = wx.getStorageSync('userInfo');
- // loginName: userInfo.loginName
-
- // 判断是更新车牌还是新增车牌
- console.info(this.data.updateFlag)
- if(this.data.updateFlag){
- console.info("更新车牌号:" + carNum + ",用户:" + userInfo.loginName + ",车牌号:" + this.data.carNum )
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carAlter?loginName=' + userInfo.loginName,
- data: {
- carId: that.data.carId,
- plateNumber: carNum,
- defaultType: that.data.isDef?"1":"0"
- },
- method: 'POST',
- success: function (res) {
- console.info(res)
- wx.navigateBack({
- delta: 1
- });
- },
- fail(e) {
- console.log("更新车牌号失败");
- log.info('[更新车牌号]','[fail]', e);
- }
- });
- }else{
- console.info("新增车牌号:" + carNum + ",用户:" + userInfo.loginName + "")
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/saveCar?loginName=' + userInfo.loginName + '&plateNumber=' + carNum + '&defaultType=' + (that.data.isDef?"1":"0"),
- // data: {
- // defaultType: 1,
- // carId: idx.carId,
- // plateNumber: idx.plateNumber
- // },
- method: 'POST',
- success: function (res) {
- console.info(res)
- wx.navigateBack({
- delta: 1
- });
- },
- fail(e) {
- console.log("新增车牌号失败",e);
- //log.info('[新增车牌号]','[fail]', e);
- }
- });
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- let {carId,plateNumber,defaultType} = options;
- let updateFlag = false;
- if(carId){
- updateFlag = true;
- }else{
- if(carId==0){
- updateFlag = true
- }else{
- updateFlag = false
- }
- }
- console.info(updateFlag?'更新模式':'新增模式')
- console.info(plateNumber)
- this.setData({
- carId,
- updateFlag,
- carNum:plateNumber,
- isDef:defaultType==1
- })
- },
- radioChange: function(e) {
- let that = this;
- this.setData({
- isDef:!that.data.isDef
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|