<template>
	<view class="complaint white_style">
		<Nav className="nav_F6" :backVisible="true" :scroll="scroll">
			<block slot="content" class="omit">{{ $t('campus.complaint.title') }}</block>
		</Nav>
		<view class="body_scroll clearfix" :style="getHeight">
			<view class="complaint_form">
				<view class="cell">
					<view class="item">
						<view class="title">对象</view>
						<view class="content">
							<view class="uni-input t-g-r">{{ options.nickname | across }}</view>
						</view>
					</view>
					<view class="item noFlex">
						<view class="title">原因</view>
						<view class="content">
							<view class="reason_list list">
								<view class="range">
									<view class="package" v-for="(item, key) in complaintReasonList" :key="key" @click="complaintReasonChange(item)">
										<view class="packageBlock">
											<view class="row" :class="{active: item.codeNo === form.complaintReason}">{{ item.codeName }}</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="item">
						<view class="content">
						<textarea :show-confirm-bar="false" class="uni-textarea" v-model="form.reasonDescription" placeholder="补充违规描述，如声音言论...（选填）" auto-height />
						</view>
					</view>
				</view>
				<view class="btn" @click="saveBefore" :class="{active: options.checked}">提交</view>
				<view class="explain">详细描述能加快审核处理</view>
			</view>
		</view>
		<!-- loading -->
		<loading :visible="loading" />
	</view>
</template>

<script>
	import mixins from '@/utils/mixins'

	export default {
		mixins: [mixins],
		data() {
			return {
				options: {
					checked: false
				},
				complaintReasonList: [],
				form: {
					targetType: 1, // 投诉类型：1个人，2房间
					targetId: '', // 投诉目标id（个人uid或房间roomId）
					complaintReason: '', // 投诉原因（code_no，其他传2）
					reasonDescription: '', // 原因描述
					roomId: '' // 房间id
				},
				rules: [
					{ name: 'complaintReason', errorMsg: '请选择原因' }
				]
			}
		},
		onLoad(e) {
			if (e) {
				this.options = Object.assign({}, this.options, e)
				this.form.complaintUid = uni.getStorageSync('uid')
				this.form.roomId = this.options.roomId
				this.form.targetId = this.options.uid
			}
		},
		created() {
			this.getComplaintReason()
		},
		methods: {
			// 获取投诉原因
			async getComplaintReason () {
				this.loading = true
				const result = await this.$axios.get(this.API.getComplaintReason, {
					params: {
						type: 1
					}
				})
				this.loading = false
				if (result && result.length) {
					this.complaintReasonList = result
					this.complaintReasonChange(this.complaintReasonList[0])
				}
			},
			// 原因
			complaintReasonChange (item) {
				this.form.complaintReason = item.codeNo
				this.options.checked = true
			},
			// 保存前
			saveBefore () {
				this.$base.FORM_VERIFICATIONS(this.rules, this.form, () => {
					this.save()
				})
			},
			// 保存
			async save () {
				this.loading = true
				const result = await this.$axios.post(this.API.complain, this.form)
				this.loading = false
				if (result) {
					this.$base.Tips('已投诉')
					uni.navigateBack()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.complaint {
		min-height: calc(100vh);

		.body_scroll {
			.complaint_form {
				padding: 60rpx 26rpx 96rpx 26rpx;
				.cell {
					background-color: $white;
					border-radius: 18rpx;
					padding: 0 20rpx;
					.item {
						display: flex;
						align-items: center;
						line-height: 48rpx;
						position: relative;
						padding: 26rpx 0;
						& + .item::before {
							content: '';
							position: absolute;
							top: 0;
							right: -20rpx;
							left: 0;
							height: 2rpx;
							background-color: $ECECEC;
						}
						&.noFlex {
							overflow: hidden;
							display: block;
							.title {
								margin-bottom: 44rpx;
							}
							& + .item {
								margin-top: 8rpx;
								&::before {
									content: none;
								}
							}
						}
						.title {
							min-width: 100rpx;
							font-size: 32rpx;
							font-weight: 400;
							width: 100rpx;
							color: $bg-0;
						}
						.content {
							position: relative;
							font-size: 32rpx;
							font-weight: 400;
							color: $J49494;
							flex: 1;
							.reason_list {
								.row {
									border: 2rpx solid $ECECEC;
									background-color: $F8F8F8;
									justify-content: center;
									border-radius: 8rpx;
									align-items: center;
									font-size: 30rpx;
									font-weight: 400;
									height: 72rpx;
									display: flex;
									color: $bg-0;
									&.active {
										border: 2rpx solid $AA2929;
										background-color: $AA2929;
										color: $white;
									}
								}
							}
							.uni-textarea {
								border: 1px solid $ECECEC;
								min-height: 252rpx;
								line-height: 42rpx;
								font-size: 30rpx;
								font-weight: 400;
								color: $J49494;
								padding: 20rpx;
							}
						}
					}
				}
			}
			.btn {
				background-color: $white;
				margin: 272rpx auto 0 auto;
				width: 368rpx;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 12rpx;
				font-size: 32rpx;
				font-weight: 500;
				color: $B18181;
				&.active {
					color: $L7C160;
				}
			}
			.explain {
				text-align: center;
				line-height: 30rpx;
				margin-top: 48rpx;
				font-size: 30rpx;
				font-weight: 400;
				color: $bg-0;
			}
		}
	}
</style>
