最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue2.0+elementui實(shí)現(xiàn)一個(gè)上門(mén)取件時(shí)間組件

 更新時(shí)間:2024年02月23日 15:30:23   作者:nihao561  
這篇文章主要給大家介紹了關(guān)于vue2.0+elementui實(shí)現(xiàn)一個(gè)上門(mén)取件時(shí)間組件的相關(guān)資料,用于預(yù)約上門(mén)服務(wù)時(shí)間 看到網(wǎng)上有很多亂七八糟的代碼,看著頭疼,于是自己寫(xiě)了一個(gè)簡(jiǎn)單的,需要的朋友可以參考下

本文使用vue2.0+elementui 制作一個(gè)上門(mén)取件時(shí)間組件,類(lèi)似順豐,樣式如下:

大概功能:點(diǎn)擊期望上門(mén)時(shí)間,下面出現(xiàn)一個(gè)彈框可以選擇時(shí)間:

首先我們定義一些需要的數(shù)據(jù):

  data() {
        return {
            isDropdown: false,
            dayList: [],
            listArray: [
                "08:00~09:00",
                "09:00~10:00",
                "10:00~11:00",
                "11:00~12:00",
                "12:00~13:00",
                "13:00~14:00",
                "14:00~15:00",
                "15:00~16:00",
                "16:00~17:00",
                "17:00~18:00",
                "18:00~19:00",
                "19:00~19:30",
            ],
            timeToList: {
            },
            timeValue: "今天",
            clickValue: "一小時(shí)內(nèi)",
            clickDay: "今天",
            time: "",
        }
    },

接著我們畫(huà)一個(gè)期望上門(mén)時(shí)間的長(zhǎng)框,點(diǎn)擊可以出現(xiàn)彈窗,點(diǎn)擊外部彈窗消失,這中間我們使用了import Clickoutside from 'element-ui/src/utils/clickoutside' 這一組件,來(lái)幫助我們達(dá)到這個(gè)目的

<template>
    <div class="time-picker" @click="openDown" v-clickoutside="clickoutside">
        <div class="content-first">
            <div class="redSpan">*</div>
            <div>期望上門(mén)時(shí)間</div>
        </div>
        <div class="content-first">
            <div>
                {{ time }}
            </div>
            <i class="el-icon-s-order"></i>
        </div>
</template>

接下來(lái)畫(huà)一個(gè)彈出頁(yè)面,彈出頁(yè)面頂部是一個(gè)tab組件,這里通過(guò)daylist循環(huán)獲得

   <div class="time">
                <div v-for="item in dayList" class="item" :class="timeValue == item.lable ? 'active' : ''"
                    @click="dayChange(item)">
                    <div>{{ item.lable }}</div>
                    <div>{{ item.ymd }}</div>
                </div>
            </div>

tab組件中的內(nèi)容,是下單時(shí)間的按鈕集合,通過(guò)timeToList 這個(gè)結(jié)構(gòu)體 ,先獲取數(shù)組再循環(huán)生成

           <div class="timeList">
                <div v-for="item  in  timeToList[timeValue]" @click="timeChange(item)" class="timeBox"
                    :class="clickDay == item.day && clickValue == item.lable ? 'active' : ''">
                    {{ item.lable }}
                </div>
            </div>

頁(yè)面寫(xiě)好了我們開(kāi)始寫(xiě)邏輯代碼,先需要一些工具函數(shù)獲取小時(shí)、分鐘、年月日,一個(gè)用來(lái)判定點(diǎn)擊了哪個(gè)按鈕的list(由于是雙層結(jié)構(gòu)tab+button集,所以需要兩個(gè)值來(lái)判定),一個(gè)獲取今天按鈕列表的函數(shù):

        getHours() {
            const now = new Date();
            return now.getHours();
        },

        getMinute() {
            const now = new Date();
            return now.getMinutes();
        },

        formatDate(date) {
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            return `${year}-${month}-${day}`;
        },
        
        transTime(arr, day) {
            let temp = []
            arr.forEach((item) => {
                temp.push({
                    lable: item,
                    day: day
                })
            })
            return temp
        },

        getTodayList(arr) {
            let minute = this.getMinute()
            let hour = this.getHours()
            if (hour < 8)
                return arr
            if (hour >= 19 && minute > 30)
                return []
            arr = arr.slice(hour - 7)
            arr = ['一小時(shí)內(nèi)', ...arr]
            return arr
        }

