<template>
	<view>
		<myForm ref="nameAndphone"></myForm>
		<u-button type="success" text="确定" color="#0EBB5B" @click="handleSureClick()"></u-button>
		<u-modal :show="showM" closeOnClickOverlay="false" confirmText="确定" @confirm="confirm">
			<rich-text :nodes="content"></rich-text>
		</u-modal>
		<view style="margin:0 20rpx;">
			<u-overlay :show="!isLoad">
				<login @success="reOnLoad()" @fail="failToLoad()"></login>
			</u-overlay>
		</view>
	</view>
</template>

<script>
	import login from 'pages/my/login/login'
	export default {
		components: {
			login
		},
		data() {
			return {
				name: '',
				phone: '',
				showM: false,
				content: `您的申请已提交<br>
								   请静待人工审核`,
				isLoad: true,
			}
		},
		onLoad() {
			this.getIdeasAndNeeds()
			if (!uni.getStorageSync('token') || uni.getStorageSync('token').length === 0) {
				console.log(uni.getStorageSync('token'))
				this.isLoad = false
				// uni.navigateTo({
				// 	url: '../../pages/my/login/login'
				// })
				return
			}
			this.isLoad = true
		},
		methods: {
			handleSureClick() {
				let name = this.$refs.nameAndphone.model.userInfo.name
				let phone = this.$refs.nameAndphone.model.userInfo.phone
				this.$apiServe.bindComponyAndUpdate({
					uid: 1,
					type: 1,
					companyName: name,
					companyPhone: phone
				}).then(res => {
					// console.log('绑定公司', res.data);
					if (res.data.code == 20003) {
						this.showM = true
					} else if (res.data.code == 20005) {
						this.$toast.warn('请完善数据')
					}
				}).finally(_ => {})
			},
			confirm() {
				this.showM = false
				// uni.switchTab({
				// 	url: '/pages/my/my'
				// })
			},
			reOnLoad() {
				console.log('----------------true')
				if (!uni.getStorageSync('token') || uni.getStorageSync('token').length === 0) {
					this.$toast.warn('登录失败请重试')
					this.isLoad = false
					// uni.navigateTo({
					// 	url: '../../pages/my/login/login'
					// })
					return
				}
				this.isLoad = true
			},
			failToLoad() {
				console.log('----------------false')
				this.$toast.warn('登录失败请重试')
			}

		}
	}
</script>

<style lang="scss">
	.u-button {
		width: 644rpx !important;
		height: 86rpx !important;
		background: #0EBB5B;
		border-radius: 20rpx !important;
		margin-top: 168rpx;
	}

	.u-modal__button-group__wrapper--hover {
		background: #0EBB5B !important;
	}
</style>
