<template>
	<view class="content">
		<view class="dyquan-wrap" v-for="(item,index) in list" :key="index">
			<view class="showtime flex">
				<text class="line2">{{ item.card_name|| '' }}</text>
				<text class="money">￥{{item.servicecard.card_price}}</text>
			</view>
			<view class="item-info" v-for="good in item.card" @click="goGoods(good)">
				<view class="img-box">
					<image class="tip" :src="good.product.image" mode=""></image>
					<view class="good-type" v-if="good.type==2">
						月卡
					</view>
				</view>
				<view class="info-info" v-if="good.type==1">
					<view class="line2">
						{{good.product.store_name || ''}}
					</view>
					<view class="info-cs">
						<view>
							原价：{{good.product.price|| ''}}
						</view>
					</view>
					<view class="info-cs">
						<view>
							剩余：{{good.repertory || 0}}次
						</view>
					</view>
				</view>
				<view class="info-info" v-if="good.type==2">
					<view class="line2">
						{{good.product.store_name || ''}}
					</view>
					<view class="info-cs">
						<view>
							原价：{{good.product.price|| ''}}
						</view>
						<view>
							剩余：{{good.repertory || 0}}次
						</view>
					</view>
					<view class="info-cs">
						<view>
							{{good.end_time_text}}继续得{{good.month_repertory}}次
						</view>
						<view>
							{{good.card_end_time_text}}到期
						</view>
					</view>
				</view>
			</view>
			<view class="good-time">
				购买时间：{{item.update_time}}
			</view>
		</view>

		<view v-if="list.length == 0 && loadingType=='nomore'">
			<emptyPage title="暂无订单信息~"></emptyPage>
		</view>
	</view>
</template>

<script>
	import {
		getMyServeList
	} from "@/api/user.js";
	import emptyPage from '@/components/emptyPage.vue';
	export default {
		components: {
			emptyPage
		},
		data() {
			return {
				page: 1,
				pageSize: 10,
				loaded: false,
				loadingType: 'more',
				list: []
			}
		},
		onLoad(opt) {

		},
		onShow() {
			this.getList()
		},
		onReachBottom() {
			this.getList()
		},
		onReady() {

		},
		methods: {
			goGoods(item) {
				console.log(item)
				uni.navigateTo({
					url: '/pages/goods_details/index?id=' + item.product_id
				})
			},
			tabClick(item, index) {
				this.tabCurrentIndex = index;
			},
			// 获取时间字符串
			getTimeText(res) {
				return (new Date(res*1000)).toLocaleString().split(" ")[0];
			},
			getList(type) {
				let that = this
				if (type == 'reload') {
					// item.list
					return
				}
				if (type == 'tab' && that.loaded) {
					return
				}
				if (that.loadingType == 'loading' || that.loadingType == 'nomore') {
					return
				}
				that.loadingType = 'loading'

				getMyServeList({
					page: that.page,
					limit: that.pageSize,
					name: ''
				}).then(({
					data
				}) => {
					let ar = data.list.map(
						(res) => {
							for (let i = 0; i < res.card.length; i++) {
								const car = res.card[i];
								if(car.type==2){
									car.card_end_time_text  = that.getTimeText(car.card_end_time);
									car.card_start_time_text  = that.getTimeText(car.card_start_time);
									car.end_time_text  = that.getTimeText(car.end_time);
									car.start_time_text  = that.getTimeText(car.start_time);
								}
							}
							return res
						}
					)
					that.list = that.list.concat(ar)
					that.page++
					if (data.length == that.pageSize) {
						that.loadingType = 'more'
					} else {
						that.loadingType = 'nomore'
					}
				})

			}
		}
	}
</script>

<style lang="scss">
	.content {
		background-color: #f8f6f6;
		height: auto;
		min-height: 100%;
		padding-top: 30rpx;

	}

	.dyquan-wrap {
		padding: 30rpx;
		background-color: #fff;
		margin: 0 30rpx;
		margin-bottom: 30rpx;
		border-radius: 20rpx;
		.good-time{
			margin-top: 20rpx;
			color:#999999;
			font-size: $uni-font-size-sm;
		}
		.showtime {
			padding-bottom: 20rpx;
			border-bottom: 1px solid #f8f6f6;
			font-size: 30rpx;
			font-weight: bold;
			justify-content: space-between;

			.money {
				flex-shrink: 0;
				color: $uni-color-warning;
			}
		}

		.item-info {
			display: flex;
			justify-content: flex-start;
			align-items: stretch;
			padding-top: 20rpx;
			.img-box{
				position: relative;
				.good-type{
					position: absolute;
					top: 0;
					left: 0;
					background-color: $uni-color-error;
					padding: 5rpx 20rpx;
					font-size: 20rpx;
					border-top-left-radius: 20rpx;
					border-bottom-right-radius: 20rpx;
					color: rgba(255, 255, 255, 0.7);
				}
				.tip {
					width: 160rpx;
					height: 160rpx;
					margin-right: 20rpx;
					border-radius: 20rpx;
					flex-shrink: 0;
				}
			}
			

			.info-info {
				font-size: 30rpx;
				font-weight: 500;
				color: #666666;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				align-items: stretch;
				flex-grow: 1;

				.info-cs {
					display: flex;
					justify-content: space-between;
					font-size: 26rpx;
					font-weight: 500;
					color: #999999;
				}
			}
		}
	}
</style>