reservation.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. // pages/reservation/reservation.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. timeList:[],
  8. chargStationId:'',
  9. chargPileName:'加载中',
  10. chargPileId:'',
  11. chargPileIdId:'',
  12. userId:'',
  13. chargStationName:'',
  14. earliestReservTime:'',
  15. advanceReservDays:'',
  16. minReservTime:'',
  17. maxReservTime:'',
  18. maxEarlyExerciseTime:'',
  19. maxReservOvertime:'',
  20. current:[],
  21. second:[],
  22. three:[],
  23. four:[],
  24. dayIndex:1,
  25. dayFlag1:'',
  26. dayFlag2:'',
  27. dayFlag3:'',
  28. dayFlag4:'',
  29. reservationBtn: false,
  30. breakPunishCount: 0
  31. },
  32. goReservation(){
  33. let {
  34. chargStationId,
  35. chargPileName,
  36. chargPileId,
  37. chargPileIdId,
  38. chargStationName,
  39. userId,
  40. earliestReservTime,
  41. advanceReservDays,
  42. minReservTime,
  43. maxReservTime,
  44. maxEarlyExerciseTime,
  45. maxReservOvertime
  46. } = this.data;
  47. let url = `/pages/reservation/reservationEdit?chargStationId=` + chargStationId + `&chargPileName=` + chargPileName +
  48. `&chargPileId=` + chargPileId +
  49. `&chargPileIdId=` + chargPileIdId +
  50. "&chargStationName=" + chargStationName +
  51. "&earliestReservTime=" + earliestReservTime +
  52. "&advanceReservDays=" + advanceReservDays+
  53. "&minReservTime=" + minReservTime +
  54. "&maxReservTime=" + maxReservTime +
  55. "&maxEarlyExerciseTime=" + maxEarlyExerciseTime +
  56. "&maxReservOvertime=" + maxReservOvertime +
  57. "&userId=" + userId;
  58. wx.navigateTo({
  59. url
  60. });
  61. },
  62. switchDay(e){
  63. let dayIndex = e.currentTarget.dataset.idx;
  64. let timeList = [];
  65. if(dayIndex==1){
  66. timeList = this.data.current;
  67. }else if(dayIndex==2){
  68. timeList = this.data.second;
  69. }else if(dayIndex==3){
  70. timeList = this.data.three;
  71. }else if(dayIndex==4){
  72. timeList = this.data.four;
  73. };
  74. this.setData({
  75. dayIndex,
  76. timeList
  77. })
  78. },
  79. /**
  80. * 生命周期函数--监听页面加载
  81. */
  82. onLoad(options) {
  83. let that = this;
  84. let {
  85. chargStationId,
  86. chargPileName,
  87. chargPileId,
  88. chargPileIdId,
  89. userId,
  90. chargStationName
  91. } = options;
  92. this.setData({
  93. chargStationId,
  94. chargPileName,
  95. chargPileId,
  96. chargPileIdId,
  97. userId,
  98. chargStationName
  99. }
  100. )
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady() {
  106. },
  107. /**
  108. * 生命周期函数--监听页面显示
  109. */
  110. onShow() {
  111. let that = this;
  112. let {
  113. chargStationId,
  114. chargPileName,
  115. chargPileId,
  116. chargPileIdId,
  117. userId,
  118. chargStationName
  119. } = this.data;
  120. wx.request({
  121. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/ReservOrder?userId=' + userId + '&pileId=' + chargPileIdId + '&stationId=' + chargStationId + '&reservPileNo=' +chargPileId ,
  122. data: {
  123. },
  124. method: 'POST',
  125. success(res) {
  126. if(res?.data?.result?.reservationConfig){
  127. that.setData({
  128. reservationBtn: true
  129. })
  130. }
  131. let earliestReservTime = res?.data?.result?.reservationConfig?.earliestReservTime
  132. earliestReservTime = earliestReservTime?earliestReservTime:0;
  133. let advanceReservDays = res?.data?.result?.reservationConfig?.advanceReservDays
  134. advanceReservDays = advanceReservDays?advanceReservDays:0;
  135. let minReservTime = res?.data?.result?.reservationConfig?.minReservTime
  136. minReservTime = minReservTime?minReservTime:0;
  137. let maxReservTime = res?.data?.result?.reservationConfig?.maxReservTime
  138. maxReservTime = maxReservTime?maxReservTime:0;
  139. let maxEarlyExerciseTime = res?.data?.result?.reservationConfig?.maxEarlyExerciseTime
  140. maxEarlyExerciseTime = maxEarlyExerciseTime?maxEarlyExerciseTime:0;
  141. let maxReservOvertime = res?.data?.result?.reservationConfig?.maxReservOvertime
  142. maxReservOvertime = maxReservOvertime?maxReservOvertime:0;
  143. let breakPunishCount = res?.data?.result?.reservationConfig?.breakPunishCount
  144. breakPunishCount = breakPunishCount?breakPunishCount:0;
  145. let nowZero = new Date();
  146. nowZero.setMilliseconds(0)
  147. nowZero.setSeconds(0)
  148. nowZero.setMinutes(0)
  149. nowZero.setHours(0)
  150. let currentStart = new Date(nowZero)
  151. let currentEnd = new Date(nowZero.setDate(nowZero.getDate() + 1 ));
  152. let secondStart = new Date(currentEnd)
  153. let secondEnd = new Date(nowZero.setDate(nowZero.getDate() + 1 ));
  154. let threeStart = new Date(secondEnd)
  155. let threeEnd = new Date(nowZero.setDate(nowZero.getDate() + 1 ));
  156. let fourStart = new Date(threeEnd);
  157. let fourEnd = new Date(nowZero.setDate(nowZero.getDate() + 1 ));
  158. let current = res?.data?.result?.current;
  159. current.forEach(series => {
  160. series.starttime = series.reservChargeStartTime.substr(11,5);
  161. series.endtime = series.reservChargeEndTime.substr(11,5);
  162. let reservChargeStartTime = new Date(series.reservChargeStartTime);
  163. let reservChargeEndTime = new Date(series.reservChargeEndTime);
  164. if(currentStart > reservChargeStartTime){
  165. series.starttime = "(前日) " + series.starttime
  166. }
  167. if(currentEnd < reservChargeEndTime){
  168. series.endtime = series.endtime + " (次日)"
  169. }
  170. });
  171. current.sort((a,b)=>{
  172. return new Date(a.reservChargeStartTime) - new Date(b.reservChargeStartTime)
  173. })
  174. let second = res?.data?.result?.second;
  175. second.forEach(series => {
  176. series.starttime = series.reservChargeStartTime.substr(11,5);
  177. series.endtime = series.reservChargeEndTime.substr(11,5);
  178. let reservChargeStartTime = new Date(series.reservChargeStartTime);
  179. let reservChargeEndTime = new Date(series.reservChargeEndTime);
  180. if(secondStart > reservChargeStartTime){
  181. series.starttime = "(前日) " + series.starttime
  182. }
  183. if(secondEnd < reservChargeEndTime){
  184. series.endtime = series.endtime + " (次日)"
  185. }
  186. });
  187. second.sort((a,b)=>{
  188. return new Date(a.reservChargeStartTime) - new Date(b.reservChargeStartTime)
  189. })
  190. let three = res?.data?.result?.three;
  191. three.forEach(series => {
  192. series.starttime = series.reservChargeStartTime.substr(11,5);
  193. series.endtime = series.reservChargeEndTime.substr(11,5);
  194. let reservChargeStartTime = new Date(series.reservChargeStartTime);
  195. let reservChargeEndTime = new Date(series.reservChargeEndTime);
  196. if(threeStart > reservChargeStartTime){
  197. series.starttime = "(前日) " + series.starttime
  198. }
  199. if(threeEnd < reservChargeEndTime){
  200. series.endtime = series.endtime + " (次日)"
  201. }
  202. });
  203. three.sort((a,b)=>{
  204. return new Date(a.reservChargeStartTime) - new Date(b.reservChargeStartTime)
  205. })
  206. let four = res?.data?.result?.four;
  207. four.forEach(series => {
  208. series.starttime = series.reservChargeStartTime.substr(11,5);
  209. series.endtime = series.reservChargeEndTime.substr(11,5);
  210. let reservChargeStartTime = new Date(series.reservChargeStartTime);
  211. let reservChargeEndTime = new Date(series.reservChargeEndTime);
  212. if(fourStart > reservChargeStartTime){
  213. series.starttime = "(前日) " + series.starttime
  214. }
  215. if(fourEnd < reservChargeEndTime){
  216. series.endtime = series.endtime + " (次日)"
  217. }
  218. });
  219. four.sort((a,b)=>{
  220. return new Date(a.reservChargeStartTime) - new Date(b.reservChargeStartTime)
  221. })
  222. let now = new Date();
  223. let dayFlag1 = (now.getMonth() + 1) + "." + now.getDate()
  224. now = new Date(now.setDate(now.getDate() + 1));
  225. let dayFlag2 = (now.getMonth() + 1) + "." + now.getDate()
  226. now = new Date(now.setDate(now.getDate() + 1));
  227. let dayFlag3 = (now.getMonth() + 1) + "." + now.getDate()
  228. now = new Date(now.setDate(now.getDate() + 1));
  229. let dayFlag4 = (now.getMonth() + 1) + "." + now.getDate()
  230. that.setData({
  231. earliestReservTime,
  232. advanceReservDays,
  233. minReservTime,
  234. maxReservTime,
  235. maxEarlyExerciseTime,
  236. maxReservOvertime,
  237. breakPunishCount,
  238. current,
  239. second,
  240. three,
  241. four,
  242. timeList: current,
  243. dayFlag1,
  244. dayFlag2,
  245. dayFlag3,
  246. dayFlag4,
  247. dayIndex:1
  248. })
  249. }
  250. });
  251. },
  252. /**
  253. * 生命周期函数--监听页面隐藏
  254. */
  255. onHide() {
  256. },
  257. /**
  258. * 生命周期函数--监听页面卸载
  259. */
  260. onUnload() {
  261. },
  262. /**
  263. * 页面相关事件处理函数--监听用户下拉动作
  264. */
  265. onPullDownRefresh() {
  266. },
  267. /**
  268. * 页面上拉触底事件的处理函数
  269. */
  270. onReachBottom() {
  271. },
  272. /**
  273. * 用户点击右上角分享
  274. */
  275. onShareAppMessage() {
  276. }
  277. })