diff --git a/app.js b/app.js
index a49e07f..e74b13c 100644
--- a/app.js
+++ b/app.js
@@ -408,11 +408,8 @@ App({
/**
* 授权登录
*/
- getUserInfo(e, callback) {
+ getUserInfo(userInfo, callback) {
let App = this;
- if (e.detail.errMsg !== 'getUserInfo:ok') {
- return false;
- }
wx.showLoading({
title: "正在登录",
mask: true
@@ -423,10 +420,7 @@ App({
// 发送用户信息
App._post_form('user/login', {
code: res.code,
- user_info: e.detail.rawData,
- encrypted_data: e.detail.encryptedData,
- iv: e.detail.iv,
- signature: e.detail.signature,
+ user_info: JSON.stringify(userInfo),
referee_id: wx.getStorageSync('referee_id')
}, result => {
// 记录token user_id
@@ -454,11 +448,17 @@ App({
*/
setCartTabBadge() {
const number = wx.getStorageSync('cartTotalNum')
- if (number <= 0) return
- wx.setTabBarBadge({
- index: 2,
- text: `${number}`
- })
+ if (number > 0) {
+ wx.setTabBarBadge({
+ index: 2,
+ text: `${number}`
+ })
+ } else {
+ wx.removeTabBarBadge({
+ index: 2
+ })
+ }
+ return
}
});
\ No newline at end of file
diff --git a/components/countdown/index.js b/components/countdown/index.js
new file mode 100644
index 0000000..7061fa3
--- /dev/null
+++ b/components/countdown/index.js
@@ -0,0 +1,130 @@
+import util from '../../utils/util'
+
+Component({
+ properties: {
+ // useSlot: Boolean,
+ // 截止的时间
+ date: String,
+ // 分隔符, colon为英文冒号,zh为中文
+ separator: {
+ type: String,
+ value: 'zh'
+ },
+ // 组件样式, text为纯文本,custom为带背景色
+ style: {
+ type: String,
+ value: 'text'
+ },
+ },
+
+ data: {
+ // 倒计时数据
+ dynamic: {
+ day: '00',
+ hou: '00',
+ min: '00',
+ sec: '00'
+ },
+ // 分隔符文案
+ separatorText: {
+ day: '天',
+ hou: '时',
+ min: '分',
+ sec: '秒'
+ }
+ },
+
+ attached() {
+ // 分隔符文案
+ this.separatorText()
+ // 开始倒计时
+ this.onTime()
+ },
+
+ detached() {
+
+ },
+
+
+ methods: {
+
+ // 分隔符文案
+ separatorText() {
+ const separatorText = this.data.separatorText
+ if (this.data.separator === 'colon') {
+ separatorText.day = ':'
+ separatorText.hou = ':'
+ separatorText.min = ':'
+ separatorText.sec = ''
+ }
+ this.setData({
+ separatorText
+ })
+ },
+
+ // 开始倒计时
+ onTime(deep = 0) {
+ const app = this
+ const dynamic = {}
+
+ // 获取当前时间,同时得到活动结束时间数组
+ const newTime = new Date().getTime()
+ // 对结束时间进行处理渲染到页面
+ const endTime = new Date(util.format_date(app.data.date)).getTime();
+
+ // 如果活动未结束,对时间进行处理
+ if ((endTime - newTime) <= 0) {
+ return false
+ }
+
+ const diffTime = (endTime - newTime) / 1000;
+ // 获取时、分、秒
+ const day = parseInt(diffTime / 86400),
+ hou = parseInt(diffTime % 86400 / 3600),
+ min = parseInt(diffTime % 86400 % 3600 / 60),
+ sec = parseInt(diffTime % 86400 % 3600 % 60);
+ dynamic.day = app.timeFormat(day)
+ dynamic.hou = app.timeFormat(hou)
+ dynamic.min = app.timeFormat(min)
+ dynamic.sec = app.timeFormat(sec)
+
+ // 渲染,然后每隔一秒执行一次倒计时函数
+ app.setData({
+ dynamic
+ })
+ // 判断倒计时是否结束
+ const isEnd = app.isEnd()
+ // 结束后执行回调函数
+ if (isEnd) {
+ deep > 0 && app.triggerEvent('finish')
+ }
+ // 重复执行
+ if (!isEnd) {
+ setTimeout(() => {
+ app.onTime(++deep)
+ }, 1000)
+ }
+ },
+
+ // 判断倒计时是否结束
+ isEnd() {
+ const {
+ dynamic
+ } = this.data
+ if (dynamic.day == '00' && dynamic.hou == '00' && dynamic.min == '00' && dynamic.sec == '00') {
+ return true
+ }
+ return false
+ },
+
+ /**
+ * 小于10的格式化函数
+ */
+ timeFormat(value) {
+ return value < 10 ? '0' + value : value
+ }
+
+
+
+ }
+})
\ No newline at end of file
diff --git a/components/countdown/index.json b/components/countdown/index.json
new file mode 100644
index 0000000..32640e0
--- /dev/null
+++ b/components/countdown/index.json
@@ -0,0 +1,3 @@
+{
+ "component": true
+}
\ No newline at end of file
diff --git a/components/countdown/index.wxml b/components/countdown/index.wxml
new file mode 100644
index 0000000..67c36e3
--- /dev/null
+++ b/components/countdown/index.wxml
@@ -0,0 +1,15 @@
+
+
+
+
+ {{ dynamic.day }}
+ {{ separatorText.day }}
+
+ {{ dynamic.hou }}
+ {{ separatorText.hou }}
+ {{ dynamic.min }}
+ {{ separatorText.min }}
+ {{ dynamic.sec }}
+ {{ separatorText.sec }}
+
+
\ No newline at end of file
diff --git a/components/countdown/index.wxss b/components/countdown/index.wxss
new file mode 100644
index 0000000..bbf9d38
--- /dev/null
+++ b/components/countdown/index.wxss
@@ -0,0 +1,33 @@
+.item {
+ display: inline-block;
+ width: 22px;
+ margin-right: 5px;
+ color: #fff;
+ font-size: 12px;
+ text-align: center;
+ background-color: #1989fa;
+ border-radius: 2px;
+}
+
+.separator {
+ padding: 0 2rpx;
+}
+
+/* 冒号分隔符 */
+.text-style.separator-colon .separator {
+ padding: 0 5rpx;
+}
+
+
+/* 带背景的样式 */
+.custom-style .dynamic-value {
+ background: #252525;
+ color: #fff;
+ padding: 0 8rpx;
+ line-height: 40rpx;
+ border-radius: 8rpx;
+}
+
+.custom-style .separator {
+ padding: 0 7rpx;
+}
\ No newline at end of file
diff --git a/components/diy/bargainGoods/index.js b/components/diy/bargainGoods/index.js
index f177b7d..fbe9ca1 100644
--- a/components/diy/bargainGoods/index.js
+++ b/components/diy/bargainGoods/index.js
@@ -27,8 +27,6 @@ Component({
* 跳转商品详情页
*/
_onTargetGoods(e) {
- // 记录formid
- App.saveFormId(e.detail.formId);
wx.navigateTo({
url: `/pages/bargain/goods/index?active_id=${e.detail.target.dataset.id}`,
});
diff --git a/components/diy/goods/goods.js b/components/diy/goods/goods.js
index b50c938..f7a3ace 100644
--- a/components/diy/goods/goods.js
+++ b/components/diy/goods/goods.js
@@ -27,8 +27,6 @@ Component({
* 跳转商品详情页
*/
_onTargetGoods(e) {
- // 记录formid
- App.saveFormId(e.detail.formId);
wx.navigateTo({
url: '/pages/goods/index?goods_id=' + e.detail.target.dataset.id,
});
diff --git a/components/diy/search/search.js b/components/diy/search/search.js
index a2090f4..40188cf 100644
--- a/components/diy/search/search.js
+++ b/components/diy/search/search.js
@@ -24,8 +24,6 @@ Component({
* 跳转到搜索页面
*/
onTargetSearch(e) {
- // 记录formid
- App.saveFormId(e.detail.formId);
App.navigationTo('pages/search/index');
},
}
diff --git a/components/diy/service/service.js b/components/diy/service/service.js
index 3f53776..c154856 100644
--- a/components/diy/service/service.js
+++ b/components/diy/service/service.js
@@ -26,8 +26,6 @@ Component({
* 点击拨打电话
*/
_onServiceEvent(e) {
- // 记录formid
- App.saveFormId(e.detail.formId);
// 拨打电话
wx.makePhoneCall({
phoneNumber: this.data.params.phone_num
diff --git a/components/diy/sharingGoods/sharingGoods.js b/components/diy/sharingGoods/sharingGoods.js
index 2890743..20fdc2f 100644
--- a/components/diy/sharingGoods/sharingGoods.js
+++ b/components/diy/sharingGoods/sharingGoods.js
@@ -27,8 +27,6 @@ Component({
* 跳转商品详情页
*/
_onTargetGoods(e) {
- // 记录formid
- App.saveFormId(e.detail.formId);
wx.navigateTo({
url: '/pages/sharing/goods/index?goods_id=' + e.detail.target.dataset.id,
});
diff --git a/components/diy/sharpGoods/index.js b/components/diy/sharpGoods/index.js
index b2b2f2e..d1c0d5e 100644
--- a/components/diy/sharpGoods/index.js
+++ b/components/diy/sharpGoods/index.js
@@ -1,14 +1,8 @@
-const App = getApp();
-
-// 工具类
import util from '../../../utils/util.js';
-
-// 倒计时插件
-import CountDown from '../../../utils/countdown.js';
-
-// 枚举类:秒杀活动商品状态
import ActiveStatusEnum from '../../../utils/enum/sharp/GoodsStatus.js';
+const App = getApp()
+
Component({
options: {
@@ -31,7 +25,7 @@ Component({
*/
data: {
ActiveStatusEnum, // 秒杀活动商品状态
- countDownList: [], // 倒计时
+ countDownTime: false, // 倒计时日期
},
/**
@@ -45,7 +39,7 @@ Component({
attached() {
let _this = this;
_this._initCountDownData();
- },
+ }
},
@@ -57,13 +51,10 @@ Component({
*/
methods: {
-
/**
* 跳转商品详情页
*/
_onTargetGoods(e) {
- // 记录formid
- App.saveFormId(e.detail.formId);
// 生成query参数
let _this = this,
query = util.urlEncode({
@@ -80,8 +71,6 @@ Component({
* 更多秒杀
*/
_onTargetSharpIndex(e) {
- // 记录formid
- App.saveFormId(e.detail.formId);
// 跳转到秒杀会场首页
wx.navigateTo({
url: `/pages/sharp/index/index`,
@@ -91,19 +80,15 @@ Component({
/**
* 初始化倒计时组件
*/
- _initCountDownData(data) {
- let _this = this,
- active = _this.data.data.active;
+ _initCountDownData() {
+ const app = this
+ const active = app.data.data.active
if (!active) return false;
// 记录倒计时的时间
- _this.setData({
- [`countDownList[0]`]: {
- date: active.count_down_time,
- }
- });
- // 执行倒计时
- CountDown.onSetTimeList(_this, 'countDownList');
- },
+ app.setData({
+ countDownTime: active.count_down_time
+ })
+ }
}
})
\ No newline at end of file
diff --git a/components/diy/sharpGoods/index.json b/components/diy/sharpGoods/index.json
index 32640e0..6027f3b 100644
--- a/components/diy/sharpGoods/index.json
+++ b/components/diy/sharpGoods/index.json
@@ -1,3 +1,6 @@
{
- "component": true
+ "component": true,
+ "usingComponents": {
+ "countdown": "/components/countdown/index"
+ }
}
\ No newline at end of file
diff --git a/components/diy/sharpGoods/index.wxml b/components/diy/sharpGoods/index.wxml
index c8e279b..8c00ac0 100644
--- a/components/diy/sharpGoods/index.wxml
+++ b/components/diy/sharpGoods/index.wxml
@@ -11,23 +11,7 @@
-
-
- {{ countDownList[0].dynamic.hou }}
-
-
- :
-
-
- {{ countDownList[0].dynamic.min }}
-
-
- :
-
-
- {{ countDownList[0].dynamic.sec }}
-
-
+
@@ -63,8 +47,10 @@
- ¥{{ dataItem.goods_sku.seckill_price }}
- ¥{{ dataItem.goods_sku.original_price }}
+ ¥{{ dataItem.goods_sku.seckill_price }}
+ ¥{{ dataItem.goods_sku.original_price }}
diff --git a/components/diy/shop/index.js b/components/diy/shop/index.js
index b11242b..eb4af2d 100644
--- a/components/diy/shop/index.js
+++ b/components/diy/shop/index.js
@@ -26,8 +26,6 @@ Component({
* 跳转门店详情页
*/
_onTargetDetail(e) {
- // 记录formid
- App.saveFormId(e.detail.formId);
wx.navigateTo({
url: '/pages/shop/detail/index?shop_id=' + e.detail.target.dataset.id,
});
diff --git a/components/diy/special/index.js b/components/diy/special/index.js
index e5c552e..2997007 100644
--- a/components/diy/special/index.js
+++ b/components/diy/special/index.js
@@ -27,8 +27,6 @@ Component({
* 跳转文章首页
*/
_onTargetIndex(e) {
- // 记录formid
- App.saveFormId(e.detail.formId);
wx.navigateTo({
url: '/pages/article/index'
});
@@ -38,8 +36,6 @@ Component({
* 跳转文章详情页
*/
_onTargetDetail(e) {
- // 记录formid
- App.saveFormId(e.detail.formId);
wx.navigateTo({
url: '/pages/article/detail/index?article_id=' + e.detail.target.dataset.id
});
diff --git a/components/shortcut/shortcut.js b/components/shortcut/shortcut.js
index e0387d9..8b8a6ae 100644
--- a/components/shortcut/shortcut.js
+++ b/components/shortcut/shortcut.js
@@ -40,8 +40,6 @@ Component({
* 导航菜单切换事件
*/
_onToggleShow(e) {
- // 记录formid
- App.saveFormId(e.detail.formId);
this.setData({
isShow: !this.data.isShow,
transparent: false
@@ -53,8 +51,6 @@ Component({
*/
_onTargetPage(e) {
let urls = App.getTabBarLinks();
- // 记录formid
- App.saveFormId(e.detail.formId);
wx.switchTab({
url: '/' + urls[e.detail.target.dataset.index]
});
diff --git a/pages/address/create.js b/pages/address/create.js
index 4c2026d..ee8e247 100644
--- a/pages/address/create.js
+++ b/pages/address/create.js
@@ -32,8 +32,6 @@ Page({
values = e.detail.value
values.region = this.data.region;
- // 记录formId
- App.saveFormId(e.detail.formId);
// 表单验证
if (!_this.validation(values)) {
diff --git a/pages/address/detail.js b/pages/address/detail.js
index 74f4abc..3eab0a9 100644
--- a/pages/address/detail.js
+++ b/pages/address/detail.js
@@ -42,8 +42,6 @@ Page({
values = e.detail.value
values.region = this.data.region;
- // 记录formId
- App.saveFormId(e.detail.formId);
// 表单验证
if (!_this.validation(values)) {
diff --git a/pages/article/index.js b/pages/article/index.js
index 5f3f521..c63ea8c 100644
--- a/pages/article/index.js
+++ b/pages/article/index.js
@@ -22,8 +22,14 @@ Page({
/**
* 生命周期函数--监听页面加载
*/
- onLoad: function(options) {
+ onLoad: function (options) {
let _this = this;
+ // 设置默认的分类
+ if (options.category_id) {
+ _this.setData({
+ category_id: options.category_id
+ })
+ }
// 设置文章列表高度
_this.setListHeight();
// Api:获取文章首页
@@ -36,7 +42,7 @@ Page({
getIndexData() {
let _this = this;
// 获取文章首页
- App._get('article/index', {}, function(result) {
+ App._get('article/index', {}, function (result) {
_this.setData({
categoryList: result.data.categoryList
});
@@ -48,7 +54,7 @@ Page({
/**
* Api:切换导航栏
*/
- onSwitchTab: function(e) {
+ onSwitchTab: function (e) {
let _this = this;
// 第一步:切换当前的分类id
_this.setData({
@@ -70,7 +76,7 @@ Page({
App._get('article/lists', {
page: page || 1,
category_id: _this.data.category_id
- }, function(result) {
+ }, function (result) {
let resList = result.data.list,
dataList = _this.data.articleList;
if (isPage == true) {
@@ -119,9 +125,6 @@ Page({
rpx = systemInfo.windowWidth / 750, // 计算rpx
tapHeight = Math.floor(rpx * 98), // tap高度
scrollHeight = systemInfo.windowHeight - tapHeight; // swiper高度
- console.log(
- systemInfo.windowHeight
- );
this.setData({
scrollHeight
});
diff --git a/pages/bargain/goods/index.js b/pages/bargain/goods/index.js
index 87e7c1a..2a6e0d4 100644
--- a/pages/bargain/goods/index.js
+++ b/pages/bargain/goods/index.js
@@ -1,19 +1,8 @@
-const App = getApp();
-
-// 富文本插件
import wxParse from '../../../wxParse/wxParse.js';
-
-// 工具类
-import util from '../../../utils/util.js';
-
-// 倒计时插件
-import CountDown from '../../../utils/countdown.js';
-
-// 对话框插件
import Dialog from '../../../components/dialog/dialog';
-// 记录规格的数组
-let goodsSpecArr = [];
+const App = getApp()
+let goodsSpecArr = []
Page({
@@ -60,9 +49,7 @@ Page({
// 返回顶部
showTopWidget: false,
- // 倒计时
- actEndTimeList: [],
-
+ countDownTime: false, // 倒计时日期
active: {}, // 砍价活动详情
goods: {}, // 商品详情
@@ -102,13 +89,10 @@ Page({
active_id: _this.data.active_id
}, (result) => {
// 初始化详情数据
- let data = _this._initData(result.data);
- _this.setData(data);
-
- // 执行倒计时
- if (!data.active.is_end) {
- CountDown.onSetTimeList(_this, 'actEndTimeList');
- }
+ const data = result.data
+ _this._initData(data)
+ // 初始化倒计时组件
+ _this._initCountDownData(data)
});
},
@@ -139,12 +123,22 @@ Page({
data.goodsMultiSpec = _this._initManySpecData(goodsDetail.goods_multi_spec);
}
// 记录活动到期时间
- data.actEndTimeList = [{
+ data.countDownObj = [{
date: data.active.end_time
}];
+ _this.setData(data)
+ data.countDownObj.date = data.active.end_time
return data;
},
+ // 初始化倒计时组件
+ _initCountDownData(data) {
+ const app = this
+ app.setData({
+ countDownTime: data.active.end_time
+ })
+ },
+
/**
* 初始化商品多规格
*/
@@ -169,8 +163,6 @@ Page({
attrIdx = e.currentTarget.dataset.attrIdx,
itemIdx = e.currentTarget.dataset.itemIdx,
goodsMultiSpec = _this.data.goodsMultiSpec;
- // 记录formid
- App.saveFormId(e.detail.formId);
for (let i in goodsMultiSpec.spec_attr) {
for (let j in goodsMultiSpec.spec_attr[i].spec_items) {
if (attrIdx == i) {
@@ -285,8 +277,6 @@ Page({
*/
onClickShare(e) {
let _this = this;
- // 记录formId
- App.saveFormId(e.detail.formId);
_this.setData({
'share.show': true
});
@@ -348,8 +338,6 @@ Page({
*/
onSavePoster(e) {
let _this = this;
- // 记录formId
- App.saveFormId(e.detail.formId);
wx.showLoading({
title: '加载中',
});
@@ -395,12 +383,8 @@ Page({
/**
* 确认购买弹窗
*/
- onToggleTrade(e) {
+ onToggleTrade() {
let _this = this;
- if (typeof e === 'object') {
- // 记录formId
- e.detail.hasOwnProperty('formId') && App.saveFormId(e.detail.formId);
- }
_this.setData({
showBottomPopup: !_this.data.showBottomPopup
});
@@ -410,8 +394,6 @@ Page({
* 显示砍价规则
*/
onToggleRules(e) {
- // 记录formId
- App.saveFormId(e.detail.formId);
// 显示砍价规则
let _this = this;
Dialog({
@@ -432,8 +414,6 @@ Page({
*/
onSubmit(e) {
let _this = this;
- // 记录formId
- App.saveFormId(e.detail.formId);
// 判断是否已参与当前的砍价活动,如果已参与的话跳转到砍价任务
if (_this.data.is_partake) {
wx.navigateTo({
@@ -455,8 +435,6 @@ Page({
*/
onSubmit2(e) {
let _this = this;
- // 记录formId
- App.saveFormId(e.detail.formId);
// 关闭选择器
_this.onToggleTrade();
// 确认发起砍价
@@ -502,8 +480,6 @@ Page({
* 跳转到首页
*/
onTargetHome(e) {
- // 记录formid
- App.saveFormId(e.detail.formId);
wx.switchTab({
url: '../../index/index',
})
diff --git a/pages/bargain/goods/index.json b/pages/bargain/goods/index.json
index 2020588..165a17f 100644
--- a/pages/bargain/goods/index.json
+++ b/pages/bargain/goods/index.json
@@ -4,6 +4,7 @@
"zan-actionsheet": "/components/actionsheet/index",
"zan-dialog": "/components/dialog/index",
"zan-popup": "/components/popup/index",
- "shortcut": "/components/shortcut/shortcut"
+ "shortcut": "/components/shortcut/shortcut",
+ "countdown": "/components/countdown/index"
}
}
\ No newline at end of file
diff --git a/pages/bargain/goods/index.wxml b/pages/bargain/goods/index.wxml
index 3ab0dd5..132c14a 100644
--- a/pages/bargain/goods/index.wxml
+++ b/pages/bargain/goods/index.wxml
@@ -8,7 +8,8 @@
-
+
@@ -47,7 +48,7 @@
-
-
+
-
- 距离活动结束 还剩{{ item.dynamic.hou }}时{{ item.dynamic.min }}分{{ item.dynamic.sec }}秒
-
+ 距离活动结束
+ 还剩
+
@@ -75,7 +76,7 @@
-