Commit 6ba41b45 by 程默

fix 限时特惠优化

parent debd7d53
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<cube-nav :datas="item"></cube-nav> <cube-nav :datas="item"></cube-nav>
</div> </div>
<div v-else-if="item.componentCode == 'time-limited-discount' && item.componentInfo.visible == 1"> <div v-else-if="item.componentCode == 'time-limited-discount' && item.componentInfo.visible == 1">
<time-limited-discount :datas="item"></time-limited-discount> <time-limited-discount :class="'time-limited-discount'+index" :datas="item" :k="index"></time-limited-discount>
</div> </div>
<div v-if="item.componentCode == 'links' && item.componentInfo.visible == 1"> <div v-if="item.componentCode == 'links' && item.componentInfo.visible == 1">
<links :datas="item"></links> <links :datas="item"></links>
...@@ -103,6 +103,7 @@ import imgText from '@/components/content/imgText' ...@@ -103,6 +103,7 @@ import imgText from '@/components/content/imgText'
import coupon from '@/components/activity/coupon' import coupon from '@/components/activity/coupon'
import integralTurntable from '@/components/activity/integralTurntable' import integralTurntable from '@/components/activity/integralTurntable'
import { setTabBarActive, checkTabbarPage,themeColor } from "../../utils/mayi.js"; import { setTabBarActive, checkTabbarPage,themeColor } from "../../utils/mayi.js";
import { throttle } from "../../utils/index.js"
const app = getApp(); const app = getApp();
export default { export default {
...@@ -179,17 +180,7 @@ export default { ...@@ -179,17 +180,7 @@ export default {
this.changeLocation = options.changeLocation || '' this.changeLocation = options.changeLocation || ''
if(this.changeLocation == 1){ if(this.changeLocation == 1){
// let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
// console.log(extConfig, "-----------extConfig");
// if (
// process.env.NODE_ENV == "development" ||
// JSON.stringify(extConfig) == "{}"
// ) {
// extConfig = { mixid: "antgood", shopid: 67 };
// }
console.log('this.$store.state.extConfig',this.$store.state.extConfig) console.log('this.$store.state.extConfig',this.$store.state.extConfig)
app.getShopInfo(this.$store.state.extConfig); app.getShopInfo(this.$store.state.extConfig);
app.getThemePage(this.$store.state.extConfig); app.getThemePage(this.$store.state.extConfig);
} }
...@@ -230,10 +221,11 @@ export default { ...@@ -230,10 +221,11 @@ export default {
onShow() { onShow() {
setTabBarActive.bind(this)(checkTabbarPage('/')); setTabBarActive.bind(this)(checkTabbarPage('/'));
this.$mp.page.onPageScroll= (el)=>{ this.$mp.page.onPageScroll= (el)=>{
this.scrolls(el); throttle(this.scrolls(el),100)
}; };
}, },
methods: { methods: {
init(pageList) { init(pageList) {
setTabBarActive.bind(this)(checkTabbarPage('/')); setTabBarActive.bind(this)(checkTabbarPage('/'));
...@@ -250,9 +242,20 @@ export default { ...@@ -250,9 +242,20 @@ export default {
}, },
scrolls(el){ scrolls(el){
this.setFooterShow(el); this.setFooterShow(el);
// 优化
if(this.$mp.page && this.$mp.page.selectComponent(".goodsListItem")){ if(this.$mp.page && this.$mp.page.selectComponent(".goodsListItem")){
this.$mp.page.selectComponent(".goodsListItem").getScroll(el); this.$mp.page.selectComponent(".goodsListItem").getScroll(el);
} }
// 优化
if (this.pageData) {
for (let i = 0; i < this.pageData.length; i++) {
const element = this.pageData[i]
if(element.componentCode=="time-limited-discount"){
let com=this.$mp.page.selectComponent(".time-limited-discount"+i) ;
com && com.getScroll(el);
}
}
}
}, },
setFooterShow(el){ setFooterShow(el){
let afterScrollTop = el.scrollTop; let afterScrollTop = el.scrollTop;
......
...@@ -2,6 +2,29 @@ function formatNumber(n) { ...@@ -2,6 +2,29 @@ function formatNumber(n) {
const str = n.toString() const str = n.toString()
return str[1] ? str : `0${str}` return str[1] ? str : `0${str}`
} }
// 防抖
export function debounce(fn, wait) {
var timeout = null;
return function() {
if (timeout !== null)
clearTimeout(timeout);
timeout = setTimeout(fn, wait);
}
}
// 节流
export function throttle(func, delay) {
var prev = Date.now();
return function() {
var context = this;
var args = arguments;
var now = Date.now();
if (now - prev >= delay) {
func.apply(context, args);
prev = Date.now();
}
}
}
//格式时间 //格式时间
export function formatTime(date) { export function formatTime(date) {
......
...@@ -39,6 +39,7 @@ xcsoft.countdown = function(a, b, c) { ...@@ -39,6 +39,7 @@ xcsoft.countdown = function(a, b, c) {
d.minute = 0; d.minute = 0;
d.second = 0; d.second = 0;
d.t = setInterval(function() { d.t = setInterval(function() {
console.log('倒计时')
e = new Date().getTime(); e = new Date().getTime();
f = parseInt(e / 1000 + x); f = parseInt(e / 1000 + x);
var l = d.time - f; var l = d.time - f;
...@@ -109,10 +110,15 @@ const componentOptions = { ...@@ -109,10 +110,15 @@ const componentOptions = {
properties: { properties: {
datas: { datas: {
type: Object type: Object
},
k:{
type:String
} }
}, },
// 组件数据 // 组件数据
data: { data: {
loaded:false,
isContain:false,
isPageHidden: false, // 页面是否处于隐藏状态 isPageHidden: false, // 页面是否处于隐藏状态
timeData: {}, timeData: {},
isLoading: true, isLoading: true,
...@@ -243,6 +249,24 @@ const componentOptions = { ...@@ -243,6 +249,24 @@ const componentOptions = {
} }
}); });
}, },
getScroll(){
this.getEleInfo(()=>{
this.getData()
});
},
// 获取当前组件位置信息
getEleInfo(cb){
if(this.loaded || this.isContain) return
this.isContain=true;
let {windowHeight} = wx.getSystemInfoSync()
let query=wx.createSelectorQuery().in(this);
query.select('.time-limited-discount').boundingClientRect(rect=>{
if (rect.top<windowHeight && rect.top+rect.height>0) {
cb && cb()
}
this.isContain=false;
}).exec();
},
onChange(e) { onChange(e) {
this.setData({ timeData: e.detail }); this.setData({ timeData: e.detail });
}, },
...@@ -275,6 +299,8 @@ const componentOptions = { ...@@ -275,6 +299,8 @@ const componentOptions = {
}); });
}, },
getData() { getData() {
if(this.loaded) return
this.loaded=true
let { dimension } = this.data.datas.componentData; let { dimension } = this.data.datas.componentData;
if (dimension == 0) { if (dimension == 0) {
this.init(); this.init();
...@@ -287,7 +313,11 @@ const componentOptions = { ...@@ -287,7 +313,11 @@ const componentOptions = {
lifetimes: { lifetimes: {
created() {}, created() {},
ready() { ready() {
this.getData(); this.loaded=false;
this.isContain=false;
this.getEleInfo(()=>{
this.getData()
});
}, },
moved() {}, moved() {},
detached() {} detached() {}
...@@ -297,7 +327,11 @@ const componentOptions = { ...@@ -297,7 +327,11 @@ const componentOptions = {
pageLifetimes: { pageLifetimes: {
// 页面被展示 // 页面被展示
show() { show() {
this.getData(); this.loaded=false;
this.isContain=false;
this.getEleInfo(()=>{
this.getData()
});
const { isPageHidden } = this.data; const { isPageHidden } = this.data;
// show事件发生前,页面不是处于隐藏状态时 // show事件发生前,页面不是处于隐藏状态时
if (!isPageHidden) { if (!isPageHidden) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment