add.js 6.7 KB

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