<template>
	<view class="teamEdit white_style">
		<Nav className="nav_F6" :backVisible="true" :saveVisible="true" @savePick="saveBefore" :notNull="form.teamName" :scroll="scroll">
			<block slot="content" class="omit">{{ $t('team.edit.title') }}</block>
		</Nav>
		<view class="body_scroll clearfix" :style="getHeight">
			<view class="teamEdit_form">
				<view class="item">
						<view class="title">队名</view>
						<view class="content">
							<input class="uni-input" placeholder-class="uni-placeholder__class" v-model.trim="form.teamName" @input="bindInput" :maxlength="7" />
						</view>
				</view>
			</view>
		</view>
	</view>
</template>

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

	export default {
		mixins: [mixins],
		data() {
			return {
				imgDict,
				form: {
					updateBy: uni.getStorageSync('uid'),
					teamName: ''
				},
				rules: [
					{ name: 'teamName', errorMsg: '请输入小队名称' }
				]
			}
		},
		onLoad (e) {
			if (e) {
				this.form.id = e.teamId
				this.form.teamName = e.name
			}
		},
		methods: {
			// 输入
			bindInput (e) {
				this.form.teamName = e.detail.value
			},
			// 保存前
			saveBefore () {
				this.$base.FORM_VERIFICATIONS(this.rules, this.form, () => {
					this.save()
				})
			},
			// 保存
			async save () {
				this.loading = true
				const result = await this.$axios.put(this.API.teamUpdate, this.form)
				this.loading = false
				if (result) {
					uni.$emit('teamVoiceRoom')
					uni.navigateBack()
				}
			}
		}
	}
</script>

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

		.body_scroll {
			.teamEdit_form {
				padding: 60rpx 26rpx 96rpx 26rpx;
				.item {
					background-color: $white;
					border-radius: 18rpx;
					padding: 36rpx;
					& + .item {
						margin-top: 70rpx;
					}
					.title {
						margin-bottom: 28rpx;
						line-height: 30rpx;
						font-size: 32rpx;
						font-weight: 400;
						color: $bg-0;
					}
					.content {
						.uni-input {
							border: 1px solid $ECECEC;
							border-radius: 18rpx;
							line-height: 42rpx;
							font-size: 30rpx;
							font-weight: 400;
							padding: 20rpx;
							color: $bg-0;
							/deep/ .uni-placeholder__class {
								color: $J49494;
							}
						}
					}
				}
			}
		}
	}
</style>
