用vue实现微信小程序的点餐首页-纯前端效果

news/2024/7/10 2:02:26 标签: 前端, vue, uni-app

一、效果图

图片来源于网络

二、代码

<template>
	<view class="container">
		<view class="top">
			<image src="../../static/img/home.png" class="home"></image>
		</view>
		<view class="content">
			<view class="scroll">
				<scroll-view scroll-y="auto">
					<ul class="ul">
						<li v-for="(item, index) in cakes" :key="index" :class="{ li: true, active_li: index == checkedIndex }" @click="checkedLI(index)">
							{{ item.name }}
						</li>
					</ul>
				</scroll-view>
			</view>
			<view class="cake">
				<view v-for="(item, index) in current_cakes" :key="index">
					<view v-for="(item2, index2) in item.detail" :key="index2">
						<view class="item">
							<view style="display: flex">
								<image :src="item2.src" class="img_cake"></image>
								<view class="flex_center" style="flex-direction: column; margin-left: 20px">
									<view>{{ item2.name }}</view>
									<view style="color: #ff5722; font-weight: bold; font-size: 16px">¥{{ item2.money }}</view>
								</view>
							</view>
							<view class="flex_center number">
								<u-icon name="minus-circle" @click="reduce(index, index2)" size="50" style="margin-right: 10px"></u-icon>
								<span style="font-size: 18px">{{ item2.number }}</span>
								<u-icon name="plus-circle" @click="add(index, index2)" size="50" style="margin-left: 10px"></u-icon>
							</view>
						</view>

						<u-gap height="10" bg-color="#e2e2e2" style="width: 100%"></u-gap>
					</view>
				</view>
			</view>
		</view>

		<view class="bottom">
			<image src="/static/img/gwc.png" class="gwc_img"></image>
			<view style="display: flex; align-items: center; margin-left: 30px; width: 75%; justify-content: space-between">
				<view>总计:{{ money }}元,共:{{ number }}件</view>
				<u-button style="margin-right: 10px" type="primary">选好了</u-button>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			cakes: [
				{ name: '蛋糕分类', id: '' },
				{
					name: '生日蛋糕',
					id: 'srdg',
					detail: [
						{ src: '/static/img/1.png', name: '动物乐园', money: '126', number: 0 },
						{ src: '/static/img/2.png', name: '森林莓莓', money: '160', number: 0 },
						{ src: '/static/img/3.png', name: '北海道', money: '178', number: 0 }
					]
				},
				{
					name: '休闲一刻',
					id: 'xxyk',
					detail: [
						{ src: '/static/img/2.png', name: '森林莓莓', money: '160', number: 0 },
						{ src: '/static/img/3.png', name: '北海道', money: '178', number: 0 }
					]
				}
			],
			money: 0,
			number: 0,
			checkedIndex: 1,
			current_cakes: []
		};
	},
	onLoad() {
		this.current_cakes = [];
		this.current_cakes.push(this.cakes[this.checkedIndex]);
		console.log(JSON.stringify(this.current_cakes));
	},
	onshow() {
		console.log('onshow');
	},
	methods: {
		checkedLI(index) {
			this.checkedIndex = index;
			this.current_cakes = [];
			this.current_cakes.push(this.cakes[this.checkedIndex]);
		},
		reduce(index, index2) {
			if (this.cakes[index+1].detail[index2].number > 0) {
				this.cakes[index+1].detail[index2].number--;
				this.money -= parseFloat(this.cakes[index+1].detail[index2].money);
				this.number--;
			}
		},
		add(index, index2) {
			this.cakes[index+1].detail[index2].number++;
			this.money += parseFloat(this.cakes[index+1].detail[index2].money);
			this.number++;
		}
	}
};
</script>

