<template>
    <div class="page">
        <headNav title="旧系统密码设置"></headNav>

        <div class="content">
            <van-cell-group>
                <van-field v-model="pwd" label="旧密码" placeholder="6-16位字母数字，区分大小写" />
                <van-field v-model="rePwd" label="确认密码" placeholder="请再次确认密码" />
            </van-cell-group>
            <div style="margin: 16px;">
                <van-button round block type="info" @click="commit">保存</van-button>
            </div>
        </div>

        <v-mask :showOverLay="showOverLay" tipMsg="保存中..."></v-mask>
    </div>
</template>

<script>
import { Notify } from 'vant';
import headNav from '@/components/headNav.vue';
import mask_overLay from "@/components/overLay_xy.vue";

import { put } from '@/utils/http.js';
import { isEmpty } from '@/utils/tool';

export default {
    components: {
        headNav,
        "v-mask": mask_overLay,
    },
    data () {
        return {
            showOverLay: false,
            pwd: '',
            rePwd: ''
        }
    },
    methods: {
        commit() {
            if (isEmpty(this.pwd)) {
                Notify({ type: 'warning', message: '请输入密码' });
                return
            }
            if (isEmpty(this.rePwd)) {
                Notify({ type: 'warning', message: '请确认密码' });
                return
            }
            if (this.pwd != this.rePwd) {
                Notify({ type: 'danger', message: '两次密码输入不一致，请重新输入' });
                return
            }
            put(`/v2/api/old_sys_user/user/${this.pwd}`).then(res => {
                this.showOverLay = false;
                this.$toast.success('保存成功');
                setTimeout(() => {
                    this.$router.back();
                }, 1500);
            }).catch(err => {
                this.showOverLay = false;
            })
        }
    }
}
</script>

<style lang="scss">
.tips {
    padding: 10px;
    color: #888888;
    font-size: 14px;
}
</style>