1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<template>
<skeleton
:loading="loading"
:avatarSize="skeleton1.avatarSize"
:row="skeleton1.row"
:showTitle="skeleton1.showTitle"
:imgTitle='skeleton1.imgTitle'
:categoryRow= 'skeleton1.categoryRow'
:flexType='skeleton1.flexType'
:categorySize='skeleton1.categorySize'
:avatarShape='skeleton1.avatarShape'
:titleWidth='skeleton1.titleWidth'
>
<view class="homeContent" style="padding: 100rpx 0 110rpx;background-color: #f8f8f8;">
<component v-for="(item, index) in data" :key="index" :is="item.name" :wrapper_props="item.wrapper_props" :isLogin="isLogin" :ref="item.name"></component>
<view class="protocol">
<text @click="jumpPhp('app=member&act=register_agree')">《服务协议》</text> | <text @click="jumpPhp('app=member&act=register_privacy')">《隐私政策》</text>
</view>
<BottomBar />
<uni-popup ref="popup" type="center" :maskClick="true">
<view class='coupon_dialog'>
<img class='coupon_dialog_img' src="https://dbc-static.oss-cn-beijing.aliyuncs.com/credit_shop/global/coupon_dialog.png">
<view class="coupon_dialog_btn" @click="receive_coupon">立即领取</view>
</view>
</uni-popup>
</view>
</skeleton>
</template>
<script>
import SearchBar from './components/searchbar.vue';
import Navigation from './components/navigation.vue';
import Slide from './components/slide.vue';
import MainTitle from './components/maintitle.vue';
import GoodsList from './components/goodslist.vue';
import FunctionMenu from './components/functionmenu.vue';
import Promotion from './components/promotion.vue';
import HotRecommd from './components/hotrecommd.vue';
import CustomStyle from './components/custowstyle.vue';
import MultImage from './components/multimage.vue';
import BottomBar from "@/components/BottomBar/BottomBar.vue";
import uniPopup from '@/components/uni-popup/uni-popup.vue';
import Skeleton from '@/components/J-skeleton/J-skeleton.vue';
import { php } from '../../common/host.js';
export default {
data() {
return {
data: [],
isLogin: 0,
fixFlag: false,
loading: true,
from_login: 0,
skeleton1 : {
avatarSize: '160rpx',
row: 2,
showTitle: true,
imgTitle: true,
flexType: 'space-between',
categoryRow: 4,
categorySize: '110rpx',
avatarShape: 'square',
titleWidth: '100%'
},
COUPON_ID: '185' //优惠券ID
}
},
onLoad(option) {
const {from_login} = option;
this.from_login = from_login;
this.loading = true;
this.getData();
// uni.showLoading({
// title: '加载中'
// });
// #ifdef H5
//默认请求微信分享
if (this.$wechat && this.$wechat.isWechat()) {
this.$wechat.share({titie: this.$getNavigationBarTitle()});
}
this.postData();
// #endif
},
onPageScroll() {
const top = this.$refs.HotRecommd[0].$refs.fix.$el.getBoundingClientRect().top;
if(top <= 50 && !this.fixFlag) {
this.fixFlag = true;
this.$refs.HotRecommd[0].fixFlag = true;
} else if(top > 50 && this.fixFlag) {
this.fixFlag = false;
this.$refs.HotRecommd[0].fixFlag = false;
}
},
methods: {
getData() {
uni.request({
url: '/uni/api/index/style_info',
method: 'GET',
dataType: 'json',
success: (res) => {
if(res && res.data && res.data.code === 0){
this.data = res.data.data;
this.isLogin = res.data.login_flg;
// uni.hideLoading();
this.loading = false;
// 获取是否领取优惠券
if(res.data.login_flg === 1){
this.get_coupon(res.data.reg_time);
}else{
// if(!this.from_login){
// window.location.href = `${php}app=member&act=login`
// }
}
}else{
uni.showToast({
title: '获取数据失败,请重试~',
duration: 2000,
icon: 'none'
});
}
},
fail: () => {
uni.showToast({
title: '获取数据失败,请重试~',
duration: 2000,
icon: 'none'
});
}
});
},
receive_coupon(){
const { origin } = location;
this.$jump(`${origin}/mobile/index.php?app=coupon&act=view&id=${this.COUPON_ID}`);
this.$refs.popup.close();
},
jumpPhp(url){
window.location.href = `${php}${url}`;
},
// 向小程序发送数据
postData(){
jWeixin.miniProgram.getEnv(function (res) {
//获取当前环境
if(res.miniprogram){
// this.$wechat.postData('谛宝多多商城-首页');
const postData = {
link: window.location.href,
title: '谛宝多多商城-首页'
}
jWeixin.miniProgram.postMessage({ data: JSON.stringify(postData) });
}
});
},
get_coupon(reg_time){
// 打开广告弹窗
const timestamp = new Date('2020/05/19 00:00:00').getTime() / 1000;
const end_timestamp = new Date('2020/06/18 23:59:59').getTime() / 1000;
uni.request({
url: '/uni/api/coupon/GetCoupon',
method: 'GET',
data:{
coupon_id: this.COUPON_ID
},
dataType: 'json',
success: (res) => {
const {code, data} = res.data;
if(code === 0 && !data){
if(reg_time > timestamp && reg_time < end_timestamp){
// this.$refs.popup.open();
}
}
}
})
}
},
components: {
BottomBar,
SearchBar,
Navigation,
Slide,
MainTitle,
GoodsList,
FunctionMenu,
Promotion,
HotRecommd,
CustomStyle,
MultImage,
uniPopup,
Skeleton
}
}
</script>
<style lang="scss" scoped>
.homeContent{
padding: 100rpx 0 110rpx;
background-color: #f8f8f8;
}
.protocol{
font-size: 24rpx;
text-align: center;
height: 46rpx;
line-height: 46rpx;
text{
color: #B1825A;
font-size: 24rpx;
}
}
.coupon_dialog{
width: 600rpx;
height: 786rpx;
position: relative;
.coupon_dialog_img{
width: 100%;
}
.coupon_dialog_btn{
position: absolute;
bottom: 125rpx;
left: 50%;
width: 520rpx;
height: 84rpx;
line-height: 84rpx;
margin-left: -260rpx;
background-color: #3E322B;
font-size: 30rpx;
font-family: PingFangSC-Medium,PingFang SC;
font-weight: 500;
color: rgba(255,255,255,1);
text-align: center;
border-radius: 84rpx;
}
}
</style>