当前位置:网站首页>[wechat applet] design and interactive implementation of auction product details page (including countdown and real-time update of bids)
[wechat applet] design and interactive implementation of auction product details page (including countdown and real-time update of bids)
2022-07-25 04:46:00 【nginx】

1、goods.wxml Code
2、goods.wxss Code
<!-- Product details page --><view class="container"><scroll-view class="main" scroll-y="true"><!-- Top rotation chart --><swiper autoplay="true" indicator-dots="true"><block wx:for="{{goodsInfo.images}}" wx:key="index"><swiper-item><image src="{{item}}" mode="heightFix"></image></swiper-item></block></swiper><!-- Commodity Title Price column --><view class="goodsPrice"><view><image src="/image/goodsPrice.png"></image><text>{{goodsInfo.current_price}} </text><!-- count down --><text wx:if="{{clock == ' The deadline has expired '}}">{{clock}}</text><text wx:else="">{{clock}}</text></view><view><text> Opening bid {{goodsInfo.start_price}}</text><image src="{{publisher.avatarUrl}}"></image><text decode="true"> {{publisher.nickName}} </text></view><view><text> {{goodsInfo.name}} </text></view></view><!-- Product publishers and auction records --><scroll-view class="goodsAuctionRecord"><view><text> Record of bids </text></view><!-- Bidding users --><block wx:for="{{auctionRecord}}" wx:key="index"><view><text>{{item.auctionTimeFormat}}</text><image src="{{item.userInfo.avatarUrl}}"></image><text decode="true"> {{item.userInfo.nickName}} Bid </text><text>{{item.putPrice}} element </text></view></block></scroll-view><!-- Product details --><view class="describe"><rich-text>{{goodsInfo.describe}}</rich-text></view></scroll-view><!-- Bottom --><view class="bottomContainer"><view><image src="/image/jianhao.png" class="changePriceIcon" bindtap="downPrice"></image><text class="addPrice">{{changePrice}} element </text><image src="/image/add.png" class="changePriceIcon" bindtap="addPrice"></image><text bindtap="putPrice"> Make an offer </text></view></view></view>
3、goods.js Code
.container {bottom: 0;top: 0;left: 0;right: 0;position: fixed;width: 100%;height: 100%;background-color: rgba(232, 234, 235, 0.89);}.main {width: 100%;height: 93%;top: 0;position: absolute;flex: 1;background-color: rgb(221, 221, 204);}swiper {height: 430rpx;background-color: white;}swiper-item {text-align: center;width: 100%;height: 100%;}swiper-item image {border-radius: 15rpx;height: 100%;}.goodsPrice {margin-top: 15rpx;width: 96%;margin-left: 2%;border-radius: 25rpx;border: aliceblue solid 1px;background-color: aliceblue;box-shadow: 4px 4px 15px rgb(180, 223, 202);}.goodsAuctionRecord {margin-top: 15rpx;width: 96%;height: auto;margin-left: 2%;border-radius: 25rpx;border: rgb(235, 238, 241) solid 1px;background-color: aliceblue;box-shadow: 4px 4px 15px rgb(180, 223, 202);}.describe {margin-top: 15rpx;width: 96%;margin-left: 2%;border-radius: 25rpx;border: rgb(235, 238, 241) solid 1px;background-color: aliceblue;box-shadow: 4px 4px 15px rgb(180, 223, 202);}.bottomContainer {position: absolute;top: 93%;width: 100%;height: 5%;white-space: nowrap;word-break:keep-all;}.addPrice {position: fixed;background-color: rgb(8, 8, 8);color: white;border-radius: 30px;margin-left: 4%;margin-top: 17rpx;padding: 10rpx 10% 10rpx 10%;}.changePriceIcon{width: 60rpx;height: 60rpx;margin-left: 4%;padding-top: 12rpx;}
4、 Time conversion js Code
var goods_idvar myTime // CounterPage({data: {goodsInfo: null,publisher: null,auctionRecord: null,clock: '',changePrice: null // offer},onLoad(options) {let goodsId = options.goodsid// take id Save it for onshow usegoods_id = goodsId// Access to product informationthis.getGoodsInfo(goodsId)// count downthis.countdown(goodsId)},onShow() {this.getGoodsInfo(goods_id)this.getAuctionRecord()},onUnload() {// Clear the timerclearInterval(myTime)},onHide() {// Clear the timerclearInterval(myTime)},// Check all productsgetGoodsInfo(goodsId) {wx.cloud.database().collection('goods').doc(goodsId).get({success: (res) => {this.setData({goodsInfo: res.data,changePrice: res.data.current_price + 1})// According to the publisher id Go to the user table to query the product publisher informationwx.cloud.database().collection('userInfo').doc(res.data.publisher_id).get({success: (res) => {this.setData({publisher: res.data})}})}})},// Bottom plus or minus priceaddPrice() {var price = this.data.changePriceprice++this.setData({changePrice: price})},downPrice() {var price = this.data.changePriceif (price > this.data.goodsInfo.current_price + 1) {price--this.setData({changePrice: price})} else {wx.showToast({title: ' The bid should be higher than the current price !',icon: 'none'})}},// Bidders bidputPrice() {// Get a bidlet price = this.data.changePrice// Get bidding userslet userInfo = wx.getStorageSync('userInfo')// Get bid timelet nowTime = new Date().getTime()// Convert to time formatvar util = require("../../util/time_transform.js")let timeFormat = util.js_date_time(nowTime)// Pop up to confirmwx.showModal({title: ' Confirm the bid ',content: ' The higher the price, the better , At the end of the auction, the high bidder can check the seller's contact information in the auction record , Thank you for your participation !',success: (res) => {if (res.confirm) {wx.showLoading({title: ' Bidding ...',})// Save auction records to the databasewx.cloud.database().collection('goodsAuctionRecord').add({data: {goodsID: goods_id,userInfo: userInfo,putPrice: price,auctionTime: nowTime,auctionTimeFormat: timeFormat},success: res => {}}),// Update current pricewx.cloud.database().collection('goods').doc(goods_id).update({data: {current_price: price}})let _this = thissetTimeout(function () {wx.hideLoading({success: (res) => {// Refresh page data_this.onShow()}})}, 1000)} else {console.log(' Cancel ')}}})},// Get the auction records of commodity usersgetAuctionRecord() {wx.cloud.database().collection('goodsAuctionRecord').where({goodsID: goods_id}).get({success: (res) => {this.setData({auctionRecord: res.data})}})},// Get the auction end time , And count downcountdown(goodsId) {wx.cloud.database().collection('goods').doc(goodsId).get({success: res => {// Take out the auction end time , Accurate to secondslet auctionEndtime = res.data.end_timeconsole.log(res)// Get current system time , Only to the secondvar nowTime = new Date().getTime() / 1000// Total seconds remainingvar totalSecond = Math.floor(auctionEndtime - nowTime)console.log(' Seconds left ', totalSecond)// Count downthis.doCountdown(totalSecond)}})},// Count down the goodsdoCountdown(totalSecond) {let _this = this// Execute the code every secondmyTime = setInterval(function () {// If the auction is overif (totalSecond < 0) {_this.setData({clock: ' The deadline has expired '})clearInterval(myTime)return} else {// Perform calculationsvar time = _this.formatTime(totalSecond)_this.setData({clock: ' The remaining ' + time})}totalSecond--;}, 1000)},// Countdown time formatformatTime(totalSecond) {// Days leftvar day = Math.floor(totalSecond / 3600 / 24)//n Hours remaining after daysvar hour = Math.floor(totalSecond / 3600 % 24)//n God n Minutes remaining after hoursvar min = Math.floor(totalSecond / 60 % 60)//n God n Hours n Seconds remaining after minutesvar sec = Math.floor(totalSecond % 60)return day + " God " + hour + " Hours " + min + " branch " + sec + " second "}})

