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

<style>
</style>

<script>
    export default {
        data() {
            return {
            }
        }
        , onLoad() {
        }
        , methods: {
            async submit(e) {
                if (e.detail.value.newpass.length < 1)
                    return this.toast('请输入新密码');
                if (e.detail.value.newpass != e.detail.value.repass)
                    return this.toast('两次输入的新密码不同');
				if (this._loading)
					return;
				this._loading = true;
				var retjson = await this.callajax({
					func: 'me.pass_change',
					data: e.detail.value
				});
				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>
