123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- const { default: api } = require("../../js/api");
- // pages/historyOrderAfter/historyOrderAfter.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- date:'',
- startDate:'',
- endDate:'',
- orders:[
- {
- buttonMessage1:'',
- buttonColor1:'',
- buttonMessage2:'',
- buttonColor2:'',
- order:{
- oilName:"92#",
- nozzleNum:'5',
- volume:'20.0',
- amount:'46.8',
- date:'2024-11-24',
- time:'09:08',
- status:'已授权'
- },
- statusColor:'#838282',
- countdown:'60'
- },
- {
- buttonMessage1:'取消订单',
- buttonColor1:'#838282',
- buttonMessage2:'重新授权',
- buttonColor2:'#d17067',
- order:{
- oilName:"0#",
- nozzleNum:'6',
- volume:'21.0',
- amount:'42.8',
- date:'2024-11-24',
- time:'09:08',
- status:'已失效'
- },
- statusColor:'#838282',
- countdown:''
- },
- {
- buttonMessage1:'',
- buttonColor1:'',
- buttonMessage2:'重新支付',
- buttonColor2:'#d17067',
- order:{
- oilName:"0#",
- nozzleNum:'6',
- volume:'21.0',
- amount:'42.8',
- date:'2024-11-24',
- time:'09:08',
- status:'支付失败'
- },
- statusColor:'#d17067',
- countdown:''
- },
- {
- buttonMessage1:'',
- buttonColor1:'',
- buttonMessage2:'重新支付',
- buttonColor2:'#d17067',
- order:{
- oilName:"0#",
- nozzleNum:'6',
- volume:'21.0',
- amount:'42.8',
- date:'2024-11-24',
- time:'09:08',
- status:'支付失败'
- },
- statusColor:'#d17067',
- countdown:''
- },
- {
- buttonMessage1:'',
- buttonColor1:'',
- buttonMessage2:'重新支付',
- buttonColor2:'#d17067',
- order:{
- oilName:"0#",
- nozzleNum:'6',
- volume:'21.0',
- amount:'42.8',
- date:'2024-11-24',
- time:'09:08',
- status:'支付失败'
- },
- statusColor:'#d17067',
- countdown:''
- },
- {
- buttonMessage1:'',
- buttonColor1:'',
- buttonMessage2:'重新支付',
- buttonColor2:'#d17067',
- order:{
- oilName:"0#",
- nozzleNum:'6',
- volume:'21.0',
- amount:'42.8',
- date:'2024-11-24',
- time:'09:08',
- status:'支付失败'
- },
- statusColor:'#d17067',
- countdown:''
- },
- ]
- },
- /** 获取当前日期 */
- getNowDate(){
- const date = new Date(); // 获取当前日期
- const year = date.getFullYear(); // 获取年份
- const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份,补零
- const day = String(date.getDate()).padStart(2, '0'); // 获取日期,补零
-
- return `${year}-${month}-${day}`; // 拼接成 yyyy-MM-dd 格式
- },
- /** 获取上个月日期 */
- getLastMouthDate(){
- const currentDate = new Date(); // 获取当前日期
- const year = currentDate.getFullYear(); // 当前年份
- const month = currentDate.getMonth(); // 当前月份(0-11)
- const day = currentDate.getDate(); // 当前日期
- // 计算一个月前的日期
- const oneMonthAgoDate = new Date(year, month - 1, day);
- // 处理跨年问题(如果当前月份是 1 月,month - 1 会是 0,即上一年的 12 月)
- // 无需额外处理,Date 对象会自动处理
- // 格式化日期为 YYYY-MM-DD
- const formattedDate = `${oneMonthAgoDate.getFullYear()}-${String(oneMonthAgoDate.getMonth() + 1).padStart(2, '0')}-${String(oneMonthAgoDate.getDate()).padStart(2, '0')}`;
- return formattedDate;
- },
- /** 计算倒计时,倒计时结束后发起取消授权 */
- startCountdow(){
- this.timer = setInterval(() => {
- const countDownZeroOrders = []
- const orders = this.data.orders.map(order => {
- if(order.countdown && order.countdown != '0') {
- const currentCountDown = (Number(order.countdown) - 1);
- order.countdown = currentCountDown.toString();
- if(currentCountDown <= 0) countDownZeroOrders.push(order)
- }
- return order
- })
- this.setData({
- orders:orders
- })
- this.toUnAnthorization(countDownZeroOrders)
- },1000);
- },
- /** 结束倒计时 */
- endCountDown(){
- if(this.timer) {
- clearInterval(this.timer)
- this.timer = null
- }
- },
- /** 发送取消授权 */
- toUnAnthorization(orders) {
- console.log(orders)
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- const today = this.getNowDate();
- const lastMouthDay = this.getLastMouthDate();
- this.setData({
- date:today,
- startDate:today,
- endDate:lastMouthDay
- });
- // this.startCountdow();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- this.endCountDown()
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
- /** 日期选择器选择时间 */
- bindDateChange(date) {
- this.setData({
- date: date.detail.value
- });
- console.log(date)
- },
- /** 组件按钮一点击事件 */
- onOrderButtonClick1(event){
- console.log(event)
- },
- /** 组件按钮二点击事件 */
- onOrderButtonClick2(event){
- console.log(event)
- },
- /** 获取订单 */
- getOrder(){
- api.request_GetMiniProgramTransactionsUnpaidQuery(null).then(res => {
- console.log("未支付订单",res)
- }).catch(err => {
- console.log("获取未支付订单失败",err)
- })
- }
- })
|