当前位置: 首页 > news >正文

uniapp 学习笔记二十一 路由跳转及产品详情数据渲染

uniapp 学习笔记二十一 路由跳转及产品详情数据渲染

 

 

cake.vue

<template>
    <view>
        <nav-custom></nav-custom>
        <view class="cont">
            <good-item v-for="(item,index) in glist" :gdata="item"></good-item>
        </view>
        <view class="fixed flex justify-center bg-fff padding-sm">
            <view v-for="(item,index) in tabArr" :key="index" @tap="handleTab(item)"
                class="flex justify-around align-center">
                <view class="">{{item.name}}</view>
                <u-line v-if="index<tabArr.length-1" direction="col" length="15" margin="30upx"></u-line>
            </view>
        </view>
        <u-popup :show="show" mode="left" @close="handleClose">
            <view class="pop-cont">
                <view v-for="(item,index) in cfylist" class="padding-sm u-border-bottom">
                    {{item.bname}}
                    <view v-if="index==0">
                        <view 
                            @tap="listShow=!listShow" 
                            :class="['padding-tb-sm',{'u-border-bottom':!listShow}]"
                        >
                            口味筛选
                        </view>
                        <u-cell-group v-if="listShow">
                            <u-cell 
                                v-for="(itm,idx) in item.list" 
                                :title="itm.tname" 
                                isLink
                                @click="handleList(itm,1)" 
                            ></u-cell>
                        </u-cell-group>
                        <view @tap="sceneShow=!sceneShow" class="padding-tb-sm u-border-top">
                            场景筛选
                        </view>
                        <u-cell-group v-if="sceneShow">
                            <u-cell 
                            v-for="(itm,idx) in item.scene" 
                            :title="itm.tname" 
                            isLink                            
                            @click="handleList(itm,2)" 
                        ></u-cell>
                        </u-cell-group>
                    </view>
                </view>
            </view>
        </u-popup>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                // condition:{ // 商品列表查询条件对象
                //     bcid:1,
                // },
                cfylist:[],
                sceneShow:false,
                listShow:false,
                show: false,
                glist: [],
                page: 0,
                tabArr: [{
                        name: '分类',
                        bcid: '',
                        target: ''
                    },
                    {
                        name: '蛋糕',
                        bcid: '1',
                        target: '/pages/cake'
                    },
                    {
                        name: '面包',
                        bcid: '11',
                        target: '/pages/bread'
                    },
                    {
                        name: '小食',
                        bcid: '6',
                        target: '/pages/food'
                    },
                    {
                        name: '购物车',
                        bcid: '',
                        target: '/pages/cart'
                    }
                ]
            }
        },
        computed:{
            num(){
                return this.$store.state.count.num
            },
            condition(){
                return this.$store.state.condition.cond
            }
        },
        methods: {
            /* handleDetail(idx) {
                console.log(idx);
                uni.navigateTo({
                    url: '../detail/detail?idx=' + idx
                })
            }, */
            loadData() {
                let skip = this.page * 8
                let wh = JSON.stringify(this.condition)
                let url = `/1.1/classes/goods?where=${wh}&limit=8&skip=${skip}`;
                this.$get(url).then(res => {
                    uni.stopPullDownRefresh()
                    let {
                        results
                    } = res
                    if (results.length) {
                        this.page++
                        this.glist = [
                            ...this.glist,
                            ...res.results
                        ]
                        return
                    }
                    uni.showToast({
                        title: '这回真没了...',
                        icon: 'none'
                    })
                })
            },
            handleTab(item) {
                let {
                    bcid,
                    target
                } = item
                if (bcid) {
                    // this.glist = []
                    // this.page = 0
                    // this.condition.bcid = Number(bcid)
                    this.$store.commit('changeCondition',{
                        bcid:Number(bcid)
                    })
                    this.reloadData()
                }
                if (!bcid && !target) {
                    this.show = true
                }
            },
            handleClose(){
                this.show = false
            },
            handleList({bid,tid},type){
                // 口味场景筛选
                // console.log(typeof bid);
                let obj = {bcid:bid}
                type === 1 ? obj.fid=tid : obj.sid=tid
                this.$store.commit('changeCondition',obj)
                this.reloadData()
            },
            reloadData(){ //刷新页面数据
                this.glist = []
                this.page = 0
                this.loadData()
            }
        },
        onLoad() {
            this.loadData()            
            this.$get('/1.1/classes/classify').then(res=>{
                console.log(res)
                this.cfylist = res.results
            })
        },
        onReachBottom() {
            console.log('触底了');
            this.loadData()
        },
        onPullDownRefresh() {
            this.glist = []
            this.page = 0
            this.loadData()
        }
    }
