• 微信 小程序组件 分页菜单


    HML*****************

    <view class="container flex-wrap flex-direction-row">
    <!-- left aside -->
    <view class="aside flex-wrap flex-direction-col">
    <block wx:key="navList" wx:for="{{navList}}">
    <text class="type-nav {{curNav == item.id ? 'selected' : ''}}" bindtap="selectNav" data-index="{{index}}" data-id="{{item.id}}">{{item.name}}</text>
    </block>
    </view>

    <!-- content -->
    <view class="content flex-item">
    <block wx:key="ishesList" wx:for="{{dishesList[curIndex]}}">
    <view class="dish flex-wrap flex-direction-row" catchtap="selectDish" data-dish="{{item.id}}">
    <view class="flex-item">
    <text class="title">{{item.name}}</text>
    <p>¥{{item.price}}</p>
    </view>
    <view class="add-btn"><icon type="{{item.status ? 'success' : 'circle'}}" color="orange" size="30"></icon></view>
    </view>
    </block>

    </view>

    </view>

    <!-- cart -->
    <view class="cart">
    <text class="total">购物车:{{cartTotal}}</text>
    </view>

    <!-- <loading hidden="{{hidden}}">玩命加载中…</loading> -->

    js****************************************

    //index.js
    //获取应用实例
    var app = getApp()
    Page({
    data: {
    hidden: false,
    curNav: 1,
    curIndex: 0,
    cart: [],
    cartTotal: 0,
    navList: [
    {
    id: 1,
    name: '热销菜品'
    },
    {
    id: 2,
    name: '热菜'
    },
    {
    id: 3,
    name: '凉菜'
    },
    {
    id: 4,
    name: '套餐'
    }
    ],
    dishesList: [
    [
    {
    name: "红烧肉",
    price: 38,
    num: 1,
    id: 1
    },
    {
    name: "宫保鸡丁",
    price: 58,
    num: 1,
    id: 29
    },
    {
    name: "水煮鱼",
    price: 88,
    num: 1,
    id: 2
    }
    ],
    [
    {
    name: "小炒日本豆腐",
    price: 18,
    num: 1,
    id: 3
    },
    {
    name: "烤鱼",
    price: 58,
    num: 1,
    id: 4
    }
    ],
    [
    {
    name: "大拌菜",
    price: 18,
    num: 1,
    id: 5
    },
    {
    name: "川北凉粉",
    price: 8,
    num: 1,
    id: 6
    }
    ],
    []
    ],
    dishes: []
    },
    // 页面加载改变时执行
    // loadingChange(){
    // setTimeout(function(){
    // this.setData({hidden:true})
    // },1000)
    // },
    // 分页菜单函数
    selectNav(event) {
    let id = event.target.dataset.id,
    index = parseInt(event.target.dataset.index);
    self = this;
    this.setData({
    curNav: id,
    curIndex: index
    })
    },

    // 加入购物车控制代码
    selectDish(event) {
    let dish = event.currentTarget.dataset.dish;
    let flag = true;
    let cart = this.data.cart;

    if (cart.length > 0) {
    cart.forEach(function (item, index) {
    if (item == dish) {
    cart.splice(index, 1);
    flag = false;
    }
    })
    }
    if (flag) cart.push(dish);
    this.setData({
    cartTotal: cart.length
    })
    this.setStatus(dish)
    },
    // 加入购物车后图像显示
    setStatus(dishId) {
    let dishes = this.data.dishesList;
    for (let dish of dishes) {
    dish.forEach((item) => {
    if (item.id == dishId) {
    item.status = !item.status || false
    }
    })
    }

    this.setData({
    dishesList: this.data.dishesList
    })
    },
    onLoad() {
    this.loadingChange()
    }

    })

    CSS**********************************

    .aside{
    4rem;
    border-right: 1px solid #ddd;
    font-size: .85rem;
    }
    .type-nav{
    position: relative;
    padding:.7rem .3rem;
    text-align: center;
    border-bottom: 1px solid #ddd;
    z-index: 10;
    }
    .type-nav.selected{
    margin-right: -1px;
    padding-left:-1px;
    color: #333;
    background-color: #fff;
    }
    .content{
    background-color: #fff;
    }

    .dish{
    margin-left: 1rem;
    padding: 1rem;
    border-bottom: 1px solid #ddd;
    }
    .dish .title{
    display: block;
    font-size: 1rem;
    }
    .dish p{
    color: orange;
    font-size: .75rem;
    }
    .dish .add-btn{
    3rem;
    text-align: right;
    }

    .cart{
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 1rem;
    background: #ddd;
    }

    app css***************************************************

    /**app.wxss**/
    .container {
    height: 100%;
    box-sizing: border-box;
    background-color: #f4f4f4;
    }

    .flex-wrap{
    display: flex;
    }
    .flex-item{
    flex: 1;
    }
    .flex-wrap.flex-direction-col{
    flex-direction: column;
    }
    .flex-wrap.flex-direction-row{
    flex-direction: row;
    }
  • 相关阅读:
    laravel进阶知识大纲
    spring boot 配置多个DispatcherServlet
    RepeatReadRequestWrapper
    RestTemplate HttpClient详解及如何设置忽略SSL
    Swagger注解-@ApiModel 和 @ApiModelProperty
    SpringBoot 接收 单个String入参之解决方案
    spring boot添加 LocalDateTime 等 java8 时间类序列化和反序列化的支持
    Mybatisplus实现MetaObjectHandler接口自动更新创建时间更新时间
    关于SpringBoot 2.0,Pageable 无法注入,提示缺少默认构造方法的解决办法
    OP_REQUIRES failed at save_restore_v2_ops.cc:109 : Permission denied: model/variables/variables_t emp; Permission denied
  • 原文地址:https://www.cnblogs.com/dianzan/p/7482481.html
Copyright © 2020-2023  润新知