companyMy.vue 6.9 KB
<template>
	<view class="app-container">
		<up-navbar placeholder :leftIconSize="0" bgColor="transparent" />
		<view class="car_list">
			<view class="line_title">
				<text class="left_title" style="color: #fff;">我的信息</text>
				<text style="color: #fff;" @click="submit">更新实名信息</text>
			</view>
			<view class="user-box">
				<up-form :model="userInfo" ref="userFormRef">
					<up-form-item prop="nickName">
						<up-input v-model="userInfo.nickName" shape="circle" border="none" fontSize="28rpx" color="#bbb" :placeholderStyle="placeholderStyle" :customStyle="customStyle" placeholder="请输入真实姓名">
							<template #prefix>
								<image style="width: 32rpx;height:32rpx;margin-right: 18rpx;margin-top: 10rpx;" src="@/static/commonImage/user.png" mode="widthFix"></image>
							</template>
						</up-input>
					</up-form-item>
					<up-form-item prop="identificationNumber">
						<up-input v-model="userInfo.identificationNumber" shape="circle" border="none" fontSize="28rpx" color="#bbb" :placeholderStyle="placeholderStyle" :customStyle="customStyle" placeholder="请输入身份证号">
							<template #prefix>
								<image style="width: 32rpx;height:32rpx;margin-right: 18rpx;margin-top: 10rpx;" src="@/static/commonImage/IdCard.png" mode="widthFix"></image>
							</template>
						</up-input>
					</up-form-item>
					<up-form-item prop="phonenumber">
						<up-input v-model="userInfo.phonenumber" shape="circle" border="none" fontSize="28rpx" color="#bbb" :placeholderStyle="placeholderStyle" :customStyle="customStyle" placeholder="请输入手机号码">
							<template #prefix>
								<image style="width: 32rpx;height:32rpx;margin-right: 18rpx;margin-top: 10rpx;" src="@/static/commonImage/phone.png" mode="widthFix"></image>
							</template>
						</up-input>
					</up-form-item>
				</up-form>
				<view class="status">
					<view class="statusBtn" :class="{active: userInfo.jobStatus === '0'}" @click="changeStatus('0')">在岗</view>
					<view class="statusBtn" :class="{active: userInfo.jobStatus === '1'}" @click="changeStatus('1')">离岗</view>
				</view>
			</view>
			
			
			<view class="loginBtn" @click="loginOut">退出登录</view>
		</view>
		<!-- 底部导航栏 -->
		<up-tabbar
			:value="useTabbar.employeeCurrent"
			activeColor="#3680FE"
			inactiveColor="#707070"
		>
			<up-tabbar-item text="主页" icon="home" :badge="useTabbar.companyTotal" @click="goRouter"></up-tabbar-item>
			<up-tabbar-item text="我的" icon="account"></up-tabbar-item>
		</up-tabbar>
	</view>
</template>

<script setup>
import { ref } from 'vue'
import { updateUserInfo, getPhome } from '@/api/user.js'
import { onReady } from '@dcloudio/uni-app'
import useTabbarStore from '@/store/modules/tabbar.js'
import useUserStore from '@/store/modules/user.js';
const { userInfo, Logout, getUser } = useUserStore()
const useTabbar = useTabbarStore()
const showNotice = ref(true)
const customStyle = {
	height: '80rpx',
	backgroundColor: '#F9F9F9',
	paddingLeft: '40rpx'
}
const placeholderStyle = {
	color: '#bbb',
	fontSize: '28rpx'
}
// 表单引用  
const userFormRef = ref(null)
// 校验规则
const rules = {
	nickName: [ 
		{ required: true, message: '请输入姓名', trigger: ['blur', 'change'] },
		{ min: 2, max: 6, message: '名字应在2到6个字', trigger: ['blur', 'change'] }, 
		{ validator: (rule, value, callback) => {
				return uni.$u.test.chinese(value)
			},
			message: '请输入中文',
			// 触发器可以同时用blur和change
			trigger: ['change','blur'],
		}
	],
	identificationNumber: [
		{ required: true, message: '请输入身份证号', trigger: ['blur', 'change'] },
		{ validator: (rule, value, callback) => {
				return uni.$u.test.idCard(value)
			},
			message: '身份证号码不正确',
			// 触发器可以同时用blur和change
			trigger: ['change','blur'],
		}
	],
	phonenumber: [
		{ required: true, message: '请输入手机号', trigger: ['blur', 'change'] },
		{ validator: (rule, value, callback) => {
				return uni.$u.test.mobile(value)
			},
			message: '手机号码不正确',
			// 触发器可以同时用blur和change
			trigger: ['change','blur'],
		}
	]
}
// 微信小程序需要在此注册校验规则
onReady(() => {
	userFormRef.value.setRules(rules)
})
const loginOut = () => {
	uni.showModal({
		title: '提示',
		content: '是否退出登录',
		success: async (res) =>  {
			if (res.confirm) {
				await Logout()
				uni.$u.toast('退出成功')
				uni.redirectTo({
					url: '/pages/login/login'
				})
			} else if (res.cancel) {
				console.log('用户点击取消');
			}
		}
	});
}