</script>

<style lang="scss">
page {
    padding-top: 100upx;
    padding-bottom: 120upx;
}

.cont {
    display: flex;
    flex-wrap: wrap;
    padding: 15upx;
    justify-content: space-between;
}

.fixed {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    box-shadow: 0 0 10upx 2upx rgba(0, 0, 0, 0.2);
}
.cu-bar{
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 2;
}
.pop-cont{
    width: 400upx;
    margin-top: 200upx;
}
</style>

detail.vue

<template>
    <view>
        <swiper class="banner" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
        	<swiper-item>
        		<view class="swiper-item">
					<image :src="detail.img" mode="widthFix"></image>
				</view>
        	</swiper-item>
        </swiper>
		<view class="flex justify-around">
			<view 
				v-for="(item,index) in detail.list" 
				:key="index" 
				:class="['text-center padding-sm tab',{active:tabIdx}]" 
				@tap="tabIdx = index"
			>
				<view class="">{{item.spec}}</view>
				<view class="">{{item.weight}}</view>
				<view class="">{{item.edible}}</view>
			</view>
		</view>
		
		<view class="padding fs-28 u-border-bottom">
			¥{{detail.list[tabIdx].price}}
		</view>
		
		<view class="padding fs-28 u-border-bottom">
			{{detail.list[tabIdx].ahead}}
			<text class="margin-lr">{{detail.list[tabIdx].size}}</text>
			{{detail.list[tabIdx].edible}}
		</view>
	
		<view class="padding fs-28 u-border-bottom">
			{{detail.list[tabIdx].fittings}}
		</view>
		
		<view class="flex justify-around fixed padding-tb-sm">
			<button class="cu-btn bg-brown lg">加入购物车</button>
			<button class="cu-btn bg-yellow lg">立即购买</button>
		</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                tabIdx:0,
				detail:null
            }
        },
        methods: {
        },
        onLoad() {
            uni.getStorage({
            	key:'detail',
				success:(res)=>{
					// console.log(res.data);
					this.detail = res.data
				}
            })
        },
        onShow() {
            console.log('onShow 生命周期 执行');
        },
        onHide() {
            console.log('onHide 生命周期 执行');
        },
        onLaunch() {
            console.log('onLaunch 生命周期 执行');
        }
    }
</script>

<style>
.banner{
	height: 600upx;
	.swiper-item{
		height: 600upx;
	}
}
</style>

goods-item.vue

<template>
    <view class="cake-item">
        <image @tap="handleDetail" class="poster" :src="gdata.img" mode=""></image>
        <view class="info-cont">
            <view class="info flex align-center justify-between">
                <view class="">
                    <view class="fs-28">
                        {{gdata.name}}
                    </view>
                    <view class="fs-16">
                        {{gdata.french}}
                    </view>
                </view>
                <view class="cart-btn margin-right-sm">
                    <text class="iconfont icon-caigou"></text>
                </view>
                
            </view>
            <view class="fs-18">
                <text class="fs-14">Y</text>
                {{gdata.price}}
            </view>
            
        </view>
    </view>
    
</template>

<script>
    export default {
        name:"goods-item",
        props:['gdata'],
        data() {
            return {
                
            };
        },
		methods:{
			handleDetail() {
				uni.setStorage({
					key:'detail',
					data:this.gdata,
					success: () => {
						uni.navigateTo({
							url: '/pages/detail/detail'
						})
					}
				})
			    
			},
		}
    }
