小程序分类页面

样式(二级分类)

在这里插入图片描述

html

结构说明:list 列表分为 left 和 right 两块

<view class="category">
    <view class="search">
        <input type="text" name="search" bindconfirm='shop_search_function' confirm-type='search'
            placeholder="请输入关键词" />
        <image src="{{imgurl}}l_shousuo.png" />
    </view>

    <!-- tab切换 -->
    <view class="list flex">
        <view class="left">
            <view class="item flex {{i==index?'active':''}}" data-index="{{index}}" wx:for="{{list}}" wx:key="{{index}}"
                bindtap="clickTab">{{item.name}}</view>
        </view>
        <view class="right flex">
            <view class="item flex" wx:for='{{rightList.auctionMateriaList}}' wx:key="{{index}}">
                <image src="{{item.smallimage}}" />
                <text>{{item.name}}</text>
            </view>
        </view>
    </view>
</view>

less

样式说明:分类页面高度是100%,list列表给定高,然后overflow: auto;实现页面固定盒子滚动
页面所有盒子高度采用百分比

.category {
    height: 100%;
    border: 1rpx solid transparent;

    .search {
        height: 6%;
        margin: 1.5% 60rpx 1.5% 24rpx;
        position: relative;

        input {
            height: 100%;
            background: rgba(245, 245, 245, 1);
            border-radius: 32rpx;
            padding-left: 85rpx;
        }

        image {
            width: 44rpx;
            height: 44rpx;
            position: absolute;
            left: 30rpx;
            top: 10rpx;
        }
    }

    .list {
        border-top: 1rpx solid #F5F5F5;
        align-items: flex-start;
        height: 91%;
        padding-top: 10rpx;

        .left {
            width: 168rpx;
            background: rgba(245, 245, 245, 1);
            height: 100%;
            overflow: auto;

            .item {
                width: 100%;
                height: 130rpx;
                justify-content: space-around;
                position: relative;

                &.active {
                    background-color: #fff;
                    color: #FC5E62;

                    &:before {
                        content: '';
                        width: 6rpx;
                        height: 40rpx;
                        position: absolute;
                        left: 0;
                        top: 50%;
                        margin-top: -20rpx;
                        background-color: #FC5E62;
                    }
                }
            }
        }

        .right {
            flex: 1;
            margin-top: 10rpx;
            height: 100%;
            overflow: auto;
            font-size: 24rpx;
            flex-wrap: wrap;
            justify-content: flex-start;
            align-items: flex-start;
            .item {
                flex-direction: column;
                width: 33%;
                margin-bottom: 60rpx;
                image {
                    width: 105rpx;
                    height: 110rpx;
                    margin-bottom: 35rpx;
                }
            }
        }

    }
}

js

逻辑说明:左右分开渲染
左边渲染list,右边单独定义一个变量rightList,默认初始值为list的第一项,即第一大类
点击左侧类别名称,获取索引,动态给右边列表赋值 list [index] , 实现点击左边渲染右边的效果

// pages/category/category.js
const app = getApp()
const request = require('../../utils/request.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl: app.globalData.pmhImgurl, //全局img路径
    list: [], //分类列表
    rightList: {}, //分类右边列表
    i: 0, //分类点击的分类索引
  },
  // 点击分类左侧,渲染右侧
  clickTab(e) {
    let index = e.currentTarget.dataset.index
    this.setData({
      i: index,
      rightList: this.data.list[index]
    })
  },
  // 键盘搜索功能
  shop_search_function: function (e) {
    var value = e.detail.value;
    console.log("------->" + value);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    request('classify/selectClassify').then(data => {
      console.log(data);
      this.setData({
        list: data,
        rightList: data[0]
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
  • 0
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小曲曲

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值