edit.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // pages/reservationOther/edit.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. carzheArray:[],//车辆轴数
  18. carzheIndex:'',
  19. },
  20. //输入框焦点聚焦时隐藏车牌号输入框
  21. hideKeybord: function () {
  22. this.setData({
  23. isKeyboard: false,
  24. inputOnFocusIndex: ''
  25. })
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. //获取详情
  32. var pages = getCurrentPages();
  33. var prevPage = pages[pages.length - 2];
  34. let getInfo = prevPage.data.resData[options.index]
  35. let getCarNumArr = getInfo.licenseNumber ? getInfo.licenseNumber.split('') : ''
  36. let inputPlates = {};
  37. for (let i = 0; i < getCarNumArr.length; i++) {
  38. inputPlates['index' + i] = getCarNumArr[i]
  39. }
  40. this.setData({
  41. info: getInfo,
  42. isWeigh:getInfo.isWeigh,
  43. driverMobile: getInfo.driverMobile,
  44. driverName: getInfo.driverName,
  45. inputPlates: inputPlates,
  46. isNewEnergy: getCarNumArr.length > 7 ? true : false,
  47. licensePlate: getInfo.licenseNumber,
  48. })
  49. //获取车辆轴数
  50. this.getCarzheData()
  51. //获取司机信息
  52. this.loadUserData()
  53. },
  54. //获取车牌号
  55. licensePlate: function (e) {
  56. this.setData({
  57. licensePlate: e.detail.carNum
  58. })
  59. },
  60. //获取车辆轴数下拉列表
  61. getCarzheData:function(){
  62. //获取车辆轴数下拉列表
  63. app.request.GET({
  64. url: app.API.getCarzheList,
  65. params: {},
  66. page: this,
  67. successFun: true
  68. }).then(res => {
  69. this.setData({
  70. carzheArray : res.data.data,
  71. carzheIndex : app.util.getDicIndex(res.data.data, this.data.info.overId, 'id')
  72. })
  73. })
  74. },
  75. //司机
  76. loadUserData:function(){
  77. app.request.GET({
  78. url: app.API.roleUser,
  79. params: {
  80. roleName : '司机',
  81. },
  82. page: this,
  83. successFun: true
  84. }).then(res => {
  85. this.setData({
  86. driverArray : res.data.data,
  87. driverIndex : app.util.getDicIndex(res.data.data, this.data.info.driverId, 'id')
  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. switch (pickername) {
  97. case 'driver': //选择司机
  98. this.setData({
  99. driverName : this.data.driverArray[this.data.driverIndex].name,
  100. driverMobile : this.data.driverArray[this.data.driverIndex].phone,
  101. })
  102. break;
  103. }
  104. },
  105. // 单选
  106. dangerStatusChange: function (e) {
  107. this.setData({
  108. [e.currentTarget.dataset.radiotype]: e.detail.value
  109. })
  110. },
  111. //多选
  112. checkboxChange: function (e) {
  113. this.setData({
  114. [e.currentTarget.dataset.checkboxtype]: e.detail
  115. })
  116. },
  117. /**
  118. * 页面上拉触底事件的处理函数
  119. */
  120. bindscrolltolowerFun() {
  121. },
  122. //表单提交 carTaskAdd
  123. formSubmit: function ({detail:{value}}) {
  124. var warn = ""; //弹框时提示的内容
  125. let reg = /^1[3-9]\d{9}$/;
  126. var xreg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
  127. var creg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
  128. if (value.licenseNumber == '') {
  129. warn = "车牌不能为空!";
  130. } else if (value.licenseNumber.length < 7) {
  131. warn = "请选择车牌号!";
  132. } else if (value.licenseNumber.length == 7 && !xreg.test(value.licenseNumber)) {
  133. warn = "车牌号格式错误!";
  134. } else if(value.driverId == ''){
  135. warn = "请选择司机!";
  136. }
  137. if (warn != '') {
  138. app.util.checkForm(warn);
  139. } else {
  140. app.request.POST({
  141. url: app.API.otherEdit,
  142. params: value,
  143. page: this,
  144. isLoadingTxt: '提交中...',
  145. isSubmitting: true,
  146. successFun: true
  147. }).then(res => {
  148. wx.showToast({
  149. title: '修改成功',
  150. icon: 'success',
  151. duration: 2000,
  152. mask:true,
  153. complete: function () {
  154. setTimeout(() => {
  155. wx.navigateBack()
  156. }, 1500) //延迟时间
  157. }
  158. })
  159. })
  160. }
  161. },
  162. /**
  163. * 生命周期函数--监听页面初次渲染完成
  164. */
  165. onReady: function () {
  166. },
  167. /**
  168. * 生命周期函数--监听页面显示
  169. */
  170. onShow: function () {
  171. },
  172. /**
  173. * 生命周期函数--监听页面隐藏
  174. */
  175. onHide: function () {
  176. },
  177. /**
  178. * 生命周期函数--监听页面卸载
  179. */
  180. onUnload: function () {
  181. },
  182. /**
  183. * 页面相关事件处理函数--监听用户下拉动作
  184. */
  185. onPullDownRefresh: function () {
  186. },
  187. /**
  188. * 页面上拉触底事件的处理函数
  189. */
  190. onReachBottom: function () {
  191. },
  192. /**
  193. * 用户点击右上角分享
  194. */
  195. onShareAppMessage: function () {
  196. }
  197. })