<template>
	<view class="container">
		<view class="header">
			<view :class="clkIndex == index?'participate-record-btn join-btn': 'participate-record-btn'"
				v-for="(item,index) in canIndex" @click="clkItem(index)">{{item}}</view>
		</view>
		<view class="info-box">
			<u-table font-size="24" border-color="#fff" :th-style="thStyle">
				<u-tr>

					<u-th>会员昵称</u-th>
					<u-th>奖品</u-th>
					<u-th>时间</u-th>
					<u-th>发放方式</u-th>
				</u-tr>
				<u-tr v-for="(item, index) in activityList" :key="index">
					<u-td>
						<view style="display: flex;" v-if="clkIndex==1">
							<u-checkbox v-model="activityList[index].gouxuan" :label-disabled="false"
								active-color="#0EBB5A" @change="xuanAll(item,$event)" />
							{{ item.type  }}
						</view>
						<view style="display: flex;" v-else>
							<u-checkbox v-model="activityList[index].gouxuan" :label-disabled="false"
								active-color="#0EBB5A" @change="danAll(item,$event)" />
							{{ item.type  }}
						</view>
					</u-td>
					<u-td>{{ item.name }}</u-td>
					<u-td >{{ item.time }}</u-td>
					<u-td>{{item.fangshi}}</u-td>
				</u-tr>
			</u-table>
		</view>
		<view class="page-footer">
			<view class="footer-buy">
				<u-checkbox-group v-if="clkIndex ==1">
					<u-checkbox @change="quanxuan" v-model="showAll" active-color="#0EBB5A">全选</u-checkbox>
				</u-checkbox-group>
				<view
					:style="clkIndex ==1?'display: flex;justify-content: space-between; width: 80%;':'display: flex;justify-content: space-between; width: 100%;'">
					<u-button type="" style="width: 45%;background-color: ##A5A5A5;border:none" :border="false"
						@click="close">取消</u-button>
					<u-button type="success" style="width: 45%;" @click="submit">提交</u-button>
				</view>
			</view>
		</view>
		<u-popup class="userForm" v-model="show" mode="center" border-radius="20" :closeable="false" width="100%">
			<view style="padding: 20rpx;">
				<u-form class="form-box" :model="kdForm" ref="uForm" :label-width="120">
					<view style="padding: 10rpx;">
						<view class="title">寄件方式</view>
						<view class="" style="background-color: #F0F0F0;border-radius: 20rpx;padding:10px 15px;">
							<view style="display: flex;">
								<view style="width: 50%;">
									<view class="titlechich">姓名</view>
									<view class="">张三</view>
								</view>
								<view style="width: 50%;">
									<view class="titlechich">手机号</view>
									<view class="">1535116515313</view>
								</view>
							</view>
							<view>
								<view class="titlechich">邮寄地址</view>
								<view class="">这里有地址这里有地址这里有地址这里有地址这里有地址这里有地址这里有地址</view>
							</view>
						</view>
						<view class="title">快递公司</view>
						<view class="" style="background-color: #F0F0F0;border-radius: 20rpx;padding:10px 15px;">

							<view>
								<u-input style="width: 50%;" height="30"  v-model="kdForm.gongsi" :clearable="false"	/>
							</view>
						</view>
						<view class="title">快递单号</view>
						<view class="" style="background-color: #F0F0F0;border-radius: 20rpx;padding:10px 15px;">

							<view>
								<u-input style="width: 50%;" height="30" v-model="kdForm.danhao" :clearable="false" />
							</view>
						</view>
						<view style="display: flex;justify-content: space-between;margin-top: 10px;">
							<u-button type="" style="width: 45%;background-color: ##A5A5A5;border:none" :border="false"
								@click="closeShow">取消</u-button>
							<u-button type="success" style="width: 45%;" @click="jicheck">提交</u-button>
						</view>
					</view>
				</u-form>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activityList: [],
				canIndex: ['邮寄', '现场兑换'],
				clkIndex: 0,
				show: false,
				query: {
					pageNumber: 0,
					pageSize: 10,
				},
				showAll: false,
				thStyle: {
					background: '#fff'
				},
				kdForm:{
					gongsi:'',
					danhao:'',
					id:''
				}
			}
		},
		watch: {
			activityList: {
				deep: true,
				handler(newVal) {
					const allTrue = this.activityList.every(item => item.gouxuan)
					this.showAll = allTrue
				}
			}
		},
		onLoad(option) {

		},
		onReady() {},
		mounted() {
			this.search()

		},
		methods: {
			// 查询
			search() {
				this.activityList = [{
						type: '张三',
						name: '玩偶',
						num: '50',
						tu: 'www.baidu.com',
						fangshi: '邮寄',
						xianz: false,
						time: '2024-01-01 14:00',
						gouxuan: false
					},
					{
						type: '张三',
						name: '糖果',
						num: '不限制数量',
						tu: 'www.baidu.com',
						fangshi: '邮寄',
						xianz: false,
						time: '2024-01-01 14:00',
						gouxuan: false
					}
				]
				// this.$http.sendRequest('/cereBasicInformationShop/queryByPage', 'POST', this.query, 1).then(res => {
				// 	//成功回调
				// 	this.tableData = res.data.data.content
				// })
			},
			clkItem(index) {
				this.clkIndex = index
				if (index == 0) {
					this.activityList = [{
							type: '张三',
							name: '玩偶',
							num: '50',
							tu: 'www.baidu.com',
							fangshi: '邮寄',
							xianz: false,
							time: '2024-01-01 14:00',
							gouxuan: false
						},
						{
							type: '张三',
							name: '糖果',
							num: '不限制数量',
							tu: 'www.baidu.com',
							fangshi: '邮寄',
							xianz: false,
							time: '2024-01-01 14:00',
							gouxuan: false
						}
					]
				} else {
					this.activityList = [{
							type: '张三',
							name: '玩偶',
							num: '20',
							tu: 'www.baidu.com',
							fangshi: '现场兑换',
							xianz: false,
							time: '2024-01-01 14:00',
							gouxuan: false
						},
						{
							type: '张三',
							name: '糖果',
							num: '20',
							tu: 'www.baidu.com',
							fangshi: '现场兑换',
							xianz: false,
							time: '2024-01-01 14:00',
							gouxuan: false
						}
					]
				}
			},
			xuanAll(item, e) {
				console.log(e)
				console.log(item)
			},
			danAll(item, e) {
				this.activityList.forEach(item => {
					item.gouxuan = false
				})
				item.gouxuan = true
			},
			quanxuan(e) {
				const allTrue = this.activityList.every(item => item.gouxuan)
				if (allTrue) {
					this.showAll = !this.showAll
					this.activityList.forEach(item => {
						item.gouxuan = !allTrue;
					});
				} else {
					this.showAll = true
					this.activityList.forEach(item => {
						item.gouxuan = !allTrue;
						this.payAll += item.paymentAmount
					});
				}
			},
			checkGouxuan(activityList) {
				const trueItems = [];
				for (let i = 0; i < activityList.length; i++) {
					if (activityList[i].gouxuan) {
						trueItems.push(activityList[i]);
					}
				}
				if (trueItems.length === 0) {
					return false;
				} else if (trueItems.length != 0) {
					return trueItems;
				}
			},
			submit() {
				const res = this.checkGouxuan(this.activityList)
				if (!res) {
					uni.showToast({
						icon: 'none',
						title: '请选择发放人员'
					});
					return
				} else {
					if (this.clkIndex == 0) {
						this.show = true
					} else {
						uni.showToast({
							icon: 'none',
							title: '成功'
						});
					}
				}
			},
			closeShow(){
				this.show = false
			},
			jicheck(){
				this.show = false
			},

		}
	};
