<template>
  <view class="nav">
		<view class="navbar">
			<view class="status">{{userInfo.status === 1?"接单中":"暂停接单"}}</view>
			<view class="userinfo">
				<button type="primary" class="lef" @click="hangdleChange">{{userInfo.status === 1?"暂停接单":"开始接单"}}</button>
				<image class="mid" aspectFill :src="userInfo.faceurl?userInfo.faceurl:'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/cat-1.png'" />
				<view class="rig">
					<text class="name">{{props.userInfo.name?props.userInfo.name:"张三三"}}</text>
					<button size="mini" type="primary" @click="handleLogout"  class="logout">退出</button>
				</view>
			</view>
		</view>
  </view>
</template>

<script>
  export default {
    name: 'NavBar'
  }
</script>

<script setup>
import { onMounted,ref } from 'vue'

const props = defineProps({
	userInfo: {
		default: function() {
			return {}
		},
		type: Object
	}
})

const emit = defineEmits(['updateUser'])

const userInfo = ref({})

onMounted(() => {
	userInfo.value = props.userInfo
	// console.log("props.userInfo.name", props.userInfo.name)
})

const hangdleChange =()=>{
	console.log("hangdleChange", 555)
	if(userInfo.value.status ===1){
		userInfo.value.status = 0
	} else {
		userInfo.value.status = 1
	}
	emit('updateUser', userInfo)
}

const handleLogout = ()=>{
	console.log("handleLogout", 555)
	uni.redirectTo({
		url:"/pages/login/login"
	})
	// emit('updateUser', userInfo)
}

</script>

<style lang="scss">
.nav{
	display:flex;
	justify-content:flex-end;
	align-items:flex-end;
	width: 1200px;
	
	background-color: #cfcfcf;
	padding-bottom: 20rpx;
	// position: fixed;
	.navbar{
		width: 440rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.status{
			font-size: 20rpx;
		}
		.userinfo{
			display: flex;
			justify-content: space-between;
			align-items: center;
			.lef{
				height: 60rpx;
				width: 60rpx;
				padding: 14rpx;
				margin-right: 30rpx;
				font-size: 15rpx;
				line-height: 15rpx;
			}
			.mid{
				height: 50rpx;
				width: 50rpx;
				margin-right: 30rpx;
			}
			.rig{
				margin-right: 10rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				.name{
					margin-bottom: 10rpx;
					width: 50rpx;
					 text-align: center;
				}
				.logout{
					width: 50rpx;
				}
			}
		}
	}
}
</style>