<template>
	<view class="change-gongsi">
		<u-navbar :background="{background:'rgba(0,0,0,0)'}" :border-bottom="false" :is-fixed="false"></u-navbar>
		<image style="position: fixed;top: 0;left: 0;width: 750rpx;height: 100vh;z-index: -1;" src="../../static/img/group.png" mode=""></image>
		<view class="u-flex-col" style="padding: 96rpx;">
			<text style="font-size: 56rpx;font-weight: 500;">你好，</text>
			<text style="font-size: 32rpx;">欢迎使用病例收集及调研问卷项目</text>
		</view>
		<view @click="show = true" class="u-flex u-row-between" style="margin: 200rpx 96rpx;height: 100rpx;border-bottom: 2rpx solid rgba(0, 0, 0, 0.08);">
			<input :disabled="true" v-model="gongsiname" type="text" placeholder="请选择公司" class="u-flex-1" style="font-size: 28rpx;">
			<u-icon name="arrow-down-fill"></u-icon>
		</view>
		<view class="" @click="next" style="line-height: 80rpx;background: #167FFF;border-radius: 40rpx;text-align: center;font-size: 28rpx;color: #FFFFFF;width: 558rpx;margin: 0 auto;">
			下一步
		</view>
		<u-select v-model="show" label-name="compName" value-name="id" :list="list" @confirm="confirm"></u-select>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				list: [],
				gongsiname: '',
				gongsivalue: '',
				type: 1
			}
		},
		onLoad(option) {
			this.type = option.type
			this.getdata()
		},
		methods: {
			getdata() {
				this.$http.getCompName({
					type: this.type
				}).then(res => {
					this.list = res.data.result
				})
			},
			next() {
				if (!this.gongsiname || !this.gongsivalue) {
					this.$u.toast('请选择公司')
					return
				}
				uni.showLoading({
					mask: true,
					title: '请稍后'
				})
				this.$http.setCompNameTrue({
					id: this.gongsivalue
				}).then(res => {
					uni.hideLoading()

					if (res.data.code == 200) {
						this.$u.toast("切换成功")
						setTimeout(() => {
							this.getUserInfo()
						}, 800)
					} else {
						this.$u.toast(res.data.message)
					}
				})
			},
			confirm(e) {
				this.gongsiname = e[0].label
				this.gongsivalue = e[0].value
			},
			getUserInfo() {
				this.$http.getUserInfo().then(res => {
					if (res.data.code == 200) {
						// 是否信息完整
						uni.setStorageSync('doctorAndSpecialist', res.data.result.doctorAndSpecialist);
						if (res.data.result.completeInformation != 2) {
							uni.navigateTo({
								url: '/pages/login/perfect',
							})
						} else {
							uni.reLaunch({
								url: '/pages/index/index',
							})
						}
					}else{
						this.$u.toast(res.data.message)
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.change-gongsi {}
</style>