饭侠mall.vue 首页 模块化 flexBox 布局

<template>
    <div class="mallBox">
        <div class="mask" v-show="showShopcart" @click="toggleShopcart"></div>
        <div class="maskForCode" v-show="showMealCode" @click="closeMealCode"></div>
        <!-- 主页面模块-->//底部不再需要绝对定位 防止出现闪屏
        <flexbox orient="vertical" :gutter="0">
            <flexbox-item>
                <div class="flex-demo">
                    <scroller lock-x height="-120px" >
                        <div class="scrollBox">
                            <div class="swiperBox">
                                <swiper :options="swiperHeader">
                                    <swiper-slide v-for="item in carouselList ">
                                        <div class="swiperBox_img">
                                            <img :src="item.url" alt="">
                                        </div>
                                    </swiper-slide>
                                    <div class="swiper-pagination" slot="pagination"></div>
                                </swiper>
                            </div>
                            <div class="userBox" @click="personal">
                                <icon name="user" scale="3"></icon>
                            </div>
                            <div class="positionBox" @click="selectStore">
                                <span class="positionBox_icon"><icon name="position" scale="2"></icon></span>
                                <span class="positionBox_store">{{storeName.name}}</span>
                            </div>
                            <div class="foodBox">
                                <div v-for="item in foodList">
                                    <divider>{{item.name}}</divider>
                                    <swiper :options="swiperOption">
                                        <swiper-slide v-for="i in item.data ">
                                            <div  class="swiper-box">
                                                <div class="swiper-box_img" @click="showDetail(i)">
                                                    <img :src="i.url[0]" alt="">
                                                </div>
                                                <div class="food_height" @click="showDetail(i)">
                                                    <span>{{i.name}}</span>
                                                </div>
                                                <div>
                                                    <span class="food-font_color">¥</span>
                                                    <span class="food-font food-font_color">{{i.price}}</span>
                                                    <span class="food_unit">/份</span>
                                                    <span class="shopCart_add" @click="cartAdd(i)">+</span>
                                                </div>
                                                <div class="soldOut" v-show="i.count==0">
                                                    <img src="../../images/u229.png" alt="">
                                                    <span class="countEmpty">售罄</span>
                                                </div>
                                            </div>
                                        </swiper-slide>
                                    </swiper>
                                </div>
                            </div>
                        </div>
                    </scroller>
                </div>
            </flexbox-item>
            <flexbox-item>
                <div class="flex-demo menu-bottom" >
                    <flexbox :gutter="0">
                        <flexbox-item :span="9">
                            <div class="flex-demo menu-box"  @click="toggleShopcart">
                                <span><icon name="cart" :scale="3"></icon></span>
                                <badge :text="shopCart.num" ></badge>
                                <span class="menu-box_money">¥{{shopCart.totalMoney}}</span>
                            </div>
                        </flexbox-item>
                        <flexbox-item>
                            <div class="flex-demo goPay" @click="goToPay">
                                    <span>去结算</span>
                            </div>
                        </flexbox-item>
                    </flexbox>
                    <div class="date-box">
                        <checker   v-model="mallDate"  radio-required default-item-class="demo1-item" selected-item-class="demo1-item-selected">
                            <checker-item v-for="item in dateList" :value="item.key" @on-item-click="changeDate">
                                <div>{{item.label}}</div>
                                <div>{{item.date}}</div>
                            </checker-item>
                        </checker>
                    </div>
                </div>
            </flexbox-item>
        </flexbox>
        <!--取餐图片模块-->
        <div class="takeMealImg" @click="getMealCode">
            <div class="takeMealImg_img">
                <img src="../../images/u617.png" alt="">
            </div>
            <div class="takeMealImg_bgImg">
                <img src="../../images/u618.png" alt="">
                <span>取餐啦</span>
            </div>
        </div>
        <!--取餐码模块-->
        <div class="takeMealCode" v-show="showMealCode">
            <span class="cancelCode" @click="closeMealCode"><icon name="cancel" :scale="4"></icon></span>
            <div class="takeMealCode_header">
                <span>目前可取</span>
            </div>
            <div class="takeMealCode_scoll">
                <scroller lock-x height="300px">
                    <div class="scollCodeBox">
                        <div class="detailCodeBox" v-for="item in codeList">
                            <flexbox>
                                <flexbox-item :span="5" >
                                    <div class="codeName">
                                        {{item.codeName}}
                                    </div>
                                </flexbox-item>
                                <flexbox-item :span="7" >
                                    <div class="codeName codeColor">
                                        <div>
                                            <span>取餐码:</span>
                                            <span class="codeColor_font">{{item.codeNum}}</span>
                                        </div>
                                        <div>
                                            <span>机柜号:</span>
                                            <span class="codeColor_font">{{item.cabinetNum}}</span>
                                        </div>
                                    </div>
                                </flexbox-item>
                            </flexbox>
                        </div>
                    </div>
                </scroller>
            </div>
            <div class="takeMealCode_footer" @click="refreshCode">
                <span>{{refreshTime}}秒</span>
            </div>
        </div>

        <!--购物车详情模块 -->
            <shopcart  v-show="showShopcart" >
                <template v-for="list of shopCart.items">
                    <shopcart-item :good=item v-for="item of list"></shopcart-item>
                </template>
            </shopcart>
