国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信小程序購(gòu)物車頁(yè)面實(shí)現(xiàn)

這篇具有很好參考價(jià)值的文章主要介紹了微信小程序購(gòu)物車頁(yè)面實(shí)現(xiàn)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

目錄

32.商品加入購(gòu)物車邏輯實(shí)現(xiàn)(前端)

33.購(gòu)物車頁(yè)面收貨地址實(shí)現(xiàn)

34.購(gòu)物車商品列表顯示實(shí)現(xiàn)

37.購(gòu)物車商品復(fù)選框選中業(yè)務(wù)處理

38.購(gòu)物車全選復(fù)選框選中業(yè)務(wù)處理

39.購(gòu)物車商品數(shù)量編輯實(shí)現(xiàn)

40.購(gòu)物車商品數(shù)量為0判定是否刪除

42.商品詳情立即購(gòu)買邏輯實(shí)現(xiàn)




32.商品加入購(gòu)物車邏輯實(shí)現(xiàn)(前端)

1.先在product_detail下的index.wxml的view標(biāo)簽下添加bindtap

<view class="tool_item btn_cart" bindtap="handleCartAdd">
    <view>加入購(gòu)物車</view>
</view>

2.對(duì)應(yīng)在js文件夾下寫點(diǎn)擊事件handleCartAdd:商品加入購(gòu)物車

3.需要判斷商品加入購(gòu)物車的邏輯:一種是已經(jīng)存在購(gòu)物車中,如果再加,數(shù)量加一即可;還有是不存在購(gòu)物車中的。

```Java
 // 點(diǎn)擊事件 商品加入購(gòu)物車
  handleCartAdd(){
   let cart=wx.getStorageSync('cart')||[];
    console.log("cart="+cart);
    let index=cart.findIndex(v=>v.id===this.productInfo.id);
    if(index===-1){ // 購(gòu)物車?yán)锩娌淮嬖诋?dāng)前商品 
      this.productInfo.num=1;
      cart.push(this.productInfo);
    }else{ // 已經(jīng)存在
      cart[index].num++;//數(shù)量加一
    }
    wx.setStorageSync('cart', cart); // 把購(gòu)物車添加到緩存中
    //設(shè)置提示,加入成功
    wx.showToast({
      title: '加入成功',
      icon:'success',
      mask:true
    })
  },
```

4.上面代碼優(yōu)化:可以將上面代碼封裝為setCartadd

// 點(diǎn)擊事件 商品加入購(gòu)物車
  handleCartAdd(){
    this.setCartadd();
    wx.showToast({
      title: '加入成功',
      icon:'success',
      mask:true
    })
  },
  // 加入購(gòu)物車
  setCartadd(){
    let cart=wx.getStorageSync('cart')||[];
    console.log("cart="+cart);
    let index=cart.findIndex(v=>v.id===this.productInfo.id);
    if(index===-1){ // 購(gòu)物車?yán)锩娌淮嬖诋?dāng)前商品 
      this.productInfo.num=1;
      cart.push(this.productInfo);
    }else{ // 已經(jīng)存在
      cart[index].num++;
    }
    wx.setStorageSync('cart', cart); // 把購(gòu)物車添加到緩存中
  },

33.購(gòu)物車頁(yè)面收貨地址實(shí)現(xiàn)

1.先在第三個(gè)標(biāo)簽“購(gòu)物車”cart下的index.json添加頂部標(biāo)題

{
  "usingComponents": {},
  "navigationBarTitleText": "購(gòu)物車"
}

2.開(kāi)始在cart下的index.wxml寫“獲取收貨地址”標(biāo)簽bindtap="handleChooseAddress" 作為點(diǎn)擊事件,并在index.less設(shè)置樣式。index.js寫具體的handleChooseAddress方法

1)index.wxml

```Java
<!-- 收貨地址 開(kāi)始 -->
<view class="recevie_address_row">
  <view class="address_btn" wx:if="{{!address}}">
    <button type="warn" plain bindtap="handleChooseAddress" >獲取收貨地址</button>
  </view>

  <view wx:else class="user_info_row">
    <view class="user_info">
      <view>收貨人:{{address.userName}},{{address.telNumber}}</view>
      <view>{{address.provinceName+address.cityName+address.countyName+address.detailInfo}}</view>
    </view>

    <view class="change_address_btn">
      <button size="mini" plain>更換地址</button>
    </view>
  </view>
</view>
<!-- 收貨地址 結(jié)束 -->
```

2)index.less:設(shè)置樣式包括:獲取收貨地址按鈕,更換地址按鈕。左右分采用伸縮盒子flex

