<template>
	<view>
		<view class="infotop">
			<u-tabs lineWidth="50" lineHeight="2" :scrollable="false" :list="list" lineColor="#EF9525"
				:is-scroll="false" :current="current" @change="handleChange"></u-tabs>
		</view>
		<u-empty mode="list" :marginTop="100" v-if="isloading&&listOrder.length==0" />
		<view class="orderBoxList" v-else>
			<block v-for="(item,index) in listOrder" :key="index">
				<view class="orderBox" :class="{'cancelBox':item.status==0}" @click="toinfo(item.id)">
					<view class="orderBoxTitle flex-row">
						<text class="orderBoxTitleTxt">{{item.type==1?"团队预约":"个人预约"}}</text>
						<view :class="item.status!=1?'cancelStatus orderBoxStatus':'orderBoxStatus'">
							{{item.status_name}}
						</view>
					</view>

					<view class="orderBoxInfo flex-col">
						<view class="orderBoxInfoRow flex-row">
							<text class="iconfont icon-youkexuzhi"></text>
							<text class="orderBoxInfoRowTxt">活动名称：{{item.activity.name||"加载中..."}}</text>
						</view>
						<view class="orderBoxInfoRow flex-row" style="margin-top: 20rpx;">
							<text class="iconfont icon-youkexuzhi"></text>
							<text class="orderBoxInfoRowTxt">
								订单信息：{{timeFormat(item.activity.created_at, 'MM月DD日')}}{{getHm(item.activity.start_time)}}-{{getHm(item.activity.end_time)}}丨{{item.total}}位观众</text>

						</view>
						<view class="orderBoxInfoRow flex-row" v-if="item.type==1" style="margin-top: 20rpx;">
							<text class="iconfont icon-iconfontgerenzhongxin"></text>
							<text class="orderBoxInfoRowTxt">领队：{{item.leader}}丨 {{item.mobile}}</text>
						</view>
						<view class="orderBoxInfoRow flex-row" v-if="item.type==1" style="margin-top: 20rpx;">
							<text class="iconfont icon-danwei"></text>
							<text class="orderBoxInfoRowTxt">单位名称：{{item.unit}}</text>
						</view>
					</view>
					<view class="orderBoxTime">
						<text>下单时间：{{item.created_at}}</text>
					</view>

					<view class="orderBoxFooter  flex-row flex_end">
						<view class="fbtn cancel" v-if="item.status==1" style="margin-right: 23rpx;"
							@click.stop="tocancel(item.id)">取消</view>
						<view class="fbtn" :class="{'cancel':item.status!=1}" @click.stop="toinfo(item.id)">查看详情</view>
					</view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activity_list: [],
				itemStyle: {
					height: '44px',
					flex: 1
				},
				list: [{
					name: '全部',
					idx: ""
				}, {
					name: '已预约',
					idx: "1"
				}, {
					name: '已核销',
					idx: "2"
				}, {
					name: '已取消',
					idx: "0"
				}, {
					name: '已过期',
					idx: "3"
				}],
				current: 0,
				isloading: true,
				listOrder: []
			}
		},
		onShow() {
			this.loadOrder();
		},
		methods: {
			handleChange(e) {
				this.current = e.index;
				this.loadOrder();
			},
			toinfo(id) {
				uni.navigateTo({
					url: "/pages/order/activityorderinfo?id=" + id
				})
			},
			tocancel(id) {
				var that = this;
				uni.showModal({
					title: '确认要取消预约？',
					success: function(res) {
						if (res.confirm) {
							that.util.request({
								api: '/api/mobile/activity/cancel-order',
								data: {
									id: id
								},
								utilSuccess: function(res) {
									that.loadOrder()
								},
								utilFail: function(res) {
									uni.showToast({
										icon: "none",
										title: res
									})
								}
							})
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			loadOrder() {
				var that = this;
				this.util.request({
					api: '/api/mobile/user/my-activity-order',
					data: {
						status: this.list[this.current].idx
					},
					utilSuccess: function(res) {
						that.listOrder = res;
						this.isloading = false;
					},
					utilFail: function(res) {
						uni.showToast({
							icon: "none",
							title: res
						})
					}
				})
			},
			getHm(val) {
				if (val) {
					return this.$moment(val).format("HH:mm")
				} else return "";
			},
			timeFormat(val, format) {
				return this.$moment(val).format(format)
			}
		}
	}
</script>

<style>
	.orderBoxFooter {
		padding: 20rpx 0 0 0;
	}

	.fbtn {
		background: #EF9525;
		border-radius: 8rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		padding: 7rpx 17rpx;
	}

	.cancel {
		background: #F7F6F4;
		color: #828282;
	}

	.cancelBox .iconfont {
		color: #828282;
	}

	.cancelBox .fbtn {
		background: #CFCFCF;
		color: #828282;
	}

	.iconfont {
		color: #6EAC97;
		margin-right: 20rpx;
		font-size: 24rpx;
	}

	.infotop {
		background: #FFFFFF;
		box-shadow: 2rpx 3rpx 10rpx 0px rgba(107, 94, 77, 0.3);
	}

	page {
		background-color: #f7f6f4;
	}

	.orderBoxList {
		padding: 26rpx;
		box-sizing: border-box;
	}

	.orderBox {
		min-height: 393rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		box-sizing: border-box;
		padding: 29rpx 18rpx;
		position: relative;
		margin-bottom: 17rpx;
	}

	.orderBoxTitle {
		padding: 0rpx 0rpx 25rpx 0rpx;
		border-bottom: 2rpx solid #F7F6F4;
	}

	.orderBoxInfoRow {
		align-items: center;
	}

	.orderBoxTitleTxt {
		font-size: 32rpx;
		color: #351C1B;
	}

	.cancelStatus {
		background: #CFCFCF !important;
	}

	.orderBoxStatus {
		background: #EF9525;
		border-top-right-radius: 16rpx;
		border-bottom-left-radius: 16rpx;
		font-size: 24rpx;
		padding: 19rpx 23rpx 17rpx 23rpx;
		color: #FFFFFF;
		position: absolute;
		right: 0;
		top: 0;
	}

	.orderBoxInfo {
		padding: 29rpx 0rpx;
		border-bottom: 2rpx solid #F7F6F4;
	}


	.orderBoxInfoRowTxt {
		font-size: 24rpx;
		font-family: PingFang SC;
		color: #828282;
	}

	.orderBoxTime {
		color: #CFCFCF;
		padding: 23rpx 0;
		border-bottom: 2rpx solid #F7F6F4;
		font-size: 24rpx;
	}
</style>