//shopcart.vue  注意写入<slot></slot>    
        <!--商品详情页模块-->
        <div v-show="showDetailFood">
            <mall-detail ></mall-detail>
        </div>

    </div>
</template>
<script>
    import { mapGetters } from ‘vuex‘
    import {Shopcart,ShopcartItem} from "../shopcart"
    import MallDetail from "../malldetail/malldetail.vue"
    import {Divider,Scroller,Checker, CheckerItem,Flexbox, FlexboxItem,Badge  } from ‘vux‘
    import { swiper, swiperSlide } from ‘vue-awesome-swiper‘
    export default {
        data() {
            return {
                storeName:{},
                codeList:[
                    {"codeName":‘黄焖鸡米饭1‘,"codeNum":‘112365‘,"cabinetNum":"1235"},
                    {"codeName":‘黄焖鸡米饭2‘,"codeNum":‘212365‘,"cabinetNum":"2235"},
                    {"codeName":‘黄焖鸡米饭3‘,"codeNum":‘312365‘,"cabinetNum":"3235"},
                    {"codeName":‘黄焖鸡米饭4‘,"codeNum":‘412365‘,"cabinetNum":"4235"},
                ],
                refreshTime:60,
                showMealCode:false,
                dateList:[],
                mallDate:‘‘,
                carouselList:"",
                foodList:[],
                swiperOption: {
                    slidesPerView:2.2,
                    spaceBetween: 0,
                },
                swiperHeader: {
                    spaceBetween: 30,
                    centeredSlides: true,
                    autoplay: {
                        delay: 2500,
                        disableOnInteraction: false
                    },
                    pagination: {
                        el: ‘.swiper-pagination‘,
                        clickable: true
                    },
                },
            }
        },
        computed:{
            ...mapGetters([
                ‘shopCart‘,
                "showShopcart",
                "showDetailFood",
                "cartStyle"
            ]),
        },
        created(){
            this.getImg()
            this.getProduct()
            this.getStore()
            this.getStorage()
        },
        methods: {
            getStorage(){
                let cartStorage = JSON.parse(window.sessionStorage.getItem(‘shopCart‘))
                    if(cartStorage){
                        this.$store.commit("saveShopCart",cartStorage)
                    }
                },
            getStore(){
                this.$http.get(‘/shop/api/get-mall-device-data‘).then((response) => {
                    let res = response.data;
                    if (res.status == 1) {
                        this.storeName=res.data[0]
                        this.$store.dispatch("storageStore",res.data[0])
                    }
                    else{
                        this.$vux.toast.show({
                            text: res.message,
                            type: ‘cancel‘
                        })
                    }
                }).catch((error)=>{
                    this.$vux.toast.show({
                        text: "网络异常",
                        type:‘cancel‘
                    })
                })
            },
            getProduct(){
                this.$http.get(‘/shop/api/get-mall-data‘,{
                    params: {
                        date:this.mallDate,
                        type:‘new‘,
                    }
                }).then((response) => {
                    let res = response.data;
                    if (res.status == 1) {
                        this.mallDate=res.data.oldDate
                        this.foodList=res.data.productArr
                        this.dateList=res.data.date
                    }
                    else{
                        this.$vux.toast.show({
                            text: res.message,
                            type: ‘cancel‘
                        })
                    }
                }).catch((error)=>{
                    this.$vux.toast.show({
                        text: "网络异常",
                        type:‘cancel‘
                    })
                })
            },
            getImg(){
                this.$http.get(‘/shop/api/get-img-arr‘).then((response) => {
                    let res = response.data;
                    if (res.status == 1) {
                        this.carouselList=res.data
                    }
                    else{
                        this.$vux.toast.show({
                            text: res.message,
                            type: ‘cancel‘
                        })
                    }
                }).catch((error)=>{
                    this.$vux.toast.show({
                        text: "网络异常",
                        type:‘cancel‘
                    })
                })
            },
            selectStore(){

            },
            toggleShopcart(){
                if(this.shopCart.num==0){
                    this.showShopcart=false
                    return
                }
                this.$store.dispatch("showCart")
                if(this.cartStyle=="2"){
                    document.getElementById("all-order").setAttribute(‘style‘,‘bottom:60px‘)
                }else{
                   document.getElementById("all-order").setAttribute(‘style‘,‘bottom:120px‘)
               }

            },
            closeMealCode(){
                this.showMealCode=false
            },
            times(){
                var IntervalName= setInterval(() => {
                    this.time--;
                    if(this.time<1){
                        this.refreshTime=60
                    }
                }, 1000)
            },
            getMealCode(){
                this.showMealCode=true
                this.refreshTime=60
            },
            refreshCode(){

            },
            showDetail(item){
                this.$store.commit(‘controlCartStyle‘,"2")
                this.$store.dispatch("watchDetail", item)
                this.$store.dispatch("showDetailFood")
            },
            cartMinus(item){
                this.$store.dispatch("minusCart", item)
            },
            cartAdd(item,module){
                if(module==2&&item.count==0){
                    return
                }
                if(item.count==0){
                    this.$vux.alert.show({
                        content: ‘商品已售罄‘,
                    })
                    return
                }
                this.$store.dispatch("addCart", item)
                this.$vux.toast.show({
                    text: "商品已加进购物车",
                    time:"1000",
                    type:‘text‘
                })
            },
            goToPay(){
                let $this=this
                if(this.shopCart.num==0){
                    this.$vux.toast.show({
                        text: "请选择商品",
                        type:‘warn‘
                    })
                    return
                }
                this.$router.push({path:‘/account‘})
            },
            personal(){
                this.$router.push({ path: ‘personal‘ });
            },
            changeDate(value){
                if(value==this.mallDate){
                    return
                }
                this.mallDate=value
                this.getProduct()
            }
        },
        components: {
            MallDetail,
            Shopcart,ShopcartItem,
            Divider,
            swiper,
            swiperSlide,
            Scroller,
            Checker, CheckerItem
            ,Flexbox, FlexboxItem,Badge
        }
    }
