购物车产品列表
本节主要讲解购物车产品列表界面的实现。效果如图14-3所示。
1.布局分析
根据上面的布局分析,我们会产生基础的框架,代码示例如下:
<view><!—第1层-开始-->
<image></image><!—第2层-->
<view><!—第2层-->
<view>珀莱雅水动力护肤品套装</view><!—第3层-->
<view>月售:11 件 / 库存:121件</view><!—第3层-->
<view class="price">¥:129.00</view><!—第3层-->
</view>
<view class="food-numb"><!—第2层-->
<view>-</view><!—第3层-->
<text>数量</text><!—第3层-->
<view>+</view><!—第3层-->
</view>
</view><!—第1层-结束-->
根据效果图分析出框架的层级后,在每个层级的view加上样式,编码实现即可。
第1层:定义产品链接 navigator,无需样式。
第2层:定义flex模式,默认从左到右排列。
第3层:图片样式,多行文字的总体排列样式(参考上面的代码和注释)。
2.功能实现
.wxml文件代码示例如下:
<scroll-view class="foodList" scroll-y="true">
<!--第一个产品开始-->
<view class="food">
<image class="img" src="/img/cp01.jpg"></image>
<view class="food-info">
<view class="name">珀莱雅水动力护肤品套装</view>
<view class="sales">月售:11 件 / 库存:121件</view>
<view class="price">¥:129.00</view>
</view>
<view class="food-numb">
<view class="remove" hidden="" >-</view>
<text class="mytext" hidden="">2</text>
<view class="add" >+</view>
</view>
</view><!--第一个产品结束-->
……
</scroll-view>
.wxss文件样式代码示例如下:
page{ background-color: floralwhite;
}
/*购物车产品列表*/
.foodList{
flex: 1;
display: flex;
flex-direction: column;
height: 100%;
background: #ECECEC;
}
.food{
display: flex;
align-items: center;
height: 170rpx;
border-bottom: 1rpx solid #ECECEC;
background: white;
}
.food::before{
content: "";
width: 15rpx;
height: 100%;
left: -15rpx;
top: 0;
border: 1px solid white;
}
.img{
width: 120rpx;
height: 120rpx;
}
.food-info{
padding-left: 15rpx;
line-height: 40rpx;
flex: 1;
}
.name{
font-size: 30rpx;
}
.sales{
font-size: 25rpx;
color: #ACACAC;
}
.price{
font-size: 30rpx;
color: red;
}
.food-numb{
height: 50rpx;
display: flex;
align-items: center;
margin-right: 30rpx;
line-height: 50rpx;
font-size: 40rpx;
}
.add{
width: 50rpx; height: 50rpx; border-radius: 25rpx; border: 1rpx;
background: #FFD161; font-size: 50rpx;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.mytext{
width: 80rpx; height: 50rpx; text-align: center;
}
.remove
{
width: 50rpx; height: 50rpx; border-radius: 25rpx; font-size: 50rpx;
border: 1rpx #ECECEC solid; background: white;
text-align: center; line-height: 50rpx;
}
小程序商城配备了javaweb、php、asp、net几个版本的后台、其他版本陆续制作中