.recevie_address_row{
  .address_btn{
    padding: 20rpx;
    button{
      width: 60%;
    }
  }

  .user_info_row{
    display: flex;
    padding: 20rpx;
    .user_info{
      flex:5;
    }
    .change_address_btn{
      flex:3;
      text-align: right;
      button{
        border: 1px solid gray;
        font-weight: normal;
      }
    }
  }
}

3)index.js

寫具體的handleChooseAddress方法:先在data里定義,再具體寫。由于獲取收貨地址基本不變??纱嫒刖彺嬷校??wx.setStorageSync('address',?result)

 data: {
    address:{}
  },

  handleChooseAddress(){
    wx.chooseAddress({
      success: (result) => {
        console.log(result)
        wx.setStorageSync('address', result)
      },
    })
  },

然后onShow中監(jiān)聽(tīng)頁(yè)面顯示,從緩存中獲取地址

/**
   * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示
   */
  onShow: function () {
    console.log("show")
    const address=wx.getStorageSync('address');
    this.setData({
      address
    })
  },

3.然后在頁(yè)面顯示,在index.wxml中寫,引入wx:if="{{!address}}"判斷沒(méi)有值的話顯示“獲取收貨地址”,有值的話顯示的是wx:else?class="user_info_row"

<!-- 收貨地址 開(kāi)始 -->
<view class="recevie_address_row">
  <view class="address_btn" wx:if="{{!address}}">
    <button type="warn" plain bindtap="handleChooseAddress" >獲取收貨地址</button>
  </view>

  <view wx:else class="user_info_row">
    <view class="user_info">
      <view>收貨人:{{address.userName}},{{address.telNumber}}</view>
      <view>{{address.provinceName+address.cityName+address.countyName+address.detailInfo}}</view>
    </view>

    <view class="change_address_btn">
      <button size="mini" plain>更換地址</button>
    </view>
  </view>
</view>
<!-- 收貨地址 結(jié)束 -->

效果如下圖:

微信小程序購(gòu)物車頁(yè)面實(shí)現(xiàn)

微信小程序購(gòu)物車頁(yè)面實(shí)現(xiàn)

34.購(gòu)物車商品列表顯示實(shí)現(xiàn)

1.首先數(shù)據(jù)要顯示在頁(yè)面上,先在index.js的data里定義數(shù)據(jù)cart:[]。然后可以在onShow里獲取,如果購(gòu)物車是空的,可以||一個(gè)空數(shù)組。編譯后可以在AppData中查看是否存入數(shù)據(jù):
?

onShow: function () {
    console.log("show")
    const address=wx.getStorageSync('address');
    const cart=wx.getStorageSync('cart')||[];
    this.setData({
      address,
      cart
    })
  },

2.在cart包index.wxml下寫view標(biāo)簽,購(gòu)物車列表包括的要素有:復(fù)選框,商品圖片,商品信息。同時(shí)點(diǎn)擊商品圖片,點(diǎn)擊商品名可以跳轉(zhuǎn),做法是navigator標(biāo)簽里寫url:"/pages/product_detail/index?id={{item.id}}"。大致思路仍然先寫標(biāo)簽,再設(shè)樣式

index.wxml:

<!-- 購(gòu)物車清單 開(kāi)始 -->
<view class="cart_content">
  <view class="cart_main">
    <view class="cart_item"
      wx:for="{{cart}}"
      wx:key="id"
    >
      <!-- 復(fù)選框 開(kāi)始 -->
      <view class="cart_chk_wrap">
        <checkbox-group>
          <checkbox></checkbox>
        </checkbox-group>
      </view>
      <!-- 復(fù)選框 結(jié)束 -->

      <!-- 商品圖片 開(kāi)始 -->
      <navigator class="cart_img_wrap" url="/pages/product_detail/index?id={{item.id}}">
        <image mode="widthFix" src="{{baseUrl+'/image/product/'+item.proPic}}"></image>
      </navigator>
      <!-- 商品圖片 結(jié)束 -->

      <!-- 商品信息 開(kāi)始 -->
      <view class="cart_info_wrap">
        <navigator url="/pages/product_detail/index?id={{item.id}}">
          <view class="goods_name">{{item.name}}</view>
        </navigator>
        <view class="goods_price_wrap">
          <view class="goods_price">
            ¥{{item.price}}
          </view>
          <view class="cart_num_tool">
            <view class="num_edit">-</view>
            <view class="goods_num">{{item.num}}</view>
            <view class="num_edit">+</view>
          </view>
        </view>
      </view>
      <!-- 商品信息 結(jié)束 -->
    </view>
  </view>
