时间选择 -固定时间

1 .给出两个时间段,还有算间隔的时间,然后返回可以选择的列表

<template>
    <div class="time">
            <h1>固定时间点可供选择</h1>
    <div class="input">
        <input type="text" 
               :placeholder="chooseTime"
               @focus="onFocus"
               @click="handleClick" 
               :class="hoverClass">
    </div>
    <div class="ul" v-show="isShow">
        <scroll :boxSizeing='scrollStyle'
                v-on:scroll="scrollEnd"
                :pos="posSon" 
                :isShow="isShow">
            <ul>
                <li v-for="(cell,index) in allTime" :key="index"> 
                    <list :cell="cell" v-on:handleChange="handleChange">
                    </list>
                </li>
            </ul>
        </scroll>
    </div> 
    </div>
</template>
<script>
import scroll from '@/components/base/scroll/scroll'
import list from './li'
export default {
    data:function(){
        return {
            allTime:null,
            hoverClass:[],
            scrollStyle:{
                width:205,
                height:200
            },
            isShow:false,
            chooseTime:'请选择时间',
            pos:null,
            posSon:null,
            isFirst:true,
        }   
    },
    props:{
        pickerOptions:{
            type:Object,
            default:function(){
                return {
                    start:'00:45',
                    step:15,
                    end:'07:45'
                }
            }
        }
    },
    mounted:function(){
        this._initTime()
    },
    methods:{
        _initTime:function(){
            const sH=this.pickerOptions.start.slice(0,2)
            const sM=this.pickerOptions.start.slice(3,5)
            const eH=this.pickerOptions.end.slice(0,2)
            const eM=this.pickerOptions.end.slice(3,5)

            let sTime=this.dayjs().set('hour',sH).set('minute',sM)
            let eTime=this.dayjs().set('hour',eH).set('minute',eM)
            const step=Number(this.pickerOptions.step)*60*1000
            let diffTime=Math.ceil(Math.abs(sTime.diff(eTime))/step)+1
            let allTime=[]
            for(let x=0;x<diffTime;x++){
                let newTime=sTime.add(this.pickerOptions.step*x,'minute').format('HH:mm--A')
                allTime.push(newTime)
            }
            if(allTime.length!==diffTime){
                allTime.push(eTime.format('HH:mm--A'))
            }
            this.allTime=allTime
        },
        onFocus:function(){
            if(this.hoverClass.length==0){
                 this.hoverClass.push('hoverClass')
            } 
            this.isShow=true 
        },
        handleChange:function(e){
            this.$emit('handleChange',e.substring(0,5))
            console.log('现在已选好')
            console.log(e)
            this.isShow=!this.isShow
            this.isFirst=false
            this.chooseTime=e

             
        },
        handleClick:function(){
            this.isShow=true;
            if(!this.isFirst){
                this.posSon=this.pos
            }
        },
        scrollEnd:function(e){
            this.pos=e
        }
    },
    components:{
        scroll,
        list
    }
}
</script>
<style scoped>
.input input{
    background-color: #fff;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 40px;
    line-height: 40px;
    outline: none;
    padding: 0 15px;
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    width: 200px;
    font-size:12px;
}
.hoverClass{
    border-color:#409eff !important;
    outline: none;
}
.time{
    width: 205px;
} 
.ul li{
    width: 100%;
    font-size: 14px;
    color: #606266;
    background: #fff;
    line-height: 30px;
    margin: 5px 0;
    letter-spacing: 2px;
}
.ul li:hover{
    background: #eee;
    color:#000;
}
ul{
    width:203px;
    color: #606266;
    border: 1px solid #e4e7ed;
    box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
    background: #fff;
    border-radius: 4px;
    line-height: 30px;
    margin: 5px 0;
}
</style>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 官网 中文版本 好的网站 Content-type: text/htmlBASH Section: User ...
    不排版阅读 4,500评论 0 5
  • 一、Python简介和环境搭建以及pip的安装 4课时实验课主要内容 【Python简介】: Python 是一个...
    _小老虎_阅读 5,875评论 0 10
  • (写一个系列聊一聊runtime源码 希望不错过一些小的细节 然后一点一点深入解说,不知道自己能坚持多久) (采用...
    易爆物品阅读 419评论 0 0
  • 麦田 刘青菊 五月的风带着夏的热情 把麦浪染成了金黄色 布谷鸟盘旋在麦浪的上空 映着着骄阳 与偷袭的暴风雨赛跑 她...
    成功者都是含泪奔跑阅读 201评论 0 0
  • 感赏回到爸爸妈妈身边好幸福!每天睡到自然醒...不用那么辛苦!每天做我爱吃的饭菜...感赏这次回娘家老公不让我带孩...
    我就是我hxh阅读 220评论 0 0