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

郑秀明's avatar
郑秀明 committed
178
<style lang="scss" scoped>
郑秀明's avatar
郑秀明 committed
179
	.homeContent{
王建威's avatar
王建威 committed
180
		padding: 100rpx 0 110rpx;
王建威's avatar
王建威 committed
181
		background-color: #f8f8f8;
郑秀明's avatar
郑秀明 committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
	}
	.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
206 207
	}
</style>