</script>
<style lang="less">
    /* 公共样式*/
        .demo1-item {
            width: 14.28%;
            box-sizing: border-box;
            text-align: center;
            div{
                height: 30px;
                line-height: 30px;
                font-size: 16px;
            }
        }
        .demo1-item-selected {
            background: orangered;
            color:white;
        }
        .menu-box{
            height:60px;
            padding:10px 12px;
            font-size: 18px;
            line-height: 60px;
            background: transparent;
            position: relative;
            box-sizing: border-box;
            text-align: left;
            &_money{
                position: absolute;
                top:-8px;
                left:60px;
                color: red;
                font-size: 18px;
            }
            .vux-badge{
                position: absolute;
                top:14px;
                left:30px;
            }
        }
        .goPay{
            background:#0c6;
            height: 60px;
            line-height: 60px;
            font-size: 18px;
            text-align: center;
            color: white;
        }
    .mallBox{
        position: relative;
        img{
            width: 100%;
            height: 100%;
            display: block;
        }

        .mask{
            height: 100%;
            width: 100%;
            position: absolute;
            bottom:120px;
            left:0;
            z-index:5;
            background: rgba(0,0,0,0.5);
        }
        .maskForCode{
            height: 100%;
            width: 100%;
            position: absolute;
            top: 0;
            left:0;
            z-index:888;
            background: rgba(0,0,0,0.5);
        }
        .food_unit{
            color:#c0c0c0;
            position: relative;
            top:-1px;
        }
        .food-font_color{
            color:red;
        }
        .food-font{
            font-size: 20px;
        }
        .inner-box{
            .meal-detial{
                font-weight: 600;
            }
            .money{
                color: orangered;
            }

        }
        .food-box{
            border-bottom: 1px solid #cccccc;
        }

        .disables{
            color: #ccc;
            .rightButton{
                color:#ccc;
            }
            .leftButton{
                color:#ccc;
            }
        }
    }

    /*取餐 样式*/
    .takeMealImg{
        position: absolute;
        bottom:150px;
        right:25px;
        z-index: 3;
        &_img{
            width:70px;
        }
        &_bgImg{
            position: relative;
            width: 80px;
            height: 35px;
            top:-12px;
            right:5px;
            transform:rotate(7deg);
            span{
                position: absolute;
                color: white;
                top: 3px;
                left: 15px;
            }
        }
    }
    /*取餐码样式*/
    .takeMealCode{
        z-index:999;
        height:400px;
        width:90%;
        position: absolute;
        background: #fff0f0;
        margin-left:5%;
        top:50%;
        margin-top:-200px;
        .cancelCode{
            position: absolute;
            top: -50px;
            right:0;
        }
        &_header{
            font-size: 20px;
            padding: 8px;
            text-align: center;
            color: white;
            background: rgba(241, 99, 61, 1);
        }
        &_footer{
            background:rgba(215, 215, 215, 1);
            box-shadow: 0px 5px 5px rgba(0, 0, 0, 0.349019607843137);
            padding: 10px;
            text-align: center;
            font-size: 20px;
            color:#fff;
        }
        .scollCodeBox{
            padding:10px;
            .detailCodeBox{
                padding:10px;
                height: 100px;
                margin-bottom: 10px;
                box-shadow:1px 2px 18px #ccc;
                .codeName{
                    padding:10px;
                    color:#999;
                    height: 80px;
                    overflow: hidden;
                }
                .codeColor{
                    background: #666666;
                    color:#fff;
                    div{
                        padding: 10px 0;
                        .codeColor_font{
                            font-size: 18px;
                            float:right;
                        }
                    }
                }
            }
        }
    }
    /*购物车样式--*/
    #all-order{
        max-height:350px;
        position: fixed;
        z-index: 6;
        bottom: 120px;
        left: 0;
        background: #ffffff;
        .menuDetailBox{
            .menu-header{
                font-size: 18px;
                position: relative;
                background: mediumseagreen;
                display: inline-block;
                width: 30%;
                height: 100%;
                text-align: center;
                &_top{
                    position: relative;
                    top:3px;
                }
            }
            .menu_address{
                padding:10px;
                box-sizing: border-box;
                border-bottom: 1px solid darkgray;
                .menu-font{
                    font-size: 20px;
                    color:gray;
                }
            }
        }
        .vux-flexbox #menu_empty{
            text-align: center;
            span{
                position: relative;
                top:4px;
            }
        }
    }

    /* 商品详情样式*/

    /*底部下单样式*/
    .mall_bottom{
        height: 84px;
        z-index: 7;
        .myMenu{
            background: transparent;

            .go-pay{
                background: transparent;
                width:30%;
                right:0;
                &_icon{
                    position: relative;
                    top: 2px;
                }
                &_img{
                    height:100%;
                    img{
                        width: 100%;
                        height:100%;
                    }
                }
            }
        }
        .box {
            background: white;
        }

    }

    /*主页面下单样式 &&商品详情样式*/
    .scrollBox{
        position: relative;
        .detail_box{
            height: 40px;
        }
        .swiper-pagination{
            text-align: left;
        }
        .foodBox{
            .swiper-slide{
                box-sizing: border-box;
                min-width: 145px;
                padding: 8px;
            }
            .vux-divider{
                margin: auto;
                font-size: 20px;
            }
            .vux-divider:after, .vux-divider:before{
                width: 43%;
            }
        }
        .swiperBox_img{
            height: 150px;
        }

        .userBox{
            display: inline;
            position: absolute;
            top: 20px;
            right: 20px;
            z-index: 2;
        }
        .positionBox{
            position: absolute;
            top: 20px;
            left: 20px;
            z-index: 2;
            background:rgba(222, 216, 216, 0.43);
            min-width: 85px;
            padding: 0 5px;
            border-radius:20px;
            &_icon{
                position: relative;
                top:3px;
            }
            &_store{
                position: relative;
                font-size:16px;
                color:white;
            }
        }
        .swiper-box{
            position: relative;
            padding: 10px;
            min-width: 117px;
            max-width: 150px;
            box-shadow:1px 2px 18px #ccc;
            &_img{
                min-width: 117px;
                max-width: 150px;
                height: 100px;
            }
            .food_height{
                height: 50px;
            }
            .soldOut{
                position: absolute;
                top:-2px;
                right:-9px;
                color: #fff;
                width: 60px;
                text-align: center;
                transform:rotate(-1deg);
                padding: 1px 10px;
                .countEmpty{
                    position: absolute;
                    top: 7px;
                    right: 11px;
                    transform: rotate(48deg);
                }
            }
            .shopCart_add{
                float: right;
                display: inline-block;
                width: 20px;
                height: 20px;
                font-size: 18px;
                border-radius:50%;
                border: 1px solid red;
                line-height: 18px;
                text-align: center;
                margin-top:8px;
                color: red;
            }

        }
    }

