home.vue 6.09 KB
Newer Older
郑秀明's avatar
郑秀明 committed
1 2 3 4 5 6 7 8 9 10 11 12 13
<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'
	>
郑秀明's avatar
郑秀明 committed
14
		<view class="homeContent" style="padding: 100rpx 0 110rpx;background-color: #f8f8f8;">
郑秀明's avatar
郑秀明 committed
15
			<component v-for="(item, index) in data" :key="index" :is="item.name" :wrapper_props="item.wrapper_props" :isLogin="isLogin" :ref="item.name"></component>
郑秀明's avatar
郑秀明 committed
16 17 18
			<view class="protocol">
				<text @click="jumpPhp('app=member&act=register_agree')">《服务协议》</text> | <text @click="jumpPhp('app=member&act=register_privacy')">《隐私政策》</text>
			</view>
郑秀明's avatar
郑秀明 committed
19
			<BottomBar />
郑秀明's avatar
郑秀明 committed
20
			<uni-popup ref="popup" type="center" :maskClick="true">
郑秀明's avatar
郑秀明 committed
21 22 23 24
				<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>
郑秀明's avatar
郑秀明 committed
25 26
			</uni-popup>
		</view>
郑秀明's avatar
郑秀明 committed
27 28 29 30 31 32 33 34 35 36 37 38 39
	</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';
王建威's avatar
王建威 committed
40
	import MultImage from './components/multimage.vue';
郑秀明's avatar
郑秀明 committed
41 42
	import BottomBar from "@/components/BottomBar/BottomBar.vue";
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
郑秀明's avatar
郑秀明 committed
43 44 45 46 47
	import Skeleton from '@/components/J-skeleton/J-skeleton.vue';
	import { php } from '../../common/host.js';
	export default {
		data() {
			return {
王建威's avatar
王建威 committed
48
				data: [],
王建威's avatar
王建威 committed
49
				isLogin: 0,
郑秀明's avatar
郑秀明 committed
50 51
				fixFlag: false,
				loading: true,
郑秀明's avatar
郑秀明 committed
52
				from_login: 0,
郑秀明's avatar
郑秀明 committed
53 54 55 56 57 58 59 60 61 62
				skeleton1 : {
				  avatarSize: '160rpx',
				  row: 2,
				  showTitle: true,
					imgTitle: true,
					flexType: 'space-between',
					categoryRow: 4,
					categorySize: '110rpx',
					avatarShape: 'square',
					titleWidth: '100%'
郑秀明's avatar
郑秀明 committed
63
				},
郑秀明's avatar
郑秀明 committed
64 65
				COUPON_ID: '185' //优惠券ID
			}
王建威's avatar
王建威 committed
66
		},
郑秀明's avatar
郑秀明 committed
67 68 69
		onLoad(option) {
			const {from_login} = option;
			this.from_login = from_login;
郑秀明's avatar
郑秀明 committed
70
			this.loading = true;
王建威's avatar
王建威 committed
71
			this.getData();
郑秀明's avatar
郑秀明 committed
72 73 74
			// uni.showLoading({
			//   title: '加载中'
			// });
王建威's avatar
王建威 committed
75 76 77 78 79
			// #ifdef H5
			//默认请求微信分享
			if (this.$wechat && this.$wechat.isWechat()) {
				this.$wechat.share({titie: this.$getNavigationBarTitle()});
			}
80
			this.postData();
王建威's avatar
王建威 committed
81
			// #endif
王建威's avatar
王建威 committed
82
		},
王建威's avatar
王建威 committed
83 84 85 86 87 88 89 90 91 92
		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;
			}
		},
王建威's avatar
王建威 committed
93 94 95 96 97 98 99
		methods: {
			getData() {
				uni.request({
					url: '/uni/api/index/style_info',
					method: 'GET',
					dataType: 'json',
					success: (res) => {
郑秀明's avatar
郑秀明 committed
100 101 102 103 104
						if(res && res.data && res.data.code === 0){
							this.data = res.data.data;
							this.isLogin = res.data.login_flg;
							// uni.hideLoading();
							this.loading = false;
郑秀明's avatar
郑秀明 committed
105 106 107
							// 获取是否领取优惠券
							if(res.data.login_flg === 1){
								this.get_coupon(res.data.reg_time);
郑秀明's avatar
郑秀明 committed
108 109 110 111
							}else{
								// if(!this.from_login){
								// 	window.location.href = `${php}app=member&act=login`
								// }
郑秀明's avatar
郑秀明 committed
112 113 114
							}
						}else{
							uni.showToast({
郑秀明's avatar
郑秀明 committed
115 116 117
								title: '获取数据失败,请重试~',
								duration: 2000,
								icon: 'none'
郑秀明's avatar
郑秀明 committed
118 119 120 121 122 123 124 125 126
							});
						}	
					},
					fail: () => {
						uni.showToast({
						    title: '获取数据失败,请重试~',
						    duration: 2000,
								icon: 'none'
						});
王建威's avatar
王建威 committed
127 128
					}
				});
郑秀明's avatar
郑秀明 committed
129 130 131 132 133
			},
			receive_coupon(){
				const { origin } = location;
				this.$jump(`${origin}/mobile/index.php?app=coupon&act=view&id=${this.COUPON_ID}`);
				this.$refs.popup.close();
郑秀明's avatar
郑秀明 committed
134
			},
郑秀明's avatar
郑秀明 committed
135 136 137
			jumpPhp(url){
					window.location.href = `${php}${url}`;
			},
138 139 140 141 142 143 144 145 146 147 148 149 150 151
			// 向小程序发送数据
			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) });
					}
				});
			},
郑秀明's avatar
郑秀明 committed
152 153
			get_coupon(reg_time){
				// 打开广告弹窗
郑秀明's avatar
郑秀明 committed
154 155
				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;
郑秀明's avatar
郑秀明 committed
156 157 158 159 160 161 162 163 164 165 166
				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){
王建威's avatar
王建威 committed
167
								// this.$refs.popup.open();
郑秀明's avatar
郑秀明 committed
168 169 170 171
							}
						}
					}
				})
王建威's avatar
王建威 committed
172
			}
郑秀明's avatar
郑秀明 committed
173
		},
王建威's avatar
王建威 committed
174
		components: {
郑秀明's avatar
郑秀明 committed
175 176 177 178 179 180 181 182 183 184
			BottomBar,
			SearchBar,
			Navigation,
			Slide,
			MainTitle,
			GoodsList,
			FunctionMenu,
			Promotion,
			HotRecommd,
			CustomStyle,
郑秀明's avatar
郑秀明 committed
185 186
			MultImage,
			uniPopup,
郑秀明's avatar
郑秀明 committed
187 188 189 190 191
			Skeleton
		}
	}
</script>

郑秀明's avatar
郑秀明 committed
192
<style lang="scss" scoped>
郑秀明's avatar
郑秀明 committed
193
	.homeContent{
王建威's avatar
王建威 committed
194
		padding: 100rpx 0 110rpx;
王建威's avatar
王建威 committed
195
		background-color: #f8f8f8;
郑秀明's avatar
郑秀明 committed
196
	}
郑秀明's avatar
郑秀明 committed
197 198 199 200 201 202 203 204 205 206
	.protocol{
		font-size: 24rpx;
		text-align: center;
		height: 46rpx;
		line-height: 46rpx;
		text{
			color: #B1825A;
			font-size: 24rpx;
		}
	}
郑秀明's avatar
郑秀明 committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
	.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;
		}
郑秀明's avatar
郑秀明 committed
230
	}
王建威's avatar
王建威 committed
231
</style>