<template>
	<view class="password-page">
		<u-form :model="form" ref="uForm">
			<u-form-item label="密码：" label-width="100">
				<u-input v-model="form.password" :type="type" :password-icon="passwordIcon" :clearable="true"/>
			</u-form-item>
			<u-form-item label="确认密码：" label-width="150">
				<u-input v-model="form.password_confirmation" :type="type" :password-icon="passwordIcon" :clearable="true"/>
			</u-form-item>
			<view class="btns" style="margin-top: 68rpx;">
				<u-button type="primary" @click="passwordEditFn()">确定</u-button>
			</view>
		</u-form>
	</view>
</template>

<script>
	import {showLoading,hideLoading} from '@/com/utils.js'
	import md5 from 'js-md5'
	export default {
		data() {
			return {
				form: {
					password: '',
					password_confirmation: '',
				},
				type: 'password',
				passwordIcon: true,
				
			};
		},
		onLoad() {
			
		},
		methods:{
			passwordEditFn(){
				console.log(this.form);
				if (!this.form.password) {
					uni.showToast({ title: '请输入新密码', icon: 'none' });
					return;
				}
				if (!this.form.password_confirmation) {
					uni.showToast({ title: '请输入确认密码', icon: 'none' });
					return;
				}
				if (this.form.password != this.form.password_confirmation) {
					uni.showToast({ title: '两次密码不一致', icon: 'none' });
					return;
				}

				showLoading('请稍等...');
				this.$http.put('/api/users/reset-password',{
					...this.form,
					password:md5(this.form.password),
					password_confirmation:md5(this.form.password_confirmation)
				}).then(({data})=>{
					hideLoading();
					console.log(data)
					if(data.code==200){
						uni.showToast({ title: '修改成功', icon: 'none' });
					}else{
						uni.showToast({ title: data.message, icon: 'none' });
					}
				}).catch(()=>{
					hideLoading();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.password-page{
	padding: 32rpx;
}
</style>