stay util So let's make a new one time_transform.js file
notes : Plagiarism of online articles is serious , Please respect the achievements of labor , especially CSDN Users of , Please indicate the source of reprint .
// Time stamp is converted to date time , The incoming time is accurate to millisecondsfunction js_date_time(unixtime) {var date = new Date(unixtime)var y = date.getFullYear();var m = date.getMonth() + 1;m = m < 10 ? ('0' + m) : m;var d = date.getDate();d = d < 10 ? ('0' + d) : d;var h = date.getHours();h = h < 10 ? ('0' + h) : h;var minute = date.getMinutes();var second = date.getSeconds();minute = minute < 10 ? ('0' + minute) : minute;second = second < 10 ? ('0' + second) : second;return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;// Mm / DD / yyyy HHM / S// return y + '-' + m + '-' + d + ' ' + h + ':' + minute;// return y + '-' + m + '-' + d;}module.exports = {js_date_time: js_date_time}
边栏推荐
- 今天很重要
- 【浅析STM32之GPIO寄存器(CRL/CRH)配置 】
- Introduction to fundamentals of operations research [1]
- Very clear organization
- Style transfer -- CCPL: contrast coherence preserving loss for versatile style transfer
- LVGL 8.2 Roller
- Open source summer interview | "after 00" PMC member Bai Zeping
- Druid连接池——从0开始坚强的一点点的自学,Druid一点不懂的可以点进来,懂得别点进来,点进来你会嫌我啰嗦的
- Natural state is the best
- QT download installation tutorial
猜你喜欢

【基于stm32f103的SHT30温湿度显示】

Detailed explanation of security authentication of mongodb
![[golang from introduction to practice] poker licensing game](/img/b4/4e8bc421f82e9dcdaa48381154bfc8.png)
[golang from introduction to practice] poker licensing game

ThreadLocal Kills 11 consecutive questions

Database design process

Basic knowledge of scratch crawler framework

Interview required: how to design the seckill system?

Ffmpeg download and installation

Druid连接池——从0开始坚强的一点点的自学,Druid一点不懂的可以点进来,懂得别点进来,点进来你会嫌我啰嗦的
![[analysis of GPIO register (crl/crh) configuration of STM32]](/img/63/a7b262e95f1dc74201ace9d411b46f.png)
[analysis of GPIO register (crl/crh) configuration of STM32]
随机推荐
推荐系统-协同过滤在Spark中的实现
[daily question] 731. My schedule II
Druid连接池——从0开始坚强的一点点的自学,Druid一点不懂的可以点进来,懂得别点进来,点进来你会嫌我啰嗦的
tiny-emitter.js:一个小型的事件订阅发布库
QT download installation tutorial
暗黑王者|ZEGO 低照度图像增强技术解析
How to get the database creation time?
ESWC 2018 | r-gcn: relational data modeling based on graph convolution network
GetData table table data join MySQL method
[analysis of GPIO register (crl/crh) configuration of STM32]
PHP Baidu qianqianhua installment API
mitt.js:小型事件发布订阅库
[detailed tutorial] a thorough article on mongodb aggregation query
Interviewer: explain the core principle of ThreadLocal
数据链路层协议 ——— 以太网协议
Ffmpeg download and installation
读书的思考
LVGL Switch & Table
LVGL 8.2 Message box
Spire. Office for net 7.7.2 and news