edit.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. // pages/index/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. orderArray:[],//订单
  17. orderIndex:'',
  18. overArray:[],//车辆轴数
  19. overIndex:'',
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. //获取详情
  26. var pages = getCurrentPages();
  27. var prevPage = pages[pages.length - 2];
  28. let getInfo = prevPage.data.resData[options.index]
  29. let getCarNumArr = getInfo.licenseNumber ? getInfo.licenseNumber.split('') : ''
  30. let inputPlates = {};
  31. for (let i = 0; i < getCarNumArr.length; i++) {
  32. inputPlates['index' + i] = getCarNumArr[i]
  33. }
  34. this.setData({
  35. info: getInfo,
  36. orderId: getInfo.orderId,
  37. inputPlates: inputPlates,
  38. isNewEnergy: getCarNumArr.length > 7 ? true : false,
  39. licensePlate: getInfo.licenseNumber,
  40. })
  41. this.getSelectData()
  42. //装卸点位
  43. this.loadPointData('info')
  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. switch (pickername) {
  77. case 'loadPoint': //客户
  78. this.loadTimeData() //获取销售订单
  79. break;
  80. }
  81. },
  82. // 单选
  83. dangerStatusChange: function (e) {
  84. this.setData({
  85. [e.currentTarget.dataset.radiotype]: e.detail.value
  86. })
  87. },
  88. //多选
  89. checkboxChange: function (e) {
  90. console.log(e.detail)
  91. this.setData({
  92. [e.currentTarget.dataset.checkboxtype]: e.detail
  93. })
  94. },
  95. //输入框焦点聚焦时隐藏车牌号输入框
  96. hideKeybord: function () {
  97. this.setData({
  98. isKeyboard: false,
  99. inputOnFocusIndex: ''
  100. })
  101. },
  102. //获取车牌号
  103. licensePlate: function (e) {
  104. this.setData({
  105. licensePlate: e.detail.carNum
  106. })
  107. },
  108. /**
  109. * 页面上拉触底事件的处理函数
  110. */
  111. bindscrolltolowerFun() {
  112. },
  113. //装卸点位
  114. loadPointData:function(type){
  115. app.request.GET({
  116. url: app.API.loadPointYY,
  117. params: {
  118. orderId:this.data.orderId
  119. },
  120. page: this,
  121. successFun: true
  122. }).then(res => {
  123. this.setData({
  124. loadPointArray:res.data.data,
  125. loadPointIndex: app.util.getDicIndex(res.data.data, this.data.info.loadPointId, 'loadPointId'),
  126. })
  127. if(type){
  128. this.loadTimeData('info')
  129. }
  130. })
  131. },
  132. //装卸时间
  133. loadTimeData:function(type){
  134. app.request.GET({
  135. url: app.API.loadTimeYY,
  136. params: {
  137. pointId:this.data.loadPointArray[this.data.loadPointIndex].loadPointId,
  138. orderId:this.data.orderId
  139. },
  140. page: this,
  141. successFun: true
  142. }).then(res => {
  143. let orderList = res.data.data
  144. orderList.forEach((element,index) => {
  145. orderList[index].time = element.beginTime + '~' + element.endTime
  146. });
  147. this.setData({
  148. loadTimeArray:orderList,
  149. loadTimeIndex:type?app.util.getDicIndex(orderList, this.data.info.loadTimeId, 'loadTimeId'):null
  150. })
  151. })
  152. },
  153. formSubmit: function ({detail:{value}}) {
  154. let formData = value;
  155. let reg = /^1\d{10}$/;
  156. var xreg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
  157. var creg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
  158. var warn = ""; //弹框时提示的内容
  159. if (formData.licenseNumber == '') {
  160. warn = "请选择车牌!";
  161. } else if (formData.licenseNumber.length < 7) {
  162. warn = "请选择完整车牌号!";
  163. } else if (formData.licenseNumber.length == 7 && !creg.test(formData.licenseNumber)) {
  164. warn = "车牌号格式错误!";
  165. } else if (formData.licenseNumber.length == 8 && !xreg.test(formData.licenseNumber)) {
  166. warn = "车牌号格式错误!";
  167. } else if (formData.overId == '') {
  168. warn = "请选择车辆轴数!";
  169. } else if (formData.driverName == '') {
  170. warn = "请填写司机姓名!";
  171. } else if (formData.driverMobile == '') {
  172. warn = "请填写司机电话!";
  173. } else if (!reg.test(formData.driverMobile)) {
  174. warn = "司机电话格式错误!";
  175. }
  176. if (warn != '') {
  177. app.util.checkForm(warn);
  178. } else {
  179. app.request.POST({
  180. url: app.API.appointmentEdit,
  181. params: value,
  182. page: this,
  183. isLoadingTxt: '提交中...',
  184. isSubmitting: true,
  185. successFun: true
  186. }).then(res => {
  187. wx.showToast({
  188. title: '修改成功',
  189. icon: 'success',
  190. duration: 2000,
  191. mask:true,
  192. complete: function () {
  193. setTimeout(() => {
  194. wx.navigateBack()
  195. }, 1500) //延迟时间
  196. }
  197. })
  198. })
  199. }
  200. },
  201. /**
  202. * 生命周期函数--监听页面初次渲染完成
  203. */
  204. onReady: function () {
  205. },
  206. /**
  207. * 生命周期函数--监听页面显示
  208. */
  209. onShow: function () {
  210. },
  211. /**
  212. * 生命周期函数--监听页面隐藏
  213. */
  214. onHide: function () {
  215. },
  216. /**
  217. * 生命周期函数--监听页面卸载
  218. */
  219. onUnload: function () {
  220. },
  221. /**
  222. * 页面相关事件处理函数--监听用户下拉动作
  223. */
  224. onPullDownRefresh: function () {
  225. },
  226. /**
  227. * 页面上拉触底事件的处理函数
  228. */
  229. onReachBottom: function () {
  230. },
  231. /**
  232. * 用户点击右上角分享
  233. */
  234. onShareAppMessage: function () {
  235. }
  236. })