add.js 6.1 KB

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