<template>
	<!--修改密码-->
	<view class="pwd">
		<view class="title">闪现出行运维平台</view>
		<view class="inp">
			<view>
				<text class="iconfont iconmima"></text>
				<input placeholder="请输入原密码" type="password" v-model="oldPwd"></input>
			</view>
			<view>
				<text class="iconfont iconkey-result"></text>
				<input placeholder="请输入新密码" type="password" v-model="newPwd"></input>
			</view>
			<view>
				<text class="iconfont iconkey-result"></text>
				<input placeholder="请输入确认密码" type="password" v-model="sPwd"></input>
			</view>
		</view>
		<view class="btn flexC" @click="submit">确认修改</view>
	</view>
</template>

<script>
	var app = getApp();
	export default {
		data() {
			return {
				oldPwd: '', //旧密码
				newPwd: '', //新密码
				sPwd: '' //确认密码


			}
		},
		methods: {
			submit: function() {
				if (!this.oldPwd) {
					uni.showToast({
						title: "原密码不能为空",
						icon: 'none'
					})
				} else if (!this.newPwd) {
					uni.showToast({
						title: '新密码不能为空',
						icon: 'none'
					})
				} else if (!this.sPwd) {
					uni.showToast({
						title: '确认密码不能为空',
						icon: 'none'
					})
				} else if (this.newPwd != this.sPwd) {
					uni.showToast({
						title: '确认密码与新密码不一致',
						icon: 'none'
					})
				} else {
					var data = {
						ole_password: this.oldPwd
					}
					app.request('personal/verifyOldPassword', data, 'POST').then(res => {
						if (res.statusCode == 400) {
							uni.showToast({
								title: '原始密码不正确',
								icon: 'none'
							})
						} else {
							var data = {
								old_password: this.oldPwd,
								re_password: this.newPwd,
								new_password: this.sPwd,
							}
							app.request('personal/changePassword', data, 'POST').then(res => {
								if (res.statusCode == 200) {
									uni.showToast({
										title: '修改密码成功',
										icon: 'none'
									})
									uni.clearStorage();
									uni.navigateTo({
										url: '/pages/login/login'
									})
								} else {
									
									uni.showToast({
										title: '修改密码失败',
										icon: 'none'
									})
								}
							})
						}
					})
				}
			}
		}
	}
</script>

<style>
	/* pages/password/password.wxss */

	.pwd {
		width: 85%;
		margin: 0 auto;
	}

	.pwd .title {
		width: 80%;
		font-size: 40rpx;
		font-family: FZCQJW--GB1-0;
		font-weight: 400;
		color: rgba(135, 135, 135, 1);
		padding: 63rpx 0 78rpx 0;
	}

	.pwd .inp>view {
		display: flex;
		margin-top: 60rpx;
		border-bottom: 1px solid #ccc;
	}

	.inp .iconfont {
		font-size: 40rpx;
		color: #878787;
		margin-left: 15rpx;
	}

	.inp view input {
		font-size: 28rpx;
		width: 80%;
		padding: 0 0 15rpx 10rpx;
	}

	.inp view .placeholder {
		color: #b6b6b6;
		font-size: 28rpx;
	}

	.btn {
		width: 600rpx;
		height: 88rpx;
		line-height: 88rpx;
		margin: 0 auto;
		text-align: center;
		background: rgba(24, 213, 185, 1);
		box-shadow: 0rpx 8rpx 13rpx 0rpx rgba(100, 239, 218, 1);
		border-radius: 10rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: rgba(255, 255, 255, 1);
		margin-top: 80rpx !important;
	}
</style>
