当前位置:网站首页>[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}
边栏推荐
- Properties of trees
- Style transfer -- CCPL: contrast coherence preserving loss for versatile style transfer
- Preparation for Android development in big companies
- In the Internet of things market, Bosch sensor has launched a number of new solutions
- Implementation of some basic operation codes of string
- MCU experiment record
- Gbase JDBC connection database exception
- 如何取得数据库创建时间?
- How to merge cells in a table by markdown
- In depth understanding of service
猜你喜欢

Data link layer protocol -- Ethernet protocol

【微信小程序】拍卖商品详情页设计与交互实现(包含倒计时、实时更新出价)

1. If function of Excel

中创算力荣获「2022年科技型中小企业」认定

运筹学基础【一】 之 导论

IT自媒体高调炫富,被黑客组织盯上,铁定要吃牢饭了…

Grafana visual configuration diagram histogram

01 create project warehouse

The strongest JVM in the whole network is coming!
![[analysis of GPIO register (crl/crh) configuration of STM32]](/img/63/a7b262e95f1dc74201ace9d411b46f.png)
[analysis of GPIO register (crl/crh) configuration of STM32]
随机推荐
GDT,LDT,GDTR,LDTR
运筹学基础【一】 之 导论
etcd学习
LVGL 8.2 Tabview
How to test data in the process of data warehouse migration?
Network engineering case: integrated network design of CII company
Mit.js: small event publishing and subscription library
一般在进行数仓迁移过程中,是如何进行数据测试的?
I didn't expect Mysql to ask these questions
Introduction to fundamentals of operations research [1]
[cloud picture theory] 247 first introduction to Huawei cloud analysis service
When the development of the meta universe begins to show more and more the style of the Internet, we need to be vigilant
# 1. Excel的IF函数
Paper:《Peeking Inside the Black Box: Visualizing Statistical Learning with Plots of Individual Condi
Data link layer protocol -- Ethernet protocol
MongoDB的安全认证详解
LVGL 8.2 Message box
Tiny-emitter.js: a small event subscription and Publishing Library
Preparation for Android development in big companies
Sudden! Britain accuses Huawei of major defects in its equipment (with report)