add.js 6.1 KB

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