123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <template>
-
- <view>
- <view class="" style="height:1rpx">
-
- </view>
- <view class="commons-time-box">
- <view
- class="time-box"
- :class="value.type == i.type ? 'active' : ''"
- v-for="i in typeList"
- :key="i.type"
- @click="changeTypeFn(i.type)">
- {{i.name}}
- </view>
- <view :class="value.type == 6 ? 'active' : ''" class="time-box time-box-icon" @click="openBotomModal">
- <uni-icons type="calendar" size="20"></uni-icons>
- </view>
- <uni-popup ref="popup" type="bottom" background-color="#fff">
- <view class="btn-box">
- <view class="" style="color:red">
- 取消
- </view>
- <view class="" style="color:#007AFF" @click="confirm">
- 确认
- </view>
- </view>
- <view class="commons-time-box">
- <view
- class="modal-select-box"
- :class="modalTimeType == i.type ? 'active' : ''"
- v-for="i in modalTimeList"
- @click="modalTimeSelect(i.type)"
- :key="i.type">
- {{i.name}}
- </view>
- </view>
- <view>
- <view class="color-bl text-center" style="margin:30rpx">
- 选择时间区间
- </view>
- <view class="">
- <uni-datetime-picker @change="selectPicker" v-model="value.time" type="daterange" rangeSeparator="至" />
- </view>
- <view style="height:200rpx">
-
- </view>
- </view>
- </uni-popup>
- </view>
- </view>
-
- </template>
- <script>
- import {format} from '../../util/uitl.js'
- export default {
- props: {
- value: {
- type: Object,
- }
- },
- watch: {
- value: {
- handler() {
- this.$emit("input", this.value)
- },
- deep: true,
- immediate: true,
-
- },
- },
- data() {
- return {
- typeList:[{
- name:"本日",
- type:0,
- },{
- name:"昨日",
- type:1,
- },{
- name:"本周",
- type:2,
- },{
- name:"上周",
- type:3,
- },{
- name:"本月",
- type:4,
- },{
- name:"上月",
- type:5,
- }],
- modalTimeList:[
- {
- name:"昨日",
- type:1,
- },{
- name:"前日",
- type:2,
- },{
- name:"上周",
- type:3,
- },{
- name:"上月",
- type:4,
- },{
- name:"近三个月",
- type:5,
- },{
- name:"近半年",
- type:6,
- }
- ],
- modalTimeType:null,
- }
- },
- methods:{
- selectPicker(){
-
- },
- //确认
- confirm(){
-
- if(this.modalTimeType || this.value.time.length != 0){
- this.value.type = 6
- this.$emit('change')
- }
- this.$refs.popup.close()
-
- },
- //外部选择时间
- changeTypeFn(_type){
- this.value.type = _type
- this.value.beginTime = null
- this.value.endTime = null
- this.value.time = []
- this.$emit('change')
- },
- modalTimeSelect(_type){
- const v = this
- v.modalTimeType = _type
- const todayNum = new Date(new Date().toLocaleDateString()).getTime()
- const today = new Date()
- //年
- var year = today.getFullYear();
- //月
- const month = today.getMonth() + 1
- //周
- const nows = today.getDay() || 7
- //天
- const day = today.getDate()
- if(_type == 1){
- v.value.beginTime = format(todayNum - 86400000)
- v.value.endTime = format(todayNum)
- }
- if(_type == 2){
- v.value.beginTime = format(todayNum - (86400000 * 2))
- v.value.endTime = format(todayNum - 86400000)
- }
- if(_type == 3){
- v.value.beginTime = format(todayNum - (86400000 * (nows + 6)))
- v.value.endTime = format(todayNum - 86400000 * (nows - 1))
- }
- if(_type == 4){
- if(month == 1){
- v.value.beginTime = (year - 1) + '-' + 12 + '-' + '1 00:00:00'
- v.value.endTime = year + '-' + 1 + '-' + '1 00:00:00'
- }else{
- v.value.beginTime = year + '-' + (month - 1) + '-' + '1 00:00:00'
- v.value.endTime = year + '-' + month + '-' + '1 00:00:00'
- }
- }
- if(_type == 5){
- if(month < 4){
- v.value.beginTime = (year - 1) + '-' + (12 - 3 + month) + '-' + day + ' 00:00:00'
- v.value.endTime = format(today.getTime())
- }else{
- v.value.beginTime = year + '-' + (month - 3) + '-' + day + ' 00:00:00'
- v.value.endTime = format(today.getTime())
- }
- }
- if(_type == 6){
- if(month < 7){
- v.value.beginTime = (year - 1) + '-' + (12 - 6 + month) + '-' + day + ' 00:00:00'
- v.value.endTime = format(today.getTime())
- }else{
- v.value.beginTime = year + '-' + (month - 6) + '-' + day + ' 00:00:00'
- v.value.endTime = format(today.getTime())
- }
- }
- v.value.time = [v.value.beginTime,v.value.endTime]
- console.log(v.value)
- },
- openBotomModal(){
- console.log(this.value)
- this.$refs.popup.open('bottom')
- },
- },
- created() {
- },
- }
- </script>
- <style lang="less">
- .btn-box{
- display: flex;
- justify-content: space-between;
- font-size: 30rpx;
- height: 80rpx;
- line-height: 80rpx;
- padding: 0 40rpx;
- font-weight: 600;
- }
- .commons-time-box {
- display: flex;
- height: 50rpx;
- line-height: 50rpx;
- font-size: 24rpx;
- margin: 30rpx 30rpx;
- border: 1px solid #dcdcdc;
- border-radius: 8rpx;
- .modal-select-box{
- width:16.66%;
- text-align: center;
- }
- .time-box {
- width: 15%;
- text-align: center;
- }
- .time-box-icon {
- width: 10%;
- }
- .time-box.active {
- background-color: #487CFF;
- color: #fff;
- }
- .active {
- background-color: #487CFF;
- color: #fff;
- text{
- color: #fff!important;
- }
- }
- }
- </style>
|