<template>
	<view class="page-container uni-column">
		<view class="logo-container uni-row">
			<image class="logo" src="../../static/images/logo.png" />
		</view>
		<view class="title"><text class="label">德迈仕数字生产线管理平台</text></view>
		<view class="user-info-container uni-row">
			<view class="icon"><text class="label">{{ userInfo.nickName.charAt(0) }}</text></view>
			<view class="user-info uni-column">
				<view class="nickname uni-row"><text class="label">{{ userInfo.userName }}</text><text class="label"
						style="margin-left: 24rpx">ID:</text><text class="label"
						style="margin-left: 6rpx">{{ userInfo.userId }}</text>
				</view>
				<view class="process uni-row"><text class="label">当前工段：</text><text class="label">{{ deptName }}</text>
				</view>
			</view>
		</view>
		<view class="user-info uni-column" style="margin: 0 20rpx 20rpx 20rpx;width: 94%;">
			<uni-section title="当前厂别" type="line">
				<uni-data-select v-model="userInfo.tenantId" :localdata="tenantList"
					@change="handleTenantChange"></uni-data-select>
			</uni-section>
		</view>
		<view class="business-btn uni-row" @click="handleRecerptSfprod"><text class="label">半成品接收</text></view>
		<view class="business-btn uni-row" @click="handleToProductionPlan"><text class="label">报工</text></view>
		<view class="business-btn uni-row" @click="handleToHandlingList"><text class="label">周转</text></view>
		<view class="bottom-btn-container">
			<view class="start-batch-btn uni-row"><text class="label" @click="handleToEquiPmentList">绑定设备</text></view>
			<view class="start-batch-btn uni-row" @click="handleSwitchOrQuit"><text class="label">切换 / 退出账号</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onLoad,
		onReady
	} from '@dcloudio/uni-app'
	import {
		getSubPlanDetailsList
	} from '../../api/business/subPlanDetails'
	import {
		getTenantList,
		getDeptName
	} from '@/api/login/index.js'
	import {
		store
	} from '@/store/index.js'


	const deptName = ref('')
	const name = ref('')
	const userName = ref('')
	const userId = ref(null)
	const userInfo = ref({})
	const tenantList = ref([])

	onLoad(() => {
		userInfo.value = store.userInfo || {
			nickName: ""
		};
		store.tenantId = userInfo.value.tenantId
		getDepartmentName()
		getTenant()
	})

	function handleRecerptSfprod() {
		uni.navigateTo({
			url: '/pages/recerptSfprod/index'
		})
	}
	
	function handleToProductionPlan() {
		uni.navigateTo({
			url: '/pages/productionPlan/index'
		})
	}
	
	function handleToHandlingList() {
		uni.navigateTo({
			url: '/pages/handlingList/index'
		})
	}
	
	function handleSwitchOrQuit() {
		uni.navigateTo({
			url: '/pages/index/index'
		})
	}

	function handleToEquiPmentList() {
		uni.navigateTo({
			url: "/pages/equipmentList/index"
		})
	}

	function getDepartmentName() {
		getDeptName(userInfo.value.userId).then((res) => {
			if (res.code == 200) {
				deptName.value = res.msg
			}
		})
	}

	function getTenant() {
		getTenantList().then((res) => {
			if (res.code == 200) {
				tenantList.value = res.rows
				console.log(tenantList.value)
				for (var i = 0; i < res.rows.length; i++) {
					tenantList.value[i] = {
						text: res.rows[i].orgName,
						value: res.rows[i].id
					}
				}
			}
		})
	}

	function handleTenantChange() {
		store.tenantId = userInfo.value.tenantId
		console.log(store.tenantId)
	}
</script>

<style lang="scss">
	.page-container {
		height: 1000rpx;
		overflow: auto;
	}
	.logo-container {
		justify-content: center;

		.logo {
			width: 120rpx;
			height: 120rpx;
		}
	}

	.title {
		align-items: center;

		.label {
			font-size: 40rpx;
			font-weight: bold;
		}
	}

	.user-info-container {
		margin: 64rpx 0 20rpx 20rpx;

		.icon {
			width: 120rpx;
			height: 120rpx;
			justify-content: center;
			align-items: center;
			border-radius: 60rpx;
			border: 1px solid #e1e1e1;

			.label {
				font-size: 64rpx;
			}
		}

		.user-info {
			margin-left: 8rpx;
			justify-content: center;

			// font-size: 20rpx;
			.nickname {
				margin-bottom: 16rpx;

				.label {
					font-weight: bold;
					font-size: 32rpx;
				}
			}

			.process {
				.label {
					font-size: 32rpx;
				}
			}
		}

		.data-select {
			flex: 3;
			width: 100%;
			height: 50rpx;
			border-radius: 18rpx;
			background-color: #FFF;

			.data-select-options {
				width: 200rpx;
			}
		}
	}

	.business-btn {
		margin: 0 20rpx 20rpx 20rpx;
		background-color: #fff;
		height: 200rpx;
		width: 94%;
		border-radius: 4;
		align-items: center;
		justify-content: center;
		border: 1px solid #e1e1e1;
		border-radius: 8rpx;

		.label {
			font-size: 40rpx;
		}
	}

	.bottom-btn-container {
		position: fixed;
		right: 20rpx;
		bottom: 0;
		left: 20rpx;

		.start-batch-btn {
			// background-color: grey;
			background-color: #1684fc;
			margin-bottom: 24rpx;
			border-radius: 8rpx;
			justify-content: center;
			align-items: center;
			height: 80rpx;

			.label {
				font-size: 32rpx;
				color: #ffffff;
			}
		}
	}
</style>