<template>
	<ciy-header title="修改密码"></ciy-header>
	<view>
		<view class="ciy-card char4">
			<view class="content">
				<view class="ciy-form" v-if="!me.needpass">
					<label class="imp">旧密码</label>
					<view>
						<ciy-input v-model="editdata.oldpass" type="password" bb></ciy-input>
					</view>
				</view>
				<view class="ciy-form">
					<label class="imp">新密码</label>
					<view>
						<ciy-input v-model="editdata.newpass" type="password" bb></ciy-input>
					</view>
				</view>
				<view class="ciy-form">
					<label class="imp">再次输入</label>
					<view>
						<ciy-input v-model="editdata.repass" type="password" bb></ciy-input>
					</view>
				</view>
				<view class="ciy-form-bottom">
					<button class="btn lg cc" @tap="submit">修改密码</button>
				</view>
			</view>
		</view>
	</view>
</template>

<style>
</style>

<script>
	export default {
		data() {
			return {}
		},
		onLoad() {},
		methods: {
			async submit() {
				if (this.editdata.newpass.length < 1)
					return this.toast('请输入新密码');
				if (this.editdata.newpass != this.editdata.repass)
					return this.toast('两次输入的新密码不同');
				if (this._loading)
					return;
				this._loading = true;
				var retjson = await this.callfunc({
					func: 'me.safe_password_change',
					data: this.editdata
				});
				this._loading = false;
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.me.needpass = false;
				this.setstorage('me', this.me);
				await this.toast('修改成功');
				uni.navigateBack();
			}
		}
	}
</script>