当前位置:网站首页>uniapp实现点击加载更多
uniapp实现点击加载更多
2022-07-03 10:35:00 【罗汉爷】
使用场景
举个栗子:外卖app当订单商品数量比较多时,不方便一次性展示出来。通常会展示一部分,并在页面给出一个查看更多功能。点击后即可自定义展示剩余内容,比如可以每次点击多展示N个内容,或展示所有。
实现效果
实现步骤
以下为整个页面的所有代码,涉及到的数据可以自己造一些,此处不再赘述。
vue页面
<template>
<view class="box">
<h3>订单信息</h3>
<!-- 商品列表-->
<view class="productlist">
<block v-for="(item,index) in cartList" :key="index">
<view class="product" v-show="index < max">
<!-- 左边商品图片 -->
<view class="image">
<image :src="item.image" mode="aspectFill"></image>
</view>
<view class="info">
<text>{
{item.name}}</text>
<text>x{
{item.count}}</text>
</view>
<view class="price">
实付¥<text class="red-text">{
{item.totalPrice}}</text>
</view>
</view>
</block>
<view style="text-align: center;color: #737373;" v-show="total > max" @tap="more">查看更多</view>
</view>
<view class="summary">
<uni-list :border="true">
<view class="right-fixed">
合计:¥<text class="red-text">{
{totalPrice}}</text>
</view>
<view class="receive">
<view>
<text>收货地址</text>
<text class="right-fixed">{
{checkedAddress.address}}</text>
</view>
<view>
<text>收货人信息</text>
<text class="right-fixed">{
{checkedAddress.receiver}} {
{checkedAddress.contact}}</text>
</view>
<view>
<text>备注</text>
<!-- <text class="right-fixed">少放辣!</text> -->
<input type="text" name="remark" v-model="remark">
</view>
</view>
</uni-list>
</view>
<button @click="pay" type="primary">立即支付</button>
</view>
</template>
JS
<script>
import {
mapState,
mapMutations
} from 'vuex'
import {
guid} from '../../util/util.js'
export default {
data(){
return{
max: 3, //默认展示几条数据
remark: ''
}
},
components: {
},
computed: {
...mapState(['cartList']),
...mapState({
checkedAddress: state => state.checkedAddr,
orderShopInfo: state => state.orderShopInfo
}),
// 计算所有商品总数量
totalCount() {
return this.cartList.reduce((total, item) => {
return total + item.count
}, 0)
},
// 所有商品累积的总价
totalPrice() {
let amount = this.cartList.reduce((total, item) => {
return total + item.totalPrice
}, 0)
// 加上配送费
return (Math.round((amount+this.orderShopInfo.physical) * 10) / 10).toFixed(1)
},
// 商品个数
total(){
return this.cartList.length
}
},
methods: {
more() {
console.log(this.max)
this.max = this.total; //每次点击加1条
},
pay() {
let that = this
uni.showModal({
title: '提示',
content: '确定支付订单?',
success: function (res) {
if (res.confirm) {
// 遍历购物车中商品信息
let items = [];
that.cartList.forEach((item)=>{
let e = {
product_id: item.gid,
product_name: item.name,
image: item.image,
qty: item.count,
amount: item.totalPrice
}
items.push(e)
})
//console.log(JSON.stringify(items))
let mydate = new Date();
// 构建订单实体
let order = {
userid: that.$store.state.loginUser._id,
order_no: 'sa'+guid(),
shop_id: that.orderShopInfo._id,
shop_name: that.orderShopInfo.shop,
shop_image: that.orderShopInfo.logo,
total_qty: that.totalCount,
total_amount: that.totalPrice,
deliver_fee: that.orderShopInfo.physical,
address: that.checkedAddress.address,
receiver: that.checkedAddress.receiver,
contact: that.checkedAddress.contact,
remark: that.remark,
order_time: mydate.toLocaleDateString()+' '+mydate.toLocaleTimeString(),
items: items
}
console.log(order);
// 提交订单
that.$post('/addOrder', JSON.stringify(order)).then(res => {
// 清空购物车
that.$store.commit('clearCart')
uni.showToast({
title:'添加成功!',
duration:1000
})
setTimeout(function () {
uni.switchTab({
url:'/pages/order/order'
})
}, 1000);
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
}
}
</script>
CSS
<style lang="scss" scoped>
$base-color: red;
.red-text{
color: $base-color;
}
.box {
padding: 10px;
color: #898989;
}
.productlist {
justify-content: space-between;
margin: 30upx 0;
color: #898989;
.product {
height: 110px;
display: flex;
}
.product .image {
width: 100px !important;
height: 100px !important;
overflow: hidden;
}
.product .image image {
width: 100%;
height: 100%;
border-radius: 10upx;
overflow: hidden;
}
.product .info {
width: 300upx;
line-height: 100px;
padding-left: 10px;
}
.product .price {
position: fixed;
right: 20px;
line-height: 100px;
}
}
.summary{
view{
padding: 5px;
}
.receive{
margin-top: 30px;
}
}
// 右对齐 .right-fixed{
position: fixed;
right: 20px;
}
</style>
边栏推荐
- 00后抛弃互联网: 毕业不想进大厂,要去搞最潮Web3
- [VTK] vtkPolydataToImageStencil 源码解读
- 如何成为一名高级数字 IC 设计工程师(1-5)Verilog 编码语法篇:操作数
- (2) Base
- PHP server interacts with redis with a large number of close_ Wait analysis
- P3250 [HNOI2016] 网络 + [NECPC2022] F.Tree Path 树剖+线段树维护堆
- 用了这么久线程池,你真的知道如何合理配置线程数吗?
- A simple method of adding dividing lines in recyclerview
- JGG专刊征稿:时空组学
- 历经一个月,终于拿到金蝶Offer!分享一下四面面经+复习资料
猜你喜欢
ASP.NET-酒店管理系统
[OBS] configFile in ini format of OBS
一文搞懂Go语言Context
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
面試題總結(2) IO模型,集合,NIO 原理,緩存穿透,擊穿雪崩
Gut | 香港中文大学于君组揭示吸烟改变肠道菌群并促进结直肠癌(不要吸烟)
ASP. Net hotel management system
行业唯一!法大大电子合同上榜36氪硬核科技企业
DS90UB949
Encapsulate a koa distributed locking middleware to solve the problem of idempotent or repeated requests
随机推荐
Double linked list of linear list
The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities
Android log system
POI excel cell wrap
C语言日志库zlog基本使用
Oracle withdraw permission & create role
Leetcode 46: full arrangement
Redis things
Event preview | the live broadcast industry "rolled in" to drive new data growth points with product power
CorelDRAW Graphics Suite 2022新版功能详情介绍
Arctangent entropy: the latest SCI paper in July 2022
C语言 AES加解密
如何成为一名高级数字 IC 设计工程师(1-3)Verilog 编码语法篇:Verilog 行为级、寄存器传输级、门级(抽象级别)
Encapsulation attempt of network request framework of retro + kotlin + MVVM
图解网络:什么是虚拟路由器冗余协议 VRRP?
2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func mai
Incremental database backup - DB incr DB full
How to: configure ClickOnce trust prompt behavior
After using the thread pool for so long, do you really know how to reasonably configure the number of threads?
AIDL