<template>
	<view class="contair">
		<view class='bargain-list'>
			<view class='back' @tap='goBack' ><image src='../../../static/img/img45.png'></image></view>
			<view class='header'></view>
			<view class='list'>
				<block v-for="(item,index) in bargainList" :key="index">
					<view class='item acea-row row-between-wrapper' @tap="openSubscribe('/pages/activity/goods_bargain_details/index?id='+ item.id +'&bargain='+ userInfo.uid)">
						<view class='pictrue'>
							<image :src='item.image'></image>
						</view>
						<view class='text acea-row row-column-around'>
							<view class='name line1'>{{item.title}}</view>
							<view class='num'><text class='iconfont icon-pintuan'></text>{{item.people}}人正在参与</view>
							<view class='money font-color'>最低: ￥<text class='price'>{{item.min_price}}</text></view>
						</view>
						<view class='cutBnt bg-color'>参与砍价</view>
					</view>
				</block>
			</view>
		</view>
		
		<!-- <home></home> -->
	</view>
</template>
<script>
	let app = getApp();
	import {
		openBargainSubscribe
	} from '@/utils/SubscribeMessage.js';
	import {
		userinfos,getBargainList
	} from '@/api/user.js';
	import home from '@/components/home';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapState
	} from "vuex";
	// #ifdef MP
	// import authorize from '@/components/Authorize';
	// #endif
	export default {
		components: {
			home,
			// #ifdef MP
			// authorize
			// #endif
		},
		data() {
			return {
				bargainList: [],
				page: 1,
				limit: 20,
				loading: false,
				loadend: false,
				userInfo: {},
				//navH: '',
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false //是否隐藏授权
			};
		},
		computed: {
			...mapState(['hasLogin'])
		},
		onLoad: function(options) {
			uni.setNavigationBarTitle({
				title:"砍价列表"
			})

			//this.navH = app.globalData.navHeight;
			if (this.hasLogin) {
				this.getUserInfo();
				this.getBargainList();
			} else {
				// #ifdef H5 || APP-PLUS
				toLogin();
				// #endif 
				// #ifdef MP
				this.isAuto = true;
				this.$set(this, 'isShowAuth', true);
				// #endif
			}
		},
		methods: {
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
			},
			/*
			 * 获取用户信息
			 */
			getUserInfo: function() {
				let that = this;
				userinfos({}).then(({ data }) => {
					that.$set(that, 'userInfo', data);
				});
			},
			goBack: function() {
				uni.switchTab({
				    url: '/pages/index/index'
				});
			},
			onLoadFun: function(e) {
				this.getBargainList();
				this.userInfo = e;
				
			},
			openSubscribe: function(e) {
				let page = e;
				// #ifndef MP
				uni.navigateTo({
					url: page
				});
				// #endif
				// #ifdef MP
				uni.showLoading({
					title: '正在加载',
				})
				openBargainSubscribe().then(res => {
					uni.hideLoading();
					uni.navigateTo({
						url: page,
					});
				}).catch((err) => {
					uni.hideLoading();
				});
				// #endif
			},
			getBargainList: function() {
				let that = this;
				if (that.loadend) return;
				if (that.loading) return;
				that.loading = true;
				getBargainList({
					page: that.page,
					limit: that.limit
				}).then(function(res) {
					that.$set(that, 'bargainList', that.bargainList.concat(res.data));
					that.$set(that, 'page', that.page + 1);
					that.$set(that, 'loadend', that.limit > res.data.length);
					that.$set(that, 'loading', false);
				}).catch(res => {
					that.loading = false;
				});
			}
		},
		onReachBottom: function() {
			this.getBargainList();
		},
	}
</script>

<style lang="scss">
	page {
		background-color: #e93323 !important;
	}
	.bargain-list .back {
		image{
			width: 40rpx;
			height: 40rpx;
			transform:rotate(180deg);
		}
		position: fixed;
		left: 25rpx;
		top: 50rpx;
		z-index: 99;
		
	}

	.bargain-list .header {
		background-image: url('data:image/png;base64,[encoded data, 103360 characters]');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		width: 750rpx;
		height: 713rpx;
	}

	.bargain-list .list {
		background-color: #fff;
		border: 6rpx solid #fc8b42;
		border-radius: 30rpx;
		margin: -45rpx 30rpx 66rpx 30rpx;
		padding: 0 24rpx;
	}

	.bargain-list .list .item {
		border-bottom: 1rpx solid #eee;
		position: relative;
		height: 223rpx;
	}

	.bargain-list .list .item .pictrue {
		width: 160rpx;
		height: 160rpx;
	}

	.bargain-list .list .item .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 6rpx;
	}

	.bargain-list .list .item .text {
		width: 450rpx;
		font-size: 30rpx;
		color: #282828;
		height: 160rpx;
	}

	.bargain-list .list .item .text .name {
		width: 100%;
	}

	.bargain-list .list .item .text .num {
		font-size: 26rpx;
		color: #999;
	}

	.bargain-list .list .item .text .num .iconfont {
		font-size: 35rpx;
		margin-right: 7rpx;
	}

	.bargain-list .list .item .text .money {
		font-size: 24rpx;
		font-weight: bold;
	}

	.bargain-list .list .item .text .money .price {
		font-size: 32rpx;
	}

	.bargain-list .list .item .cutBnt {
		position: absolute;
		width: 180rpx;
		height: 50rpx;
		border-radius: 50rpx;
		font-size: 24rpx;
		color: #fff;
		text-align: center;
		line-height: 46rpx;
		right: 24rpx;
		bottom: 28rpx;
		box-shadow: 0 7rpx 0 #f8c1bd;
	}

	.bargain-list .list .item .cutBnt .iconfont {
		margin-right: 8rpx;
		font-size: 30rpx;
	}

	.bargain-list .list .load {
		font-size: 24rpx;
		height: 85rpx;
		text-align: center;
		line-height: 85rpx;
	}
</style>
