Authored by lea guo

yohood原价购

... ... @@ -2,6 +2,7 @@
import ZeroSellService from '../../service/zero-sell';
import CommonService from '../../service/common';
import { fomartCountdownTime } from '../../../../utils/util';
const event = global.event;
... ... @@ -12,6 +13,14 @@ Component({
* 组件的属性列表
*/
properties: {
// UNKNOWN: 0,
// READY: 1, // 未开始
// START: 2, // 参加
// ALEADY: 3, // 已参加活动
// WAIT: 4, // 等待抽奖中
// LUCK: 5, // 抽奖结束
// END: 6, // 活动结束
// PEOPLE_LIMIT_WAIT: 7 // 人数达到活动限制、已满员、人数不足统一为待开奖状态
status: {
type: Number,
value: 1,
... ... @@ -40,21 +49,46 @@ Component({
type: Number,
value: 0,
},
// time in seconds
startTime: {
type: Number,
value: 0,
observer: function(startTime) {
this.setData({
remainingTime: fomartCountdownTime({ startTime }).join(':'),
});
},
},
},
/**
* 组件的初始数据
*/
data: {
show: false,
show: true,
code: '',
error: false,
fellow: false,
isStart: false,
remainingTime: '',
},
ready() {
this.service = new ZeroSellService();
this.commonService = new CommonService();
const timeId = setInterval(() => {
if (this.data.isStart) {
this.triggerEvent('onActivityEnd');
clearInterval(timeId);
}
const fomartTimes = fomartCountdownTime({
startTime: this.properties.startTime,
});
this.setData({
remainingTime: fomartTimes.join(':'),
isStart: fomartTimes.length === 0,
});
}, 1000);
},
/**
... ...
<!-- page/subPackage/pages/zeroSell/components/action-bar.wxml -->
<view class="action-bar">
<block wx:if="{{status === 1}}">
<view class="action-item over">即将开始</view>
<view class="action-item over">
<text>距开始</text>
<text class="remaining-time">{{remainingTime}}</text>
</view>
</block>
<block wx:elif="{{status === 2}}">
<form bindsubmit='submitFormId' report-submit='true' class="action-item">
... ... @@ -13,23 +16,11 @@
<block wx:elif="{{status === 3}}">
<view class="action-item ok" bindtap="goShare">邀请好友参加,增加中奖率</view>
</block>
<block wx:elif="{{status === 4}}">
<view class="action-item confirm" bindtap="goMyList">我的抽奖码({{num}})</view>
</block>
<block wx:elif="{{status === 5}}">
<view class="action-item confirm" bindtap="goMyList">我的抽奖码({{num}})</view>
<view class="action-item ok" bindtap="openFellowAlert">查看开奖结果</view>
</block>
<block wx:elif="{{status === 6}}">
<view class="action-item over">活动已结束</view>
<view class="action-item over">已结束</view>
</block>
<block wx:elif="{{status === 7}}">
<block wx:if="{{num > 0}}">
<view class="action-item confirm" bindtap="goMyList">我的抽奖码({{num}})</view>
</block>
<block wx:else>
<view class="action-item over">活动已结束</view>
</block>
<block wx:else>
<view class="action-item over">已结束</view>
</block>
</view>
<new-lucky-alert wx:if="{{show}}" bindhiddenalert="hiddenAlert">
... ...
... ... @@ -3,3 +3,12 @@
.ok {
background-color: #132f48;
}
.remaining-time {
margin-left: 20rpx;
width: 140rpx;
display: inline-block;
}
.share {
background-color: #64ad88;
}
... ...
// page/subPackage/pages/zeroSell/components/product-detail-header.js
import { fomartCountdownTime } from '../../../../utils/util';
Component({
properties: {
product: {
... ... @@ -42,21 +43,8 @@ Component({
methods: {
formatCountDown() {
// 时间单位为S
let { end_time: endTimeInSeconds = 0 } = this.properties.product || {};
if (endTimeInSeconds * 1000 - Date.now() < 0) {
return [];
}
let remainingTime = endTimeInSeconds - Date.now() / 1000;
const timeInHour = Math.floor(remainingTime / 3600);
remainingTime = remainingTime - timeInHour * 3600;
const timeInMinute = Math.floor(remainingTime / 60);
remainingTime = parseInt(remainingTime - timeInMinute * 60);
return [timeInHour, timeInMinute, remainingTime].map(time => {
return `${time > 9 ? time : `0${time}`}`;
});
let { end_time: endTime = 0 } = this.properties.product || {};
return fomartCountdownTime({ endTime });
},
},
});
... ...
... ... @@ -43,11 +43,11 @@
</view>
<!-- <group-recommend groupRecommendList="{{groupList}}" bindgoToGroupMiniApp="goToGroupMiniApp"></group-recommend> -->
<view class="action-bar">
<action-bar wx:if="{{isLogin}}" status="{{actionStatus}}" num="{{myPrizeCount}}" share-uid="{{shareUid}}" act-prize-id="{{actPrizeId}}" bindgetcode="changeActionStatus" bindshare="share" copyText="{{lottery.miniappCopy}}" text="{{lottery.miniappTip}}" bindgaincodesuccess="reportSuccess" type="{{lottery.miniappType}}"></action-bar>
<action-bar start-time="{{product.end_time}}" wx:if="{{isLogin}}" status="{{actionStatus}}" num="{{myPrizeCount}}" share-uid="{{shareUid}}" act-prize-id="{{actPrizeId}}" bindgetcode="changeActionStatus" bindshare="share" copyText="{{lottery.miniappCopy}}" text="{{lottery.miniappTip}}" bindgaincodesuccess="reportSuccess" type="{{lottery.miniappType}}"></action-bar>
<block wx:else>
<view class="action-bar2">
<block wx:if="{{product.status === 1}}">
<button class="action-item over" bindtap="goLogin">即将开始</button>
<button class="action-item over" bindtap="goLogin">开始</button>
</block>
<block wx:if="{{product.status === 2}}">
<button class="action-item confirm" bindtap="goLogin">参加抽奖</button>
... ...
'use strict'
'use strict';
//获取应用实例
/**
* 时间戳转化为年 月 日 时 分 秒
/**
* 时间戳转化为年 月 日 时 分 秒
* time: 传入时间戳
* format:返回格式,支持自定义,但参数必须与formateArr里保持一致
* format:返回格式,支持自定义,但参数必须与formateArr里保持一致
* formatTimeByDefined(1488481383,'Y/M/D h:m:s') => 2017/03/03 03:03:03
*/
*/
function formatTimeByDefined(time, format) {
var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
var returnArr = [];
... ... @@ -26,31 +25,35 @@ function formatTimeByDefined(time, format) {
format = format.replace(formateArr[i], returnArr[i]);
}
return format;
}
}
function formatTime(date) {
var year = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()
var hour = date.getHours()
var minute = date.getMinutes()
var second = date.getSeconds()
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
return (
[year, month, day].map(formatNumber).join('/') +
' ' +
[hour, minute, second].map(formatNumber).join(':')
);
}
function formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
n = n.toString();
return n[1] ? n : '0' + n;
}
function getDeviceInfo(wx) {
let res = wx.getSystemInfoSync(),
windowWidth;
let res = wx.getSystemInfoSync(),
windowWidth;
windowWidth = res.windowWidth;
return { windowWidth };
windowWidth = res.windowWidth;
return { windowWidth };
}
function shouldDiscardTap(currentTimeStamp, lastTimeStamp) {
... ... @@ -61,31 +64,41 @@ function shouldDiscardTap(currentTimeStamp, lastTimeStamp) {
return false;
}
function formatImgUrl (json) {
json.data && json.data.map((item, index) => {
let replaceStr = "{width}";
let url = item.src;
url = url.replace(new RegExp('{width}'), windowWidth * 2).replace(new RegExp('{height}'), 100).replace(new RegExp('{mode}'), '2');
item.src = url;
// console.log(url)
});
function formatImgUrl(json) {
json.data &&
json.data.map((item, index) => {
let replaceStr = '{width}';
let url = item.src;
url = url
.replace(new RegExp('{width}'), windowWidth * 2)
.replace(new RegExp('{height}'), 100)
.replace(new RegExp('{mode}'), '2');
item.src = url;
// console.log(url)
});
return json;
}
function getImageUrl(url, windowWidth,height){
if(!url){
function getImageUrl(url, windowWidth, height) {
if (!url) {
return '';
}
return url.replace(new RegExp('{width}'), windowWidth *2).replace(new RegExp('{height}'), height?height:100).replace(new RegExp('{mode}'), '2');
return url
.replace(new RegExp('{width}'), windowWidth * 2)
.replace(new RegExp('{height}'), height ? height : 100)
.replace(new RegExp('{mode}'), '2');
}
function formatImageUrl(url, width, height, mode){
function formatImageUrl(url, width, height, mode) {
url = url || '';
if (url && url.indexOf('?') === -1) {
url = url + '?imageView2/{mode}/w/{width}/h/{height}';
url = url + '?imageView2/{mode}/w/{width}/h/{height}';
}
return url.replace(/{width}/g, width).replace(/{height}/g, height).replace('{mode}', mode || 2);
return url
.replace(/{width}/g, width)
.replace(/{height}/g, height)
.replace('{mode}', mode || 2);
}
// 自动识别 2倍 3倍图
... ... @@ -98,31 +111,40 @@ function getImageUrlWithWH(image_url, image_width, image_height) {
if (!image_url) {
return '';
}
return image_url.replace(/{width}/g, parseInt(image_width * DEVICE_WIDTH_RATIO * pixelRatio)).replace(/{height}/g, parseInt(image_height * DEVICE_WIDTH_RATIO * pixelRatio)).replace('{mode}', 2);
return image_url
.replace(
/{width}/g,
parseInt(image_width * DEVICE_WIDTH_RATIO * pixelRatio),
)
.replace(
/{height}/g,
parseInt(image_height * DEVICE_WIDTH_RATIO * pixelRatio),
)
.replace('{mode}', 2);
}
function getBrandID (url) {
let params = url.split("openby:yohobuy=")
function getBrandID(url) {
let params = url.split('openby:yohobuy=');
if (params.length == 2) {
let jsonParam = JSON.parse(params[1])
let jsonParam = JSON.parse(params[1]);
return jsonParam.params.brand_id;
}
return null;
}
function isStringEmpty(str){
if (str===undefined || str ===null || str ===''){
return true
}else{
return false
function isStringEmpty(str) {
if (str === undefined || str === null || str === '') {
return true;
} else {
return false;
}
return true;
}
function getGoodDetailParam(url) {
let params = url.split("openby:yohobuy=")
let params = url.split('openby:yohobuy=');
if (params.length == 2) {
let jsonParam = JSON.parse(params[1])
let jsonParam = JSON.parse(params[1]);
return JSON.stringify(jsonParam.params);
}
return null;
... ... @@ -130,29 +152,29 @@ function getGoodDetailParam(url) {
function formatDateTime(inputTime) {
var date = new Date();
date.setTime(inputTime*1000);
date.setTime(inputTime * 1000);
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
m = m < 10 ? '0' + m : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
return y + '.' + m + '.'+d;
};
function formateTimestamp(start,end){
var startTime = formatDateTime(start)
var endTime = formatDateTime(end)
return startTime+'-'+endTime
d = d < 10 ? '0' + d : d;
return y + '.' + m + '.' + d;
}
function formateTimestamp(start, end) {
var startTime = formatDateTime(start);
var endTime = formatDateTime(end);
return startTime + '-' + endTime;
}
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
function getSknFromUrl(url) {
... ... @@ -160,7 +182,9 @@ function getSknFromUrl(url) {
url = decodeURIComponent(url).toLowerCase();
let components = url.split('/');
let lastElement = components.pop();
let startLegal = url.startsWith('https://m.yohobuy.com/product') || url.startsWith('http://m.yohobuy.com/product');
let startLegal =
url.startsWith('https://m.yohobuy.com/product') ||
url.startsWith('http://m.yohobuy.com/product');
let endLegal = lastElement.endsWith('.html');
if (!startLegal || !endLegal) {
return '';
... ... @@ -175,7 +199,9 @@ function getShopIdFromUrl(url) {
url = decodeURIComponent(url).toLowerCase();
let components = url.split('/');
let lastElement = components.pop();
let startLegal = url.startsWith('https://m.yohobuy.com/shop') || url.startsWith('http://m.yohobuy.com/shop');
let startLegal =
url.startsWith('https://m.yohobuy.com/shop') ||
url.startsWith('http://m.yohobuy.com/shop');
let endLegal = lastElement.endsWith('.html');
if (!startLegal || !endLegal) {
return '';
... ... @@ -187,9 +213,9 @@ function getShopIdFromUrl(url) {
}
function getShopID(url) {
let params = url.split("openby:yohobuy=")
let params = url.split('openby:yohobuy=');
if (params.length == 2) {
let jsonParam = JSON.parse(params[1])
let jsonParam = JSON.parse(params[1]);
return jsonParam.params.shop_id;
}
return null;
... ... @@ -202,22 +228,23 @@ function contains(arr, obj) {
}
}
return -1;
}
}
function getGuangType(url) {
let params = url.split("openby:yohobuy=")
let params = url.split('openby:yohobuy=');
if (params.length == 2) {
let jsonParam = JSON.parse(params[1])
let jsonParam = JSON.parse(params[1]);
return jsonParam.params.type;
}
return null;
}
// public method for encoding
// public method for encoding
function base64Encode(input) {
let _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
let _keyStr =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var output = "";
var output = '';
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = _utf8_encode(input);
... ... @@ -234,21 +261,25 @@ function base64Encode(input) {
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
_keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
_keyStr.charAt(enc3) + _keyStr.charAt(enc4);
output =
output +
_keyStr.charAt(enc1) +
_keyStr.charAt(enc2) +
_keyStr.charAt(enc3) +
_keyStr.charAt(enc4);
}
return output;
}
// public method for decoding
// public method for decoding
function base64Decode(input) {
let _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var output = "";
let _keyStr =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var output = '';
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
while (i < input.length) {
enc1 = _keyStr.indexOf(input.charAt(i++));
enc2 = _keyStr.indexOf(input.charAt(i++));
... ... @@ -270,13 +301,13 @@ function base64Decode(input) {
}
function _utf8_encode(string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
string = string.replace(/\r\n/g, '\n');
var utftext = '';
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
} else if (c > 127 && c < 2048) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
} else {
... ... @@ -284,16 +315,15 @@ function _utf8_encode(string) {
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
// private method for UTF-8 decoding
// private method for UTF-8 decoding
function _utf8_decode(utftext) {
var string = "";
var string = '';
var i = 0;
var c = 0;
var c = 0;
var c1 = 0;
var c2 = 0;
var c3 = 0;
... ... @@ -302,14 +332,16 @@ function _utf8_decode(utftext) {
if (c < 128) {
string += String.fromCharCode(c);
i++;
} else if ((c > 191) && (c < 224)) {
} else if (c > 191 && c < 224) {
c2 = utftext.charCodeAt(i + 1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
} else {
c2 = utftext.charCodeAt(i + 1);
c3 = utftext.charCodeAt(i + 2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
string += String.fromCharCode(
((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63),
);
i += 3;
}
}
... ... @@ -319,7 +351,7 @@ function _utf8_decode(utftext) {
key: 关键词
fromPage: 来源页面名称
**/
function getYHStorageSync(key,fromPage) {
function getYHStorageSync(key, fromPage) {
// console.log(key)
// console.log(fromPage)
try {
... ... @@ -344,7 +376,7 @@ key: 关键词
value: 内容
fromPage: 来源页面名称
**/
function setStorageSync(key,value, fromPage) {
function setStorageSync(key, value, fromPage) {
try {
wx.setStorageSync(key, value);
return true;
... ... @@ -366,6 +398,34 @@ function removeStorageSync(key, fromPage) {
}
}
/**
* 格式化倒计时时间
* time in seconds
*/
function fomartCountdownTime({ startTime, endTime }) {
let remainingTime = 0;
if (endTime) {
remainingTime = endTime - Date.now() / 1000;
} else if (startTime) {
remainingTime = startTime - Date.now() / 1000;
}
if (remainingTime <= 0) {
return [];
}
const timeInHour = Math.floor(remainingTime / 3600);
remainingTime = remainingTime - timeInHour * 3600;
const timeInMinute = Math.floor(remainingTime / 60);
remainingTime = parseInt(remainingTime - timeInMinute * 60);
return [timeInHour, timeInMinute, remainingTime].map(time => {
return `${time > 9 ? time : `0${time}`}`;
});
}
module.exports = {
formatTimeByDefined,
formatTime: formatTime,
... ... @@ -389,5 +449,6 @@ module.exports = {
base64Decode,
getYHStorageSync,
setStorageSync,
removeStorageSync
}
\ No newline at end of file
removeStorageSync,
fomartCountdownTime,
};
... ...