reservationEdit.js 10 KB

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