diff --git a/app.js b/app.js
index 89c41a4..a49e07f 100644
--- a/app.js
+++ b/app.js
@@ -441,4 +441,24 @@ App({
});
},
+ /**
+ * 记录购物车商品总数量
+ * @param {*} value
+ */
+ setCartTotalNum(value) {
+ wx.setStorageSync('cartTotalNum', Number(value))
+ },
+
+ /**
+ * 设置购物车tabbar的角标
+ */
+ setCartTabBadge() {
+ const number = wx.getStorageSync('cartTotalNum')
+ if (number <= 0) return
+ wx.setTabBarBadge({
+ index: 2,
+ text: `${number}`
+ })
+ }
+
});
\ No newline at end of file
diff --git a/components/toast/index.js b/components/toast/index.js
new file mode 100644
index 0000000..a5044c5
--- /dev/null
+++ b/components/toast/index.js
@@ -0,0 +1,36 @@
+'use strict';
+
+var DEFAULT_DATA = {
+ show: false,
+ message: '',
+ icon: '',
+ image: '',
+ mask: false
+};
+
+var SUPPORT_TYPE = ['loading', 'success', 'fail'];
+
+Component({
+ data: Object.assign({}, DEFAULT_DATA),
+
+ methods: {
+ show: function show(options) {
+ var toastOptions = Object.assign({}, options);
+
+ var icon = options.icon || '';
+ var image = options.image || '';
+ if (SUPPORT_TYPE.indexOf(options.type) > -1) {
+ icon = options.type;
+ image = '';
+ }
+
+ this.setData(Object.assign({}, toastOptions, {
+ icon: icon,
+ image: image
+ }));
+ },
+ clear: function clear() {
+ this.setData(Object.assign({}, DEFAULT_DATA));
+ }
+ }
+});
\ No newline at end of file
diff --git a/components/toast/index.json b/components/toast/index.json
new file mode 100644
index 0000000..467ce29
--- /dev/null
+++ b/components/toast/index.json
@@ -0,0 +1,3 @@
+{
+ "component": true
+}
diff --git a/components/toast/index.wxml b/components/toast/index.wxml
new file mode 100644
index 0000000..ac180b7
--- /dev/null
+++ b/components/toast/index.wxml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+ {{ message }}
+
diff --git a/components/toast/index.wxss b/components/toast/index.wxss
new file mode 100644
index 0000000..67c418f
--- /dev/null
+++ b/components/toast/index.wxss
@@ -0,0 +1,58 @@
+.zan-toast {
+ position: fixed;
+ top: 35%;
+ left: 50%;
+ -webkit-transform: translate3d(-50%, -50%, 0);
+ transform: translate3d(-50%, -50%, 0);
+ background: rgba(0, 0, 0, .7);
+ color: #fff;
+ font-size: 14px;
+ line-height: 1.5em;
+ margin: 0 auto;
+ box-sizing: border-box;
+ padding: 10px 30rpx;
+ text-align: center;
+ border-radius: 4px;
+ z-index: 100
+}
+
+.zan-toast--notitle {
+ padding: 18px
+}
+
+.zan-toast__icon {
+ display: block;
+ width: 40px;
+ height: 40px;
+ line-height: 40px;
+ margin: 0 auto;
+ padding: 12px 15px;
+ font-size: 38px;
+ text-align: center
+}
+
+.zan-toast__icon-loading {
+ line-height: 0
+}
+
+.zan-loading {
+ width: 20px;
+ height: 20px;
+ display: inline-block;
+ vertical-align: middle;
+ -webkit-animation: weuiLoading 1s steps(12, end) infinite;
+ animation: weuiLoading 1s steps(12, end) infinite;
+ background: transparent url(data:image/svg+xml;base64,PHN2ZyBjbGFzcz0iciIgd2lkdGg9JzEyMHB4JyBoZWlnaHQ9JzEyMHB4JyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj4KICAgIDxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIiBmaWxsPSJub25lIiBjbGFzcz0iYmsiPjwvcmVjdD4KICAgIDxyZWN0IHg9JzQ2LjUnIHk9JzQwJyB3aWR0aD0nNycgaGVpZ2h0PScyMCcgcng9JzUnIHJ5PSc1JyBmaWxsPScjRTlFOUU5JwogICAgICAgICAgdHJhbnNmb3JtPSdyb3RhdGUoMCA1MCA1MCkgdHJhbnNsYXRlKDAgLTMwKSc+CiAgICA8L3JlY3Q+CiAgICA8cmVjdCB4PSc0Ni41JyB5PSc0MCcgd2lkdGg9JzcnIGhlaWdodD0nMjAnIHJ4PSc1JyByeT0nNScgZmlsbD0nIzk4OTY5NycKICAgICAgICAgIH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4=) no-repeat;
+ background-size: 100%
+}
+
+.zan-toast__icon-loading .zan-loading {
+ width: 40px;
+ height: 40px
+}
+
+.zan-toast__icon-image {
+ background-size: 40px;
+ background-position: center;
+ background-repeat: no-repeat
+}
\ No newline at end of file
diff --git a/components/toast/toast.js b/components/toast/toast.js
new file mode 100644
index 0000000..934dbab
--- /dev/null
+++ b/components/toast/toast.js
@@ -0,0 +1,134 @@
+'use strict';
+
+var TOAST_CONFIG_KEY = 'zanui.__zanToastPageConfig';
+var DEFAULT_SHOW_TOAST_TIME = 3000;
+
+var timeoutData = {
+ timeoutId: 0,
+ toastCtx: null
+};
+
+var globalToastUserConfig = {};
+
+// 获取页面上下文
+function getPageCtx(pageCtx) {
+ var ctx = pageCtx;
+
+ if (!ctx) {
+ var pages = getCurrentPages();
+ ctx = pages[pages.length - 1];
+ }
+
+ return ctx;
+}
+
+// 获取当前页面的 toast 配置数据
+function getPageToastConfig(pageCtx) {
+ var zanuiData = pageCtx.data.zanui || {};
+ return zanuiData.__zanToastPageConfig || {};
+}
+
+// Toast 显示函数
+function Toast(optionsOrMsg, pageCtx) {
+ // 参数格式化处理
+ // 如果是文字,默认为 message
+ var options = optionsOrMsg || {};
+ if (typeof optionsOrMsg === 'string') {
+ options = { message: optionsOrMsg };
+ }
+
+ var ctx = getPageCtx(pageCtx);
+ var pageToastUserSetting = getPageToastConfig(ctx);
+ var parsedOptions = Object.assign({}, globalToastUserConfig, pageToastUserSetting, options);
+ var toastCtx = ctx.selectComponent(parsedOptions.selector);
+
+ if (!toastCtx) {
+ console.error('无法找到对应的toast组件,请于页面中注册并在 wxml 中声明 toast 自定义组件');
+ return;
+ }
+
+ if (timeoutData.timeoutId) {
+ Toast.clear();
+ }
+
+ toastCtx.show(Object.assign({}, parsedOptions, {
+ show: true
+ }));
+
+ var timeoutId = 0;
+ // toast 计时,如果小于0,就不会去关闭。
+ // 如果不传,就取默认值
+ var timeoutOption = parsedOptions.timeout || DEFAULT_SHOW_TOAST_TIME;
+ if (timeoutOption >= 0) {
+ timeoutId = setTimeout(function () {
+ toastCtx.clear();
+ }, timeoutOption);
+ }
+
+ timeoutData = {
+ timeoutId: timeoutId,
+ toastCtx: toastCtx
+ };
+}
+
+// 设置 toast 基础属性
+Toast.setDefaultOptions = function () {
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+ var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'page';
+
+ var parsedDefaultOptions = {
+ selector: options.selector || '',
+ type: options.type || '',
+ icon: options.icon || '',
+ image: options.image || '',
+ timeout: options.timeout || DEFAULT_SHOW_TOAST_TIME
+ };
+
+ if (type === 'global') {
+ globalToastUserConfig = Object.assign({}, parsedDefaultOptions);
+ } else if (type === 'page') {
+ var _ctx$setData;
+
+ var ctx = getPageCtx();
+ ctx.setData((_ctx$setData = {}, _ctx$setData['' + TOAST_CONFIG_KEY] = parsedDefaultOptions, _ctx$setData));
+ }
+};
+
+// 重置 toast 基础属性
+Toast.resetDefaultOptions = function () {
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'page';
+
+ if (type === 'global') {
+ globalToastUserConfig = {};
+ } else {
+ var _ctx$setData2;
+
+ var ctx = getPageCtx();
+ ctx.setData((_ctx$setData2 = {}, _ctx$setData2['' + TOAST_CONFIG_KEY] = {}, _ctx$setData2));
+ }
+};
+
+// 清理所有 toast
+Toast.clear = function () {
+ clearTimeout(timeoutData.timeoutId);
+
+ try {
+ timeoutData.toastCtx && timeoutData.toastCtx.clear();
+ } catch (e) {}
+
+ timeoutData = {
+ timeoutId: 0,
+ toastCtx: null
+ };
+};
+
+// 显示 loading
+Toast.loading = function () {
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
+
+ Toast(Object.assign({}, options, {
+ type: 'loading'
+ }));
+};
+
+module.exports = Toast;
\ No newline at end of file
diff --git a/pages/category/index.js b/pages/category/index.js
index dbee921..cedce0d 100644
--- a/pages/category/index.js
+++ b/pages/category/index.js
@@ -32,6 +32,14 @@ Page({
_this.getCategoryList();
},
+ /**
+ * 生命周期函数--监听页面显示
+ */
+ onShow() {
+ // 更新购物车角标
+ App.setCartTabBadge()
+ },
+
/**
* 设置分类列表高度
*/
diff --git a/pages/flow/checkout.js b/pages/flow/checkout.js
index f36884b..3df380d 100644
--- a/pages/flow/checkout.js
+++ b/pages/flow/checkout.js
@@ -1,20 +1,11 @@
-const App = getApp();
-
-// 工具类
import Util from '../../utils/util.js';
-
-// 验证类
import Verify from '../../utils/verify.js';
-
-// 枚举类:发货方式
import DeliveryTypeEnum from '../../utils/enum/DeliveryType.js';
-
-// 枚举类:支付方式
import PayTypeEnum from '../../utils/enum/order/PayType';
-
-// 对话框插件
import Dialog from '../../components/dialog/dialog';
+import Toast from '../../components/toast/toast';
+const App = getApp()
Page({
/**
@@ -447,15 +438,27 @@ Page({
* 选择优惠券
*/
onSelectCoupon(e) {
- let _this = this;
+ const app = this;
+ // 当前选择的优惠券
+ const index = e.currentTarget.dataset.index
+ const couponItem = app.data.coupon_list[index]
+ // 判断是否在适用范围
+ if (!couponItem['is_apply']) {
+ Toast({
+ selector: '#zan-toast',
+ message: couponItem.not_apply_info,
+ timeout: 1800
+ });
+ return
+ }
// 记录选中的优惠券id
- _this.setData({
- selectCouponId: e.currentTarget.dataset.id
+ app.setData({
+ selectCouponId: couponItem.user_coupon_id
});
// 重新获取订单信息
- _this.getOrderData();
+ app.getOrderData();
// 隐藏优惠券弹层
- _this.onTogglePopupCoupon();
+ app.onTogglePopupCoupon();
},
/**
diff --git a/pages/flow/checkout.json b/pages/flow/checkout.json
index 7842454..251cbfd 100644
--- a/pages/flow/checkout.json
+++ b/pages/flow/checkout.json
@@ -3,6 +3,7 @@
"usingComponents": {
"zan-popup": "/components/popup/index",
"zan-dialog": "/components/dialog/index",
+ "zan-toast": "/components/toast/index",
"van-switch": "/components/switch/index",
"shortcut": "/components/shortcut/shortcut"
}
diff --git a/pages/flow/checkout.wxml b/pages/flow/checkout.wxml
index 0d77efd..09a53cb 100644
--- a/pages/flow/checkout.wxml
+++ b/pages/flow/checkout.wxml
@@ -2,7 +2,9 @@
-
+
{{ item.name }}
@@ -20,7 +22,8 @@
{{ address.phone }}
- {{address.region.province}} {{address.region.city}} {{address.region.region}} {{address.detail}}
+ {{address.region.province}} {{address.region.city}} {{address.region.region}}
+ {{address.detail}}
@@ -48,7 +51,8 @@
{{ extract_shop.shop_name }}
- {{extract_shop.region.province}} {{extract_shop.region.city}} {{extract_shop.region.region}} {{extract_shop.address}}
+ {{extract_shop.region.province}} {{extract_shop.region.city}}
+ {{extract_shop.region.region}} {{extract_shop.address}}
@@ -135,7 +139,7 @@
-¥{{ coupon_money }}
- 有{{ coupon_list.length }}张优惠券可用
+ 有{{ coupon_list.length }}张优惠券
无优惠券可用
@@ -241,7 +245,8 @@
-
+
{{ item.coupon_type.text }}
@@ -283,6 +288,8 @@
+
+
diff --git a/pages/flow/checkout.wxss b/pages/flow/checkout.wxss
index dad05bf..3158712 100644
--- a/pages/flow/checkout.wxss
+++ b/pages/flow/checkout.wxss
@@ -167,6 +167,15 @@
background: linear-gradient(-141deg, #f7d059, #fdb054);
}
+
+.popup__coupon .coupon-list .coupon-item .item-wrapper.color__gray {
+ background: linear-gradient(-113deg, #bdbdbd, #a2a1a2);
+}
+
+.popup__coupon .coupon-list .coupon-item .item-wrapper.color__gray .coupon-type {
+ background: #9e9e9e;
+}
+
.popup__coupon .coupon-list .coupon-item .item-wrapper .tip {
position: relative;
flex: 0 0 32%;
diff --git a/pages/flow/index.js b/pages/flow/index.js
index fa88c84..3f3953a 100644
--- a/pages/flow/index.js
+++ b/pages/flow/index.js
@@ -55,7 +55,12 @@ Page({
getCartList() {
let _this = this;
App._get('cart/lists', {}, result => {
- _this._initGoodsChecked(result.data);
+ const data = result.data
+ // 更新购物车数量及角标
+ App.setCartTotalNum(data.order_total_num)
+ App.setCartTabBadge()
+ // 初始化商品选中状态
+ _this._initGoodsChecked(data)
});
},
diff --git a/pages/goods/index.js b/pages/goods/index.js
index 916be6c..819e249 100644
--- a/pages/goods/index.js
+++ b/pages/goods/index.js
@@ -285,6 +285,8 @@ Page({
}, (result) => {
App.showSuccess(result.msg);
_this.setData(result.data);
+ // 记录购物车商品数量
+ App.setCartTotalNum(result.data.cart_total_num)
});
}
},
diff --git a/pages/index/index.js b/pages/index/index.js
index 6d85568..41bed6f 100644
--- a/pages/index/index.js
+++ b/pages/index/index.js
@@ -22,6 +22,14 @@ Page({
this.getPageData();
},
+ /**
+ * 生命周期函数--监听页面显示
+ */
+ onShow() {
+ // 更新购物车角标
+ App.setCartTabBadge()
+ },
+
/**
* 加载页面数据
*/
diff --git a/pages/sharp/goods/index.js b/pages/sharp/goods/index.js
index 9843b7e..447b0c3 100644
--- a/pages/sharp/goods/index.js
+++ b/pages/sharp/goods/index.js
@@ -62,7 +62,10 @@ Page({
showTopWidget: false,
// 倒计时
- actEndTimeList: [],
+ countDownObj: {
+ date: '',
+ dynamic: {}
+ },
active: {}, // 秒杀活动详情
goods: {}, // 商品详情
@@ -73,7 +76,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(options) {
- let _this = this,
+ const _this = this,
scene = App.getSceneData(options);
// 秒杀商品id
_this.setData({
@@ -81,14 +84,16 @@ Page({
sharp_goods_id: options.sharp_goods_id ? options.sharp_goods_id : scene.gid,
});
// 获取秒杀商品信息
- _this.getActiveDetail();
+ _this.onRefreshPage();
},
/**
- * 生命周期函数--监听页面显示
+ * 刷新页面数据
*/
- onShow(options) {
-
+ onRefreshPage() {
+ // 获取秒杀商品信息
+ const _this = this
+ _this.getActiveDetail()
},
/**
@@ -100,12 +105,12 @@ Page({
active_time_id: _this.data.active_time_id,
sharp_goods_id: _this.data.sharp_goods_id,
}, (result) => {
+ const data = result.data
// 初始化详情数据
- let data = _this._initData(result.data);
- _this.setData(data);
- // 执行倒计时
- CountDown.onSetTimeList(_this, 'actEndTimeList');
- });
+ _this._initData(data);
+ // 初始化倒计时组件
+ _this._initCountDownData(data);
+ })
},
/**
@@ -134,12 +139,27 @@ Page({
if (goodsDetail.spec_type == 20) {
data.goodsMultiSpec = _this._initManySpecData(goodsDetail.goods_multi_spec);
}
- // 记录活动到期时间
- data.actEndTimeList = [{
- date: data.active.active_status == ActiveStatusEnum.STATE_SOON.value ?
- data.active.start_time : data.active.end_time
- }];
- return data;
+ _this.setData(data)
+ },
+
+ /**
+ * 初始化倒计时组件
+ */
+ _initCountDownData(data) {
+ const app = this
+ // 记录倒计时的时间
+ const countDownTime = data.active.active_status == ActiveStatusEnum.STATE_SOON.value ?
+ data.active.start_time : data.active.end_time
+ app.setData({
+ 'countDownObj.date': countDownTime
+ })
+ // 执行倒计时
+ CountDown.start(0, app, 'countDownObj', () => {
+ // 倒计时结束刷新页面
+ setTimeout(() => {
+ app.onRefreshPage()
+ }, 800)
+ })
},
/**
diff --git a/pages/sharp/goods/index.wxml b/pages/sharp/goods/index.wxml
index 461e525..5efce9a 100644
--- a/pages/sharp/goods/index.wxml
+++ b/pages/sharp/goods/index.wxml
@@ -8,7 +8,8 @@
-
+
@@ -47,7 +48,7 @@
-
-
+
-
- 距离秒杀{{ active.active_status == ActiveStatusEnum.STATE_SOON.value ? '开始' : '结束' }} 还剩{{ item.dynamic.hou }}时{{ item.dynamic.min }}分{{ item.dynamic.sec }}秒
-
+ 距离秒杀{{ active.active_status == ActiveStatusEnum.STATE_SOON.value ? '开始' : '结束' }}
+ 还剩{{ countDownObj.dynamic.hou }}时{{ countDownObj.dynamic.min }}分{{ countDownObj.dynamic.sec }}秒
@@ -162,7 +163,8 @@
-
+
@@ -183,7 +187,7 @@
-
- {{ countDownList[0].dynamic.hou }}
+ {{ countDownObj.dynamic.hou }}
:
- {{ countDownList[0].dynamic.min }}
+ {{ countDownObj.dynamic.min }}
:
- {{ countDownList[0].dynamic.sec }}
+ {{ countDownObj.dynamic.sec }}
@@ -56,7 +55,7 @@
-