From 53ddca24ab235c2cf2eac2d49c95b17ba1a539e5 Mon Sep 17 00:00:00 2001 From: zhouzhongping Date: Fri, 16 Jul 2021 16:36:54 +0800 Subject: [PATCH] 1.1.45 --- app.js | 20 ++++++ components/toast/index.js | 36 ++++++++++ components/toast/index.json | 3 + components/toast/index.wxml | 30 ++++++++ components/toast/index.wxss | 58 +++++++++++++++ components/toast/toast.js | 134 +++++++++++++++++++++++++++++++++++ pages/category/index.js | 8 +++ pages/flow/checkout.js | 35 ++++----- pages/flow/checkout.json | 1 + pages/flow/checkout.wxml | 17 +++-- pages/flow/checkout.wxss | 9 +++ pages/flow/index.js | 7 +- pages/goods/index.js | 2 + pages/index/index.js | 8 +++ pages/sharp/goods/index.js | 54 +++++++++----- pages/sharp/goods/index.wxml | 33 +++++---- pages/sharp/index/index.js | 94 ++++++++++++++++-------- pages/sharp/index/index.json | 3 +- pages/sharp/index/index.wxml | 37 +++++----- pages/user/index.js | 4 +- utils/countdown.js | 100 +++++++++++++++----------- version.json | 2 +- 22 files changed, 550 insertions(+), 145 deletions(-) create mode 100644 components/toast/index.js create mode 100644 components/toast/index.json create mode 100644 components/toast/index.wxml create mode 100644 components/toast/index.wxss create mode 100644 components/toast/toast.js 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,PHN2ZyBjbGFzcz0iciIgd2lkdGg9JzEyMHB4JyBoZWlnaHQ9JzEyMHB4JyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMj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0ZSgyNzAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNEQURBREEnCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgzMDAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNFMkUyRTInCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgzMzAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0Pgo8L3N2Zz4=) 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 @@ - -
+
-
+
diff --git a/pages/sharp/index/index.js b/pages/sharp/index/index.js index 444392d..fc77c52 100644 --- a/pages/sharp/index/index.js +++ b/pages/sharp/index/index.js @@ -26,7 +26,10 @@ Page({ StateEnum, // 枚举类:秒杀会场活动状态 // 倒计时 - countDownList: [], + countDownObj: { + date: '', + dynamic: {} + }, // 秒杀活动场次 tabbar: [], @@ -40,46 +43,78 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad(options) { - + const _this = this; + _this.onRefreshPage() }, /** * 生命周期函数--监听页面显示 */ onShow() { - let _this = this; - if (_this.data.curTabIndex == 0) { - // 获取列表数据 - _this.getApiData(); - } + // const _this = this; + // if (_this.data.curTabIndex == 0) { + // // 刷新页面 + // _this.onRefreshPage() + // } }, /** - * 获取列表数据 + * 刷新页面数据 + */ + onRefreshPage() { + const _this = this + return new Promise((resolve, reject) => { + // 获取列表数据 + _this.getApiData().then(() => { + resolve() + }) + }) + }, + + /** + * 下拉刷新 + */ + onPullDownRefresh() { + // 获取首页数据 + this.onRefreshPage().then(() => { + wx.stopPullDownRefresh() + }) + }, + + /** + * 获取页面数据 */ getApiData() { - let _this = this; - App._get('sharp.index/index', {}, (result) => { - _this.setData(result.data); - // 初始化倒计时组件 - _this._initCountDownData(); - }); + const app = this; + return new Promise((resolve, reject) => { + App._get('sharp.index/index', {}, (result) => { + const data = result.data + app.setData(data); + // 初始化倒计时组件 + app._initCountDownData(); + resolve(data) + }); + }) }, /** * 初始化倒计时组件 + * mix: 怎么才能每次执行这里的时候不重复触发定时器 */ - _initCountDownData(data) { - let _this = this, - curTabbar = _this.data.tabbar[_this.data.curTabIndex]; + _initCountDownData(countId = 0) { + const app = this, + curTabbar = app.data.tabbar[app.data.curTabIndex]; // 记录倒计时的时间 - _this.setData({ - [`countDownList[0]`]: { - date: curTabbar.count_down_time, - } - }); + app.setData({ + 'countDownObj.date': curTabbar.count_down_time + }) // 执行倒计时 - CountDown.onSetTimeList(_this, 'countDownList'); + CountDown.start(countId, app, 'countDownObj', () => { + // 倒计时结束刷新页面 + setTimeout(() => { + app.onRefreshPage() + }, 800) + }) }, /** @@ -87,11 +122,10 @@ Page({ */ onToggleTab(e) { let _this = this; - // 保存formid - App.saveFormId(e.detail.formId); // 设置当前tabbar索引,并重置数据 + const curTabIndex = e.currentTarget.dataset.index _this.setData({ - curTabIndex: e.detail.target.dataset.index, + curTabIndex, goodsList: [], page: 1, isLoading: true, @@ -100,17 +134,15 @@ Page({ // 获取列表数据 _this.getGoodsList(); // 初始化倒计时组件 - _this._initCountDownData(); + _this._initCountDownData(curTabIndex); }, /** - * 跳转到砍价商品详情 + * 跳转到秒杀商品详情 */ onTargetActive(e) { let _this = this, curTabbar = _this.data.tabbar[_this.data.curTabIndex]; - // 保存formid - App.saveFormId(e.detail.formId); let query = util.urlEncode({ active_time_id: curTabbar.active_time_id, sharp_goods_id: e.detail.target.dataset.id, @@ -146,7 +178,7 @@ Page({ */ getGoodsList(isNextPage) { let _this = this, - curTabbar = _this.data.tabbar[_this.data.curTabIndex];; + curTabbar = _this.data.tabbar[_this.data.curTabIndex]; App._get('sharp.goods/lists', { page: _this.data.page || 1, active_time_id: curTabbar.active_time_id diff --git a/pages/sharp/index/index.json b/pages/sharp/index/index.json index c83c387..b1ebaa0 100644 --- a/pages/sharp/index/index.json +++ b/pages/sharp/index/index.json @@ -1,3 +1,4 @@ { - "navigationBarTitleText": "整点秒杀" + "navigationBarTitleText": "整点秒杀", + "enablePullDownRefresh": true } \ No newline at end of file diff --git a/pages/sharp/index/index.wxml b/pages/sharp/index/index.wxml index 244df06..070e825 100644 --- a/pages/sharp/index/index.wxml +++ b/pages/sharp/index/index.wxml @@ -2,21 +2,19 @@ -
- - + + + + {{ item.status_text }} + + + {{ item.active_time }} + {{ item.status_text }} + - +
@@ -25,7 +23,8 @@ - {{ tabbar[curTabIndex].active_time }} + {{ tabbar[curTabIndex].active_time }} {{ tabbar[curTabIndex].status_text2 }} @@ -35,19 +34,19 @@
- {{ 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 @@ -
+