<template>
	<view class="cardList">
		<view class="container">
			<view class="content">
				<view class="left">
					<image :src="imgArr[0]"></image>
				</view>
				<view class="right">
					<view class="detailed">
						<view class="title">{{$ot(item, 'active', 'title')}}</view>
						<view class="date">{{item.startTime}}</view>
						<view class="address">
							<view class="img-box">
								<image src="@/static/image/cart/addressIcon.png" mode=""></image>
							</view>
							<view>{{$ot(item, 'active', 'address')}}</view>
						</view>
					</view>
					<view class="tips-box">
						<view class="tips-box-item" v-for="(val,i) in iconTextArr" :key="i">{{val}}</view>
					</view>
				</view>
			</view>
			<view class="bottom-box">
				<view class="bottom-box-l">
					<!-- <uv-avatar-group :urls="urls" keyName="headImage" size="45rpx" gap="0.1"></uv-avatar-group>
					<view class="num">{{item.num}}人参加</view> -->
				</view>

				<view class="bottom-box-r" v-if="!item.openState" @click="toZhaomu(item)">
					{{$t('components.zhaomu.zhaomuItem.joinRecruit')}}
				</view>

				<view class="bottom-box-r" v-else-if="item.openState == 3" @click="toZhaomu(item)">
					{{$t('components.zhaomu.zhaomuItem.rejected')}}
				</view>

				<view class="bottom-box-r" v-else>
					{{ [$t('components.zhaomu.zhaomuItem.reviewing'), $t('components.zhaomu.zhaomuItem.joined')][item.openState - 1] }}
				</view>

			</view>
			<view class="tabs-box" :class="item == 1? 'bzcx-item' : 'ycx-item'">
				{{item == 1? $t('components.zhaomu.zhaomuItem.guaranteed') : $t('components.zhaomu.zhaomuItem.confirmed')}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			item: {
				type: Object,
				default: () => {}
			},
		},
		data() {
			return {
				iconTextArr: [],
				imgArr: [],
				urls: [
					'https://cdn.uviewui.com/uview/album/1.jpg',
					'https://cdn.uviewui.com/uview/album/2.jpg',
					'https://cdn.uviewui.com/uview/album/3.jpg',
				]
			};
		},
		watch: {
			item: {
				handler(val) {
					this.iconTextArr = val.iconText ? val.iconText.split("，") : [];
					this.imgArr = val.image ? val.image.split(",") : []
					this.urls = val.popularizeRecruitLogList;
				},
				immediate: true
			}
		},
		mounted() {},
		methods: {
			//订阅模版消息
			onSubscribeMessageTap(fn) {
				let templateIds = [
					'SQd2axWZD7KCw3jkw--tumMz9-cmP_R2FUhJzByxrP8',
				];
				wx.requestSubscribeMessage({
					tmplIds: templateIds, // 需要订阅的模板ID列表
					success(res) {
						fn && fn(res)
						console.log('订阅消息调用成功', res);
						// res[tmplId] 表示用户是否同意订阅该模板ID对应的消息
						// 例如：res['your_template_id_1'] === 'accept' 表示用户同意订阅
						templateIds.forEach(tmplId => {
							if (res[tmplId] === 'accept') {
								console.log(`用户同意订阅模板ID：${tmplId}`);
								// 这里可以添加用户同意后的逻辑，比如发送消息等（注意：发送消息需要在后端进行）
							} else if (res[tmplId] === 'reject') {
								console.log(`用户拒绝订阅模板ID：${tmplId}`);
							} else {
								console.log(`用户对该模板ID的订阅请求：${res[tmplId]}`); // 'ban' 表示用户被禁止订阅该模板
							}
						});
					},
					fail(err) {
						console.error('订阅消息调用失败', err);
					}
				});
			},
			skip(val) {
				uni.navigateTo({
					url: '/pages_order/orderDetails'
				})
			},
			toZhaomu(item) {
				let params = {
					recruitId: item.id,
				}
				this.onSubscribeMessageTap(res => {
					this.$api('shopUserAuth', params, res => {
						this.$emit('getData')
						if (res.code == 200) {
							this.$Toast(this.$t('components.zhaomu.zhaomuItem.joinSuccess'))
						}
					})
				})
			}
		}
	};
</script>

<style scoped lang="scss">
	.cardList {
		.container {
			margin-bottom: 30rpx;
			border-radius: 20rpx;
			background: #1B1713;
			position: relative;

			.content {
				display: flex;
				padding: 24rpx 35rpx;
				border-bottom: 1px solid #2A2A2A;

				.left {
					image {
						width: 228rpx;
						height: 228rpx;
						border-radius: 20rpx;
					}
				}

				.right {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					flex: 1;
					margin-left: 23rpx;
					color: $uni-text-color-grey;
					font-size: 24rpx;

					.detailed {
						.title {
							font-size: 32rpx;
							color: #fff;
							padding-top: 11rpx;
						}

						.date {
							padding: 25rpx 0 19rpx;
							display: flex;
							align-items: center;

							&::before {
								content: '';
								display: block;
								background: url('@/static/image/cart/timeIcon.png') no-repeat;
								background-size: 100% 100%;
								width: 24rpx;
								height: 24rpx;
								margin-right: 10rpx;
							}
						}

						.address {
							display: flex;
							margin-bottom: 10rpx;

							.img-box {
								width: 22rpx;
								height: 26rpx;
								margin-right: 10rpx;
								flex-shrink: 0;

								image {
									width: 100%;
									height: 100%;
								}
							}

						}
					}

					.tips-box {
						display: flex;
						align-items: center;
						flex-wrap: wrap;

						.tips-box-item {
							padding: 0 24rpx;
							height: 38rpx;
							line-height: 38rpx;
							background: #282421;
							border-radius: 7rpx;
							font-size: 20rpx;
							color: #999999;
							margin-right: 14rpx;
							margin-bottom: 5px;

							&:last-child {
								margin-right: 0;
							}
						}


					}
				}
			}

			.bottom-box {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 104rpx;
				padding: 0 21rpx;

				&-l {
					display: flex;
					align-items: center;

					.num {
						font-weight: 500;
						font-size: 25rpx;
						color: #999999;
						margin-left: 20rpx;
					}
				}

				&-r {
					width: 180rpx;
					height: 53rpx;
					background: url('@/static/image/member/canyu-bg.png') no-repeat;
					background-size: 100% 100%;
					font-weight: 500;
					font-size: 23rpx;
					color: #FFFFFF;
					text-align: center;
					line-height: 53rpx;
				}
			}

			.tabs-box {
				position: absolute;
				top: 0;
				right: 0;
				width: 117rpx;
				height: 40rpx;
				font-weight: 500;
				font-size: 21rpx;
				text-align: center;
				line-height: 40rpx;
			}

			.bzcx-item {
				background: url('@/static/image/member/bzcx-bg.png') no-repeat;
				background-size: 100% 100%;
				color: #FF9000;
			}

			.ycx-item {
				background: url('@/static/image/member/ycx-bg.png') no-repeat;
				background-size: 100% 100%;
				color: #FF3B47;
			}
		}
	}
</style>