reservationEdit.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. let Util = require("../../utils/util");
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. chargStationId:'',
  8. chargPileName:'加载中',
  9. chargPileId:'',
  10. chargPileIdId:'',
  11. userId:'',
  12. plateNumber:'',
  13. chargStationName:'',
  14. startparams:{
  15. placeholder: '请选择时间',
  16. startDateTime: '2020-01-01 00:00',
  17. endDateTime: '2040-01-01 00:00',
  18. // pText: Util.formatTimePicker(new Date()) //'2022-04-30 00:00'
  19. pText: '' //'2022-04-30 00:00'
  20. },
  21. finishparams:{
  22. placeholder: '请选择时间',
  23. startDateTime: '2020-01-01 00:00',
  24. endDateTime: '2040-01-01 00:00',
  25. // pText: Util.formatTimePicker(new Date()) //'2022-04-30 00:00'
  26. pText: ''
  27. },
  28. },
  29. bindStartparamsChange(e){
  30. let startparams = this.data.startparams;
  31. let endparams = this.data.finishparams;
  32. startparams.pText = e.detail
  33. this.setData({
  34. startparams:startparams
  35. })
  36. let currTime = new Date(e.detail);
  37. console.info(currTime)
  38. let curTime3 = new Date(currTime);
  39. let estime = new Date(curTime3.setMinutes(curTime3.getMinutes() + parseInt(this.data.minReservTime)));
  40. let curTime4 = new Date(currTime);
  41. let eetime = new Date(curTime4.setMinutes(curTime4.getMinutes() + parseInt(this.data.maxReservTime)));
  42. if(endparams?.pText){
  43. let currEndTime = new Date(endparams.pText);
  44. if(currEndTime<=currTime){
  45. this.selectComponent("#end").changeDateTime('')
  46. // this.selectComponent("#end").initData()
  47. }
  48. }
  49. this.selectComponent("#end").data.startDateTime = Util.formatTimePicker(estime);
  50. this.selectComponent("#end").data.endDateTime = Util.formatTimePicker(eetime),
  51. this.selectComponent("#end").initData()
  52. },
  53. bindFinishparamsChange(e){
  54. let startparams = this.data.startparams;
  55. let finishparams = this.data.finishparams;
  56. finishparams.pText = e.detail
  57. this.setData({
  58. finishparams:finishparams
  59. })
  60. console.info("finishparams " + finishparams.pText)
  61. },
  62. /**
  63. * 生命周期函数--监听页面加载
  64. */
  65. onLoad(options) {
  66. this.initCar();
  67. let {
  68. chargStationId,
  69. chargPileName,
  70. chargPileId,
  71. chargPileIdId,
  72. userId,
  73. chargStationName,
  74. earliestReservTime,
  75. advanceReservDays,
  76. minReservTime,
  77. maxReservTime,
  78. maxEarlyExerciseTime,
  79. maxReservOvertime
  80. } = options;
  81. console.info(options);
  82. let curTime = new Date();
  83. let sstime = new Date(curTime.setMinutes(curTime.getMinutes() + parseInt(earliestReservTime)));
  84. let curTime2 = new Date();
  85. let setime = new Date(curTime2.setMinutes(curTime2.getMinutes() + (parseInt(advanceReservDays)) * 60 * 24));
  86. setime.setHours(23, 59, 0)
  87. let curTime3 = new Date(sstime);
  88. let estime = new Date(curTime3.setMinutes(curTime3.getMinutes() + parseInt(minReservTime)));
  89. let curTime4 = new Date(setime);
  90. let eetime = new Date(curTime4.setMinutes(curTime4.getMinutes() + parseInt(maxReservTime)));
  91. this.setData({
  92. chargStationId,
  93. chargPileName,
  94. chargPileId,
  95. chargPileIdId,
  96. userId,
  97. chargStationName,
  98. earliestReservTime,
  99. advanceReservDays,
  100. minReservTime,
  101. maxReservTime,
  102. maxEarlyExerciseTime,
  103. maxReservOvertime,
  104. "startparams.startDateTime":Util.formatTimePicker(sstime),
  105. // "startparams.pText":Util.formatTimePicker(sstime),
  106. "startparams.endDateTime":Util.formatTimePicker(setime),
  107. "finishparams.startDateTime":Util.formatTimePicker(estime),
  108. // "finishparams.pText":Util.formatTimePicker(estime),
  109. "finishparams.endDateTime":Util.formatTimePicker(eetime),
  110. }
  111. );
  112. },
  113. SubmitBtn(){
  114. // 预约充电站ID * 预约充电桩ID * 预约用户ID * 预约充电开始时间 * 预约充电结束时间
  115. let reservChargeStartTime = this.data.startparams.pText
  116. let reservChargeEndTime = this.data.finishparams.pText
  117. let reservPileId = this.data.chargPileIdId;
  118. let reservStationId = this.data.chargStationId;
  119. let sysUserId = this.data.userId;
  120. let plateNumber = this.data.plateNumber;
  121. if(!plateNumber){
  122. wx.showModal({
  123. title: '提示',
  124. content: '请先选择车牌',
  125. showCancel:false,
  126. confirmColor:'#00AADD',
  127. });
  128. return;
  129. }
  130. if(!reservChargeStartTime){
  131. wx.showModal({
  132. title: '提示',
  133. content: '请先选择预约开始充电时间',
  134. showCancel:false,
  135. confirmColor:'#00AADD',
  136. });
  137. return;
  138. }
  139. reservChargeStartTime = reservChargeStartTime + ':00'
  140. if(!reservChargeEndTime){
  141. wx.showModal({
  142. title: '提示',
  143. content: '请先选择预约结束充电时间',
  144. showCancel:false,
  145. confirmColor:'#00AADD',
  146. });
  147. return;
  148. }
  149. reservChargeEndTime = reservChargeEndTime + ':00'
  150. wx.requestSubscribeMessage({
  151. tmplIds: ['DA80dlHRpvYMfZVICp-SVFEqo6v7_7S9wPM4nndHyjE'],
  152. success (res) {
  153. wx.request({
  154. // url: getApp().globalData.postHeadAgreement +'/restapi/wechat/reserv2?reservChargeStartTime=' + reservChargeStartTime +
  155. // '&reservChargeEndTime=' + reservChargeEndTime +
  156. // '&reservPile.id=' + reservPileId +
  157. // '&reservStation.id=' + reservStationId +
  158. // '&sysUser.id=' + sysUserId,
  159. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/reserv',
  160. data: {
  161. reservPlateNum:plateNumber,
  162. reservChargeStartTime:reservChargeStartTime,
  163. reservChargeEndTime:reservChargeEndTime,
  164. reservPile:{
  165. id:reservPileId
  166. },
  167. reservStation:{
  168. id:reservStationId
  169. },
  170. sysUser:{
  171. userId:sysUserId
  172. },
  173. },
  174. method: 'POST',
  175. success(res) {
  176. console.info(res)
  177. if(res?.data?.msg=="操作成功"){
  178. wx.showModal({
  179. title: '提示',
  180. content: '预约成功',
  181. showCancel:false,
  182. confirmColor:'#00AADD',
  183. complete: (res2) => {
  184. if (res2.cancel) {
  185. }
  186. if (res2.confirm) {
  187. wx.navigateBack()
  188. }
  189. }
  190. });
  191. }else{
  192. wx.showModal({
  193. title: '提示',
  194. content: res?.data?.msg,
  195. showCancel:false,
  196. confirmColor:'#00AADD',
  197. });
  198. }
  199. }
  200. });
  201. }
  202. })
  203. },
  204. chooseCar(){
  205. let url = '/pages/ucenter/car/chooseCar'
  206. wx.setStorageSync('chooseCar_plateNumber',{plateNumber:this.data.plateNumber})
  207. wx.navigateTo({
  208. url
  209. });
  210. },
  211. initCar(){
  212. let that = this
  213. let userInfo = wx.getStorageSync('userInfo');
  214. let isLogin = wx.getStorageSync('isLogin');
  215. // 读取默认车牌
  216. wx.request({
  217. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carList?loginName=' + userInfo.loginName,
  218. // data: {
  219. // loginName: userInfo.loginName
  220. // },
  221. method: 'POST',
  222. success: function (res) {
  223. let userCarList = res.data;
  224. userCarList = userCarList.filter(it=>it.defaultType==1);
  225. console.info(userCarList)
  226. if(userCarList.length==0 ){
  227. // wx.showModal({
  228. // title: '提示',
  229. // content: '当前充电站可减免停车费,是否绑定车牌信息?',
  230. // confirmText: '绑定车牌',
  231. // cancelText: '直接启动',
  232. // showCancel:true,
  233. // confirmColor:'#00AADD',
  234. // cancelColor:'#00AADD',
  235. // success: function (ress1) {
  236. // if(ress1.confirm){
  237. // let url = '/pages/ucenter/car/chooseCar'
  238. // wx.navigateTo({
  239. // url
  240. // });
  241. // }else{
  242. // that.beginChargeInner(that,'')
  243. // }
  244. // }
  245. // });
  246. }else{
  247. let userCar = userCarList[0]
  248. that.setData({
  249. plateNumber: userCar.plateNumber
  250. })
  251. // wx.showModal({
  252. // title: '提示',
  253. // content: '确定使用' + userCar.plateNumber + '车牌信息减免停车费?',
  254. // confirmText: '确定',
  255. // cancelText: '其他车牌',
  256. // showCancel:true,
  257. // confirmColor:'#00AADD',
  258. // cancelColor:'#00AADD',
  259. // success: function (ress1) {
  260. // if(ress1.confirm){
  261. // that.beginChargeInner(that,userCar.plateNumber)
  262. // }else{
  263. // let url = '/pages/ucenter/car/chooseCar'
  264. // wx.navigateTo({
  265. // url
  266. // });
  267. // }
  268. // return;
  269. // },
  270. // fail: function(res1){
  271. // console.info(res1)
  272. // }
  273. // });
  274. }
  275. },
  276. fail(e) {
  277. console.log("查询车辆失败");
  278. log.info('[查询车辆]','[fail]', e);
  279. }
  280. });
  281. },
  282. /**
  283. * 生命周期函数--监听页面初次渲染完成
  284. */
  285. onReady() {
  286. },
  287. /**
  288. * 生命周期函数--监听页面显示
  289. */
  290. onShow() {
  291. let car = wx.getStorageSync('chooseCar_plateNumber')
  292. console.info(car)
  293. let plateNumber = ''
  294. if(car){
  295. plateNumber = car.plateNumber;
  296. wx.removeStorageSync('chooseCar_plateNumber')
  297. }
  298. this.setData({
  299. plateNumber
  300. })
  301. },
  302. /**
  303. * 生命周期函数--监听页面隐藏
  304. */
  305. onHide() {
  306. },
  307. /**
  308. * 生命周期函数--监听页面卸载
  309. */
  310. onUnload() {
  311. },
  312. /**
  313. * 页面相关事件处理函数--监听用户下拉动作
  314. */
  315. onPullDownRefresh() {
  316. },
  317. /**
  318. * 页面上拉触底事件的处理函数
  319. */
  320. onReachBottom() {
  321. },
  322. /**
  323. * 用户点击右上角分享
  324. */
  325. onShareAppMessage() {
  326. }
  327. })