add.js 7.1 KB

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