<template> <view class="page"> <u-navbar title="房租到期提醒" :border-bottom="false" :background="bgc" title-color='#2E4975' title-size='36' height='36'></u-navbar> <view class="card"> <view class="tip"> <view class="txt"> 房租到期提醒 </view> <u-switch v-model="checked" active-color="#8883F0"></u-switch> </view> <view class="tip"> <view class="tit"> 开启后,发送通知到微信公众号 </view> </view> <view class="tip" style="margin-top: 62rpx;"> <view class="txt"> 提醒方式 </view> <view class="switch"> <view class="cont" :class="tipindex==0?'act':''" @click="tipindex=0"> 单次 </view> <view class="cont " :class="tipindex==1?'act':''" @click="tipindex=1"> 每月 </view> </view> </view> <view class="tip" style="margin-top: 70rpx;"> <view class="txt"> 提醒日期 </view> <view class="txt"> 请选择 <view class="iconfont icon-xiangyou1" style="color: #C4C4C4;"></view> </view> </view> <u-picker mode="time" v-model="show" :params="params" :default-time="defaultTime" start-year='2024'></u-picker> </view> </view> </template> <script> export default { data() { return { bgc: { backgroundColor: "#F7FAFE", }, checked: false, tipindex: 0, show: true, params: { year: true, month: true, day: true, hour: false, minute: false, second: false }, times: '2024-1-26', defaultTime:'' } }, onReady() { this.onPickerReady() }, methods: { onPickerReady() { // 在onReady生命周期中设置默认时间为当前时间 this.setDefaultTime(); }, setDefaultTime() { // 获取当前时间 const currentTime = new Date(); // 格式化时间,以符合 u-picker 组件的要求 const formattedTime = this.formatTime(currentTime); // 设置默认时间 this.defaultTime = formattedTime; console.log(this.defaultTime, 'defaultTime'); }, formatTime(time) { // 实现一个函数,以符合所需的日期格式(年月日) const year = time.getFullYear(); const month = (time.getMonth() + 1).toString().padStart(2, '0'); const day = time.getDate().toString().padStart(2, '0'); return `${year}-${month}-${day}`; }, } } </script> <style lang="scss"> page { background-color: #F7FAFE; } .page { width: 750rpx; .card { padding: 62rpx 38rpx; margin: 50rpx auto 0; width: 654rpx; height: 390rpx; background: #FFFFFF; border-radius: 30rpx; box-shadow: 0rpx 16rpx 40rpx 0rpx rgba(42, 130, 228, 0.1); .tip { display: flex; flex-wrap: nowrap; justify-content: space-between; align-items: center; .txt { display: flex; flex-wrap: nowrap; align-items: center; font-size: 32rpx; font-family: HarmonyOS Sans SC, HarmonyOS Sans SC; font-weight: 400; color: #000000; } .tit { font-size: 24rpx; font-family: HarmonyOS Sans SC, HarmonyOS Sans SC; font-weight: 400; color: #808080; } .switch { display: flex; flex-wrap: nowrap; align-items: center; justify-content: space-between; padding: 0 10rpx; width: 132rpx; height: 48rpx; background: #E5E5E5; border-radius: 15rpx; .cont { display: flex; flex-wrap: nowrap; align-items: center; justify-content: center; width: 60rpx; height: 42rpx; font-size: 20rpx; font-family: HarmonyOS Sans SC, HarmonyOS Sans SC; font-weight: 400; color: #383838; } .act { border-radius: 10rpx; width: 60rpx; height: 42rpx; background: #FFFFFF; } } } } } </style>