</style>

原文地址:https://www.cnblogs.com/MR-cui/p/8918869.html

时间: 2024-10-10 10:17:01

饭侠mall.vue 首页 模块化 flexBox 布局的相关文章

HTML5移动开发之Flexbox布局讲解与使用技巧

现在来详细介绍一下Flexbox布局语法跟使用.大家可能非常关心以下几个问题: 1 .什么是Flexbox布局? 2. Flexbox布局主要用于什么场景? 3. Flexbox布局它的语法是什么? 4. 如何实际使用Flexbox布局? 5. Flexbox布局它的缺陷是什么? 下面就这五个问题给大家分析分析.希望给那些想尝试用Flexbox的行内人有所帮助. 在恰当的地方能够使用恰当的布局方法,如果有说的不到位,希望大家指正,一起进步. 1 .什么是Flexbox布局? 1.1 W3C解释

Android商城开发系列(十三)—— 首页热卖商品布局实现

热卖商品布局效果如下图: 这个布局跟我们上节做的推荐是一样的,也是用LinearLayout和GridView去实现的,新建一个hot_item.xml,代码如下所示: 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 android:ori

网站首页之早期布局

网站首页之早期布局方法,虽然现在基本不用了,但是我感觉还是应该知道的,说你不定哪一年的哪一天这种布局格式又火了.不排除这种可能,就像十年之前非常流行的喇叭裤一样,说不定十年之后这种网站布局方式又火了呢?,至少值得收藏.当然,后期还会给出目前计算机行业比较流行的网站布局方式. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xht