const goRouter = (index) => {
	useTabbar.employeeCurrent = index
	uni.redirectTo({
		url: '/pages/companyHome/companyHome'
	})
}

// 设置在岗状态
const changeStatus = async (status) => {
	userInfo.jobStatus = status
	await updateUserInfo(userInfo)
	await getUser()
	uni.$u.toast('更新成功')
}
// 提交方法
const submit = () => {
	userFormRef.value.validate().then(async valid => {
		if (valid) {
			await updateUserInfo(userInfo)
			await getUser()
			uni.$u.toast('更新成功')
		} else {
			uni.$u.toast('校验失败')
		}  
	}).catch(() => {
		// 处理验证错误  
		uni.$u.toast('校验失败')
	});  
}
</script>

<style lang="scss" scoped>
.app-container{
	width: 100%;
	height: 100vh;
	padding: 0 30rpx;
	background: url('http://bxhd.crgx.net/profile/avatar/2024/09/25/bg-index_20240925113012A004.png') no-repeat;
	background-size: 100% 100%;
	overflow: hidden;
	
	.user-box{
		width: 690rpx;
		padding: 40rpx 44rpx;
		background-color: #fff;
		z-index: 10;
		margin: 0 auto 40rpx;
		box-shadow: 0rpx 8rpx 40rpx 0rpx rgba(10,22,44,0.06);
		border-radius: 40rpx;
	}
	
	// 车辆列表
	.car_list{
		display: flex;
		flex-direction: column;
		gap: 20rpx;
		.line_title{
			display: flex;
			justify-content: space-between;
			font-size: 	24rpx;
			color: #999;
			line-height: 32rpx;
			.left_title{
				font-size: 32rpx;
				line-height: 42rpx;
				color: #333;
			}
		}
		.car_data{
			padding: 0 30rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 8rpx 40rpx 0rpx rgba(10,22,44,0.06);
			border-radius: 40rpx;
			margin-bottom: 60rpx;
			.car_item{
				padding: 30rpx 0;
				border-bottom: 2rpx solid #eee;
				&:last-child{
					border-bottom: 0;
				}
			}
		}
		.loginBtn{
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			font-size: 28rpx;
			color: #fff;
			font-weight: 500;
			background: #3680FE;
			box-shadow: 0rpx 8rpx 40rpx 0rpx rgba(10,22,44,0.06);
			border-radius: 40rpx;
			margin-top: 40rpx;
		}
	}
}
.authBtn{
	width: 210rpx;
	font-size: 20rpx;
	margin-right: 30rpx;
}

.status{
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-top: 20rpx;
	.statusBtn{
		width: 280rpx;
		height: 80rpx;
		text-align: center;
		line-height: 80rpx;
		color: #999;
		background: #FFFFFF;
		border-radius: 200rpx;
		border: 2rpx solid #BBBBBB;
		&.active{
			color: #fff;
			background: #3680FE;
		}
	}
}
</style>