当前位置:网站首页>Uniapp implementation Click to load more
Uniapp implementation Click to load more
2022-07-03 11:36:00 【Lord arhat】
Use scenarios
Take a chestnut : Take-out food app When the order quantity is large , It's not convenient to show it at one time . It usually shows a part , And give a To view more function . Click to customize the display of the remaining content , For example, you can display more per click N A content , Or show all .
Realization effect
Implementation steps
The following is all the code of the whole page , The data involved can be made by yourself , No more details here .
vue page
<template>
<view class="box">
<h3> Order information </h3>
<!-- List of goods -->
<view class="productlist">
<block v-for="(item,index) in cartList" :key="index">
<view class="product" v-show="index < max">
<!-- Product picture on the left -->
<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">
Paid in ¥<text class="red-text">{
{item.totalPrice}}</text>
</view>
</view>
</block>
<view style="text-align: center;color: #737373;" v-show="total > max" @tap="more"> To view more </view>
</view>
<view class="summary">
<uni-list :border="true">
<view class="right-fixed">
total :¥<text class="red-text">{
{totalPrice}}</text>
</view>
<view class="receive">
<view>
<text> Shipping address </text>
<text class="right-fixed">{
{checkedAddress.address}}</text>
</view>
<view>
<text> Consignee information </text>
<text class="right-fixed">{
{checkedAddress.receiver}} {
{checkedAddress.contact}}</text>
</view>
<view>
<text> remarks </text>
<!-- <text class="right-fixed"> Less spicy !</text> -->
<input type="text" name="remark" v-model="remark">
</view>
</view>
</uni-list>
</view>
<button @click="pay" type="primary"> Pay now </button>
</view>
</template>
JS
<script>
import {
mapState,
mapMutations
} from 'vuex'
import {
guid} from '../../util/util.js'
export default {
data(){
return{
max: 3, // Several pieces of data are displayed by default
remark: ''
}
},
components: {
},
computed: {
...mapState(['cartList']),
...mapState({
checkedAddress: state => state.checkedAddr,
orderShopInfo: state => state.orderShopInfo
}),
// Calculate the total quantity of all goods
totalCount() {
return this.cartList.reduce((total, item) => {
return total + item.count
}, 0)
},
// The cumulative total price of all goods
totalPrice() {
let amount = this.cartList.reduce((total, item) => {
return total + item.totalPrice
}, 0)
// Plus shipping charges
return (Math.round((amount+this.orderShopInfo.physical) * 10) / 10).toFixed(1)
},
// Number of goods
total(){
return this.cartList.length
}
},
methods: {
more() {
console.log(this.max)
this.max = this.total; // Add... Every time you click 1 strip
},
pay() {
let that = this
uni.showModal({
title: ' Tips ',
content: ' Confirm payment order ?',
success: function (res) {
if (res.confirm) {
// Traverse the product information in the shopping cart
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();
// Build order entity
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);
// place order
that.$post('/addOrder', JSON.stringify(order)).then(res => {
// empty cart
that.$store.commit('clearCart')
uni.showToast({
title:' Add success !',
duration:1000
})
setTimeout(function () {
uni.switchTab({
url:'/pages/order/order'
})
}, 1000);
})
} else if (res.cancel) {
console.log(' The user clicks cancel ');
}
}
});
}
}
}
</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 alignment .right-fixed{
position: fixed;
right: 20px;
}
</style>
边栏推荐
- Key switch: press FN when pressing F1-F12
- R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据、在折线移动方向添加数据点
- 基于turtlebot3实现SLAM建图及自主导航仿真
- VPP three-layer network interconnection configuration
- 进程与线程
- C language AES encryption and decryption
- Static library vs shared library
- 2022 东北四省赛 VP记录/补题
- FL Studio 20 unlimited trial fruit arranger Download
- LeetCode 46:全排列
猜你喜欢
The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.
Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable
Arctangent entropy: the latest SCI paper in July 2022
FL Studio 20无限试用版水果编曲下载
鸿蒙第三次培训(项目实训)
PHP基础
用了这么久线程池,你真的知道如何合理配置线程数吗?
Multi dimensional monitoring: the data base of intelligent monitoring
Google Earth engine (GEE) - ghsl global population grid dataset 250 meter resolution
随机推荐
asyncio 警告 DeprecationWarning: There is no current event loop
Google Earth engine (GEE) -- when we use the front and back images to make up for the interpolation effect, what if there is no effect?
如何成为一名高级数字 IC 设计工程师(1-5)Verilog 编码语法篇:操作数
C language two-dimensional array
Empire CMS no thumbnail smart tag (e:loop) two ways to judge whether there is a titlepic
How to make others fear you
1. Hal driven development
抓包整理外篇fiddler———— 会话栏与过滤器[二]
How to: configure ClickOnce trust prompt behavior
软件测试周刊(第78期):你对未来越有信心,你对现在越有耐心。
Phpcms prompt message page Jump showmessage
软考中级软件设计师该怎么备考
Application of high-precision indoor positioning technology in safety management of smart factory
How should intermediate software designers prepare for the soft test
DS90UB949
[vtk] source code interpretation of vtkpolydatatoimagestencil
Solicitation for JGG special issue: spatio-temporal omics
机器学习 3.2 决策树模型 学习笔记(待补)
高精度室内定位技术,在智慧工厂安全管理的应用
POI excel cell wrap