<template>
	<view>
		<view class="header-nav" :style="{height: `calc(88rpx + ${statusBarHeight}px)`,paddingTop: statusBarHeight + 'px'}">
			<view class="arrow-left" :style="{top: statusBarHeight + 'px'}" @click="goBack"><u-icon name="arrow-left" size="24"></u-icon></view>
			<view class="header-title" :style="{height:menuButtonH+'px',lineHeight:menuButtonH+'px'}">投诉反馈</view>
		</view>
		<view class="container" :style="{paddingTop: `calc(88rpx + ${statusBarHeight}px)`}">
			<view class="list-item title">{{pageIndex==0 ? '请选择反馈类型':'请选择'}}</view>
			<view class="list-item" v-for="(item, index) in feedbackItems" :key="index" @click="handleClick(item,index)">
				{{ item.complaintTypeName }}
			</view>
			<view class="list-item" @click="goBack">
				返回上一层
			</view>
		</view>
	</view>
</template>

<script>
	import{ getTypeTree, complaintRecord } from "@/api/course.js"
	export default {
		data() {
			return {
				statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
				menuButtonH: 45,
				pageIndex: 0,
				list:[],
				feedbackItems: [],
				userId:'',
				courseId: '',
				videoId:''
			};
		},
		onLoad(option) {
			this.userId = option.userId || ''
			this.courseId = option.courseId || ''
			this.videoId = option.videoId || ''
			this.getMenuButton()
			this.getList()
		},
		methods: {
			getMenuButton(){
				const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
				this.menuButtonH = menuButtonInfo.height
			},
			goBack() {
				// 返回上一层逻辑
				if(this.pageIndex == 0){
					uni.navigateBack();
				}else {
					this.pageIndex = 0
					this.feedbackItems = this.list
				}
			},
			handleClick(item,index) {
				if(this.pageIndex ==0) {
					this.feedbackItems = this.list[index].childrenType || [];
					this.pageIndex = 1;
				} else if(this.pageIndex ==1){
					const param = {
						userId: this.userId,
						complaintTypeId: item.complaintTypeId,
						complaintContent: item.complaintContent,
						courseId: this.courseId,
						videoId: this.videoId,
					}
					complaintRecord(param).then(res=>{
						uni.showModal({
							title: '',
							content: '我们已收到您的反馈，谢谢',
							showCancel: false
						});
					})
				}
			},
			getList(){
				getTypeTree().then(res=>{
					if(res.code == 200) {
						this.list = res.data
						this.pageIndex = 0
						this.feedbackItems = this.list
					}
				})
			}
		}
	};
</script>

<style scoped lang="scss">
	.header-nav {
		height: 88rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		overflow: hidden;
		background-color: #fff;
		box-sizing: border-box;
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		.header-title {
			flex: 1;
			text-align: center;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			font-family: PingFang SC,PingFang SC;
			font-weight: 500;
			font-size: 15px;
			color: #000;
			box-sizing: border-box;
		}
	}
	.arrow-left {
		position: absolute;
		left: 24rpx;
		height: 88rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		overflow: hidden;
	}
	.list-item {
		background-color: #fff;
		padding: 24rpx;
		border-bottom: 1rpx solid #f4f4f4;
		font-size: 15px;
		color: #333;
	}

	.title {
		background-color: #f4f4f4;
	}
</style>
