Applet vehicle to Library

wx5a0a5e76a9c09 2021-08-10 10:44:02 阅读数:918

本文一共[544]字,预计阅读时长:1分钟~
applet vehicle library

 

const { formatTime, isEmpty } = require('../../utils/util.js')

var {request} = require("../../utils/request.js")

const { validatePlateNum} = require('../../utils/validate.js')

const { uploadFile, getFileBase64 }  = require('../../utils/request.js')

const { newRequest } = require("../../utils/request") 

const {getListByScanCode,getCheckData,submitForm} = require("../../api/carWareApi.js") 

const {testData,testMsg}= require("../../pages/carWare/data.js")

const app = getApp()

Page({

  /**

   *  Initial data of the page

   */

  data: {

    dList:'',

    dTextArea_list:[],

    loading: false,

    items: [

      { name: 'leave', value: ' Leave the library ', checked: false },

      { name: 'reach', value: ' To the library ', checked: false } 

    ],  

    isShow:true,// Whether the submit button displays  true Show ,false No display

    carTel:'',

    dCode: '',// The entered dispatch order No

    showArrivalTimePicker: false,

    formData: {

      isArrival:'',//0 To the library ,1 Leave the library

      isRecord:'',//0 There is no record of arrival ,1 There are arrival records

      scanCode:'',// Scan code data

      wareName: '',// Warehouse name

      wareCode: '',// Warehouse number   

      arrivalTime: formatTime(new Date()),// Arrival time

      djType: '',// Registration type

      vehicleCode:'',// license plate number

      latitude:'',// dimension

      longitude:'',// longitude

      carTel:'',// Driver's phone

      fileList:[],// To upload pictures

    },

    formatter(type, value) {

      if (type === 'year') {

        return `${value} year `;

      } else if (type === 'month') {

        return `${value} month `;

      } else if (type === 'day') {

        return `${value} Japan `;

      } else if (type === 'hour') {

        return `${value} when `;

      } else if (type === 'minute') {

        return `${value} branch `;

      }

      return value;

    },

    validateMap: {

      vehicleCode: validatePlateNum

    },

    errMsgShow: {

      vehicleCode: false

    }

  },

  onReady() {  

    // Initialize the phone  

    let { formData,carTel,latitude,longitude } = this.data

    var phone= wx.getStorageSync('phone')

    if(phone==null||phone==''){

      request('/reserve/api/user/check/bind', { open_id: wx.getStorageSync('openId')}).then(res => {

        wx.hideLoading()

        app.globalData.refresh = false

        if(res.status==200&&res.msg=='success'){

          carTel=res.data.tel;

          formData.carTel = res.data.tel; 

          this.setData({formData})

          console.log(' obtain bind Current user's mobile phone >>>>>>>>>'+JSON.stringify(this.data.formData)); 

        } 

      }).catch(err => {

        console.log(' obtain err Current user's mobile phone >>>>>>>>>'+err);

        wx.hideLoading()

        wx.showToast({

          title: ' Server internal error , Please contact the Administrator ',

          icon: 'none',

          duration: 2000

        })

      })

    }else{

      wx.hideLoading()

      formData.carTel=phone; 

      this.setData({formData})

      console.log(' Get current getStorageSync User's mobile phone >>>>>>>>>'+JSON.stringify(this.data.formData)); 

    } 

  // Initialize latitude and longitude  

    wx.getLocation({

      type: 'wgs84',

      isHighAccuracy:true,// Improve accuracy

      success: function (res) { 

        latitude=res.latitude;

        longitude=res.longitude; 

        formData.latitude=latitude; 

        formData.longitude=longitude; 

      } 

    }) 

    // Select to keyboard component

    this.setData({

      formData,

      keyboard: this.selectComponent('#keyboard')

    });

    console.log(" Get the current latitude and longitude :" + JSON.stringify(formData));

  },

   

  showArrivalTimePicker() {

    this.setData({

      showArrivalTimePicker: true

    })

  },

  onCloseArrivalTimePicker() {

    this.setData({

      showArrivalTimePicker: false

    })

  },

  onConfirmArrivalTimePicker(e) {

    const { formData } = this.data

    formData.arrivalTime = formatTime(new Date(e.detail))

    this.setData({

      formData: formData,

      showArrivalTimePicker: false

    })

  },

  // Warehouse code scanning

  scanQRCode() {

    let that = this

    let { formData } = that.data

    wx.scanCode({

      onlyFromCamera: true,

      success: (res) => {

        console.log(res.result)

        formData.scanCode = res.result

        formData.wareName = res.result

        formData.wareCode = res.result

        that.setData({formData}) 

        this.scanCode()

      }

    }) 

  },

    // Code scanning of dispatching order

    scanQRCodeD() {

      let that = this

      let { formData,dCode,dList} = that.data

      wx.scanCode({

        onlyFromCamera: true,

        success: (res) => {

          dCode = res.result

          that.setData({

            dCode:res.result

          }) 

          this.dAdd()

          

        }

      })

    },

    // Enter the dispatch list

  dInput(e) {

    this.setData({

      dCode:e.detail.value

    })

  },

  // Check for repetition

  checkRepeat: function(arr,value) {

    for(var i=0;i<arr.length;i++){

      if(value===arr[i]){

        return false; 

        }

    } 

    return true;

  },

  // Additional

  dAdd: function(e) {

    let {dList,dTextArea_list} = this.data

    if(this.data.dCode != ''){

      // Prevent repeated appending   

      var isBH=this.checkRepeat(dTextArea_list,this.data.dCode) 

      console.log(isBH)

     // var isBH=dList.search(this.data.dCode)

      debugger

      // Prevent duplicate submissions

      if(isBH){

        dTextArea_list.push(this.data.dCode)

        this.setData({

          dCode:'',

          dList:dTextArea_list.join("\n")

        })

      }else{

        wx.showToast({

          title: ' The dispatch list already exists ',

          icon:'none'

        },2000) 

      }

    }else{

      wx.showToast({

        title: ' Please enter the dispatch order No ',

        icon:'none'

      },2000)

    }

  },

  // Delete

  dRemove: function(e) {

    let {dList,dTextArea_list} = this.data

    if(dTextArea_list.length != 0) {

      dTextArea_list.pop(this.data.dCode)

      this.setData({

        dList:dTextArea_list.join("\n")

      })

    }else{

      wx.showToast({

        title: ' There is no dispatch list to delete ',

        icon:'none'

      },2000)

    }

  },

   //radio

   radioChange: function(e) {

    let {formData} = this.data 

    formData.djType=e.detail.value;

    this.setData({formData})

  },

 

   // Display keyboard , At the same time, set the virtual input box to the active state

  showKeyboard () {

    this.data.keyboard.showKeyboard();

  },

  //  Hidden keyboard , At the same time, set the virtual input box to inactive

  hideKeyboard (e) {

    this.data.keyboard.hideKeyboard();

  },

  // Enter events with the keyboard :input, Get the input content into the virtual input box

  inputChange (e) {

    const { formData, validateMap, errMsgShow } = this.data

    formData.vehicleCode = e.detail

    if (validateMap.vehicleCode) {

      if (!!e.detail && !validateMap.vehicleCode(e.detail)) {

        errMsgShow.vehicleCode = true

      } else {

        errMsgShow.vehicleCode = false

      }

    }

    this.setData({

      errMsgShow,

      formData

    })

  },

  // Image upload -- Show

  afterRead(event) {

    wx.showLoading()

    const { file } = event.detail; 

   for(let i in file ){

    uploadFile(file[i].path,'/services/exit/api/minio/uploadFile').then(res=>{ 

     newRequest({

            url:`/exit/api/getFileBase64/${res.fileId}`

        }).then(res64=>{

            const{ fileList = [] } = this.data;

            debugger

            fileList.push({

                url:`data:image/${res.fileName.split('.').pop()};base64,` + res64.data,

                isImage:true,

                fileId:res.fileId,

                fileName:res.fileName,

            })

            this.setData({  fileList })

        })

       

    }).catch(err=>{

        wx.hideLoading()

        console.log('err',err)

        wx.showToast({

          title: ' Upload failed , Please try again ',

          icon:'none'

        },2000)

    })

   }  

 },

 // Delete pictures

 deleteImage(event) {

  const { index, name } = event.detail;

  const { fileList } = this.data

  if (name == "imageList") {

    fileList.splice(index, 1)

    this.setData({ fileList })

  }

},

// Scan code to obtain warehouse data

scanCode: function(e) {

  let {formData,isShow,items,dList,dCode,dTextArea_list,fileList } = this.data  

  getListByScanCode(formData).then(res => {

   var  res=testData 

    wx.hideLoading()

    if(res.code == 200) {

      //   isArrival:'',//0 To the library ( Inside the fence ),1 Leave the library ( Outside the fence ) isRecord:'',//0 There is no record of arrival ,1 There are arrival records

      // Outside the fence -- Prompt: unable to operate in the library

      if(res.data.isArrival=='1'){

        wx.showToast({

          title: ' Beyond the allowable distance , Unable to reach the vehicle ',

          icon: 'none',

        }, 1500) 

      }else{

        // Inside the fence -- Can go to the library to operate

        isShow=true;

        formData.isArrival=res.data.isArrival; 

      }

      //isRecord:'',//0 There is no record of arrival ,1 There are arrival records

      if(res.data.isRecord=='0'){

        items[0].checked=true;

        formData.djType='leave';

        formData.isRecord=res.data.isRecord;

      }else{

        items[1].checked=true;

        formData.djType='reach';

      }

      // Dispatch sheet data is added

      if(isEmpty(res.data.dCodeList)||res.data.dCodeList.length<=0){

        wx.showToast({

          title: ' Transport task not found , Please contact the dispatcher ',

          icon: 'none',

        }, 1500) 

      }else{

        var len=res.data.dCodeList.length;

        var arr=res.data.dCodeList;

        debugger

        for(var i=0;i<len;i++){

          var isBH=this.checkRepeat(dTextArea_list,arr[1])

          if(isBH){

            dTextArea_list.push(arr[i]) 

          } 

        }

        dList=dTextArea_list.join("\n") 

      }

      this.setData({isShow,items,dList,dTextArea_list,formData})

    }else {

      wx.showToast({

        title: res.message,

        icon: 'none',

      }, 1500)

    }

    this.setData({ loading: false })

  }).catch(err => {

    wx.hideLoading()

    this.setData({ loading: false })

  })

},

 // Submit

 submit() {

  let { loading,formData,dList,fileList,dTextArea_list } = this.data

  if(loading) return

  if (isEmpty(formData.scanCode)) {

    wx.showToast({

      title: ' Please scan the warehouse code first ',

      icon: 'none',

    }, 1000)

    return

  }  

  if (isEmpty(dList)) {

    wx.showToast({

      title: ' Please enter the dispatch list ',

      icon: 'none',

    }, 1000)

    return

  }else{

    debugger

    formData.dCode=dTextArea_list;

  }

  if (isEmpty(formData.djType )) {

    wx.showToast({

      title: ' Please select the registration type ',

      icon: 'none',

    }, 1000)

    return

  }

  if (isEmpty(formData.vehicleCode)) {

    wx.showToast({

      title: ' Please enter the license plate number ',

      icon: 'none',

    }, 1000)

    return

  }  

  if (isEmpty(fileList)) {

    wx.showToast({

      title: ' Please upload license plate photos ',

      icon: 'none',

    }, 1000)

    return

  }else{

    formData.fileList=fileList;

  }

  wx.showLoading({

    title: ' In submission ',

  })

  this.setData({

    loading: true

  })

  

  submitForm(formData).then(res => {

    debugger

    wx.hideLoading()

    if(res.code == 200) {

      wx.showToast({

        title: ' Submit successfully !',

        icon: 'success'

      }, 1500)

      setTimeout(() => { 

        wx.navigateBack({// return

          delta: 1

        })

      }, 1500)

    }else {

      wx.showToast({

        title: res.message,

        icon: 'none',

      }, 1500)

    }

    this.setData({ loading: false })

  }).catch(err => {

    wx.hideLoading()

    this.setData({ loading: false })

  })

},

// Submit validation  

})

版权声明:本文为[wx5a0a5e76a9c09]所创,转载请带上原文链接,感谢。 https://car.inotgo.com/2021/08/20210810104117621S.html