li-guang
2021-01-05 01b55d7e82c3b13554a412e9c5be0fc96a4906a3
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
    <uni-popup ref="popup" type="top">
        <view class="popup-container" :style="{'height':windowHeight}">
            <view class="popup-content">
                <view class="input-group-row">
                    <text class="label">统计单位</text>
                    <view class="right-text">
                        <picker mode="selector" :range="unitList" @change="_unitChange">
                            <view>
                                <text>{{unit}}</text>
                                <text class="iconfont iconjiantouarrow486 gray"></text>
                            </view>
                        </picker>
                    </view>
                </view>
                <view class="input-group-row">
                    <text class="label">开始时间</text>
                    <view class="right-text" @click="_showbeginTime">
                        <text :class="beginTime?'':'gray'">{{beginTime || '请选择开始时间'}}</text>
                    </view>
                </view>
                <view class="input-group-row">
                    <text class="label">结束时间</text>
                    <view class="right-text" @click="_showEndTime">
                        <text :class="endTime?'':'gray'">{{endTime || '请选择开始时间'}}</text>
                    </view>
                </view>
            </view>
            <view class="btn-group">
                <text class="btn" @click="_reset">取消</text>
                <text class="btn btn-blue" @click="_confirm">确认</text>
            </view>
            <date-time-picker ref='beginTime' :type='datePickerType' toolBarTitle="" :dateString="beginTime" @change='_beginTimeChange'></date-time-picker>
            <date-time-picker ref='endTime' :startDate="startDate" :type='datePickerType' toolBarTitle="" :dateString="endTime" @change='_endTimeChange'></date-time-picker>
        </view>
    </uni-popup>
</template>
 
<script>
    import uniPopup from '../../../components/uni-popup/uni-popup'
    import DateTimePicker from '../../../components/bory-dateTimePicker/bory-dateTimePicker.vue'
    export default {
        components: {
            uniPopup,
            DateTimePicker
        },
        props:{
            isShow: {
                default: false
            }
        },
        watch:{
            isShow(newVal){
                if(newVal){
                    this.$refs.popup.open()
                }else{
                    this.$refs.popup.close()
                }
            }
        },
        data(){
            return {
                windowHeight: "200px",
                unit: '日',
                unitList: ['年', '月', '日'],
                beginTime: '',
                endTime: ''
            }
        },
        computed:{
            datePickerType(){
                if(this.unit==='年'){
                    return 'year'
                } else if(this.unit==='月'){
                    return 'year-month'
                } else{
                    return 'date'
                }
            },
            startDate(){
                return this.beginTime
            }
        },
        created() {
            this.beginTime = this.$utils.formmatTime('YY-mm')+'-01';
            this.endTime = this.$utils.formmatTime('YY-mm-dd')
        },
        mounted() {
            uni.getSystemInfo({
                success: (res) => {
                    this.windowHeight = res.windowHeight+"px";
            } })
        },
        methods:{
            _unitChange(e){
                let val = this.unitList[e.detail.value];
                if(this.unit == val){
                    return
                }
                this.unit = val;
                if(this.unit == '年'){
                    this.beginTime = '';
                    this.endTime = this.$utils.formmatTime('YY');
                } else if(this.unit == '月'){
                    this.beginTime = '';
                    this.endTime = this.$utils.formmatTime('YY-mm')
                } else {
                    this.beginTime = this.$utils.formmatTime('YY-mm')+'-01';
                    this.endTime = this.$utils.formmatTime('YY-mm-dd')
                }
            },
            _showbeginTime () {
                this.$refs['beginTime'].show();
            },
            _showEndTime(){
                this.$refs['endTime'].show();
            },
            _beginTimeChange(val){
                this.beginTime = val;
            },
            _endTimeChange(val){
                this.endTime = val;
            },
            _reset(){
                this.$refs.popup.close()
            },
            _confirm(){
                if(!this.beginTime){
                    this.$toast.info('请选择开始时间');
                    return;
                }
                if(!this.endTime){
                    this.$toast.info('请选择结束时间');
                    return;
                }
                this.$refs.popup.close();
                this.$emit('change', {
                    beginTime: this.beginTime,
                    endTime: this.endTime,
                    unit: this.unit
                })
            }
        }
    }
</script>
 
<style>
    .popup-container{
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        width: 100%;
        background: #FFFFFF;
    }
    .input-group-row{
        padding-left: 10px;
        padding-right: 10px;
    }
    .btn-group{
        display: flex;
        border-top: 1px solid #EDEAF4;
        margin-top: 20px;
    }
    .btn-group .btn{
        flex: 1;
        line-height: 44px;
        text-align: center;
        font-size: 15px;
        color: #666666;
    }
    .btn-group .btn-blue{
        background: #518EFF;
        color: #FFFFFF;
    }
</style>