<template>
	<view class="container">
		<uni-card :is-shadow="false" :border="false" padding="0" is-full>
			<view class="form">
				<view class="line">
					<uni-data-checkbox v-model="myVal" :localdata="checkList" @change="myChange"></uni-data-checkbox>
					<text>我的邮箱</text>
					<uni-easyinput v-model="email" disabled />
					<view class="bind" @click="$util.to('../email/email')">绑定</view>
				</view>
				<view class="line">
					<uni-data-checkbox v-model="otherVal" :localdata="checkList" @change="otherChange"></uni-data-checkbox>
					<text>其他邮箱</text>
					<uni-easyinput v-model="otherEmail" placeholder="请输入其他邮箱" />
				</view>
				<button type="primary" @click="submit">确认</button>
			</view>
		</uni-card>
	</view>
</template>

<script>
	import { mailFileSend } from '@/apis/modules/parner.js'
	import { my } from '@/apis/modules/parner.js'
	export default {
		data() {
			return {
				copyWriting: '',
				url: '',
				email: '',
				otherEmail: '',
				myVal: 1,
				otherVal: '',
				checkList: [{
					text: '',
					value: 1
				}],
			}
		},
		onShow() {
			const pages = getCurrentPages()
			const { options } = pages[pages.length - 1]
			this.url = options.url
			this.copyWriting = options.copyWriting
			this.getInfo()
		},
		methods: {
			// 获取个人信息
			getInfo() {
				const team = uni.getStorageSync('team')
				my({
					partnerId: team.partnerId,
					teamId: team.teamId
				}).then(({ my }) => {
					this.email = my.info.email
				}).catch(e => {})
			},
			myChange(e) {
				this.otherVal = ''
			},
			otherChange(e) {
				this.myVal = ''
			},
			// 提交
			submit() {
				const { otherEmail } = this
				if (this.myVal && !this.email) return this.$util.errMsg('请选择其他邮箱！')
				if (this.otherVal && !otherEmail) return this.$util.errMsg('请输入邮箱！')
				mailFileSend({
					url: this.url,
					copyWriting: this.copyWriting,
					mail: this.myVal ? this.email : otherEmail
				}).then(res => {
					this.$util.sucMsg('发送成功！')
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				}).catch(e => {})
			},
		}
	}
</script>

<style scoped lang="scss">
.form {
	padding: 15px;
	background-color: #fff;
}
.line {
	display: flex;
	align-items: center;
	margin-bottom: 15px;
	text {
		margin: 0 10px 0 -20px;
	}
}
.bind {
	margin-left: 20rpx;
	font-size: 26rpx;
	color: #1f83ff;
	white-space: nowrap;
}
</style>
