// components/tail_tip/index.js import { getDate, getWaterDrop, formatTime } from '../../utils/index/index' const app = getApp() Component({ /** * 组件的属性列表 */ properties: {}, props: { onFinish: { type: Function, value: () => {} }, showTitText: true, //是否显示“操作时间" countdown: 0, // 倒计时时间 urlPath: '../../', //图片路径 titleText: '', // 右侧展示页面小标题 isHomePage: false, // 是否是首页 }, /** * 组件的初始数据 */ data: { newDate: '', //现在时间 remainingTime: '', //倒计时剩余时间 timer: null, timer2: null, count: 0, hasNetworkType: false, cusModalObj: { visible: false, showCloseBtn: true, daysDifference: 0 }, }, didMount() { let showTitText = this.props.showTitText let remainingTime = showTitText ? '操作时间 ' + this.props.countdown + ' 秒' : this.props.countdown + ' 秒' this.setData({ newDate: getDate(), remainingTime, }) this.data.timer2 && clearInterval(this.data.timer2) let _this = this this.data.timer2 = setInterval(() => { // 获取当前时间 const currentHour = (new Date()).getHours(); if (currentHour == 24) { app.globalData.expirationDateTodayOpen = false; } _this.checkExpiryDate() this.setData({ newDate: getDate() }) this.getNetworkType() }, 1000); this.getNetworkType() this.startCountdown() }, /** * 组件的方法列表 */ methods: { checkExpiryDate() { let expiryDate = app.globalData.snDisposition.expirationDate; // let expiryDate = '2025-01-01'; // let expiryDate = '2024-12-26'; if (expiryDate && expiryDate !== '') { let { cusModalObj } = this.data const now = new Date(); // 计算当前日期 const currentDate = new Date(formatTime(now,'YYYY-MM-DD 00:00:00')); // 计算到期日期 const expiry = new Date(formatTime(expiryDate,'YYYY-MM-DD 00:00:00')); const timeDifference = expiry - currentDate; // 将毫秒转换为天数 const daysDifference = Math.ceil(timeDifference / (1000 * 3600 * 24)); console.log(`弹窗次数:${app.globalData.expirationDateTodayOpen}`, daysDifference); // 检查是否在30天内 if (!app.globalData.expirationDateTodayOpen && !cusModalObj.visible && daysDifference <= 30 && daysDifference > 0) { console.log(`您的FKJ账户将在 ${daysDifference} 天后到期:${expiry.toLocaleDateString()}`); app.globalData.expirationDateTodayOpen = true; this.setData({ 'cusModalObj.visible': true, 'cusModalObj.showCloseBtn': true, 'cusModalObj.daysDifference': daysDifference, }) return; } // 如果当前日期超过到期日期 if (!cusModalObj.visible && currentDate.getTime() >= expiry.getTime()) { console.log(`您的FKJ账户已到期。${expiry.toLocaleDateString()}`); this.setData({ 'cusModalObj.visible': true, 'cusModalObj.showCloseBtn': false, }) } } }, onOk() { this.setData({ 'cusModalObj.visible': false }) }, // 倒计时 startCountdown() { let that = this let { count } = that.data count = that.props.countdown let showTitText = that.props.showTitText if (count && count > 0) { that.data.timer && clearInterval(that.data.timer) that.data.timer = setInterval(() => { count-- let remainingTime = showTitText ? '操作时间 ' + count + ' 秒' : count + ' 秒' that.setData({ remainingTime }) if (count <= 0) { that.data.timer && clearInterval(that.data.timer) that.props.onFinish('finish') // 倒计时结束,清除定时器 } }, 1000) // 每秒更新一次倒计时数字 } }, // 网络状态 getNetworkType() { my.getNetworkType({ success: (res) => { if (res.networkType == 'NOTREACHABLE') { this.setData({ hasNetworkType: false, }) my.showToast({ content: '网络状态异常', duration: 2000 }); } else { this.setData({ hasNetworkType: true, }) } }, fail: (error) => { console.log(error) this.setData({ hasNetworkType: false, }) }, }) }, // 长按logo进入设置 goto() { this.data.timer && clearInterval(this.data.timer) getWaterDrop() if (this.props.isHomePage) { this.clearIntervalAll() my.reLaunch({ url: '/pages/settings/login/index' }); } }, clearIntervalAll() { this.data.timer && clearInterval(this.data.timer) this.data.timer2 && clearInterval(this.data.timer2) }, onClose() { console.log('onclose') this.clearIntervalAll(); my.reLaunch({ url: '/pages/home/index' }); } }, didUnmount() { this.clearIntervalAll(); }, onUnload() { this.clearIntervalAll(); }, observers: {} })