historyOrder.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. const { default: api } = require("../../js/api");
  2. // pages/historyOrderAfter/historyOrderAfter.js
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. date:'',
  9. startDate:'',
  10. endDate:'',
  11. orders:[
  12. {
  13. order:{
  14. nozzle:5,
  15. status:'已授权',
  16. statusColor:'#bbe06e',
  17. oilName:"92#",
  18. volume:20.0,
  19. amount:46.8,
  20. payAmount:46.8,
  21. discount:0.00,
  22. time:'2024-11-24 09:08',
  23. },
  24. bottonText2:'请尽快提枪'
  25. },
  26. ]
  27. },
  28. /** 获取当前日期 */
  29. getNowDate(){
  30. const date = new Date(); // 获取当前日期
  31. const year = date.getFullYear(); // 获取年份
  32. const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份,补零
  33. const day = String(date.getDate()).padStart(2, '0'); // 获取日期,补零
  34. return `${year}-${month}-${day}`; // 拼接成 yyyy-MM-dd 格式
  35. },
  36. /** 获取上个月日期 */
  37. getLastMouthDate(){
  38. const currentDate = new Date(); // 获取当前日期
  39. const year = currentDate.getFullYear(); // 当前年份
  40. const month = currentDate.getMonth(); // 当前月份(0-11)
  41. const day = currentDate.getDate(); // 当前日期
  42. // 计算一个月前的日期
  43. const oneMonthAgoDate = new Date(year, month - 1, day);
  44. // 处理跨年问题(如果当前月份是 1 月,month - 1 会是 0,即上一年的 12 月)
  45. // 无需额外处理,Date 对象会自动处理
  46. // 格式化日期为 YYYY-MM-DD
  47. const formattedDate = `${oneMonthAgoDate.getFullYear()}-${String(oneMonthAgoDate.getMonth() + 1).padStart(2, '0')}-${String(oneMonthAgoDate.getDate()).padStart(2, '0')}`;
  48. return formattedDate;
  49. },
  50. /** 计算倒计时,倒计时结束后发起取消授权 */
  51. startCountdow(){
  52. this.timer = setInterval(() => {
  53. const countDownZeroOrders = []
  54. const orders = this.data.orders.map(order => {
  55. if(order.countdown && order.countdown != '0') {
  56. const currentCountDown = (Number(order.countdown) - 1);
  57. order.countdown = currentCountDown.toString();
  58. if(currentCountDown <= 0) countDownZeroOrders.push(order)
  59. }
  60. return order
  61. })
  62. this.setData({
  63. orders:orders
  64. })
  65. this.toUnAnthorization(countDownZeroOrders)
  66. },1000);
  67. },
  68. /** 结束倒计时 */
  69. endCountDown(){
  70. if(this.timer) {
  71. clearInterval(this.timer)
  72. this.timer = null
  73. }
  74. },
  75. /** 发送取消授权 */
  76. toUnAnthorization(orders) {
  77. console.log(orders)
  78. },
  79. /**
  80. * 生命周期函数--监听页面加载
  81. */
  82. onLoad(options) {
  83. const today = this.getNowDate();
  84. const lastMouthDay = this.getLastMouthDate();
  85. this.setData({
  86. date:today,
  87. startDate:today,
  88. endDate:lastMouthDay
  89. });
  90. // this.startCountdow();
  91. },
  92. /**
  93. * 生命周期函数--监听页面初次渲染完成
  94. */
  95. onReady() {
  96. },
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow() {
  101. },
  102. /**
  103. * 生命周期函数--监听页面隐藏
  104. */
  105. onHide() {
  106. },
  107. /**
  108. * 生命周期函数--监听页面卸载
  109. */
  110. onUnload() {
  111. this.endCountDown()
  112. },
  113. /**
  114. * 页面相关事件处理函数--监听用户下拉动作
  115. */
  116. onPullDownRefresh() {
  117. },
  118. /**
  119. * 页面上拉触底事件的处理函数
  120. */
  121. onReachBottom() {
  122. },
  123. /**
  124. * 用户点击右上角分享
  125. */
  126. onShareAppMessage() {
  127. },
  128. /** 日期选择器选择时间 */
  129. bindDateChange(date) {
  130. this.setData({
  131. date: date.detail.value
  132. });
  133. console.log(date)
  134. },
  135. /** 组件按钮一点击事件 */
  136. onOrderButtonClick1(event){
  137. console.log(event)
  138. },
  139. /** 组件按钮二点击事件 */
  140. onOrderButtonClick2(event){
  141. console.log(event)
  142. },
  143. /** 获取订单 */
  144. getOrder(){
  145. api.request_GetMiniProgramTransactionsUnpaidQuery(null).then(res => {
  146. console.log("未支付订单",res)
  147. }).catch(err => {
  148. console.log("获取未支付订单失败",err)
  149. })
  150. }
  151. })