任务十:Flexbox 布局练习

面向人群: 有一定HTML及CSS基础的同学 难度: 中 重要说明 百度前端技术学院的课程任务是由百度前端工程师专为对前端不同掌握程度的同学设计.我们尽力保证课程内容的质量以及学习难度的合理性,但即使如此,真正决定课程效果的,还是你的每一次思考和实践. 课程多数题目的解决方案都不是唯一的,这和我们在实际工作中的情况也是一致的.因此,我们的要求不仅仅是实现设计稿的效果,更是要多去思考不同的解决方案,评估不同方案的优劣,然后使用在该场景下最优雅的方式去实现.那些最终没有被我们采纳的方案,同样也可以帮

flexbox布局

flexbox布局(RN基础) flexbox是Flexible Box的缩写, 弹性盒子布局 主流的浏览器都支持flexbox布局是伸缩容器(container)和伸缩项目 (item)组成Flexbox布局的主体思想是元素可以改变大小以适应可用空间, 当可用空间变大, Flex元素将伸展大小以填充可用空间, 当Flex元素超出可用空间时将自动缩小. 总之, Flex元素是可以让你的布局根据浏览器的大小变化进行自动伸缩.按照伸缩流的方向布局伸缩容器有主轴和交叉轴组成! 主轴既可以是水平轴, 也

我对Flexbox布局模式的理解

样实现一个div盒子水平垂直居中的.在知道对象高宽的情况下,对居中元素绝对百分比定位,然后通过margin偏移的方式来实现. <style> .container{ width:600px; height:400px; border:1pxsolid#000; position:relative; } .box{ width:200px; height:100px; border:1pxsolid#000; position:absolute; left:50%; top:50%; margi

flexbox布局神器

前言 2009年,W3C提出了一种新的方案----Flexbox布局(弹性布局),可以简便.完整.响应式地实现各种页面布局.Flex布局模型不同于块和内联模型布局,块和内联模型的布局计算依赖于块和内联的流方向.目前,它已经得到了所有浏览器的支持,这意味着,现在就能很安全地使用这项功能. 注:"Bootstrap v4 放弃支持 IE9,并默认使用 flexbox" ,由于 IE9 并不支持flexbox,这也意味着 Bootstrap 4 不再支持 IE9. 一.Flex布局是什么?

Flexbox 布局的正确使用方法

Flexbox 布局的正确使用方法 在项目中,我们还会大量使用到flexbox的新旧属性,但大多数人一般只会写新属性,旧属性交由autoprefixer处理,但其实完成同样功能的新旧属性表现形式却不尽相同.还有部分人只使用"万能"的flex:number属性为伸缩项目分配空间,但有些特殊情景却无法满足,此文为此梳理了flexbox的新旧属性区别和分配空间的原理,为大家用flexbox布局的项目通通渠. Flexbox兼容性 PC端的兼容性 移动端的兼容性 如上图,为了兼容IE10-11

View的介绍和运用 &amp;&amp; FlexBox布局

开始我们今天的项目学习啦~~~~~~ 1> 第一步当然是创建项目啦: 进入终端: 创建ViewDemo项目 命令如下啦,你看懂了对吧...嘻嘻!!! 2>View的介绍和运用 项目安装创建成功后,用webStorm打开项目,开始编写代码看效果啦~~~ /** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from 'react