<style lang="less">
.container {
	display: flex;
	flex-direction: column;
	height: 100vh;
	width: 100%;
	.top {
		height: 30%;
		width: 100%;
		.home {
			width: 100%;
			height: 100%;
		}
	}
	.content {
		height: 60%;
		width: 100%;
		display: grid;
		grid-template-columns: 1fr 3fr;
		.scroll {
			background: #ece9e9;
			.ul {
				padding: 10rpx 10rpx;
				.li {
					text-align: center;
					height: 50px;
					line-height: 50px;
				}
				.li:first-child {
					font-size: 18px;
				}
				.active_li {
					background: #fff;
				}
			}
		}
		.cake {
			// display: grid;
			// grid-template-columns: 2fr 1fr;
			.item {
				margin: 10px 5px;
				display: flex;
				align-items: center;
				display: grid;
				grid-template-columns: 2fr 1fr;
			}
			.img_cake {
				width: 80px;
				height: 80px;
			}
			.flex_center {
				justify-content: center;
				display: flex;
				align-items: center;
			}
			.number {
			}
		}
	}
	.bottom {
		height: 10%;
		width: 100%;
		display: flex;
		align-items: center;
		border-top: 1px dashed #ff9800;
		.gwc_img {
			width: 80px;
			height: 80px;
		}
	}
}
</style>


http://www.niftyadmin.cn/n/5349276.html

相关文章

Vue中下载不同文件常用的方式

1. 使用window.open方法下载文件 <template><div><button click"downloadFile(filel.pdf)">下载文件1</button><button click"downloadFile(file2.jpg)">下载文件2</button></div> </template> <scri…

【C++入门到精通】特殊类的设计 |只能在堆 ( 栈 ) 上创建对象的类 |禁止拷贝和继承的类 [ C++入门 ]

阅读导航 引言一、特殊类 --- 不能被拷贝的类1. C98方式&#xff1a;2. C11方式&#xff1a; 二、特殊类 --- 只能在堆上创建对象的类三、特殊类 --- 只能在栈上创建对象的类四、特殊类 --- 不能被继承的类1. C98方式2. C11方法 总结温馨提示 引言 在面向对象编程中&#xff0…

数据结构(顺序表)

文章目录 一、线性表1、线性表1.1、线性表的定义1.2、线性表的操作 2、顺序表2.1、顺序表的实现--静态分配2.2、顺序表的实现--动态分配2.2、顺序表的特点 3、顺序表的基本操作3.1、插入操作3.2、删除操作3.3、查找操作3.2、按位查找3.2、按值查找 一、线性表 1、线性表 1.1、…

零基础学习数学建模——(三)数学建模备赛要点

本篇博客将详细介绍数学建模备赛要点。 如何学习数学建模 本人曾经担任过学校建模协会的学生教练&#xff0c;经常和各种专业各个年级的学生在一起沟通、聊天。从个人角度来看&#xff0c;我将选择数学建模这条路的人大致分为三类&#xff1a; 1、没有明确目的。这类人选择数…

给编译好的so修改rpath为当前路径

这几天调整安装&#xff0c;发现有些文件安装到/lib下。就想复制到安装目录&#xff0c;这样影响更少。然后发现rpath有问题。怎么办&#xff1f;修改为当前路径最好。 当前路径的两种表示方法 .或者$ORIGIN NEW_RPATH.:/usr/local/lib/:/lib/aarch64-linux-gnu/ NEW_RPATH\…

浅谈RPC调用

浅谈RPC调用 RPC&#xff08;Remote Procedure Call&#xff09;远程过程调用&#xff0c;是一种计算机间的通信方式&#xff0c;用于实现分布式系统中不同节点之间的方法调用。RPC调用使得开发人员可以像本地方法调用一样方便地调用远程节点上的方法&#xff0c;从而简化了分布…

阅读go语言工具源码系列之gopacket(谷歌出品)----第二集 layers-巧妙的抽象与无聊的协议包

上一集中我们讲到了wpcap.dll的go封装方法&#xff0c;对于linux系统下libpcap的go封装采用的是常用的cgo方式&#xff0c;想了解的可以看看pcap文件夹中的pcap_unix.go。 我们得到了wpcap.dll的go调用&#xff0c;就可以利用它来进行列举所有网络设备&#xff0c;例如以下代码…

设计模式_组合模式_Composite

案例引入 学校院系展示 编写程序展示一个学校院系结构: 需求是这样&#xff0c;要在一个页面中展示出学校的院系组成&#xff0c;一个学校有多个学院&#xff0c;一个学院有多个系 【传统方式】 将学院看做是学校的子类&#xff0c;系是学院的子类&#xff0c;小的组织继承大…