index.vue
2.8 KB
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
<template>
<view>
<view class="Search">
<view class="Search-l" style="margin-right: 13.5rpx;" @click="openCalendar">
<input type="text" :value="value.date" disabled placeholder="选择开始时间" class="Search-input" placeholder-style="color: #505050;">
<u-icon name="arrow-down-fill" size="10"></u-icon>
</view>
<view class="Search-r">
<input type="text" @input="inputChage" :value="value.keyword" placeholder="请输入姓名" class="Search-input" placeholder-style="color: #505050;">
<u-icon name="search" size="30" color="#659ff5"></u-icon>
</view>
</view>
<u-calendar
:defaultDate="[]"
@close="show = false"
:monthNum="monthNum"
:minDate="minDate"
:maxCount="2"
:show="show"
mode="multiple"
@confirm="confirm">
</u-calendar>
</view>
</template>
<script>
export default {
model: {
prop: 'value',
event: 'change'
},
props: {
value: {
type: [Object],
default: () => {
return {}
}
}
},
computed: {
},
data() {
const monthNum = 12;
const targetDate = new Date();
targetDate.setMonth(targetDate.getMonth() - (monthNum - 1));
// 根据年月日拼接字符串
const yyyy = targetDate.getFullYear();
const mm = (targetDate.getMonth() + 1).toString().padStart(2, '0');
const dd = targetDate.getDate().toString().padStart(2, '0');
const dateString = `${yyyy}-${mm}-${dd}`;
return {
show: false,
minDate: dateString,
monthNum
};
},
methods: {
openCalendar() {
this.show = true
},
inputChage(e) {
this.$emit('change', {...this.value, keyword: e.detail.value})
},
confirm(e) {
console.log(e)
let timeStamp_s = ''
let timeStamp_e = ''
if(!e.length) {
uni.showToast({
icon: 'none',
title: '请选择时间'
})
return
}
if(e.length === 2) {
timeStamp_s = new Date(e[0]).valueOf() > new Date(e[1]).valueOf() ? e[1] : e[0]
timeStamp_e = new Date(e[0]).valueOf() > new Date(e[1]).valueOf() ? e[0] : e[1]
} else if (e.length === 1){
timeStamp_s = e[0]
timeStamp_e = e[0]
}
const first = timeStamp_s;
const last = timeStamp_e;
this.show = false
this.$emit('change', {...this.value, date: first + ' ~ ' + last})
}
}
}
</script>
<style lang="scss" scoped>
.Search{
display: flex;
.Search-input{
color: #505050;
font-size: 28rpx;
}
.Search-l{
border-radius: 15rpx;
background-color: #fff;
flex-shrink: 0;
height: 76rpx;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 30rpx;
width: 254rpx;
}
.Search-r{
flex-grow: 1;
margin-left: 27rpx;
height: 76rpx;
border-radius: 15rpx;
background-color: #fff;
align-items: center;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 30rpx;
}
}
</style>