</script>

<style scoped lang="scss">
	.container {
		padding: 10px;
	}

	.header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 10px;
		background-color: #fff;
		padding: 5px 6px;
		border-radius: 5px;
	}

	.participate-record-btn {
		width: 50%;
		padding: 5px;
		text-align: center;
		font-weight: bold;
		color: #7C7C7C;
		border-radius: 5px;
	}

	.join-btn {
		color: #fff;
		background-color: #0FBB59;
	}

	.screen-list {
		display: flex;
		align-items: center;
		width: 100%;
		margin: 40rpx 0;
		padding: 0 20rpx;

		.zidong {
			width: 160rpx;
			background-color: #19be6b;
			color: #fff;
			padding: 10rpx;
			border-radius: 30rpx;
			font-size: 24rpx;
			text-align: center;
		}

		.list {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 25%;
			height: 100%;

			text {
				font-size: 26rpx;
				color: #555555;
			}

			image {
				width: 30rpx;
				height: 30rpx;
				margin-left: 10rpx;
			}
		}

		.action {
			text {
				color: $base;
			}
		}
	}

	.activity-item {
		display: flex;
		margin-bottom: 10px;
		background-color: #fff;
		border-radius: 5px;
		overflow: hidden;
	}

	.activity-item-image {
		width: 120px;
		height: 120px;
		position: relative;
	}

	.activity-item-image image {
		width: 100%;
		height: 100%;
	}

	.activity-item-status {
		position: absolute;
		bottom: 0;
		left: 0;
		background-color: green;
		color: white;
		padding: 5px;
	}

	.activity-item-info {
		padding: 10px;
		flex: 1;
	}

	.activity-item-title {
		font-size: 16px;
		margin-bottom: 5px;
	}

	.activity-item-time {
		font-size: 14px;
		color: #666;
		margin-bottom: 5px;
	}

	.activity-item-location {
		font-size: 14px;
		color: #666;
		margin-bottom: 5px;
	}

	.activity-item-type {
		font-size: 14px;
		color: #666;
	}

	.activity-record-btn {
		width: 100px;
		margin-top: 5px;
	}

	.goods-data {
		width: 100%;

		.goods-list {
			width: 100%;
			padding: 0 25rpx;

			.list {
				display: flex;
				margin-bottom: 20rpx;
				background-color: #fff;
				padding: 14rpx;
				border-radius: 14rpx;

				.thumb {
					display: flex;
					align-items: center;
					// width: 36%;
					width: 25vw;
					position: relative;

					image {
						width: 230rpx;
						height: 230rpx;
						border-radius: 10rpx;
					}

					.state {
						position: absolute;
						padding: 2px 7px;
						color: #fff;
						bottom: 3px;
						left: 22%;
						background-color: rgba(#0FBB59, 0.5);
						font-size: 12px;
						border-radius: 5px;
					}
				}

				.item {
					width: 66%;
					margin-left: 4%;

					.title {
						display: flex;
						align-items: center;
						width: 100%;

						text {
							font-size: 30rpx;
							font-weight: bold;
							color: #222222;
						}
					}

					.type {
						display: flex;
						justify-content: space-between;
					}
				}
			}
		}
	}

	.gray {
		color: #888D9C;
	}

	.margin {
		margin: 5px 0;
	}

	.page-footer {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		background-color: #FFFFFF;
		padding: 30rpx;
		z-index: 999;
		box-sizing: border-box;

		.footer-buy {
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 100%;
			height: 100%;

			.cart-add {
				align-items: center;
				display: flex;
				min-width: 20%;
				height: 70rpx;
			}

			.u-size-default.data-v-3bf2dba7 {
				font-size: 30rpx;
				height: 100% !important;
				line-height: 200% !important;
			}

		}
	}

	// 活动信息
	.info-box {
		margin-top: 30rpx;
		background-color: #fff;
		padding: 10px;
		border-radius: 30rpx;

		.title {
			font-weight: 700;
			color: #3D3D3D;
			font-size: 34rpx;
			margin-bottom: 10rpx;
		}

		.info-item {
			font-size: 26rpx;
			line-height: 50rpx;
		}
	}
	.userForm {
		margin: 0 40rpx;
	
		.form-box {
			padding: 0rpx 0rpx;
	
		}
	
		.title {
			font-size: 32rpx;
			font-weight: 700;
			margin:10px 0 ;
		}
		.titlechich {
			font-size: 28rpx;
			font-weight: 700;
			margin:10px 0 ;
		}
	}
</style>