<template>
	<view class="achievement-page">
		<navbar title="读者成就设置" leftClick @leftClick="$utils.navigateBack" />
		<view class="achievement-card">
			<view class="card-title-row">
				<view class="card-title">阅读成就设置</view>
				<view v-if="isPending" class="pending-tag">设置审核中</view>
			</view>
			<view class="achievement-list">
				<view class="achievement-item"
				v-for="(item, index) in list"
				:key="index">
					<image class="badge-img"
						:src="item.image"
						mode="aspectFill" />
					<view class="">
						<view class="input-area">
							<view class="label-row">
								<text class="required">*</text>
								<text class="label">{{ item.title }}</text>
							</view>
							<input class="input" 
							v-model="form[keys[index] + 'Name']" 
							placeholder="请输入" 
							placeholder-class="input-placeholder" />
						</view>
						<view class="input-area" v-if="form[keys[index] + 'Num']">
							<view class="label-row">
								<text class="label">达成人数</text>
							</view>
							<view class="Num">
								{{ form[keys[index] + 'Num'] || 0 }}
							</view>
						</view>
					</view>
				</view>
				<!-- <view class="divider"></view>
				<view class="achievement-item">
					<image class="badge-img"
						src="https://tse3-mm.cn.bing.net/th/id/OIP-C.wUsFZgl70iE4tI7b_HKaKgHaHa?w=166&h=180&c=7&r=0&o=5&dpr=1.1&pid=1.7"
						mode="aspectFill" />
					<view class="input-area">
						<view class="label-row">
							<text class="required">*</text>
							<text class="label">二级成就名称</text>
						</view>
						<input class="input" v-model="level2" placeholder="请输入" placeholder-class="input-placeholder" />
					</view>
				</view>
				<view class="divider"></view>
				<view class="achievement-item">
					<image class="badge-img"
						src="https://tse3-mm.cn.bing.net/th/id/OIP-C.wUsFZgl70iE4tI7b_HKaKgHaHa?w=166&h=180&c=7&r=0&o=5&dpr=1.1&pid=1.7"
						mode="aspectFill" />
					<view class="input-area">
						<view class="label-row">
							<text class="required">*</text>
							<text class="label">三级成就名称</text>
						</view>
						<input class="input" v-model="level3" placeholder="请输入" placeholder-class="input-placeholder" />
					</view>
				</view> -->
			</view>
		</view>
		<view class="bottom-btn-area">
			<button class="submit-btn" :disabled="isPending" :class="{disabled: isPending, pending: isPending}"
				@click="submit">
				{{ isPending ? '设置' : '提交申请' }}
			</button>
		</view>
	</view>
</template>

<script>
    import mixinsList from '@/mixins/list.js'
	export default {
        mixins: [mixinsList],
		data() {
			return {
                mixinsListApi : 'getAchievementList',
				isPending: false,
				keys : ['one', 'two', 'three'],
				form : {},
			}
		},
		onLoad() {
			this.getDetail()
		},
		methods: {
			async getDetail(){
				this.form = await this.$fetch('getAchievement')
				this.isPending = this.form.status == 0
			},
			async submit() {
				// for (var index = 0; index < this.list.length; index++) {
				// 	var element = this.list[index];
				// 	if (!element.levelName) {
				// 		uni.showToast({
				// 			title: '请填写所有成就名称',
				// 			icon: 'none'
				// 		})
				// 		return
				// 	}
				// }
				
				// this.isPending = true
				
				// let arr = []
				
				// for (var index = 0; index < this.list.length; index++) {
				// 	var element = this.list[index];
					
				// 	arr.push(this.$fetch('setAchievementName', {
				// 		name : element.levelName
				// 	}))
				// }
				
				// await Promise.all(arr)
				
				if(this.$utils.verificationAll(this.form, {
					oneName : '请填写所有成就名称',
					twoName : '请填写所有成就名称',
					threeName : '请填写所有成就名称',
				})){
					return
				}
				
				await this.$fetch('setAchievementName', this.form)
				
				uni.showToast({
					title: '提交成功',
					icon: 'none'
				})
				setTimeout(() => {
					uni.navigateBack()
				}, 1000)
			},
		}
	}
</script>

<style scoped lang="scss">
	.achievement-page {
		min-height: 100vh;
		background: #f7f8fa;
		display: flex;
		flex-direction: column;
	}

	.achievement-card {
		background: #fff;
		border-radius: 20rpx;
		margin: 40rpx 32rpx 0 32rpx;
		padding: 32rpx 24rpx;
		box-shadow: 0 4rpx 24rpx 0 rgba(0, 0, 0, 0.04);
	}

	.card-title-row {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.card-title {
		font-size: 32rpx;
		font-weight: bold;
		margin-bottom: 32rpx;
	}

	.achievement-list {
		display: flex;
		flex-direction: column;
		gap: 0;
	}

	.achievement-item {
		display: flex;
		align-items: flex-start;
		padding: 18rpx 0 10rpx 0;
	}

	.badge-img {
		width: 72rpx;
		height: 72rpx;
		margin-right: 20rpx;
		border-radius: 50%;
		background: #f5f5f5;
		object-fit: cover;
		border: 2rpx solid #fff;
		box-shadow: 0 2rpx 8rpx 0 rgba(0, 0, 0, 0.04);
	}

	.input-area {
		margin-top: 15rpx;
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
	}

	.label-row {
		display: flex;
		align-items: center;
		margin-bottom: 6rpx;
	}

	.required {
		color: #e23d3d;
		font-size: 28rpx;
		margin-right: 4rpx;
	}

	.label {
		font-size: 24rpx;
		color: #999;
		font-weight: bold;
	}
	
	.Num{
	}

	.input {
		width: 100%;
		border: none;
		border-bottom: 1.5rpx solid #ececec;
		font-size: 28rpx;
		background: transparent;
		padding: 16rpx 0;
		margin-bottom: 2rpx;
	}

	.input-placeholder {
		color: #d2d2d2;
		font-size: 26rpx;
	}

	.divider {
		height: 1rpx;
		background: #f3f3f3;
		margin: 0 0 0 92rpx;
	}

	.bottom-btn-area {
		margin-top: auto;
		padding: 48rpx 32rpx 32rpx 32rpx;
		background: transparent;
	}

	.submit-btn {
		width: 100%;
		height: 88rpx;
		background: #0a2e6d;
		color: #fff;
		font-size: 32rpx;
		border-radius: 44rpx;
		font-weight: bold;
		letter-spacing: 2rpx;
		transition: background 0.2s;
	}

	.submit-btn.disabled {
		background: #807a7a;
		color: #fff;
	}

	.submit-btn.pending {
		background: #0a226d;
		color: #fff;
	}

	.pending-tag {
		background: #807a7a;
		color: #fff;
		font-size: 24rpx;
		border-radius: 10rpx;
		padding: 6rpx 24rpx;
		margin-left: 20rpx;
		margin-bottom: 32rpx;
	}
</style>