edit.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // pages/temporary/edit.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. showModal: false,
  9. defaultText: '请选择',
  10. isSubmitting: false,
  11. reservationType: '2',
  12. isKeyboard: false, //是否显示车牌输入键盘
  13. inputOnFocusIndex: '', //当前锁定的车号位置
  14. licensePlate: '', //用于提交
  15. inputPlates: '', //用于显示
  16. appointmentClassifyArray: [
  17. { label:'充电预约',value:'1' },
  18. { label:'管桩预约',value:'2' },
  19. { label:'其他预约',value:'3' },
  20. ], //预约类型
  21. appointmentClassifyIndex: '',
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. //获取详情
  28. var pages = getCurrentPages();
  29. var prevPage = pages[pages.length - 2];
  30. let getInfo = prevPage.data.resData[options.index]
  31. let getCarNumArr = getInfo.licenseNumber ? getInfo.licenseNumber.split('') : ''
  32. let inputPlates = {};
  33. for (let i = 0; i < getCarNumArr.length; i++) {
  34. inputPlates['index' + i] = getCarNumArr[i]
  35. }
  36. this.setData({
  37. info: getInfo,
  38. inputPlates: inputPlates,
  39. isNewEnergy: getCarNumArr.length > 7 ? true : false,
  40. licensePlate: getInfo.licenseNumber,
  41. appointmentClassifyIndex: app.util.getDicIndex(this.data.appointmentClassifyArray, getInfo.appointmentClassify, 'value'),
  42. })
  43. //this.getSelectData()
  44. },
  45. //获取订单下拉列表、车辆轴数下拉列表
  46. getSelectData:function(){
  47. //获取订单下拉列表
  48. // app.request.GET({
  49. // url: app.API.orderAllList,
  50. // params: {},
  51. // page: this,
  52. // successFun: true
  53. // }).then(res => {
  54. // this.setData({
  55. // orderArray:res.data.data,
  56. // orderIndex: app.util.getDicIndex(res.data.data, this.data.info.orderId, 'id'),
  57. // })
  58. // })
  59. //获取车辆轴数下拉列表
  60. app.request.GET({
  61. url: app.API.getCarzheList,
  62. params: {},
  63. page: this,
  64. successFun: true
  65. }).then(res => {
  66. this.setData({
  67. overArray:res.data.data,
  68. overIndex: app.util.getDicIndex(res.data.data, this.data.info.overId, 'id'),
  69. })
  70. })
  71. },
  72. //下拉选择
  73. bindPickerChange: function (e) { //下拉菜单
  74. let getIndex = e.target.dataset.pickername + 'Index'
  75. app.util.getPickerIndex(this, getIndex, e);
  76. },
  77. // 单选
  78. dangerStatusChange: function (e) {
  79. this.setData({
  80. [e.currentTarget.dataset.radiotype]: e.detail.value
  81. })
  82. },
  83. //多选
  84. checkboxChange: function (e) {
  85. console.log(e.detail)
  86. this.setData({
  87. [e.currentTarget.dataset.checkboxtype]: e.detail
  88. })
  89. },
  90. //输入框焦点聚焦时隐藏车牌号输入框
  91. hideKeybord: function () {
  92. this.setData({
  93. isKeyboard: false,
  94. inputOnFocusIndex: ''
  95. })
  96. },
  97. //获取车牌号
  98. licensePlate: function (e) {
  99. this.setData({
  100. licensePlate: e.detail.carNum
  101. })
  102. },
  103. /**
  104. * 页面上拉触底事件的处理函数
  105. */
  106. bindscrolltolowerFun() {
  107. },
  108. formSubmit: function ({detail:{value}}) {
  109. let formData = value;
  110. let reg = /^1\d{10}$/;
  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. var warn = ""; //弹框时提示的内容
  114. if (formData.appointmentClassify == '') {
  115. warn = "请选择预约分类!";
  116. } else if (formData.licenseNumber == '') {
  117. warn = "请选择车牌!";
  118. } else if (formData.licenseNumber.length < 7) {
  119. warn = "请选择完整车牌号!";
  120. } else if (formData.licenseNumber.length == 7 && !creg.test(formData.licenseNumber) && formData.appointmentClassify != '1') {
  121. warn = "车牌号格式错误!";
  122. } else if (formData.licenseNumber.length == 8 && !xreg.test(formData.licenseNumber)) {
  123. warn = "车牌号格式错误!";
  124. } else if (formData.driverName == '') {
  125. warn = "请填写司机姓名!";
  126. } else if (formData.driverMobile == '') {
  127. warn = "请填写司机电话!";
  128. } else if (!reg.test(formData.driverMobile)) {
  129. warn = "司机电话格式错误!";
  130. }
  131. if (warn != '') {
  132. app.util.checkForm(warn);
  133. } else {
  134. app.request.POST({
  135. url: app.API.tempEdit,
  136. params: value,
  137. page: this,
  138. isLoadingTxt: '提交中...',
  139. isSubmitting: true,
  140. successFun: true
  141. }).then(res => {
  142. wx.showToast({
  143. title: '修改成功',
  144. icon: 'success',
  145. duration: 2000,
  146. mask:true,
  147. complete: function () {
  148. setTimeout(() => {
  149. wx.navigateBack()
  150. }, 1500) //延迟时间
  151. }
  152. })
  153. })
  154. }
  155. },
  156. /**
  157. * 生命周期函数--监听页面初次渲染完成
  158. */
  159. onReady: function () {
  160. },
  161. /**
  162. * 生命周期函数--监听页面显示
  163. */
  164. onShow: function () {
  165. },
  166. /**
  167. * 生命周期函数--监听页面隐藏
  168. */
  169. onHide: function () {
  170. },
  171. /**
  172. * 生命周期函数--监听页面卸载
  173. */
  174. onUnload: function () {
  175. },
  176. /**
  177. * 页面相关事件处理函数--监听用户下拉动作
  178. */
  179. onPullDownRefresh: function () {
  180. },
  181. /**
  182. * 页面上拉触底事件的处理函数
  183. */
  184. onReachBottom: function () {
  185. },
  186. /**
  187. * 用户点击右上角分享
  188. */
  189. onShareAppMessage: function () {
  190. }
  191. })