add.js 7.3 KB

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