picker-view.uvue 3.1 KB
Newer Older
Y
yurj26 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<template>
    <view>
        <page-head :title="title"></page-head>
        <view class="uni-padding-wrap">
            <view class="uni-title">
                日期:{{year}}年{{month}}月{{day}}日
            </view>
        </view>
        <picker-view class="picker-view" :indicator-style="indicatorStyle" :value="value" @change="bindChange"
            :mask-top-style="maskTopStyle" :mask-bottom-style="maskBottomStyle">
            <picker-view-column class="picker-view-column">
                <view class="item" v-for="(item,index) in years" :key="index"><text class="text">{{item}}年</text></view>
            </picker-view-column>
            <picker-view-column class="picker-view-column">
                <view class="item" v-for="(item,index) in months" :key="index"><text class="text">{{item}}月</text>
                </view>
            </picker-view-column>
            <picker-view-column class="picker-view-column">
                <view class="item" v-for="(item,index) in days" :key="index"><text class="text">{{item}}日</text></view>
            </picker-view-column>
        </picker-view>
    </view>
</template>

Y
yurj26 已提交
25
<script lang="uts">
Y
yurj26 已提交
26 27
    export default {
        data() {
Y
yurj26 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
            const date = new Date()
            const _years : number[] = []
            const _year = date.getFullYear()
            const _months : number[] = []
            const _month : number = date.getMonth() + 1
            const _days : number[] = []
            const _day = date.getDate()
            for (let i = 2000; i <= _year; i++) {
                _years.push(i)
            }
            for (let i = 1; i <= 12; i++) {
                _months.push(i)
            }
            for (let i = 1; i <= 31; i++) {
                _days.push(i)
            }
Y
yurj26 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
            return {
                title: 'picker-view',
                years: _years as number[],
                year: _year as number,
                months: _months as number[],
                month: _month as number,
                days: _days as number[],
                day: _day as number,
                value: [_year - 2000, _month - 1, _day - 1] as number[],
                result: [] as number[],
                indicatorStyle: 'height: 50px;',
                maskTopStyle: '',
                maskBottomStyle: ''
            }
        },
        methods: {
张磊 已提交
60 61 62
			clickView() {
				
			},
Y
yurj26 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
            bindChange(e : PickerViewChangeEvent) {
                const val = e.detail.value
                this.result = val
                this.year = this.years[val[0]]
                this.month = this.months[val[1]]
                this.day = this.days[val[2]]
            },
            setValue() {
                this.value = [0, 0, 0] as number[]
            },
            setValue1() {
                this.value = [10, 10, 10] as number[]
            },
        }
    }
</script>

<style>
    .picker-view {
        width: 100%;
Y
yurj26 已提交
83 84
        height: 320px;
        margin-top: 10px;
Y
yurj26 已提交
85 86 87 88 89 90 91 92 93 94 95
    }

    .item {
        height: 50px;
    }

    .text {
        line-height: 50px;
        text-align: center;
    }
</style>