<template>
	<view>
		<u-navbar title="修改密码" title-color="#101010"></u-navbar>
		<view class="main">
			<view class="original-password">
				<text>原密码	</text><u-input  v-model="form.oldPassword" style="padding: 0 0 0 40rpx" class="password-input" type="password"  placeholder="填写原密码" :password-icon="true" />
			</view>
			<view class="new-password">
				<text>新密码</text><u-input  v-model="form.password" style="padding: 0 0 0 40rpx" class="password-input" type="password"  placeholder="创建6-16位组合新密码" :password-icon="true" />
			</view>
		</view>
		<!-- 确认修改 -->
		<button class="confirm" @click="changePassword">确认修改</button>
	</view>
</template>

<script>
	import * as API from '@/apis/pagejs/user.js'
	
	export default {
		data() {
			return {
				form: {
					oldPassword: '',
					password: '',
				},
			}
		},
		methods: {
			changePassword(){
				
				if (!this.form.oldPassword) {
					uni.showToast({
						title: "请输入原密码",
						icon: "none"
					})
					return
				}
				
				if (!this.form.password) {
					uni.showToast({
						title: "请输入新密码",
						icon: "none"
					})
					return
				}
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				API.changePassword(this.form).then((response) => {
					uni.hideLoading();
					this.form.password=""
					this.form.oldPassword=""
					uni.showModal({
						title:"提示",
						content:"密码修改成功！",
						showCancel:false
					})
					
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main{
		background-color: #fff;
		margin-top: 24rpx;
		.original-password,.new-password{
			line-height: 96rpx;
			padding:0 32rpx;
			display: flex;
			align-items: center;
			border-bottom: 2rpx solid rgba(221,221,221,1);
			::v-deep.u-input__input{
				height: 96rpx;
			}
		}
		text{
			display: inline-block;
			width: 128rpx;
			color: rgba(51,51,51,1);
			font-size: 32rpx;
		}
	}
  // 确认修改
  .confirm{
	  border-radius: 16rpx;
	  background-color: rgba(22,119,255,1);
	  color: rgba(255,255,255,1);
	  font-size: 32rpx;
	  line-height: 88rpx;
	  margin: 24rpx 32rpx;
  }
</style>
