<template>
	<div class="container" style="margin: 10px;">
		<el-form ref="model" :model="model" label-width="80px">
			<el-form-item label="原密码">
				<el-input v-model="model.oldpassword"></el-input>
			</el-form-item>
			<el-form-item label="新密码">
				<el-input v-model="model.newpassword"></el-input>
			</el-form-item>
			<el-form-item >
				<el-button type="success" @click="UpdPwd">确认修改</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import {
		UpdPassword
	} from '../../api/user.js'
	import {removeToken,removeUser} from '../../utils/auth.js'
	export default {
		data() {
			return {
				model: {
					"id": 0,
					"oldpassword": '',
					"newpassword": ''
				}
			}
		},
		created() {

		},
		methods: {
			UpdPwd() {
				let GetRole = localStorage.getItem("userRole")
				console.log('www',GetRole)
				let jsondata=GetRole
				console.log('用户信息',jsondata)
				this.model.id=jsondata
				if(this.model.oldpassword==''){
					this.$message.error('请输入原密码')
					return
				}
				if(this.model.newpassword==''){
					this.$message.error('请输入新密码')
					return
				}
				UpdPassword(this.model).then(res => {
					if (res.data.code == 200) {
						this.$message.success('密码修改成功')
						this.model.oldpassword=''
						this.model.newpassword=''
						removeToken()
						removeUser()
						localStorage.removeItem('userRole')
						setTimeout(()=>{
								this.$router.push({
									path: '/login'
								})
						},2000)
					} else {
						this.$message.error(res.data.message)
					}
				})
			}
		}
	}
</script>

<style>
</style>
