亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

js實現購物車計算的方法

瀏覽:130日期:2024-05-31 11:51:53

本文實例為大家分享了js實現購物車計算的具體代碼,供大家參考,具體內容如下

以店鋪為單位,每個店鋪下面有對應的商品選項,可全選,商品單選,店鋪單選,商品數量加減,刪除

js實現購物車計算的方法

代碼:

<script>export default { data() {return { count:0, //所有商品的數量和 shopCarList: [], //所有商品 selectList:[] //已選擇的商品 } }, computed: {//選擇的合計價格selectPrice(){ return this.selectList.reduce((total,item,index)=>{return total+item.quantity*(item.activityPrice || item.price); },0)},//選擇的合計數量selectNum(){ return this.selectList.reduce((total,item,index)=>{return total+item.quantity; },0)},//是否全選isSelecetAll(){ return this.shopCarList.every(item=>{return item.shopSelect===true })} }, methods: {//增加increment(itm){ itm.quantity<itm.stock?itm.quantity++:’’;},//減少decrement(itm){ itm.quantity>1?itm.quantity--:’’},//全選點擊allChooseHandle(){ this.initSelectAll(!this.isSelecetAll);},//商品單選點擊productChooseHandle(itm,index){ let productFlag = !itm.productSelect; this.$set(itm,’productSelect’,productFlag); let shopFlag = this.shopCarList[index].products.every(i=>{return i.productSelect===true; }) this.$set(this.shopCarList[index],’shopSelect’,shopFlag); this.getSelected();},//店鋪單選點擊shopChooseHandle(item,index){ let Flag = !item.shopSelect; this.$set(item,’shopSelect’,Flag); item.products.forEach((itm,idx)=>{this.$set(itm,’productSelect’,Flag); }) this.getSelected();},//獲取已選商品getSelected(){ let tempArr = []; this.shopCarList.forEach((item,index)=>{item.products.forEach((itm,idx)=>{ if(itm.productSelect){tempArr.push(itm); }}) }) this.selectList = tempArr;},//是否全選初始化initSelectAll(Flag){ this.shopCarList.forEach((item,index)=>{this.$set(item,’shopSelect’,Flag);item.products.forEach((itm,idx)=>{ this.$set(itm,’productSelect’,Flag);}) }) this.getSelected();},//獲取購物車列表getCarList(){ return this.$api.personal.getCarList().then(res=>{if(res.result===’000’){ //過期商品數 let expiredNum = 0; res.data.expiredList.forEach(item=>{item.products.forEach(itm=>{ expiredNum += itm.quantity}) }) //有效商品數量 this.count = res.data.count - expiredNum; this.shopCarList = res.data.shopCarList; return Promise.resolve()} })},//刪除點擊delCarList(itm,index,idx){ this.$api.personal.delCarList( [itm.carId] ).then(res=>{if(res.result===’000’){ this.count -= itm.quantity; this.shopCarList[index].products.splice(idx,1); if(this.shopCarList[index].products.length===0){this.shopCarList.splice(index,1); } this.getSelected();} })}, }, created() {this.getCarList().then(()=>{ this.initSelectAll(true);}); },};</script>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 中文字幕亚洲综合久久202 | 国产精品不卡高清在线观看 | 亚洲国产精品嫩草影院久久 | xvideos国产在线视频 | 欧美成人一级毛片 | 色综合久久九月婷婷色综合 | 亚洲成人mv | 国产淫语对白在线视频 | 大陆一级毛片免费视频观看 | 亚洲乱理伦片在线看中字 | 日韩欧美在线中文字幕 | 久久久久久久久亚洲 | 欧美黑人在线视频 | 欧美一区精品二区三区 | 日本人伦一区二区三区 | 久久国产精品亚洲综合 | 98pao强力打造高清免费 | 免费播放观看视频大片 | 亚洲国产精品xo在线观看 | 国产成人免费永久播放视频平台 | 国产精品深夜福利免费观看 | 国产一区二区三区四卡 | 精品国产美女福到在线不卡f | 生活片一级播放免费 | 青草视频免费 | 99久久精品费精品国产一区二 | 国产一级大片在线观看 | 高清精品 | 7777sq国产精品 | 77久久 | 精品九九久久 | 欧美日韩在线播放 | a级亚洲片精品久久久久久久 | 黄色一级片在线看 | 欧美一区二区三区免费播放 | 亚洲午夜在线播放 | 青青青免费视频精品99 | 天海翼一区二区三区高清视频 | 2020国产成人精品免费视频 | 中文字幕韩国 | 日韩中文字幕视频 |