add.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // pages/reservationPipe/add.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. showModal: false,
  9. defaultText: '请选择',
  10. isSubmitting: false,
  11. isKeyboard: false, //是否显示车牌输入键盘
  12. inputOnFocusIndex: '', //当前锁定的车号位置
  13. licensePlate: '', //用于提交
  14. inputPlates: '', //用于显示
  15. driverArray:[], //司机
  16. driverIndex:null,
  17. },
  18. //输入框焦点聚焦时隐藏车牌号输入框
  19. hideKeybord: function () {
  20. this.setData({
  21. isKeyboard: false,
  22. inputOnFocusIndex: ''
  23. })
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. // 根据缓存获取司机车牌号
  30. let getCarNumArr = wx.getStorageSync('nickname')?wx.getStorageSync('nickname').split(''):''
  31. let inputPlates = {};
  32. for (let i = 0; i < getCarNumArr.length; i++) {
  33. inputPlates['index' + i] = getCarNumArr[i]
  34. }
  35. // 默认填充司机信息
  36. this.setData({
  37. driverId : wx.getStorageSync('id'),
  38. driverName : wx.getStorageSync('name'),
  39. driverPhone : wx.getStorageSync('phone'),
  40. inputPlates : inputPlates,
  41. isNewEnergy : getCarNumArr.length > 7 ? true : false,
  42. licensePlate: wx.getStorageSync('nickname')
  43. })
  44. //获取司机信息
  45. this.loadUserData()
  46. },
  47. //获取车牌号
  48. licensePlate: function (e) {
  49. this.setData({
  50. licensePlate: e.detail.carNum
  51. })
  52. },
  53. //司机
  54. loadUserData:function(loadUserId){
  55. app.request.GET({
  56. url: app.API.roleUser,
  57. params: {
  58. roleName : '司机',
  59. },
  60. page: this,
  61. successFun: true
  62. }).then(res => {
  63. this.setData({
  64. driverArray : res.data.data
  65. })
  66. })
  67. },
  68. //下拉选择
  69. bindPickerChange: function (e) {
  70. let { pickername } = e.target.dataset
  71. let getIndex = pickername + 'Index'
  72. app.util.getPickerIndex(this, getIndex, e);
  73. switch (pickername) {
  74. case 'driver': //选择司机
  75. this.setData({
  76. driverPhone : this.data.driverArray[this.data.driverIndex].name,
  77. driverMobile : this.data.driverArray[this.data.driverIndex].phone,
  78. })
  79. break;
  80. }
  81. },
  82. // 单选
  83. dangerStatusChange: function (e) {
  84. this.setData({
  85. [e.currentTarget.dataset.radiotype]: e.detail.value
  86. })
  87. },
  88. //多选
  89. checkboxChange: function (e) {
  90. this.setData({
  91. [e.currentTarget.dataset.checkboxtype]: e.detail
  92. })
  93. },
  94. /**
  95. * 页面上拉触底事件的处理函数
  96. */
  97. bindscrolltolowerFun() {
  98. },
  99. //表单提交 carTaskAdd
  100. formSubmit: function ({detail:{value}}) {
  101. var warn = ""; //弹框时提示的内容
  102. let reg = /^1[3-9]\d{9}$/;
  103. var xreg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
  104. var creg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
  105. //value.certificateNoImage = this.data.originalInvoicePhoto
  106. if (value.licenseNumber == '') {
  107. warn = "车牌不能为空!";
  108. } else if (value.licenseNumber.length < 8) {
  109. warn = "请选择新能源车牌号!";
  110. } else if (value.licenseNumber.length == 8 && !xreg.test(value.licenseNumber)) {
  111. warn = "新能源车牌号格式错误!";
  112. } else if(value.driverName == ''){
  113. warn = "请输入司机姓名!";
  114. } else if(value.driverPhone == ''){
  115. warn = "请输入司机电话!";
  116. }
  117. if (warn != '') {
  118. app.util.checkForm(warn);
  119. } else {
  120. app.request.POST({
  121. url: app.API.chargestationAdd,
  122. params: value,
  123. page: this,
  124. isLoadingTxt: '提交中...',
  125. isSubmitting: true,
  126. successFun: true
  127. }).then(res => {
  128. wx.showToast({
  129. title: '新增成功',
  130. icon: 'success',
  131. duration: 2000,
  132. mask:true,
  133. complete: function () {
  134. setTimeout(() => {
  135. wx.navigateBack()
  136. }, 1500) //延迟时间
  137. }
  138. })
  139. })
  140. }
  141. },
  142. /**
  143. * 生命周期函数--监听页面初次渲染完成
  144. */
  145. onReady: function () {
  146. },
  147. /**
  148. * 生命周期函数--监听页面显示
  149. */
  150. onShow: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面隐藏
  154. */
  155. onHide: function () {
  156. },
  157. /**
  158. * 生命周期函数--监听页面卸载
  159. */
  160. onUnload: function () {
  161. },
  162. /**
  163. * 页面相关事件处理函数--监听用户下拉动作
  164. */
  165. onPullDownRefresh: function () {
  166. },
  167. /**
  168. * 页面上拉触底事件的处理函数
  169. */
  170. onReachBottom: function () {
  171. },
  172. /**
  173. * 用户点击右上角分享
  174. */
  175. onShareAppMessage: function () {
  176. }
  177. })