<template>
	<view>
		<scroll-list ref="list" :option="option" @load="load" @refresh="refresh" @loadSuccess="loadSuccess"
			@scrolltolower="scrolltolower">

			<view style="text-align: center;border: 1rpx solid #cecece;color: #9c9c9c;">
				<uni-row>
					<uni-col :span="20">
						<uni-row>
							<uni-col :span="16">活动名</uni-col>
							<uni-col :span="8">活动类型</uni-col>
						</uni-row>
					</uni-col>
					<uni-col :span="4">
						操作
					</uni-col>
				</uni-row>
			</view>
			<view v-for="(item, index) in list" :key="index">
				<view
					style="text-align: center;border: 1rpx solid #cecece;color: #747474;padding: 20rpx 0;font-size: 50rpx;">
					<uni-row>
						<uni-col :span="20">
							<view @click="handleTest(item)">
								<uni-row>
									<uni-col :span="16">{{item.eventName}}</uni-col>
									<uni-col :span="8">{{item.eventType}}</uni-col>
								</uni-row>
								<view
									style="font-size: 20rpx;color: #a2a2a2;text-align: left;padding: 15rpx 0 0 25rpx;">
									预约时间：{{item.createTime}}
								</view>
							</view>
						</uni-col>
						<uni-col :span="4">
							<view class="yyButton" style="margin:20rpx 5rpx 0;border: 1rpx solid rgb(10, 185, 156);
										color: rgb(10, 185, 156);font-size: 22rpx; padding:  5rpx;
										 border-radius: 10rpx;" @click="back(item)">
								取消预约
							</view>
						</uni-col>
					</uni-row>
				</view>
			</view>
		</scroll-list>
	</view>
</template>
<style lang="scss" scoped>
	.page-wrap {}

	.yyButton:active {
		background-color: #dedede;
	}

	.infoBody {
		background-color: #ffffff;
		padding: 20rpx 0;
		font-size: 30px;
		margin: 2rpx;
		box-shadow: 0px 2px 5px #e5e5e5;
	}
</style>
<script>
	export default {
		data() {
			return {
				option: {
					page: 1,
					size: 5,
					auto: true
				},
				page: 1,
				list: [],
				scrollList: [],
				total: 0
			}
		},
		onLoad() {

		},
		onShow() {
			this.$refs.list.refresh()
		},
		methods: {
			async back(item) {
				const {
					data: res
				} = await this.$httpRequest({
					url: '/app/backEventOrder?id=' + item.id,
					method: 'get',
					urlType: this.$getUrlType()
				});
				if (res.code === 200) {
					this.taskList({
						page: 1,
						size: 5
					})
					this.$showModal("取消成功")
				} else {
					this.$showModal(res.msg)
				}
			},
			handleTest(item) {
				setTimeout(() => {
					this.list = []
				}, 1000)
				uni.setStorageSync("eventId", item.eventId)
				uni.setStorageSync("isUpload", 1)
				uni.navigateTo({
					url: "more"
				})
			},
			async taskList(paging) {
				// 发送请求
				const {
					data: res
				} = await this.$httpRequest({
					url: '/app/eventOrders?pageNum=' + paging.page + '&pageSize=' + paging.size,
					method: 'get',
					urlType: this.$getUrlType()
				});
				if (res.code === 200) {
					if (paging.page === 1) {
						this.scrollList = res.rows
						this.total = res.total
						this.$refs.list.loadSuccess({
							list: res.rows,
							total: this.total
						});
					} else if (paging.page > 1) {
						for (var i = 0; i < res.rows.length; i++) {
							this.scrollList.push(res.rows[i])
						}
						this.$refs.list.loadSuccess({
							list: this.scrollList,
							total: this.total
						});
					}
				}
			},
			// 刷新刷剧
			refresh(paging) {
				this.taskList(paging)
			},
			scrolltolower(e) {
				console.log(e)
			},
			load(paging) {
				this.taskList(paging)
			},
			loadSuccess(list) {
				this.list = list
			}
		}
	}
</script>
