search
HomeWeChat AppletMini Program DevelopmentWeChat mini program mall development's dynamic API implements code for product details page (below)

The content of this article is about the code (below) of the dynamic API implemented in the WeChat mini-program mall development to realize the product details page. It has certain reference value. Friends in need can refer to it. I hope it will be useful to you. Helps.

See the effect

Add to shopping cart.gif

Development plan

1. Add to shopping cart floating box, Product quantity, price calculation, collection and add to shopping cart function development
2. Call the add to shopping cart API to add to the shopping cart

Acquire product details API data model based on product ID

Visit: https ://100boot.cn/ Select the micro-mall case, as shown below:

Add to shopping cart and product collection API.jpg


There is also a detailed data model below that you can view!

detail.wxml

<!-- 底部悬浮栏 --><view class="detail-nav">
  <image bindtap="toCar" src="../../images/cart1.png" />  
  <view class="line_nav"></view>
   <image bindtap="addLike" src="{{isLike?&#39;../../images/enshrine_select.png&#39;:&#39;../../images/enshrine.png&#39;}}" /> 
  <button data-goodid="1"  class="button-green" bindtap="toggleDialog" >加入购物车</button>
  <button class="button-red" bindtap="immeBuy" formType="submit">立即购买</button></view><!--加入购物车-->#template模板引用<import src="../template/template.wxml" /><view class="dialog {{ showDialog ? &#39;dialog--show&#39; : &#39;&#39; }}">
      <view class="dialog__mask" bindtap="toggleDialog" />
      <view class="dialog__container">
        <view class="row">
          <icon bindtap="closeDialog" class="image-close" type="cancel" size="25"/>
          <image class="image-sku" src="{{goods.imgUrl}}"></image>
          <view class="column">
            <text class="sku-price">¥{{goods.totalMoney}}</text>
            <text class="sku-title">销量 {{goods.buyRate}} 件</text>
            <text class="sku-title">商品编码:{{goods.goodsId}}</text>
          </view>
        </view>
        <text class="border-line"></text>
        <view class="row">
          <text >购买数量</text>
          <view class="quantity-position">
              <!-- <template is="quantity"  data="{{ ...item,index:index}}" />  -->
               <template is="quantity" data="{{ ...goods,index:1}}" /> 
          </view>
        </view>
        <text class="border-line"></text>

        <button data-goodid="{{goods.goodsId}}" class="button-addCar" bindtap="addCar" formType="submit">确定</button>
      </view>
    </view>

detail.wxss

#template 模板引用
 @import "../template/template.wxss"; 
/* sku选择 */
.dialog__mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.7);
  display: none;
}
.dialog__container {
  position: fixed;
  bottom: 0;
  width: 100%;
  background: white;
  transform: translateY(150%);
  transition: all 0.4s ease;
  z-index: 11;
}
.dialog--show .dialog__container {
  transform: translateY(0);
}
.dialog--show .dialog__mask {
  display: block;
}
.image-sku {
  width: 200rpx;
  height: 200rpx;
  z-index: 12;
  position: absolute;
  left: 20px;
  top: -30px;
  border-radius: 20rpx;
}
.image-close {
  width: 40rpx;
  height: 40rpx;
  position: fixed;
  right: 20rpx;
  top: 10rpx;
}
.column {
  display: flex;
  flex-direction: column;
}
.row {
  display: flex;
  flex-direction: row;
  align-items: center;
}
.border-line {
  width: 100%;
  height: 2rpx;
  display: inline-block;
  margin: 30rpx 0rpx;
  background-color: gainsboro;
  text-align: center;
}
.sku-title {
  position: relative;
  left: 300rpx;
  margin: 1rpx;
}
.sku-price {
  color: red;
  position: relative;
  left: 300rpx;
  margin: 1rpx;
}
.row .quantity-position {
  position: absolute;
  right: 30rpx;
  display: flex;  
  justify-content: center;  
  flex-direction: column;  
}

detail.js

// 收藏-修改收藏状态
  addLike() {
    this.setData({
      isLike: !this.data.isLike
    });
ajax.request({
      method: 'GET',
      url: 'collection/addShopCollection?key=' + utils.key + '&goodsId=' + goodsId,
      success: data => {
        console.log("收藏返回结果:" + data.message)
        wx.showToast({
          title: data.message,
          icon: 'success',
          duration: 2000
        });
      }
    })
  },
// 立即购买-待开发
  immeBuy() {
    wx.showToast({
      title: '购买成功',
      icon: 'success',
      duration: 2000
    });
  },
// 跳到购物车-待开发
  toCar() {
    wx.navigateTo({
      url: '../cart/cart'
    })
  },
 /**
   * sku 弹出
   */
  toggleDialog: function () {
    this.setData({
      showDialog: !this.data.showDialog
    });
  },
  /**
   * sku 关闭
   */
  closeDialog: function () {
    console.info("关闭");
    this.setData({
      showDialog: false
    });
  },
/* 减数 */
  delCount: function (e) {
    console.log("刚刚您点击了减1");
    var count = this.data.goods.count;
    // 商品总数量-1
    if (count > 1) {
      this.data.goods.count--;
    }
    // 将数值与状态写回  
    this.setData({
      goods: this.data.goods
    });
    this.priceCount();
  },
  /* 加数 */
  addCount: function (e) {
    console.log("刚刚您点击了加1");
    var count = this.data.goods.count;
    // 商品总数量-1  
    if (count  1) {
      this.data.goods.count--;
    }
    // 将数值与状态写回  
    this.setData({
      goods: this.data.goods
    });
    this.priceCount();
  },
  /* 加数 */
  addCount: function (e) {
    console.log("刚刚您点击了加1");
    var count = this.data.goods.count;
    // 商品总数量-1  
    if (count  {
        console.log("加入购物车返回结果:" + data.message)
        wx.showToast({
          title: '加入购物车成功',
          icon: 'success',
          duration: 2000
        });
      }
    })
}

template template uses

due to the addition of template The source code is too long, you can just download the source code and use it.

Related recommendations:

Construction of https framework for WeChat mini program mall development and implementation of top and bottom navigation

Development of WeChat mini program mall Dynamic API implements code for product details page (Part 1)

The above is the detailed content of WeChat mini program mall development's dynamic API implements code for product details page (below). For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment