




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
第小程序?qū)崿F(xiàn)購物車完整版小程序?qū)崿F(xiàn)完整購物車[全選/反選計(jì)算金額/加減計(jì)算數(shù)量跟金額],供大家參考,具體內(nèi)容如下
一、wxml頁面代碼模塊
viewwx:if="{{hasList}}"
view
viewwx:for="{{list}}"wx:key="{{index}}"
viewwx:if="{{item.selected}}"catchtap="selectList"data-index="{{index}}"
imagesrc="/images/serch/xuanze.png"/
/view
viewcatchtap="selectList"data-index="{{index}}"wx:else
imagesrc="/images/serch/gouxuan.png"/
/view
!--列表商品圖片--
view
imagesrc="{{item.image}}"/
/view
view
view
!--列表標(biāo)題--
view{{item.title}}/view
viewcatchtap="deletes"data-index="{{index}}"
imagesrc="/images/serch/detel.png"/
/view
/view
!--規(guī)格--
view規(guī)格:{{_name}}/view
view
!--價(jià)格--
view¥{{item.price}}/view
!--商品數(shù)量加減--
view
!--減按鈕--
viewcatchtap="btn_minus"data-obj="{{obj}}"data-index="{{index}}"
!--按鈕圖片--
imagesrc="/images/serch/jian-1.png"/
/view
!--數(shù)量--
view{{item.num}}/view
!--加按鈕--
viewcatchtap="btn_add"data-index="{{index}}"
!--按鈕圖片--
imagesrc="/images/serch/add-1.png"/
/view
/view
/view
/view
/view
/view
!--固定底部--
view
view
view
viewcatchtap="selectAll"wx:if="{{selectAllStatus}}"
imagesrc="/images/serch/gouxuan.png"/
/view
viewcatchtap="selectAll"wx:else
imagesrc="/images/serch/gouxuan.png"/
/view
view全選/view
/view
view
view
imagesrc="/images/serch/fenxiang.png"/
/view
view分享/view
/view
/view
view
view
view合計(jì):¥{{totalPrice}}/view
/view
view
!--提交訂單--
viewcatchtap="btn_submit_order"立即購買/view
view預(yù)約試衣/view
/view
/view
/view
/view
!--購物車沒訂單--
viewwx:else
view購物車是空的哦~/view
/view
二、樣式代碼
page{
background-color:rgba(238,238,238,0.5);
.order{
height:238rpx;
background-color:#fefeff;
margin:27rpx;
border-radius:4rpx;
display:flex;
align-items:center;
.xuanze{
width:40rpx;
height:40rpx;
/*background-color:darkgoldenrod;*/
border-radius:50%;
margin:011rpx;
.xuanzeimage{
width:100%;
height:100%;
display:block;
border-radius:50%;
.order_img{
width:180rpx;
height:180rpx;
.order_imgimage{
width:100%;
height:100%;
display:block;
.order_text{
margin-left:20rpx;
width:58%;
height:180rpx;
.text_top{
display:flex;
justify-content:space-between;
align-items:center;
.title{
width:70%;
font-size:28rpx;
color:#4b5248;
display:-webkit-box;
-webkit-box-orient:vertical;
-webkit-line-clamp:1;
overflow:hidden;
.detel{
width:30rpx;
height:30rpx;
.detelimage{
width:100%;
height:100%;
display:block;
.size{
font-size:24rpx;
color:#a8ada6;
.text_bottom{
display:flex;
margin-top:50rpx;
align-items:center;
justify-content:space-between;
.money{
font-size:30rpx;
color:#a5937f;
.number{
display:flex;
justify-content:space-around;
align-items:center;
width:170rpx;
.reduce{
width:46rpx;
height:46rpx;
.reduceimage{
width:100%;
height:100%;
display:block;
.numb{
font-size:30rpx;
color:#a5937f;
.add{
width:46rpx;
height:46rpx;
.addimage{
width:100%;
height:100%;
display:block;
/*購買按鈕*/
.buy{
height:180rpx;
width:696rpx;
position:fixed;
left:27rpx;
bottom:41rpx;
background-color:#555555f3;
border-radius:4rpx;
.buy_top{
border-bottom:1pxsolidrgb(98,98,99);
height:75rpx;
display:flex;
align-items:center;
justify-content:space-between;
.top_left{
display:flex;
align-items:center;
.left_img{
width:37rpx;
height:37rpx;
margin:11rpx;
.left_imgimage{
width:100%;
height:100%;
display:block;
.left_name{
font-size:24rpx;
color:#fefeff;
margin-right:29rpx;
.buy_bottom{
display:flex;
height:104rpx;
justify-content:space-between;
align-items:center;
padding:0rpx30rpx0rpx12rpx;
.buy_left{
font-size:26rpx;
color:#fff;
.buy_right{
display:flex;
align-items:center;
.liji{
width:180rpx;
height:70rpx;
border:2rpxsolidrgba(248,248,248,1);
box-sizing:border-box;
border-radius:4rpx;
line-height:70rpx;
text-align:center;
font-size:26rpx;
color:#FEFEFF;
.two{
margin-left:12rpx;
.active{
background-color:#A5937F;
border:none;
}
三、js代碼模塊
Page({
*頁面的初始數(shù)據(jù)
data:{
hasList:true,//默認(rèn)展示列表數(shù)據(jù)
//商品列表數(shù)據(jù)
list:[{
id:1,
title:'園藝大師抗皺精華露',
image:'/images/serch/2.png',
pro_name:"30ml",
num:1,
price:180,
selected:true
id:2,
title:'伊芙琳玫瑰護(hù)手霜',
image:'/images/serch/1.png',
pro_name:"25g",
num:1,
price:62,
selected:true
id:2,
title:'燕麥山羊乳舒緩護(hù)手霜',
image:'/images/serch/2.png',
pro_name:"75ml",
num:1,
price:175,
selected:true
//金額
totalPrice:0,//總價(jià),初始為0
//全選狀態(tài)
selectAllStatus:true,//全選狀態(tài),默認(rèn)全選
*生命周期函數(shù)--監(jiān)聽頁面加載
onLoad:function(options){
*生命周期函數(shù)--監(jiān)聽頁面顯示
onShow:function(){
wx.showToast({
title:'加載中',
icon:"loading",
duration:1000
//價(jià)格方法
this.count_price();
/**當(dāng)前商品選中事件*/
selectList(e){
varthat=this;
//獲取選中的radio索引
varindex=e.currentTarget.dataset.index;
//獲取到商品列表數(shù)據(jù)
varlist=that.data.list;
//默認(rèn)全選
that.data.selectAllStatus=true;
//循環(huán)數(shù)組數(shù)據(jù),判斷--選中/未選中[selected]
list[index].selected=!list[index].selected;
//如果數(shù)組數(shù)據(jù)全部為selected[true],全選
for(vari=list.length-1;ii--){
if(!list[i].selected){
that.data.selectAllStatus=false;
break;
//重新渲染數(shù)據(jù)
that.setData({
list:list,
selectAllStatus:that.data.selectAllStatus
//調(diào)用計(jì)算金額方法
that.count_price();
//刪除
deletes(e){
varthat=this;
//獲取索引
constindex=e.currentTarget.dataset.index;
//獲取商品列表數(shù)據(jù)
letlist=this.data.list;
wx.showModal({
title:'提示',
content:'確認(rèn)刪除嗎',
success:function(res){
if(res.confirm){
//刪除索引從1
list.splice(index,1);
//頁面渲染數(shù)據(jù)
that.setData({
list:list
//如果數(shù)據(jù)為空
if(!list.length){
that.setData({
hasList:false
}else{
//調(diào)用金額渲染數(shù)據(jù)
that.count_price();
}else{
console.log(res);
fail:function(res){
console.log(res);
/**購物車全選事件*/
selectAll(e){
//全選ICON默認(rèn)選中
letselectAllStatus=this.data.selectAllStatus;
//truefalse
selectAllStatus=!selectAllStatus;
//獲取商品數(shù)據(jù)
letlist=this.data.list;
//循環(huán)遍歷判斷列表中的數(shù)據(jù)是否選中
for(leti=0;ilist.length;i++){
list[i].selected=selectAllStatus;
//頁面重新渲染
this.setData({
selectAllStatus:selectAllStatus,
list:list
//計(jì)算金額方法
this.count_price();
/**綁定加數(shù)量事件*/
btn_add(e){
//獲取點(diǎn)擊的索引
constindex=e.currentTarget.dataset.index;
//獲取商品數(shù)據(jù)
letlist=this.data.list;
//獲取商品數(shù)量
letnum=list[index].num;
//點(diǎn)擊遞增
num=num+1;
list[index].num=num;
//重新渲染顯示新的數(shù)量
this.setData({
list:list
//計(jì)算金額方法
this.count_price();
*綁定減數(shù)量事件
btn_minus(e){
////獲取點(diǎn)擊的索引
constindex=e.currentTarget.dataset.index;
//constobj=e.currentTarget.dataset.obj;
//console.log(obj);
//獲取商品數(shù)據(jù)
letlist=this.data.list;
//獲取商品數(shù)量
letnum=list[index].num;
//判斷num小于等于1return;點(diǎn)擊無效
if(num=1){
returnfalse;
//elsenum大于1點(diǎn)擊減按鈕數(shù)量--
num=num-1;
list[index].num=num;
//渲染頁面
this.setData({
list:list
//調(diào)用計(jì)算金額方法
this.count_price();
//提交訂單
btn_s
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- Python編程入門實(shí)踐:從零基礎(chǔ)到實(shí)戰(zhàn)應(yīng)用 課件 函數(shù)概述
- 《腰椎間盤突出的護(hù)理》課件
- 《領(lǐng)導(dǎo)者的輔導(dǎo)藝術(shù)》課件
- GUI窗體界面編程邁出軟件開發(fā)的第一步
- 2025年簽訂就業(yè)協(xié)議拒絕簽訂勞動(dòng)合同這種情況是否構(gòu)成違約
- 《營銷策略分享》課件
- 2025不銹鋼長期供貨合同
- 責(zé)任心與執(zhí)行力心得體會(huì)模版
- 《控制系統(tǒng)安全防護(hù)》課件
- 2025貨車買賣汽車購銷合同范本
- 通信工程現(xiàn)場應(yīng)急處置方案
- 某工程主體結(jié)構(gòu)拆改加固工程施工組織設(shè)計(jì)方案
- 2025國際護(hù)士節(jié)護(hù)士壓力與情緒管理講座課件
- 2025年山東省青島市市南區(qū)中考一模地理試題(含答案)
- 102解二元一次方程組【10個(gè)必考點(diǎn)】(必考點(diǎn)分類集訓(xùn))(人教版2024)
- 檔案管理員工作
- 市場營銷試題含參考答案
- 兒童支氣管哮喘診斷與防治指南解讀(2025年)課件
- 腫瘤??七M(jìn)修匯報(bào)護(hù)理
- 第2課 《 手繪線條圖像-物象的多視角表達(dá)》(教學(xué)設(shè)計(jì))-2023-2024學(xué)年人美版初中美術(shù)八年級(jí)下冊
- 腎上腺皮質(zhì)功能減退護(hù)理
評論
0/150
提交評論