目录
本组件用到了uni-ui的uni-popup弹窗组件
废话不多说直接上代码
代码分享
<template>
<view class="content-pop">
<!-- <uni-popup ref="popup" type="bottom"> -->
<view class="pop-cont" :class="showCont?'open':''">
<view class="zdp-pop">
<view class="top-cont">
<view class="close-cont" @click="close(1)">
取消
</view>
<!-- 可以自定义显示 -->
<slot name="text" :scope="{range,zdpdate}">
<view class="text-info">
请选择时间
<view>
{
{selInfo}}
</view>
</view>
</slot>
<view class="save-cont" @click="close(2)">
确认
</view>
</view>
<view class="tabs-cont">
<view class="tab-list" v-for="item in tabs" :class="item.value==activeIdx?'active':''"
@click="handleTabs(item.value)">
{
{item.label}}
</view>
</view>
<view class="date-cont">
<picker-view :value="value" @change="handleChange" class="picker-view">
<picker-view-column v-for="obj in SelArr">
<view class="item" v-for="(item,index) in obj.child" :key="index">
{
{item<10?'0'+item:item}}{
{obj.value}}
</view>
</picker-view-column>
</picker-view>
</view>
</view>
</view>
<!-- </uni-popup> -->
</view>
</template>
<script>
import {
whichWeek
} from '../../utils/getWeek.js'
import {
getMonthStartEnd
} from '../../utils/getMonth.js'
import {
getQuarterDates
} from '../../utils/getQuarter.js'
export default {
props: {
type: {
type: String,
default: '日',
validator(value, props) {
return ['日', '月', '周', '年', '季'].includes(value)
}
},
time: {
type: String, //'2024-1-1' '2024-2' '2024-2' '2024-2' '2024
}
},
data() {
return {
showCont: false,
tabs: [{
label: '日',
value: '日'
},
{
label: '周',
value: '周',
},
{
label: '月',
value: '月',
},
{
label: '季',
value: '季',
},
{
label: '年',
value: '年',
}
],
activeIdx: '日',
value: [], //选择的值,要设置默认值
dateArr: [],
day: 18,
week: 1,
month: 1, //
quarter: 2,
years: 24,
SelArr: [],
range: '',
zdpdate: ''
}
},
computed: {
selInfo() {
let str = ''
let {
activeIdx,
years,
day,
month,
week,
quarter
} = this
if (activeIdx == '日') {
str = `20${years}年 ${month<10?'0'+month:month}月 ${day<10?'0'+day:day}日`
} else if (activeIdx == '周') {
str = `20${years}年 第${week}周`
} else if (activeIdx == '月') {
str = `20${years}年 ${month<10?'0'+month:month}月`
} else if (activeIdx == '季') {
str = `20${years}年 ${quarter}季`
} else if (activeIdx == '年') {
str = `20${years}年`
}
return str
}
},
created() {
},
methods: {
//
handleProps() {
let arr = []
arr = this.time.split('-')
if (this.type == '日') {
this.month = arr[1] - 0
this.day = arr[2] - 0
} else if (this.type == '周') {
this.week = arr[1] - 0
} else if (this.type == '季') {
this.quarter = arr[1] - 0
} else if (this.type == '月') {
this.m