<template>
	<view class="claim-collage">
		<uni-nav-bar :fixed="true" :shadow="false" :statusBar="true" color="#fff"
			:backgroundColor="color == '#ffffff' ?``:primaryColor" leftIcon="icon-left"
			:title="color == '#ffffff' ?``:`众筹认养`">
		</uni-nav-bar>
		<image mode="aspectFill" lazy-load class="common-bg nav abs"
			src="https://lbqny.migugu.com/admin/farm/nav-collage.png"></image>
		<image mode="aspectFill" lazy-load class="common-bg collage abs"
			src="https://lbqny.migugu.com/admin/farm/bg-collage.png"></image>
		<view class="space-collage rel"></view>
		<view class="collage-info rel fill-base mt-md ml-md mr-md radius-24 box-shadow">
			<image lazy-load class="title-img abs" src="https://lbqny.migugu.com/admin/farm/collage-title.png">
			</image>
			<view class="title flex-center f-title c-base">简单4步 获得宠物</view>
			<view class="flex-x-between mt-md pd-lg">
				<block v-for="(item,index) in collageList" :key="index">
					<view class="flex-center flex-column">
						<image class="collage-icon" :src="`/static/image/farm/${item.img}.png`"></image>
						<view class="f-caption mt-sm">
							<text space="ensp" decode="emsp"
								style="word-break:break-all;color:#899E95">{{item.text}}</text>
						</view>
					</view>
					<i class="flex-y-center iconfont icon-xiangyou" v-if="index!=3"></i>
				</block>
			</view>
		</view>
		<view class="space-lg"></view>
		<view class="flex-between pd-md c-title">
			<view class="f-sm-title text-bold">我参与的众筹</view>
			<view @tap="$util.goUrl({url:`/claim/pages/order/collage/list`})" class="flex-y-center f-caption">查看全部<i
					class="iconfont icon-right" style="font-size: 24rpx;"></i></view>
		</view>
		<scroll-view scroll-x class="my-collage-list pl-md" :scroll-with-animation="true" v-if="user_list.length>0">
			<block v-for="(item,index) in user_list" :key="index">
				<view @tap.stop="goDetail(1,index)" class="my-item mr-md radius-16">
					<view class="flex-center rel">
						<view class="collage-status abs flex-center f-caption c-base"
							:style="{background:primaryColor}">
							<view class="flex-y-center f-icontext">
								<view class="mr-sm">距成团</view>
								<min-countdown :type="4" :targetTime="item.end_time * 1000" color="#fff"
									@callback="countEnd">
								</min-countdown>
							</view>
						</view>
						<image mode="aspectFill" lazy-load class="cover" :src="item.claim_cover"></image>
						<view class="flex-1 pl-md">
							<view class="pr-sm f-title c-title text-bold max-300 ellipsis">
								{{item.claim_title}}
							</view>
							<view class="flex-y-center f-desc c-warning mt-sm">众筹价<view
									class="flex-y-baseline f-caption ml-sm">
									¥<view class="f-sm-title text-bold">{{item.price}}</view>
								</view>
							</view>
							<view class="flex-y-center f-icontext c-title mt-sm">已参与<view :style="{color:primaryColor}">
									{{item.have_num||0}}
								</view>
								人, 还差
								<view :style="{color:primaryColor}">{{item.surplus_num||0}}</view>人众筹成功
							</view>
						</view>
					</view>
				</view>
			</block>
		</scroll-view>
		<view class="pd-md f-sm-title c-title text-bold">众筹商品</view>
		<view class="pl-md pr-md" :class="[{'mt-lg':index!=0}]" v-for="(item,index) in list.data" :key="index">
			<view @tap.stop="goDetail(2,index)" class="collage-item flex-center">
				<image mode="aspectFill" lazy-load class="cover radius-10" :src="item.claim_cover"></image>
				<view class="flex-1 ml-md">
					<view class="f-title c-title text-bold max-510 ellipsis">{{item.claim_title}}</view>
					<view class="flex-y-center f-desc c-warning mt-sm">众筹价<view class="flex-y-baseline f-caption ml-sm">
							¥<view class="f-sm-title text-bold">{{item.price}}</view>
						</view>
					</view>
					<view class="f-icontext c-caption text-delete mt-md">原价 ¥{{item.init_price}}</view>
				</view>
			</view>
			<view class="flex-between mt-md mb-md">
				<view class="flex-y-center f-desc" :style="{color:primaryColor}">
					剩余
					<min-countdown :type="2" :targetTime="item.end_time * 1000" :color="primaryColor"
						:textColor="primaryColor" :borderColor="primaryColor" @callback="countEnd">
					</min-countdown>
				</view>
				<view class="common-btn flex-center f-paragraph c-base radius" :style="{background:primaryColor}">去众筹
				</view>
			</view>
		</view>
		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
		</load-more>
		<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1"></abnor>
		<view class="space-footer"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				options: {},
				color: '#ffffff',
				collageList: [{
					img: 'pay',
					text: '    支付\n开团/参团'
				}, {
					img: 'users',
					text: '达到人数\n众筹成功'
				}, {
					img: 'claim',
					text: '    获得\n认养商品'
				}, {
					img: 'send',
					text: '认养到期\n配送到家'
				}],
				user_list: [],
				param: {
					page: 1,
				},
				list: {
					data: []
				},
				loading: true,
				lockTap: false
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			configInfo: state => state.config.configInfo,
			userInfo: state => state.user.userInfo,
		}),
		onLoad() {
			this.$util.showLoading()
			this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return
			this.param.page = this.param.page + 1
			this.loading = true
			this.getList()
		},
		onPageScroll(e) {
			let color = e.scrollTop < 20 ? '#ffffff' : '#000000'
			if (this.color == color) return
			this.color = color
		},
		methods: {
			...mapActions(['getConfigInfo', 'getUserInfo']),
			async initIndex() {
				this.user_list = await this.$api.claim.userCollageLimit()
				await this.getList()
				this.$util.hideAll()
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex()
			},
			countEnd() {
				this.$util.log("倒计时完了")
				setTimeout(() => {
					this.initRefresh()
				}, 1000)
			},
			async getList() {
				let {
					list: oldList,
					param,
				} = this
				let newList = await this.$api.claim.collageList(param);
				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			},
			goDetail(type, index) {
				let {
					start_id,
					claim_id = 0
				} = type == 1 ? this.user_list[index] : this.list.data[index]
				let page = {
					1: `/claim/pages/order/collage/detail?id=${start_id}`,
					2: `/claim/pages/detail?id=${claim_id}`
				}
				this.$util.goUrl({
					url: page[type]
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #fff;
	}

	.claim-collage {
		.space-collage {
			width: 100%;
			height: 494rpx;
			top: 0;
			z-index: -1;
		}

		.collage-info {
			height: 312rpx;
			z-index: 1;

			.title-img {
				width: 390rpx;
				height: 100rpx;
				top: -19rpx;
				left: 160rpx;
				z-index: -1;
			}

			.title {
				height: 58rpx;
			}

			.collage-icon {
				width: 88rpx;
				height: 88rpx;
			}

			.icon-xiangyou {
				color: rgba(0, 146, 84, 0.3);
			}

		}

		.my-collage-list {
			white-space: nowrap;
			width: calc(100% - 20rpx);

			.my-item {
				width: 550rpx;
				height: 180rpx;
				background: #F6F7F8;
				display: inline-block;

				.collage-status {
					width: 188rpx;
					height: 38rpx;
					top: 0;
					left: 0;
					border-radius: 16rpx 0 0 0;
				}

				.cover {
					width: 188rpx;
					height: 180rpx;
					border-radius: 16rpx 0 0 16rpx;
				}
			}
		}



		.collage-item {
			.cover {
				width: 180rpx;
				height: 170rpx;
			}
		}
	}
</style>
