<template>
	<view class="container">
		<view class="form">
			<view class="form_item">
				<view class="form_name">旧密码:</view>
				<view class="cu-form-group margin-top" :class="[shape=='round'?'round':'']">
					<input class="uni-input" placeholder="请输入您的旧密码" :password="!showPassword" v-model="oldpassword" />
					<view class="action text-lg">
					    <text :class="[showPassword ? 'cuIcon-attention' : 'cuIcon-attentionforbid']" @click="changePassword"></text>
					</view>
				</view>
			</view>
			<view class="form_item">
				<view class="form_name">新密码:</view>
				<view class="cu-form-group margin-top" :class="[shape=='round'?'round':'']">
					<input class="uni-input" placeholder="请输入您的新密码" :password="!showPassword1" v-model="newpassword" />
					<view class="action text-lg">
					    <text :class="[showPassword1 ? 'cuIcon-attention' : 'cuIcon-attentionforbid']" @click="changePassword1"></text>
					</view>
				</view>
			</view>
			<view class="form_item">
				<view class="form_name">确认密码:</view>
				<view class="cu-form-group margin-top" :class="[shape=='round'?'round':'']">
					<input class="uni-input" placeholder="请再次输入您的新密码" :password="!showPassword2" v-model="confirmPassword" />
					<view class="action text-lg">
					    <text :class="[showPassword2 ? 'cuIcon-attention' : 'cuIcon-attentionforbid']" @click="changePassword2"></text>
					</view>
				</view>
			</view>
		</view>
		<view class="bottij">
			<button class="btn" :disabled="istrue" @click="submit()">保存</button>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				oldpassword:'',
				newpassword:'',
				confirmPassword:'',
				userName:'',
				showPassword: false, //是否显示明文
				showPassword1: false, //是否显示明文
				showPassword2: false, //是否显示明文
				constant:{}
			}
		},
		onShow() {
			this.getuserInfo()
		},
		methods:{
			getuserInfo(){
				this.$http.get('/applet/userInfo').then(res=>{
					this.constant = res.data.data
				})
			},
			changePassword() {
				this.showPassword = !this.showPassword;
			},
			changePassword1() {
				this.showPassword1 = !this.showPassword1;
			},
			changePassword2() {
				this.showPassword2 = !this.showPassword2;
			},
			submit(){
				if(!this.oldpassword){
					uni.showToast({
						title:'请输入旧密码',
						icon:'error',
						duration:2000
					})
					return
				}
				if(!this.newpassword){
					uni.showToast({
						title:'请输入新密码',
						icon:'error',
						duration:2000
					})
					return
				}
				if(!this.confirmPassword){
					uni.showToast({
						title:'请确认新密码',
						icon:'error',
						duration:2000
					})
					return
				}
				if(this.newpassword != this.confirmPassword){
					uni.showToast({
						title:'输入密码不一致',
						icon:'error',
						duration:2000
					})
					return
				}
				let params = {
					userName:this.constant.userName,
					password:this.confirmPassword,
					oldPassWord:this.oldpassword
				}
				// console.log(params,'给我给我人')
				this.$http.post('/applet/userInfo/regPassword',params).then(res=>{
					if(res.data.code == 0){
						uni.showToast({
							title:'修改成功',
							icon:'success',
							duration:2000
						})
						uni.navigateBack({
							delta:1
						})
					}else{
						uni.showToast({
							title:res.data.msg,
							icon:'none',
							duration:2000
						})
						uni.navigateBack({
							delta:1
						})
						
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
		background-color: white;
	}
	.form_item{
		padding: 30rpx 30rpx;
	}
	.cu-form-group{
		padding: 0;
		min-height: 54rpx;
		border-bottom: 2rpx solid #ececec;
		padding-bottom: 16rpx;
	}
	.bottij{
		padding: 0 30rpx;
	}
	.btn{
		margin-top: 300rpx;
		height: 88rpx;
		background: #0f6efe;
		border-radius: 44rpx;
		font-size: 32rpx;
		font-family: Source Han Sans SC;
		font-weight: 500;
		color: #FFFFFF;
	}
	.form_name{
		font-weight: bold;
	}
</style>