<template>
    <div class="my">
        <headNav :Larrow="false" title="我的"></headNav>
        <div class="content">
            <div class="header" @click="showEdit">
                <!-- <img class="icon" :src="headerUrl" alt="" srcset=""> -->
                <van-image
                    round
                    width="60px"
                    height="60px"
                    :src="headerUrl"
                />
                <div class="info">
                    <div class="name">
                        <span>{{ userInfo && userInfo.name || '-' }}</span>
                        <span>{{ userInfo && userInfo.enforce_org_name || '-' }}</span>
                    </div>
                    <div class="tel">{{ userInfo && userInfo.phone_num || '-' }}</div>
                </div>
                <div>
                    <van-icon name="arrow" size="18" color="#999" />
                </div>
            </div>
            <div class="row">
                <van-cell is-link to="/my/account">
                    <template #title>
                        <div class="title">
                            <img class="row-icon" :src="safe" alt="">
                            <span>安全设置</span>
                        </div>
                    </template>
                </van-cell>
            </div>
            <div class="row">
                <van-cell is-link @click="logout">
                    <template #title>
                        <div class="title">
                            <img class="row-icon" :src="change" alt="">
                            <span>切换账号</span>
                        </div>
                    </template>
                </van-cell>
            </div>
        </div>
    </div>
</template>

<script>
import headNav from '@/components/headNav.vue'
import Svg_safe from '@/assets/safety.svg'
import Svg_change from '@/assets/change.svg'

import Bus from '@/bus'
import { Dialog } from 'vant';
import { logout, getInfo } from '@/utils/auth';
import { notEmpty } from '@/utils/tool';

export default {
    components: {
        headNav
    },
    computed: {
        userInfo() {
            return getInfo()
        },
        headerUrl() {
            if (this.userInfo) {
                const url = this.userInfo.avatar;
                if (notEmpty(url)) {
                    return url;
                }
            }
            return 'https://img2.baidu.com/it/u=1915165029,2595650850&fm=26&fmt=auto'
        }
    },
    data () {
        return {
            safe: Svg_safe,
            change: Svg_change
        }
    },
    methods: {
        showEdit() {
            this.$router.push('/my/edit');
            Bus.$on('updateInfo', res => {
                console.log('res: ', res);
            });
        },
        logout() {
            Dialog.confirm({
                title: '温馨提示',
                message: '是否确定切换帐号？',
            })
            .then(() => {
                logout();
                location.reload();
            })
            .catch(() => {
                // on cancel
            });
        }
    }
}
</script>

<style lang="scss" scoped>
.content {
    margin-top: 60px;

    .header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 20px;
        background-color: #FFFFFF;

        .icon {
            width: 60px;
            height: 60px;
            border-radius: 100%;
            &>img {
                width: 100%;
            }
        }

        .info {
            margin: 0 15px;
            flex: 1;
            display: flex;
            flex-direction: column;
            font-size: 14px;
            color: #666666;
            .name {
                display: flex;
                align-items: flex-end;
                flex-wrap: wrap;
                &>span:first-child {
                    margin-right: 10px;
                    font-size: 18px;
                    color: #343434;
                    font-weight: bolder;
                }
            }
            .tel {
                margin-top: 10px;
                font-size: 16px;
                color: #666666;
            }
        }
    }
    .row {
        .title {
            display: flex;
            align-items: center;
            &>span {
                margin-left: 8px;
            }
        }
        margin-top: 20px;
        &-icon {
            width: 18px;
        }
    }
}
</style>