zhao_js
2024-01-03 4b251816b75d1ba5423f41370b9e43bed4493f90
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<!--
 * @Description: 时间选择
 * @Author: hjh
 * @Date: 2019-08-17 23:19:32
 * @LastEditors: hjh
 * @LastEditTime: 2019-08-19 09:27:18
 * @Sign: 扬眉剑出鞘
 -->
 
<template>
    <view>
        <picker class="time-picker" mode="multiSelector" @change="bindStartMultiPickerChange" @columnchange="bindMultiPickerColumnChange" :value="multiIndex" :range="multiArray">
            <slot name="pCon"></slot>
        </picker>
    </view>
</template>
 
<script>
export default {
    props: {
        sTime: {
            //开始小时
            type: [Number, String],
            default: '0'
        },
        cTime: {
            //结束小时
            type: [Number, String],
            default: '23'
        },
        timeNum: {
            //延迟小时
            type: [Number, String],
            default: '1'
        },
        interval: {
            //分钟间隔
            type: [Number, String],
            default: '1'
        },
        sDay: {
            //开始天数
            type: [Number, String],
            default: '0'
        },
        dayNum: {
            //预约天数
            type: [Number, String],
            default: '7'
        }
    },
    data() {
        return {
            sDayNum: 0,
            multiArray: [['今天', '明天', '3-2', '3-3', '3-4', '3-5'], [0, 1, 2, 3, 4, 5, 6], [0, 10, 20]],
            multiIndex: [0, 0, 0],
            multiSelector: ''
        };
    },
    beforeMount() {
        this.pickerTap();
    },
    methods: {
        timeFormat: function(num) {
            if (num < 10 && (num + '').length == 1) {
                return '0' + num;
            }
            return num;
        },
        pickerTap: function() {
            let date = new Date();
            let monthDay = [];
            let hours = [];
            let minute = [];
            this.sDayNum = this.sDay;
 
            // 时
            let date1 = new Date(date);
            let sT = +this.sTime;
            let eT = +this.cTime;
 
            if (sT <= eT) {
                let h = date1.getHours() < sT ? sT : date1.getHours();
                h = h + parseInt(this.timeNum);
                if (h > eT || this.sDayNum > 0) {
                    this.sDayNum = this.sDayNum <= 0 ? parseInt(this.sDay) + 1 : parseInt(this.sDay);
                    for (let i = sT; i <= eT; i++) {
                        hours.push(this.timeFormat(i) + '时');
                    }
                } else {
                    for (let i = h; i <= eT; i++) {
                        hours.push(this.timeFormat(i) + '时');
                    }
                }
            } else {
                let h = date1.getHours() < sT ? sT : date1.getHours();
                h = h + parseInt(this.timeNum);
                if ((h > eT && h < sT) || h > 23 || this.sDayNum > 0) {
                    this.sDayNum = this.sDayNum <= 0 ? parseInt(this.sDay) + 1 : parseInt(this.sDay);
                    for (let i = 0; i <= 23; i++) {
                        if (i < sT && i > eT) {
                        } else {
                            hours.push(this.timeFormat(i) + '时');
                        }
                    }
                } else {
                    for (let i = h; i <= 23; i++) {
                        if (i < sT && i > eT) {
                        } else {
                            hours.push(this.timeFormat(i) + '时');
                        }
                    }
                }
            }
 
            // 月-日
            for (let i = +this.sDayNum; i <= parseInt(this.sDayNum) + parseInt(this.dayNum); i++) {
                let date1 = new Date(date);
                date1.setDate(date.getDate() + i);
                let md = date1.getFullYear() + '-' + this.timeFormat(date1.getMonth() + 1) + '-' + this.timeFormat(date1.getDate());
                monthDay.push(md);
            }
 
            let inter = +this.interval < 60 ? +this.interval : 59;
            // 分
            for (let i = 0; i < 60; i += inter) {
                minute.push(i < 10 ? '0' + i + '分' : i + '分');
            }
 
            let data = {
                multiArray: this.multiArray,
                multiIndex: this.multiIndex
            };
 
            data.multiArray[0] = monthDay;
            data.multiArray[1] = hours;
            data.multiArray[2] = minute;
            this.multiArray = data.multiArray;
            this.multiIndex = data.multiIndex;
        },
        bindMultiPickerColumnChange(e) {
            this.multiIndex.splice(e.detail.column,1,e.detail.value)
            let hours = [];
            if (e.detail.column == 0 && e.detail.value == 0 && +this.sDayNum == 0) {
                let date = new Date();
                // 时
                let date1 = new Date(date);
                let sT = +this.sTime;
                let eT = +this.cTime;
 
                if (sT <= eT) {
                    let h = date1.getHours() < sT ? sT : date1.getHours();
                    h = h + parseInt(this.timeNum);
                    if (h > eT || this.sDayNum > 0) {
                        this.sDayNum = this.sDayNum <= 0 ? parseInt(this.sDay) + 1 : parseInt(this.sDay);
                        for (let i = sT; i <= eT; i++) {
                            hours.push(this.timeFormat(i) + '时');
                        }
                    } else {
                        for (let i = h; i <= eT; i++) {
                            hours.push(this.timeFormat(i) + '时');
                        }
                    }
                } else {
                    let h = date1.getHours() < sT ? sT : date1.getHours();
                    h = h + parseInt(this.timeNum);
                    if ((h > eT && h < sT) || h > 23 || this.sDayNum > 0) {
                        this.sDayNum = this.sDayNum <= 0 ? parseInt(this.sDay) + 1 : parseInt(this.sDay);
                        for (let i = 0; i <= 23; i++) {
                            if (i < sT && i > eT) {
                            } else {
                                hours.push(this.timeFormat(i) + '时');
                            }
                        }
                    } else {
                        for (let i = h; i <= 23; i++) {
                            if (i < sT && i > eT) {
                            } else {
                                hours.push(this.timeFormat(i) + '时');
                            }
                        }
                    }
                }
                this.multiArray.splice(1,1,hours)
                
            } else if (e.detail.column == 0 && e.detail.value != 0) {
                let sT = +this.sTime;
                let eT = +this.cTime;
 
                if (sT <= eT) {
                    for (let i = sT; i <= eT; i++) {
                        hours.push(this.timeFormat(i) + '时');
                    }
                } else {
                    for (let i = 0; i <= 23; i++) {
                        if (i < sT && i > eT) {
                        } else {
                            hours.push(this.timeFormat(i) + '时');
                        }
                    }
                }
                this.multiArray.splice(1,1,hours)
            }
        },
        bindStartMultiPickerChange(e) {
            console.log(e);
            this.multiIndex = e.detail.value;
            let da = this.multiArray;
            let di = e.detail.value;
 
            let caseDate = da[0][di[0]] + ' ' + da[1][di[1]].replace('时', ':') + this.timeFormat(da[2][di[2]].replace('分', '')) + ':00';
 
            let appointTime = new Date(caseDate.replace(/-/g,'/')).getTime() / 1000;
            if (appointTime < new Date().getTime() / 1000) {
                uni.showToast({
                    title: '不能选择过去时间',
                    icon: 'none'
                });
                return false;
            }
            this.$emit('changeTime', caseDate, appointTime * 1000);
        }
    }
};
</script>
 
<style lang="scss"></style>