然后我們需要先初始化數(shù)據(jù)

     initial() {
            let minute = this.getMinute()
            let hour = this.getHours()
            if (hour < 8) {
                this.clickValue = "08:00~09:00"
                this.clickDay = "今天"
                return
            }
            if (hour >= 19 && minute > 30) {
                this.clickValue = "08:00~09:00"
                this.clickDay = "明天"
                return
            }
        },

然后將時(shí)間賦值,這里其實(shí)可以用computed,但是我還是習(xí)慣自己做這部分操作

        setTime() {
            this.time = this.clickDay + ' ' + this.clickValue
        },

接下來(lái)我們需要生成tab表單dayList,以及每個(gè)tab頁(yè)面下面的時(shí)間選項(xiàng),用了上面的兩個(gè)工具函數(shù)getTodayList(),transTime()

       getDay() {
            const today = new Date()
            const tomorrow = new Date(today)
            tomorrow.setDate(tomorrow.getDate() + 1)
            const afterTomorrow = new Date(today)
            afterTomorrow.setDate(afterTomorrow.getDate() + 2)

            let dayArray = [this.formatDate(today), this.formatDate(tomorrow), this.formatDate(afterTomorrow)]
            let dayName = ['今天', '明天', '后天']
            this.dayList = dayName.map((item, index) => {
                return {
                    lable: item,
                    ymd: dayArray[index]
                }
            })
        },

      getTimeToList() {
            this.dayList.forEach((item) => {
                let arr = JSON.parse(JSON.stringify(this.listArray))
                if (item.lable === "今天")
                    arr = this.getTodayList(arr)
                this.timeToList[item.lable] = this.transTime(arr, item.lable)
            })
        },

通過(guò)上面的初始化函數(shù),可以生成下拉頁(yè)面的組件內(nèi)容,函數(shù)順序如下

    mounted() {
        this.initial()
        this.setTime()
        this.getDay()
        this.getTimeToList()
    },

最后我們添加一些點(diǎn)擊動(dòng)作,完整代碼

        openDown() {//打開(kāi)下來(lái)框
            this.isDropdown = true
        },

        clickoutside(e) {//關(guān)閉下拉框
            if (!e) {
                this.isDropdown = false
                this.timeValue = this.clickDay
            }
        },

        dayChange(item) {//切換tab頁(yè)面
            this.timeValue = item.lable
        },

        timeChange(item) {//選擇下單時(shí)間
            this.clickValue = item.lable
            this.clickDay = item.day
            this.setTime()
        },

貼一下css代碼

<style lang="scss" scoped>
.time-picker {
    background-color: #f4f5f7;
    width: 336px;
    height: 32px;
    padding: 0 6px;

    display: flex;
    justify-content: space-between;
    cursor: pointer;

    .content-first {
        display: flex;
        align-items: center;
        gap: 3px;

        .redSpan {
            color: red;
        }
    }

    .dropdown {
        position: absolute;
        top: 32px;
        right: 0px;
        z-index: 99;
        width: 100%;
        height: 220px;
        background-color: #fff;
        box-shadow: 0 8px 12px 0 rgba(0, 0, 0, 0.04);
        border-radius: 10px;
        padding: 6px;

        .time {
            display: flex;

            .item {
                width: 33%;
                height: 45px;
                text-align: center;
                font-size: 14px;
                line-height: 18px;
                border-bottom: 1px solid #cccccc;
            }

            .active {
                color: red;
                border-bottom: 1px solid red;
            }
        }

        .timeList {
            padding: 10px;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            gap: 10px;

            .timeBox {
                width: 93px;
                height: 29px;
                background-color: #f7f8fa;
                text-align: center;
            }

            .timeBox:hover {
                color: red;
            }

            .active {
                color: red;
                background-color: #ffefef;
            }
        }
    }

}
</style>