</view>
<!-- 購(gòu)物車清單 結(jié)束 -->

設(shè)置樣式,在index.less中

.cart_content{
  background-color: #F5F5F5;
  .cart_main{
    padding: 2rpx 10rpx 10rpx 10rpx;
    .cart_item{
      display: flex;
      background-color: white;
      border-radius: 10px;
      margin: 20rpx;
      padding-right: 20rpx;
      .cart_chk_wrap{
        flex:1;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 20rpx;
      }
      .cart_img_wrap{
        flex:2;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: #F5F5F5;
        margin: 20rpx;
        border-radius: 10px;
        image{
          width: 80%;
        }
      }
      .cart_info_wrap{
        flex:4;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        .goods_name{
          font-weight: bolder;
          display: -webkit-box;
          overflow: hidden;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }
        .goods_price_wrap{
          display: flex;
          justify-content: space-between;
          .goods_price{
            color: var(--themeColor);
            font-size: 34rpx;
          }
          .cart_num_tool{
            display: flex;
            .num_edit{
              display: flex;
              justify-content: center;
              align-items: center;
              width: 55rpx;
              height: 55rpx;
            }
            .goods_num{
              display: flex;
              justify-content: center;
              align-items: center;
              width: 85rpx;
              height: 55rpx;
              background-color: #F5F5F5;
            }
          }
        }
      }
    }
  }
}

37.購(gòu)物車商品復(fù)選框選中業(yè)務(wù)處理

復(fù)選框中,并設(shè)定點(diǎn)擊事件bindchange命名為:handleItemChange,在index.js下寫具體的商品選中事件處理方法:e作為事件源。e.currentTarget.dataset表示事件發(fā)生的當(dāng)前元素的數(shù)據(jù)集合,包含了該元素的屬性值。通過(guò)獲取該數(shù)據(jù)集合中的id屬性值,可以確定當(dāng)前用戶操作的是購(gòu)物車中哪一項(xiàng)商品。

 // 商品選中事件處理
  handleItemChange(e){
    const {id}=e.currentTarget.dataset;
    let {cart}=this.data;
    let index=cart.findIndex(v=>v.id===id);
    console.log(index)
    cart[index].checked=!cart[index].checked;

    this.setCart(cart);
  },

設(shè)置緩存方便下次打開(kāi)時(shí)存在緩存

  // 設(shè)置購(gòu)物車狀態(tài) 重新計(jì)算 底部工具欄 全選 總價(jià) 總數(shù)量 重新設(shè)置緩存
  setCart(cart){
    let allChecked=true;
    let totalPrice=0;
    let totalNum=0;
    cart.forEach(v=>{
      if(v.checked){
        totalPrice+=v.price*v.num;
        totalNum+=v.num;
      }else{
        allChecked=false;
      }
    })
    allChecked=cart.length!=0?allChecked:false;
    this.setData({
      cart,
      allChecked,
      totalNum,
      totalPrice
    })
    // cart設(shè)置到緩存中
    wx.setStorageSync('cart', cart);
  }

38.購(gòu)物車全選復(fù)選框選中業(yè)務(wù)處理

在cart包下的,index.js寫具體的商品全選事件handleItemAllCheck,點(diǎn)了之后是false狀態(tài),需要取反,取反后每個(gè)新的屬性值allcheck設(shè)置到每個(gè)cart商品的屬性(foreach遍歷設(shè)置)

handleItemAllCheck(){
    let {cart,allChecked}=this.data;
    console.log(cart,allchecked)
    allChecked=!allChecked;
    cart.foreach(v=>v.checked=allChecked);
    this.setCart(cart);
}

39.購(gòu)物車商品數(shù)量編輯實(shí)現(xiàn)

購(gòu)物車?yán)锏纳唐窋?shù)量的加和減需要綁定tab事件,加1還是減1要帶operation參數(shù),綁定參數(shù)

40.購(gòu)物車商品數(shù)量為0判定是否刪除

當(dāng)把商品數(shù)量減為0時(shí),出現(xiàn)彈窗提示:您是否要?jiǎng)h除。設(shè)定彈窗出現(xiàn)條件:數(shù)量為1且操作為減一:cart[index].num===1?&&?operation?===?-1。刪除完之后重新this.setCart(cart)顯示頁(yè)面

