Home > WeChat Applet > Mini Program Development > WeChat applet payment countdown function in Android

WeChat applet payment countdown function in Android

高洛峰
Release: 2017-01-10 09:54:47
Original
1955 people have browsed it

Look at the effect

WeChat applet payment countdown function in Android

#Due to my weak web experience - - At first, my idea was to find events, but after looking at the API for a long time, it was basically click and touch, triggered by physics. - -

I actually ignored the life cycle. Life cycle + threads are completely OK~

It turns out that threads are still king. This should be done from the beginning~

I also read a lot of things written in js on Du Niang, but maybe I have just done it a few days ago, and I am not proficient enough in js and WeChat applet

Thoughts:

: Function (Options) Currency Method Method

## Defining threads for data dynamic reality


##1. Date converts to milliseclic seconds




# #2. Definition thread dynamic display

3. Rendering the rendext

## 1. milliseconds to turn into a fixed format

# 2. If there are insufficient digits, add 0

Look at the code

wxml:

<view class="pay_time">
 <image src="{{imgUrls_pay_time}}"></image>
 <text>支付剩余时间:</text>
 <text>{{clock}} </text>
</view>
Copy after login

wxjs:

// pages/order/take_order/pay/pay.js
var app = getApp()
Page({
 data: {
  imgUrls_pay_time: &#39;/image/icon_orderstatus_countdown.png&#39;,
  "productName": "",
  "productPrice": "",
  "payDetail": [],
  "wxPayMoneyDesc": "",
  "expireTime": "",
  clock: &#39;&#39;
 },
 onLoad: function (options) {
  // 页面初始化 options为页面跳转所带来的参数
  new app.WeToast()
  var that = this;
  that.count_down();
 },
 onReady: function () {
  // 页面渲染完成
 },
 onShow: function () {
  // 页面显示
 },
 onHide: function () {
  // 页面隐藏
 },
 onUnload: function () {
  // 页面关闭
 },
 /* 毫秒级倒计时 */
 count_down: function () {
  var that = this
  //2016-12-27 12:47:08 转换日期格式
  var a = that.data.expireTime.split(/[^0-9]/);
  //截止日期:日期转毫秒
  var expireMs = new Date(a[0], a[1] - 1, a[2], a[3], a[4], a[5]);
  //倒计时毫秒
  var duringMs = expireMs.getTime() - (new Date()).getTime();
  // 渲染倒计时时钟
  that.setData({
   clock: that.date_format(duringMs)
  });
  if (duringMs <= 0) {
   that.setData({
    clock: "支付已截止,请重新下单"
   });
   // timeout则跳出递归
   return;
  }
  setTimeout(function () {
   // 放在最后--
   duringMs -= 10;
   that.count_down();
  }
   , 10)
 },
  /* 格式化倒计时 */
 date_format: function (micro_second) {
  var that = this
  // 秒数
  var second = Math.floor(micro_second / 1000);
  // 小时位
  var hr = Math.floor(second / 3600);
  // 分钟位
  var min = that.fill_zero_prefix(Math.floor((second - hr * 3600) / 60));
  // 秒位
  var sec = fill_zero_prefix(second % 60);// equal to => var sec = second % 60;
  return hr + ":" + min + ":" + sec + " ";
 },
 /* 分秒位数补0 */
 fill_zero_prefix: function (num) {
  return num < 10 ? "0" + num : num
 }
})
Copy after login

tip:

If the digits are not padded with 0WeChat applet payment countdown function in Android

, the following will be displayed


The above is the payment countdown function of the WeChat applet in Android introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank you all for your support of the PHP Chinese website! #########For more articles related to the payment countdown function of the WeChat applet in Android, please pay attention to 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template