WeChat mini-program mall development's dynamic API implements code for product details page (Part 1)

不言
Release: 2018-08-16 16:50:06
Original
7360 people have browsed it

The content of this article is about the code (Part 1) 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


Development plan

1. Implement product details page layout (this article Implement 3 modules, head product image carousel, product price and product description, product details display)
2. Request API to dynamically load data according to user clicks on different products

Get product details based on product ID API data model

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


There is also a detailed data model for viewing below!

home.js Add a jump to product details event

In the previous article, do you still remember that we did event collection for product clicks to view details? Then add the function of jumping to the product details page, as shown below:


detail.wxml

      {{goods.title}}    

¥{{goods.price}}

原价¥{{goods.privilegePrice}}

商品详情
Copy after login

detail.wxss

page { display: flex; flex-direction: column; height: 100%; } /* 直接设置swiper属性 */ swiper { /* height: 500rpx; */ height: 750rpx; } swiper-item image { width: 100%; height: 100%; } /**商品价格**/ .product-price-wrap{ display: flex; justify-content:space-between;/**两边对齐**/ flex-direction: row; flex-wrap: wrap; margin:5px 5px; /* border:1rpx solid red; */ } .product-price-wrap .product-price-new{ color: red; font-size: 40rpx; margin: 10rpx; } .product-price-wrap .product-price-old{ color: #888; text-decoration: line-through; padding-left: 5px; font-size: 12px; line-height:30px; font-weight:300; } .product-name-wrap{ margin: 0px 10px; font-size: 14px; color: #404040; } .details{ padding: 0 5px 0 5px; } .detail { display: flex; flex-direction: column; margin-top: 15rpx; margin-bottom: 0rpx; } .detail .title { font-size: 40rpx; margin: 10rpx; color: black; text-align: justify; height: 100rpx; } .detail .price { color: red; font-size: 40rpx; margin: 10rpx; } .line_flag { width: 80rpx; height: 1rpx; display: inline-block; margin: 20rpx auto; background-color: gainsboro; text-align: center; } .line { width: 100%; height: 2rpx; display: inline-block; margin: 20rpx 0rpx; background-color: gainsboro; text-align: center; } .detail-nav { display: flex; flex-direction: row; align-items: center; float: left; background-color: #fff; position: fixed; bottom: 0; right: 0; z-index: 1; width: 100%; height: 100rpx; } .button-green { background-color: #4caf50; /* Green */ } .button-red { background-color: #f44336; /* 红色 */ } .button-addCar { background-color: #f44336; /* 红色 */ width: 100%; } .image_detail { width: 100%; /* height: 750rpx; */ } .detail-nav image { width: 70rpx; height: 50rpx; margin: 20rpx 40rpx; } .line_nav { width: 5rpx; height: 100%; background-color: gainsboro; } /* 占位 */ .temp { height: 100rpx; }
Copy after login

detail.js

const ajax = require('../../utils/ajax.js'); const utils = require('../../utils/util.js'); var imgUrls = []; var detailImg = []; var goodsId = null; var goods = null; Page({ /** * 页面的初始数据 */ data: { isLike: true, showDialog: false, goods:null, indicatorDots: true, //是否显示面板指示点 autoplay: true, //是否自动切换 interval: 3000, //自动切换时间间隔,3s duration: 1000, // 滑动动画时长1s }, //预览图片 previewImage: function (e) { var current = e.target.dataset.src; wx.previewImage({ current: current, // 当前显示图片的http链接 urls: this.data.imgUrls // 需要预览的图片http链接列表 }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; goodsId = options.goodsId; console.log('goodsId:' + goodsId); //加载商品详情 that.goodsInfoShow(); }, goodsInfoShow: function (success) { var that = this; ajax.request({ method: 'GET', url: 'goods/getGoodsInfo?key=' + utils.key+'&goodsId=' + goodsId, success: data => { var goodsItem = data.result; for (var i = 0; i < goodsItem.shopGoodsImageList.length; i++) { imgUrls[i] = goodsItem.shopGoodsImageList[i].imgUrl; } var details = goodsItem.details.split(";"); for (var j = 0; j < details.length; j++) { detailImg[j] = details[j]; } goods = { imgUrls: imgUrls, title: goodsItem.name, price: goodsItem.price, privilegePrice: goodsItem.privilegePrice, detailImg: detailImg, imgUrl: goodsItem.imgUrl, buyRate: goodsItem.buyRate, goodsId: goodsId, count:1, totalMoney: goodsItem.price, } that.setData({ goods : goods }) console.log(goods.title) } }) }, })
Copy after login

Related recommendations:

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

WeChat mini program mall development for the welfare field on the homepage of the mall with no limit on pull-down refresh Code implementation of dynamic API data

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!