完整代碼已經(jīng)上傳github:https://github.com/majinihao123/vue-Component

總結(jié)

到此這篇關(guān)于vue2.0+elementui實(shí)現(xiàn)一個(gè)上門(mén)取件時(shí)間組件的文章就介紹到這了,更多相關(guān)Vue上門(mén)取件時(shí)間組件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue-Router如何動(dòng)態(tài)更改當(dāng)前頁(yè)url query

    Vue-Router如何動(dòng)態(tài)更改當(dāng)前頁(yè)url query

    這篇文章主要介紹了Vue-Router如何動(dòng)態(tài)更改當(dāng)前頁(yè)url query問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • Vue實(shí)現(xiàn)Word/Excel/PDF文件預(yù)覽的詳細(xì)步驟

    Vue實(shí)現(xiàn)Word/Excel/PDF文件預(yù)覽的詳細(xì)步驟

    vue-office是一款專(zhuān)門(mén)為 Vue 設(shè)計(jì)的辦公文檔預(yù)覽組件庫(kù),支持 ??Word(.docx),Excel(.xlsx/.xls),PDF?? 等主流格式,下面我們就來(lái)看看具體實(shí)現(xiàn)步驟吧
    2025-07-07
  • Vue組件之間的數(shù)據(jù)共享詳解

    Vue組件之間的數(shù)據(jù)共享詳解

    這篇文章主要為大家介紹了Vue組件之間的數(shù)據(jù)共享,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2021-11-11
  • el-table表頭添加勾選框的實(shí)現(xiàn)示例

    el-table表頭添加勾選框的實(shí)現(xiàn)示例

    本文主要介紹了el-table表頭添加勾選框的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • vuex中數(shù)據(jù)持久化插件vuex-persistedstate使用詳解

    vuex中數(shù)據(jù)持久化插件vuex-persistedstate使用詳解

    這篇文章主要介紹了vuex中數(shù)據(jù)持久化插件vuex-persistedstate使用詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • element表單el-form的label自適應(yīng)寬度的實(shí)現(xiàn)

    element表單el-form的label自適應(yīng)寬度的實(shí)現(xiàn)

    本文主要介紹了element表單el-form的label自適應(yīng)寬度的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • Vue驗(yàn)證碼60秒倒計(jì)時(shí)功能簡(jiǎn)單實(shí)例代碼

    Vue驗(yàn)證碼60秒倒計(jì)時(shí)功能簡(jiǎn)單實(shí)例代碼

    這篇文章主要介紹了Vue驗(yàn)證碼60秒倒計(jì)時(shí)功能簡(jiǎn)單實(shí)例代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-06-06
  • Vue 子組件更新props中的屬性值問(wèn)題

    Vue 子組件更新props中的屬性值問(wèn)題

    這篇文章主要介紹了Vue 子組件更新props中的屬性值問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue遞歸實(shí)現(xiàn)自定義tree組件

    vue遞歸實(shí)現(xiàn)自定義tree組件

    這篇文章主要為大家詳細(xì)介紹了vue遞歸實(shí)現(xiàn)自定義tree組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • vue實(shí)現(xiàn)導(dǎo)航收縮框

    vue實(shí)現(xiàn)導(dǎo)航收縮框

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)導(dǎo)航收縮框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03

最新評(píng)論

班戈县| 苍南县| 商南县| 石河子市| 普兰店市| 额尔古纳市| 专栏| 基隆市| 临湘市| 南投市| 泸州市| 怀来县| 柳州市| 长沙市| 长沙市| 镇沅| 彰化县| 汾西县| 桐乡市| 江永县| 乳源| 永和县| 太和县| 福州市| 清丰县| 保亭| 溧水县| 灌南县| 永新县| 当涂县| 铁岭市| 苏尼特左旗| 广水市| 扶风县| 威远县| 汪清县| 辽中县| 台南市| 奉化市| 舟曲县| 绩溪县|