<template>
    <div style="height: 100vh; width: 100vw">
        <van-nav-bar title="密码修改" @click-left="toMain">
            <template #left>
                <van-icon name="arrow-left" />
            </template>
        </van-nav-bar>
        <van-row style="margin-top: 10%; z-index: 99">
            <van-col :span="22" :offset="1" style="border-radius: 10px; overflow: hidden">
                <van-cell-group class="bx">
                    <br />
                    <van-field
                        v-model="password.wxmm"
                        label="当前密码:"
                        placeholder="请输入当前密码"
                        type="password"
                    />
                    <van-field
                        v-model="password.newWxmm"
                        label="修改密码:"
                        placeholder="密码不少于6位，需要字母与数字构成"
                        type="password"
                    />
                    <van-field
                        v-model="password.repeatPsw"
                        label="确认修改密码:"
                        placeholder="密码不少于6位，需要字母与数字构成"
                        type="password"
                    />
                    <br />
                    <van-button
                        round
                        block
                        @click="save"
                        type="info"
                        style="width: 50%; margin: 0 auto"
                    >
                        修改
                    </van-button>
                    <br />
                </van-cell-group>
            </van-col>
        </van-row>
    </div>
</template>
<script>
import { Toast } from 'vant'
import apis from '@.mobile/api/apis'
import common from '@.mobile/plugin/axios/common'

export default {
    data() {
        return {
            password: {
                rowguid: '',
                wxmm: '',
                newWxmm: '',
                repeatPsw: ''
            }
        }
    },
    mounted() {
        const user = common.currUser()
        if (user && user.rowguid) {
            this.password.rowguid = user.rowguid
        } else {
            this.$router.push('/mobile-login')
        }
    },
    methods: {
        toMain() {
            this.$router.push('/mobile-main')
        },
        save() {
            if (this.password.newWxmm !== this.password.repeatPsw) {
                Toast('两次输入的密码不一致')
                return
            }

            apis.requestData('EcCompanyInfoController', 'editPwd', this.password).then(res => {
                if (res.data.code === 200) {
                    Toast('密码修改成功，请重新登录')
                    this.$store.dispatch('user/cleanCache').then(res => {
                        this.$router.push('/mobile-login')
                    })
                } else {
                    Toast(res.data.msg)
                }
            })
        }
    }
}
</script>
<style scoped>
::v-deep .van-cell {
    height: 60px;
    line-height: 60px;
}
::v-deep .van-cell__title {
    height: 60px;
    line-height: 60px;
}
::v-deep .van-cell__right-icon {
    height: 60px;
    line-height: 60px;
}
</style>
