uniapp 学习笔记二十四 购物车编辑弹窗页面搭建

uniapp 学习笔记二十四 购物车编辑弹窗页面搭建

cart.vue

<template>
	<view>
		<view class="flex padding" v-for="(item,index) in cartList">
			<view class="flex align-center">
				<text @click="handleCheck(index)" :class="['iconfont','icon-youxiajiaogouxuan','margin-right',{'yellow':item.isCheck}]"></text>
				<image class="poster margin-right" :src="item.img" mode=""></image>
			</view>
			<view class="flex justify-between info">
				<view class="">
					{{item.name}}
					<view class="margin-tb-xs">	{{item.french}}	</view>
					Y{{item.price}}
				</view>
				<view class="flex flex-direction align-end">
					<view @click="show=true" class="edit margin-bottom-xs">
						<text class="iconfont icon-bianjishuru"></text>
					</view>
					1磅(450g) X 1
				</view>
			</view>
		</view>
        <!-- 弹窗 -->
        <u-overlay :show="show" @click="show=false">
            <view class="bg-fff margin cover-cont" @click.stop>
                <view class="padding">
                    <view class="flex justify-between info">
                        <image class="poster margin-right" src="" mode=""></image>
                    	<view class="">
                    		草莓
                    		<view class="margin-tb-xs">	Caomei	</view>
                    		Y199
                    	</view>
                    </view>
                    <view class="flex justify-between padding-tb u-border-bottom">
                        <view class="">
                            规格选择
                        </view>
                        <view class="">
                            1 磅
                        </view>
                    </view>
                    <view class="flex justify-between align-center padding-tb u-border-bottom">
                        <view class="">
                            数量选择
                        </view>
                        <u-number-box button-size="36"></u-number-box>
                    </view>
                </view>
                <view class="flex margin-top">
                    <button type="default" class="cu-btn lg bg-brown">取消</button>
                    <button type="default" class="cu-btn lg bg-yellow">确认</button>
                </view>
            </view>
        </u-overlay>
		<view class="fixed bg-fff flex">
			<view class="flex flex-sub padding align-center">
				<text 
                @click="handleAllCheck(allInfo.allCheck)" 
                :class="['iconfont', 'icon-youxiajiaogouxuan', 'margin-right-xs',{'yellow':allInfo.allCheck}]"></text>
				全选
				<view class="margin-left">
					共计:189
				</view>
			</view>
			<view class="bg-yellow padding text-center color-fff">
				立即结算
			</view>
		</view>
	</view>
</template>

<script>
    import {mapState,mapMutations,mapGetters} from 'vuex'
	export default {
		data() {
			return {
				show:false
			}
		},
        computed: {
            ...mapState({
                cartList:state=>state.cart.cartList 
            }),
            ...mapGetters({
                allInfo:'cart/allInfo'
            })
        },
        methods:{
            ...mapMutations({
                handleCheck:'cart/cartCheckMut',
                handleAllCheck:'cart/cartAllCheckMut'                
            })
        }
	}
</script>

<style lang="scss">
page{
	padding-bottom: 100upx;
}
.poster{
	width: 180upx;
	height: 180upx;
	background-color: #d8d8d8;
}
.info{
	width: 60%;
	.edit{
		width: 80upx;
		height: 80upx;
		text-align: center;
		line-height: 80upx;
		background-color: #e6e6e6;
		border-radius: 50%;
	}
}
.icon-youxiajiaogouxuan{
	width: 50upx;
	height: 50upx;
	text-align: center;
	line-height: 50upx;
	background-color: #e6e6e6;
	border-radius: 20%;
}
.fixed {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    box-shadow: 0 0 10upx 2upx rgba(0, 0, 0, 0.2);
}

.yellow{
	background-color: yellow;
}
.cu-btn.lg{
    width: 50%;
}
.cover-cont{
    position: absolute;
    top: 50%;
    left: 0;
    width: 690upx;
    transform: translateY(-50%);
}

</style>

cart.js

export default {
    namespaced:true,
    state(){
        return {
            cartList:[{
                id:"10090",
                twoId:10089,
                name:"拿破仑草莓恋爱",
                french:"Napoleon aux fraises",
                price:"208.00",
                isCheck:false,
                img:"/static/logo.png"
            },{
                id:"10090",
                twoId:10089,
                name:"拿破仑草莓",
                french:"Napoleon aux fraises",
                price:"218.00",
                tid:11,
                tname:'限定',
                isCheck:false,
                img:"/static/logo.png"
            }
            ]
        }
    },
    getters:{
        allInfo(state){
            let allCheck = true
            state.cartList.forEach(item=>{
                if(!item.isCheck){
                    allCheck = false
                }
            })
            return {allCheck}
        }
    },
    mutations:{
        cartCheckMut(state,idx){ // 单选
            state.cartList[idx].isCheck = !state.cartList[idx].isCheck
        },
        cartAllCheckMut(state,bool){ // 全选 bool 是原本的全选状态
            state.cartList.forEach(item=>{
                item.isCheck = !bool
            })
        }
    }
}

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值