// 商品數(shù)量的編輯功能
  handleItemNumEdit(e){
    const {id,operation}=e.currentTarget.dataset;
    console.log(id,operation)
    let {cart}=this.data;
    let index=cart.findIndex(v=>v.id===id);
    if(cart[index].num===1 && operation === -1){
      wx.showModal({
        title:'系統(tǒng)提示',
        content:'您是否要?jiǎng)h除?',
        // 點(diǎn)擊取消
        cancelColor: 'cancelColor',
        // 點(diǎn)擊確定
        success:(res)=>{
          if(res.confirm){
            // 調(diào)用方法,指定索引刪除
            cart.splice(index,1);
            this.setCart(cart);
          }
        }
      })
    }else{
      cart[index].num+=operation;
      this.setCart(cart);
    }
  },

42.商品詳情立即購(gòu)買邏輯實(shí)現(xiàn)

在product_detail包下

點(diǎn)擊商品下的立即購(gòu)買,會(huì)實(shí)現(xiàn)跳轉(zhuǎn)到購(gòu)物車頁(yè)面。

首先在html的“立即購(gòu)買”的view標(biāo)簽里添加bindtap="bandleBuy"事件

  <view class="tool_item btn_buy" bindtap="handleBuy">
    <view>立即購(gòu)買</view>
  </view>

然后在index.js里寫具體的handleBuy方法文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-501248.html

// 點(diǎn)擊 立即購(gòu)買
  handleBuy(){
    this.setCartadd();
    wx.switchTab({
      url: '/pages/cart/index',
    })
  },

