小白开发微信小程序39--右侧课程内容页面实现

1、wxml

2、wxss

.course {
    height: 100%;
}

/* 顶部图片 */
.course .indeximage {
    width: 100%;
    height: 100%;
}

/* 搜索框 */
.course .search_row {
    width: 100%;
    height: 100%;
    display: flex;
    margin-top: 3px;
    margin-bottom: 4px;
}

.course .search_row input {
    border: 1px solid red;
    background-color: #FFFFFF;
    flex: 1;
    padding-left: 20rpx;
    border-radius: 5px;
}

.course .search_row button {
    display: flex;
    color: blue;
    width: 110rpx;
    font-size: 32rpx;
    height: 100%;
    padding: 0;
    margin-top: 5px;
    justify-content: center;
}

/* 分类课程布局 */
.course .cates-container {
    display: flex;
    /* 利用视图高度-上面图片-搜索框, */
    height: calc(100vh - 147px);
}

/* 左侧导航 */
.course .cates-container .leftmenu {
    width: 24%;
}

/* 左侧导航 */
.course .cates-container .leftmenu .menuitem {
    height: 110rpx;
    display: flex;
    margin-left: 2px;
    margin-top: 5px;
    font-size: 32rpx;
    align-items: center;
    justify-content: center;
}

/* 右侧内容 */
.course .cates-container .rightcontent {
    width: 76%;
}
/* 右侧的view整体 */
.course .cates-container .rightcontent .course_list {
    display: flex;
    width: 100%;
    margin: 12rpx;
    background-color: #f8f8f8;
}
/* 右侧图片 */
.course .cates-container .rightcontent .course_list image {
    flex: 2;
    width: 100%;
    height: 70px;
    border: 1px solid blue
}
/* 右侧剩余部分 */
.course .cates-container .rightcontent .course_list .right {
    flex: 3;
    margin-left: 8px;
    display: flex;
    flex-direction: column;
}
/* 名称 */
.course .cates-container .rightcontent .course_list .right .course_name {
    font-weight: 500;
    font-size: 16px;
}
/* 价格 */
.course .cates-container .rightcontent .course_list .right .course_price {
    color: red;
    padding-bottom: 13rpx;
}
/* 按钮 */
.course .cates-container .rightcontent .course_list .right .course_price button {
    float: right;
    margin-right: 25rpx;
}

3、js文件

// pages/course/course.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isFocus: false,//取消是否显示,默认是隐藏
        inputValue: "",//输入框的值,双向绑定
        leftMenuList:[],//左侧分类数据
        rightContext:[],//右侧课程信息
        imgCourseStr:"https://localhost:5601/images/course/",//课程图片地址
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getTypecourseList()
    },
    //得到课程分类数据
    getTypecourseList(){
        let that = this;
        wx.request({
            url: 'https://localhost:5601/api/WeiXin/getCTypeCourseList',
            data: {},
            method: "GET",
            header: {
                'content-type': 'application/json' // 默认值
            },
            success(res) { 
                that.setData({
                    leftMenuList: res.data,
                    rightContext:res.data[0].courseList
                }); 
            }
        })
    },
    //分类点击事件
    handlemenuitem(e){
        let that=this;
        //console.log(e.currentTarget.dataset.index);
        const currentindex=e.currentTarget.dataset.index;
        //取出当前数据中的指定索引的信息
        const currentcourse=that.data.leftMenuList[currentindex].courseList;
        that.setData({
            rightContext:currentcourse
        });

    },


    //输入框事件
    handleinput(e) {
        let that = this;
        //console.log(e.detail.value.trim());
        var inputval = e.detail.value.trim();
        if (!inputval) {//为空时,取消按钮要隐藏
            that.setData({
                isFocus: false
            });
            // to do 显示全部课程
        } else {//不为空时,按钮要显示
            that.setData({
                isFocus: true
            });
            //to do 搜索指定的课程

        }
    },
    //取消按钮
    clearsearch() {
        let that = this;
        that.setData({
            inputValue: ""
        });
    },


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

    },

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

    },

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

    },

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

    },

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

    },

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

    },

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

    }
})

4、效果

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

hqwest

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

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

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

打赏作者

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

抵扣说明:

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

余额充值