add.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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(){
  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. driverIndex : app.util.getDicIndex(res.data.data, this.data.driverId, 'id')
  66. })
  67. if(this.data.driverId){
  68. this.setData({
  69. driverName : this.data.driverArray[this.data.driverIndex].name,
  70. driverMobile : this.data.driverArray[this.data.driverIndex].phone,
  71. })
  72. }
  73. })
  74. },
  75. //下拉选择
  76. bindPickerChange: function (e) {
  77. let { pickername } = e.target.dataset
  78. let getIndex = pickername + 'Index'
  79. app.util.getPickerIndex(this, getIndex, e);
  80. switch (pickername) {
  81. case 'driver': //选择司机
  82. this.setData({
  83. driverName : this.data.driverArray[this.data.driverIndex].name,
  84. driverMobile : this.data.driverArray[this.data.driverIndex].phone,
  85. })
  86. break;
  87. }
  88. },
  89. // 单选
  90. dangerStatusChange: function (e) {
  91. this.setData({
  92. [e.currentTarget.dataset.radiotype]: e.detail.value
  93. })
  94. },
  95. //多选
  96. checkboxChange: function (e) {
  97. this.setData({
  98. [e.currentTarget.dataset.checkboxtype]: e.detail
  99. })
  100. },
  101. /**
  102. * 页面上拉触底事件的处理函数
  103. */
  104. bindscrolltolowerFun() {
  105. },
  106. //表单提交 carTaskAdd
  107. formSubmit: function ({detail:{value}}) {
  108. // console.info("----driverId---" + value.driverId)
  109. var warn = ""; //弹框时提示的内容
  110. let reg = /^1[3-9]\d{9}$/;
  111. var xreg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
  112. var creg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
  113. //value.certificateNoImage = this.data.originalInvoicePhoto
  114. if (value.licenseNumber == '') {
  115. warn = "车牌不能为空!";
  116. } else if (value.licenseNumber.length < 8) {
  117. warn = "请选择新能源车牌号!";
  118. } else if (value.licenseNumber.length == 8 && !xreg.test(value.licenseNumber)) {
  119. warn = "新能源车牌号格式错误!";
  120. } else if(value.driverName == ''){
  121. warn = "请输入司机姓名!";
  122. } else if(value.driverPhone == ''){
  123. warn = "请输入司机电话!";
  124. }
  125. if (warn != '') {
  126. app.util.checkForm(warn);
  127. } else {
  128. app.request.POST({
  129. url: app.API.chargestationAdd,
  130. params: value,
  131. page: this,
  132. isLoadingTxt: '提交中...',
  133. isSubmitting: true,
  134. successFun: true
  135. }).then(res => {
  136. wx.showToast({
  137. title: '新增成功',
  138. icon: 'success',
  139. duration: 2000,
  140. mask:true,
  141. complete: function () {
  142. setTimeout(() => {
  143. wx.navigateBack()
  144. }, 1500) //延迟时间
  145. }
  146. })
  147. })
  148. }
  149. },
  150. /**
  151. * 生命周期函数--监听页面初次渲染完成
  152. */
  153. onReady: function () {
  154. },
  155. /**
  156. * 生命周期函数--监听页面显示
  157. */
  158. onShow: function () {
  159. },
  160. /**
  161. * 生命周期函数--监听页面隐藏
  162. */
  163. onHide: function () {
  164. },
  165. /**
  166. * 生命周期函数--监听页面卸载
  167. */
  168. onUnload: function () {
  169. },
  170. /**
  171. * 页面相关事件处理函数--监听用户下拉动作
  172. */
  173. onPullDownRefresh: function () {
  174. },
  175. /**
  176. * 页面上拉触底事件的处理函数
  177. */
  178. onReachBottom: function () {
  179. },
  180. /**
  181. * 用户点击右上角分享
  182. */
  183. onShareAppMessage: function () {
  184. }
  185. })