到了這里,關(guān)于微信小程序購(gòu)物車頁(yè)面實(shí)現(xiàn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 微信小程序 - 商城項(xiàng)目 - 購(gòu)物車

    微信小程序 - 商城項(xiàng)目 - 購(gòu)物車

    ? 引入 WeUI:

    2023年04月22日
    瀏覽(21)
  • 微信小程序商城開(kāi)發(fā)-商品詳情頁(yè)跳轉(zhuǎn)購(gòu)物車

    微信小程序商城開(kāi)發(fā)-商品詳情頁(yè)跳轉(zhuǎn)購(gòu)物車

    微信小程序商城開(kāi)發(fā)中商品詳情頁(yè)中購(gòu)物車頁(yè)面的跳轉(zhuǎn)(僅限于tabbar頁(yè)面的跳轉(zhuǎn)) ? 點(diǎn)擊商品詳情頁(yè)中的購(gòu)物車圖標(biāo)跳轉(zhuǎn)不到tabbar及導(dǎo)航欄中的購(gòu)物車頁(yè)面,總是報(bào)錯(cuò) 微信小程序開(kāi)發(fā)需要跳轉(zhuǎn)tabbar頁(yè)面的話,有固定的跳轉(zhuǎn)方式,不是開(kāi)發(fā)中所有的跳轉(zhuǎn)方式都適用于tabbar跳轉(zhuǎn)

    2024年02月17日
    瀏覽(23)
  • 【微信小程序】-- uni-app 項(xiàng)目-- 購(gòu)物車 -- 首頁(yè) - 輪播圖效果(五十二)

    【微信小程序】-- uni-app 項(xiàng)目-- 購(gòu)物車 -- 首頁(yè) - 輪播圖效果(五十二)

    ?? 所屬專欄:【微信小程序開(kāi)發(fā)教程】 ?? 作??者:我是夜闌的狗?? ?? 個(gè)人簡(jiǎn)介:一個(gè)正在努力學(xué)技術(shù)的CV工程師,專注基礎(chǔ)和實(shí)戰(zhàn)分享 ,歡迎咨詢! ?? 歡迎大家:這里是CSDN,我總結(jié)知識(shí)的地方,喜歡的話請(qǐng)三連,有問(wèn)題請(qǐng)私信 ?? ?? ?? ??大家好,又見(jiàn)面了,

    2023年04月18日
    瀏覽(90)
  • 商城小程序(8.購(gòu)物車頁(yè)面)

    商城小程序(8.購(gòu)物車頁(yè)面)

    本章主要完成pages下的cart購(gòu)物頁(yè)面編寫 定義如下UI結(jié)構(gòu) 美化樣式 通過(guò) mapState 輔助函數(shù),將Store中的cart數(shù)組映射到當(dāng)前頁(yè)面中使用: 在UI結(jié)構(gòu)中,通過(guò)v-for渲染自定義組件my-goods 打開(kāi)my-goods.vue組件,為商品左側(cè)圖片區(qū)域添加radio足跡 并美化UI ,使radio組件和image組件左右布局

    2024年01月23日
    瀏覽(20)
  • HTML淘寶購(gòu)物車頁(yè)面的實(shí)現(xiàn)

    HTML淘寶購(gòu)物車頁(yè)面的實(shí)現(xiàn)

    一、實(shí)驗(yàn)?zāi)康暮鸵?本實(shí)驗(yàn)任務(wù)用HTML基本標(biāo)簽制作一個(gè)簡(jiǎn)單的淘寶購(gòu)物車頁(yè)面,具體要求如下: 以純文本格式保存為*.html文件 使用表格標(biāo)簽、div標(biāo)簽、span標(biāo)簽、圖像標(biāo)簽等實(shí)現(xiàn)效果設(shè)計(jì) 啟用瀏覽器,打開(kāi)該文件或在地址欄中直接輸入存放該文件的地址 二、 實(shí)驗(yàn)原理 首先

    2024年02月11日
    瀏覽(15)
  • ECSHOP購(gòu)物車頁(yè)面顯示商品簡(jiǎn)單描述的實(shí)現(xiàn)方法

    最近看到有朋友有這方面的需求,就整理了一下,寫出來(lái)供有同樣需求的朋友備用,這里說(shuō)的商品簡(jiǎn)單描述,不是商品的詳細(xì)信息,而是后臺(tái)編輯商品時(shí)在“其他信息”標(biāo)簽欄填寫的那個(gè)“商品簡(jiǎn)單描述”,即goods_brief字段,修改前請(qǐng)注意備份相關(guān)的系統(tǒng)文件。 修改lib_order

    2023年04月16日
    瀏覽(26)
  • 微信電商小程序購(gòu)買/加入購(gòu)物車組件設(shè)計(jì)

    微信電商小程序購(gòu)買/加入購(gòu)物車組件設(shè)計(jì)

    作為一名常常擺爛,一蹶不振的大學(xué)生,最近接到了開(kāi)發(fā)電商小程序的小任務(wù),既然是電商,總得有購(gòu)買加車功能吧?經(jīng)過(guò)n個(gè)坤年的拜讀微信小程序開(kāi)發(fā)者文檔還有別的大佬的指點(diǎn),奉上我自己的理解,歡迎各位大佬指點(diǎn)改正,學(xué)習(xí)交流,共同進(jìn)步。該文章適合微信小程序初

    2024年02月09日
    瀏覽(17)
  • 購(gòu)物車程序?qū)崿F(xiàn)教程

    購(gòu)物車程序?qū)崿F(xiàn)教程

    在本教程中,我們將實(shí)現(xiàn)一個(gè)購(gòu)物車程序,實(shí)現(xiàn)在界面中以列表的形式顯示購(gòu)物車的商品信息。商品信息包含商品名稱,價(jià)格和數(shù)量,并能實(shí)現(xiàn)對(duì)應(yīng)的增刪改查操作。我們將使用 Android Studio 和 SQLite 數(shù)據(jù)庫(kù)來(lái)完成這個(gè)任務(wù)。 我們的購(gòu)物車程序由以下四個(gè)主要類組成: MainAct

    2024年02月04日
    瀏覽(22)
  • 使用Vue.js框架的指令和事件綁定實(shí)現(xiàn)一個(gè)購(gòu)物車的頁(yè)面布局

    使用了v-model指令來(lái)實(shí)現(xiàn)全選/全不選的功能,當(dāng)全選框被點(diǎn)擊時(shí),isAllChecked的值會(huì)被改變。 使用了v-if指令來(lái)判斷購(gòu)物車中是否有商品,如果有商品則渲染商品列表,否則顯示購(gòu)物車為空的提示。 使用了v-for指令來(lái)遍歷datalist數(shù)組,渲染每個(gè)商品項(xiàng)。 使用了@change事件來(lái)監(jiān)聽(tīng)商

    2024年02月12日
    瀏覽(23)
  • 【uniapp 開(kāi)發(fā)小程序】購(gòu)物車功能,實(shí)現(xiàn)全選、反選、單選、計(jì)算總價(jià)

    【uniapp 開(kāi)發(fā)小程序】購(gòu)物車功能,實(shí)現(xiàn)全選、反選、單選、計(jì)算總價(jià)

    uniapp 開(kāi)發(fā)小程序,實(shí)現(xiàn)購(gòu)物車功能,實(shí)現(xiàn)全選、反選、單選、計(jì)算總價(jià) 關(guān)鍵代碼: return totalPrice.toFixed(2); // 保留兩位小數(shù) 否則會(huì)出現(xiàn)多位小數(shù)現(xiàn)象:

    2024年02月11日
    瀏覽(23)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包