</script>

<style lang="scss">
.cake-item{
    width: 350upx;
    .poster{
        height: 350upx;
        background-color: #f5f5f5;
    }
    .fs-28{
        font-size: 28upx;
        margin-top: 24upx;
    }
    .fs-16{
        font-size: 16upx;
        margin: 14upx 0;
    }
    .fs-18{
        font-size: 18upx;
        margin-bottom: 22upx;
    }
    .cart-btn{
        width: 60upx;
        height: 60upx;
        border-radius: 50%;
        background-color: #ffe32a;
        text-align: center;
        line-height: 60upx;
    }
}

</style>

相关文章:

  • 怎么预防鸡葡萄球菌病 防治鸡球菌病的特效药
  • 阿里巴巴中国站1688按关键词搜索商品api电商数据接口
  • 艺术大观杂志艺术大观杂志社艺术大观编辑部2022年第20期目录
  • 神经网络专家系统的意思,神经网络专家系统结构
  • html多图片下载方法1:<a>标签 涉及nginx
  • 基于SSM学术会议管理系统毕业设计源码061504
  • Spring——简介和IOC底层原理
  • 面试必备:《Java 最常见 200+ 面试题全面解析》
  • 安卓毕业设计选题基于Uniapp实现的鲜花购物商城
  • 运维工程师——学习路线技能图谱
  • 集合Set集合详解
  • 金属标记/荧光标记/功能化改性/官能团表面包覆聚苯乙烯微球
  • 猿创征文|一个网站的完整部署流程
  • springCloud(踩坑)springCloud-gateway配合Nacos访问接口404,503
  • 数据格式转换篇---VOC(xml)标注格式转换为YOLOv5(txt)
  • Cookie 在前端中的实践
  • ES6核心特性
  • MQ框架的比较
  • MySQL-事务管理(基础)
  • springMvc学习笔记(2)
  • vue学习系列(二)vue-cli
  • XML已死 ?
  • 基于Volley网络库实现加载多种网络图片(包括GIF动态图片、圆形图片、普通图片)...
  • 面试题:给你个id,去拿到name,多叉树遍历
  • 让你的分享飞起来——极光推出社会化分享组件
  • 一起参Ember.js讨论、问答社区。
  • #Linux杂记--将Python3的源码编译为.so文件方法与Linux环境下的交叉编译方法
  • ${ }的特别功能
  • $L^p$ 调和函数恒为零
  • (k8s中)docker netty OOM问题记录
  • (读书笔记)Javascript高级程序设计---ECMAScript基础
  • (论文阅读30/100)Convolutional Pose Machines
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (十一)c52学习之旅-动态数码管
  • (学习日记)2024.04.10:UCOSIII第三十八节:事件实验
  • .NET Conf 2023 回顾 – 庆祝社区、创新和 .NET 8 的发布
  • .NET CORE 第一节 创建基本的 asp.net core
  • .net core 依赖注入的基本用发
  • .net mvc部分视图
  • .Net下C#针对Excel开发控件汇总(ClosedXML,EPPlus,NPOI)
  • /dev/sda2 is mounted; will not make a filesystem here!
  • @entity 不限字节长度的类型_一文读懂Redis常见对象类型的底层数据结构
  • @javax.ws.rs Webservice注解
  • @RunWith注解作用
  • [.NET 即时通信SignalR] 认识SignalR (一)
  • [23] GaussianAvatars: Photorealistic Head Avatars with Rigged 3D Gaussians
  • [BUUCTF 2018]Online Tool
  • [C++]unordered系列关联式容器
  • [CF407E]k-d-sequence
  • [E单调栈] lc2487. 从链表中移除节点(单调栈+递归+反转链表+多思路)
  • [IDF]啥?
  • [iOS]GCD(一)
  • [LeetCode] 2.两数相加
  • [Linux](16)网络编程:网络概述,网络基本原理,套接字,UDP,TCP,并发服务器编程,守护(精灵)进程
  • [MYSQL]mysql常用操作命令