WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2021-04-01 d7cf84bd603bcab89d44e9942348f017665cb756
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
 * CDateRangeAction - 选择日期范围操作
 * @author Tevin
 */
 
<template>
    <view class="c-date-range-action">
        <view
            class="c-date-range-slot"
            @tap="evt => handleOpen()"
        >
            <slot />
        </view>
        <view
            class="c-data-range-float"
            ref="floadLayer"
        >
            <AtDrawer
                class="c-data-range-drawer"
                ref="floatDrawer"
                mask
                :show="drawerShow"
                :onClose="evt => drawerShow=false"
            >
                <view class="title">请选择日期</view>
                <view class="date">
                    <picker
                        mode='date'
                        :value="startDate"
                        @change="evt => handleStartDateChange(evt.detail.value)"
                    >
                        <view class="item">
                            <view class="label">开始日期</view>
                            <view :class="startDate?'filled':'empty'">
                                {{ startDate?startDate:'请选择开始日期' }}
                            </view>
                            <view class="at-icon at-icon-chevron-right" />
                        </view>
                    </picker>
                    <picker
                        mode='date'
                        :value="endDate"
                        @change="evt => handleEndDateChange(evt.detail.value)"
                    >
                        <view class="item">
                            <view class="label">结束日期</view>
                            <view :class="endDate?'filled':'empty'">
                                {{ endDate?endDate:'请选择结束日期' }}
                            </view>
                            <view class="at-icon at-icon-chevron-right" />
                        </view>
                    </picker>
                </view>
                <AtButton
                    class="btn"
                    type="primary"
                    full
                    :circle="false"
                    :onClick="evt => handleFinish()"
                >确定</AtButton>
            </AtDrawer>
        </view>
    </view>
</template>
 
<script>
import Taro from '@tarojs/taro';
import { $ } from '@tarojs/extend';
import { AtDrawer, AtButton } from 'taro-ui-vue';
import './cDateRangeAction.scss';
 
export default {
    name: 'CDateRangeAction',
    components: {
        AtDrawer,
        AtButton,
    },
    props: {
        value: null,
        onChange: Function,
    },
    data() {
        return {
            drawerShow: false,
            startDate: '',
            endDate: '',
        };
    },
    computed: {},
    methods: {
        handleOpen() {
            this.drawerShow = true;
            const curDates = (this.value || ',').split(',');
            this.startDate = curDates[0];
            this.endDate = curDates[1];
        },
        handleStartDateChange(date) {
            this.startDate = date;
        },
        handleEndDateChange(date) {
            this.endDate = date;
        },
        handleFinish() {
            this.drawerShow = false;
            if (!this.startDate && !this.endDate) {
                this.onChange();
            } else {
                this.onChange(this.startDate + ',' + this.endDate);
            }
        },
    },
    mounted() {
        const $cFilter = $(this.$refs.floadLayer).parents('.c-filter');
        if ($cFilter.length > 0) {
            $cFilter.eq(0).after(this.$refs.floadLayer);
        }
    },
};
</script>