<template>
    <van-pull-refresh
        success-text="加载成功"
        success-duration="500"
        class="mine"
        v-model="isLoading"
        @refresh="onRefresh"
    >
        <div class="userInfo" v-if="isLogin">
            <!-- <van-image
                width="100%"
                height="52vw"
                :src="userInfo.bg ? userInfo.bg + '?r=' + refreshFlag : require('@assets/creatorBg.png')"
                loading-icon=""
                fit="cover"
                class="top-img"
            /> -->
            <!-- <template v-if="publishShow">
                <div class="yinsi" v-if="userInfo.isPublicShow" @click="changeShow(false)">
                    <img src="@assets/icon-kaiqiyinsi.png" alt="" />
                    <span>开启隐私</span>
                </div>
                <div class="yinsi not" v-else @click="changeShow(true)">
                    <img src="@assets/icon-guanbiyinsi.png" alt="" />
                    <span>关闭隐私</span>
                </div>
            </template> -->

            <!-- <div class="edit-btn" @click="$router.push('/setting')">
                <img src="../assets/icon-bianji1.png" alt="" />
                <span>编辑</span>
            </div> -->
            <div class="userInfo-content">
                <div class="userInfo-top" @click="$router.push('/' + $route.params.companyId + '/setting')">
                    <van-image
                        radius="100"
                        width="84"
                        height="84"
                        :src="
                            userInfo.avatar
                                ? userInfo.avatar + '?r=' + refreshFlag
                                : require('@assets/img_default_photo.png')
                        "
                        fit="cover"
                        :class="{ activeAvatar: isLogin && userInfo.useCollectionPic }"
                    />
                    <div class="text">
                        <div class="text1">
                            <span class="van-ellipsis" style="max-width: 120px">{{ userInfo.nickname }}</span>
                        </div>
                        <div class="text2">
                            <span> 用户ID:{{ userInfo.id }} </span>
                            <img @click.stop="copy" src="@assets/svgs/copy_icon.svg" alt="" />
                        </div>
                        <div class="icons" @click.stop="goAuth">
                            <div class="auth-imgs" v-if="authStatus !== '已认证'">
                                <img src="../assets/renzheng_icon.png" alt="" />
                                <span>未实名认证</span>
                            </div>
                            <div class="auth-imgs authed" @click="goAuth" v-else>
                                <img src="../assets/yirenzhng-geren-icon.png" alt="" />
                                <span>个人已认证</span>
                            </div>

                            <level ref="level" @showOverlay="showOverlay"></level>
                        </div>
                    </div>
                    <img class="inter" src="@assets/icon_inter.png" alt="" />
                </div>

                <!-- <div class="sub" :class="{ 'van-multi-ellipsis--l2': !showMore }">
                    {{ userInfo.intro }}
                </div>
                <div class="sub-right" v-if="userInfo && userInfo.intro && userInfo.intro.length > 50">
                    <img
                        @click="showMore = !showMore"
                        :class="{ subAll: showMore }"
                        src="../assets/icon-xialajiantou.png"
                        alt=""
                    />
                </div> -->

                <div class="btns">
                    <div class="collect" @click="$router.push('/' + $route.params.companyId + '/store')">
                        <div class="text1">{{ assetNum }}</div>
                        <div class="text2">藏品:</div>
                    </div>
                    <div class="collect" @click="$router.push('/' + $route.params.companyId + '/mineFollowers')">
                        <div class="text1">{{ userInfo.followers }}</div>
                        <div class="text2">粉丝:</div>
                    </div>
                    <div class="collect" @click="$router.push('/' + $route.params.companyId + '/mineFollows')">
                        <div class="text1">{{ userInfo.follows }}</div>
                        <div class="text2">关注:</div>
                    </div>
                </div>
            </div>
        </div>
        <div class="userInfo" v-else>
            <div class="userInfo-content">
                <div class="userInfo-top" @click="$router.push('/' + $route.params.companyId + '/login')">
                    <van-image
                        round
                        width="84"
                        height="84"
                        :src="require('@assets/img_default_photo.png')"
                        fit="cover"
                    />

                    <div class="text">
                        <div class="text1">点击登录</div>
                        <div class="text2" style="padding-bottom: 16px">立即登录获取精彩服务</div>
                    </div>
                </div>
            </div>
        </div>
        <div class="orderList">
            <div class="order-info" @click="$router.push('/' + $route.params.companyId + '/orders?type=DEFAULT')">
                <img src="@assets/info_icon_yishuping.png" alt="" />
                <span>我的订单</span>
            </div>
            <div class="order-info" @click="$router.push('/' + $route.params.companyId + '/mineWallet')">
                <img src="@assets/icon_qianbao.png" alt="" />
                <span>我的钱包</span>
            </div>
            <div class="order-info" @click="wait">
                <img src="@assets/icon-jifen.png" alt="" />
                <span>我的积分</span>
            </div>
        </div>
        <van-cell-group class="menus" :border="false">
            <van-cell title="我喜欢的" :to="{ path: '/' + $route.params.companyId + '/mineLikes' }" is-link>
                <template #icon>
                    <van-icon :name="require('@assets/icon-woxihuande.png')" class="search-icon" />
                </template>
            </van-cell>
            <van-cell
                title="交易历史"
                :to="{ path: '/' + $route.params.companyId + '/mineExchange' }"
                v-if="!$store.state.review"
                is-link
            >
                <template #icon>
                    <van-icon :name="require('@assets/info_icon_jiaoyijilu.png')" class="search-icon" />
                </template>
            </van-cell>
            <!-- <van-cell
                title="客服留言"
                :to="{ path: '/' + $route.params.companyId + '/message' }"
                v-if="!$store.state.review"
                is-link
            >
                <template #icon>
                    <van-icon :name="require('@assets/icon_kefuliuyan.png')" class="search-icon" />
                </template>
            </van-cell> -->
            <van-cell title="账号与安全" :to="{ path: '/' + $route.params.companyId + '/security' }" is-link>
                <template #icon>
                    <van-icon :name="require('@assets/icon-anquan.png')" class="search-icon" />
                </template>
            </van-cell>
            <van-cell title="关于我们" :border="false" :to="{ path: '/' + $route.params.companyId + '/about' }" is-link>
                <template #icon>
                    <van-icon :name="require('@assets/icon-guanyuwomen.png')" class="search-icon" />
                </template>
            </van-cell>
        </van-cell-group>

        <div class="tabbar-placeholder"></div>
        <level-overly ref="overly"></level-overly>
    </van-pull-refresh>
</template>

<script>
import { mapState } from 'vuex';
import Level from '../components/level/Level.vue';
import LevelOverly from '../components/level/LevelOverly.vue';
export default {
    data() {
        return {
            org: false,
            showMore: false,
            assetNum: 0,
            shareProduct: {
                openQuota: false
            },
            shareMoney: 0,
            refreshFlag: Number(localStorage.getItem('refreshFlag') || '0'),
            enableWallet: false,
            faceAuth: false,
            publishShow: false
        };
    },
    components: { Level, LevelOverly },
    computed: {
        ...mapState(['userInfo', 'companyId'])
    },
    created() {
        this.getInit();
    },
    methods: {
        showOverlay(show) {
            this.$refs.overly.show = show;
        },
        getInit(refresh) {
            if (this.isLogin) {
                this.$http
                    .post(
                        '/asset/all',
                        {
                            query: {
                                page: 0,
                                size: 1,
                                userId: this.$store.state.userInfo.id,
                                status: 'NORMAL,TRADING,GIFTING,MINTING',
                                companyId: this.companyId
                            }
                        },
                        { body: 'json' }
                    )
                    .then(res => {
                        this.assetNum = Number(res.totalElements);
                    });
            }

            if (window.cordova && StatusBar && StatusBar.isVisible) {
                StatusBar.styleLightContent();
            }

            return this.$store.dispatch('getUserInfo', refresh);
        },
        copy() {
            this.$copyText(this.userInfo.id).then(
                e => {
                    this.$toast.success('复制成功');
                    console.log(e);
                },
                e => {
                    this.$toast('复制失败');
                    console.log(e);
                }
            );
        },
        goAuth() {
            if (this.authStatus === '认证中' || this.authStatus === '认证失败') {
                this.$router.push('/' + this.$route.params.companyId + '/waiting');
            } else if (this.authStatus === '未认证') {
                this.$router.push('/' + this.$route.params.companyId + '/faceAuth');
                // if (this.faceAuth) {
                //     this.$router.push('/' + this.$route.params.companyId + '/faceAuth');
                // } else {
                //     this.$router.push('/' + this.$route.params.companyId + '/verified');
                // }
            }
        },
        getProduct() {
            return this.$http
                .get('/sysConfig/get/share_collection_id')
                .then(res => {
                    if (res.value) {
                        return this.$http.get('collection/get/' + res.value);
                    } else {
                        return Promise.reject('活动未开始');
                    }
                })
                .catch(e => {
                    return Promise.reject('活动未开始');
                })
                .then(res => {
                    this.shareProduct = res;
                    return Promise.resolve();
                });
        },
        onRefresh() {
            this.refreshFlag++;
            localStorage.setItem('refreshFlag', this.refreshFlag);
            return this.getInit(true)
                .then(() => {
                    this.isLoading = false;
                })
                .catch(() => {
                    this.isLoading = false;
                });
        },
        changeShow(isPublicShow) {
            this.$dialog
                .confirm({
                    title: isPublicShow ? '关闭隐私' : '开启隐私',
                    message: isPublicShow ? '关闭后，他人将看到你的主页信息' : '开启后，他人将无法查看你的主页信息'
                })
                .then(() => {
                    this.updateUser({ isPublicShow: isPublicShow });
                });
        }
    }
};
</script>

<style lang="less" scoped>
.mine {
    background-color: #272b2e;
    padding-top: 0 !important;
    position: relative;
    min-height: var(--app-height);
}

.top {
    display: flex;
    align-items: center;
    padding: 36px 16px 30px;
    border-bottom: 1px solid @bg2;
    position: relative;

    .van-image {
        border: 5px solid @bg;
    }

    .text {
        margin-left: 12px;
        position: relative;
        z-index: 2;

        .text1 {
            font-size: @font3;
            font-weight: bold;
            color: @text0;
            line-height: 24px;
            img {
                width: 18px;
                height: 18px;
                display: inline-block;
                margin-left: 6px;
            }
        }

        .text2 {
            font-size: @font2;
            color: #949699;
            line-height: 24px;
        }
    }

    .top-bg {
        position: absolute;
        top: -83px;
        left: 0;
        right: 0;
        width: 100%;
        display: block;
        height: auto;
        z-index: 0;
    }
}

/deep/ .title {
    padding: 12px 12px 6px;
    border-bottom: 1px solid @bg3;
    .van-cell__title {
        span {
            font-size: @font3;
            line-height: 28px;
            color: @text0;
            font-weight: bold;
        }
    }

    .van-cell__value {
        span {
            font-size: @font1;
            line-height: 28px;
        }
    }

    .van-icon {
        line-height: 28px;
    }
}
.orderList {
    .flex();
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    margin: 0 16px;
    // padding: 0 12px;
    .order-info {
        padding: 16px 0;
        position: relative;
        width: 33%;
        box-sizing: border-box;
        .flex-col();
        align-items: center;
        justify-content: center;

        .order-info-box {
            .flex();
            width: 132px;
        }
        img {
            width: 32px;
            height: 32px;
            // margin-right: 8px;
        }
        span {
            font-size: 14px;
            font-weight: bold;
            color: #939599;
            line-height: 24px;
            margin-top: 2px;
        }
    }
    .order-info + .order-info {
        // margin-left: 20px;
        &::before {
            content: '';
            width: 1px;
            background-color: #373b3e;
            position: absolute;
            left: -0.5px;
            top: 0;
            bottom: 0;
        }
    }

    // /deep/.van-badge__wrapper {
    //     width: 50%;
    //     .order-info {
    //         width: 100%;
    //     }
    // }

    &.prim {
        span {
            font-weight: normal;
            color: #43ce00;
            font-family: 'ZhenyanGB';
        }
    }
}
.orderList {
    .flex();
    // padding: 0 12px;
    .menu-info {
        padding: 16px 0;
        position: relative;
        width: 50%;
        box-sizing: border-box;
        .flex();
        justify-content: center;

        .menu-info-box {
            .flex();
            width: 132px;
        }
        img {
            width: 28px;
            height: 28px;
            margin-right: 8px;
        }
        span {
            font-size: 14px;
            font-weight: bold;
            color: #ffffff;
            line-height: 24px;
        }
    }
    .menu-info + .menu-info {
        // margin-left: 20px;
        &::before {
            content: '';
            width: 1px;
            background-color: #373b3e;
            position: absolute;
            left: -0.5px;
            top: 0;
            bottom: 0;
        }
    }

    // /deep/.van-badge__wrapper {
    //     width: 50%;
    //     .order-info {
    //         width: 100%;
    //     }
    // }

    &.prim {
        span {
            font-weight: normal;
            color: #43ce00;
            font-family: 'ZhenyanGB';
        }
    }
}
.grid-img {
    display: block;
}

.driver {
    background-color: #373b3e;
}

/deep/ .van-grid-item {
    .van-grid-item__text {
        font-size: @font1;
        color: @text0;
        line-height: 18px;
        margin-top: 4px;
        white-space: nowrap;
    }
    .van-grid-item__content {
        padding: 4.2vw 2.1vw;
    }
}

/deep/.menu {
    .van-cell {
        padding: 22px 20px 24px;

        &::after {
            left: 52px;
            right: 16px;
        }
    }

    .van-cell__title {
        span {
            font-weight: bold;
        }
    }
}

.search-icon {
    width: 28px;
    height: 28px;
    margin-right: 13px;
    display: block;
    /deep/.van-icon__image {
        width: 28px;
        height: 28px;
        display: block;
    }
}
.userInfo {
    // padding-top: 52vw;
    // border-bottom: 1px solid @bg2;
    position: relative;
    // margin-bottom: -103px;

    .top-img {
        position: absolute;
        top: 0;
        left: 0;
        z-index: 1;
        &::after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 0;
            height: 90px;
            right: 0;
            z-index: 1;
            background: linear-gradient(180deg, rgba(39, 43, 46, 0) 0%, #272b2e 100%);
        }
    }
}
.userInfo-content {
    padding: 0 16px;
    z-index: 2;
    position: relative;
    .sub {
        font-size: 12px;
        color: @text3;
        line-height: 17px;
        padding: 2px 0 0;
        text-align: center;
    }

    .sub-right {
        .flex();
        margin-top: 4px;
        justify-content: center;
        img {
            width: 18px;
            height: 18px;
            display: block;
            transition: transform ease-in-out 0.3s;

            &.subAll {
                transform: rotate(180deg);
            }
        }
    }

    .sub-right > div {
        font-size: 12px;
        color: @text0;
        line-height: 17px;
        text-decoration: underline;
    }

    .btns {
        display: flex;
        // padding-bottom: 16px;
        align-items: center;
        border-top: 1px solid rgba(255, 255, 255, 0.06);

        .collect {
            width: 33%;
            .flex();
            flex-direction: row-reverse;
            justify-content: center;
            padding: 12px 0;
            .text1 {
                font-size: 14px;
                color: #939599;
                line-height: 24px;
            }
            .text2 {
                font-size: 14px;
                color: #939599;
                line-height: 24px;
            }
        }
    }
}
.userInfo-top {
    display: flex;
    align-items: center;
    transform: translateX(-5px);
    position: relative;
    padding: 20px 0 16px;
    .van-image {
        // border: 5px solid @bg;
        flex-shrink: 0;
        border-radius: 100px;
    }

    .text {
        margin: 0 10px 0 12px;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        flex-grow: 1;
        .text1 {
            font-size: 24px;
            font-weight: bold;
            color: @bg;
            line-height: 24px;
            margin-top: 15px;
            .flex();
            // img {
            //     width: 18px;
            //     height: 18px;
            //     display: inline-block;
            //     // margin-left: 5px;
            //     vertical-align: middle;
            // }
        }
        .text2 {
            font-size: 12px;
            color: #949699;
            line-height: 24px;
            display: flex;
            align-items: center;
            margin-top: 3px;
            img {
                display: block;
                margin-left: 6px;
            }
        }

        .icons {
            .flex();
            transform: translateX(-16px);
            .auth-imgs {
                .flex();
                transform: translateX(15px);
                img {
                    width: 28px;
                    height: 28px;
                    position: relative;
                    z-index: 1;
                }
                span {
                    font-size: 12px;
                    color: @text3;
                    line-height: 18px;
                    background: #373b3e;
                    border-radius: 2px;
                    padding: 0 4px 0 10px;
                    transform: scale(0.8) translateX(-24px);
                    position: relative;
                    z-index: 0;
                }

                &.authed {
                    span {
                        color: #ff8f3e;
                        background-color: #ffefe8;
                        position: relative;
                    }
                }
            }
        }
    }

    .inter {
        width: 24px;
        height: 24px;
    }

    .renzhen-img {
        position: absolute;
        left: 60px;
        bottom: 5px;
        width: 20px;
        height: 20px;
    }
}
.menus {
    margin: 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    /deep/ .van-cell {
        padding: 14px 16px;
        .van-cell__title {
            font-size: 14px;
            color: #ffffff;
            line-height: 28px;
        }
        &::after {
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            left: 16px;
            right: 16px;
        }
        .van-cell__right-icon {
            line-height: 28px;
        }
    }
}

/deep/.auth {
    color: @text3!important;
    padding: 0 10px;
    margin-left: 6px;
    .van-button__content {
        .flex();
        .van-icon__image {
            display: block;
        }
        font-weight: normal;
    }
    height: 24px;
}

.edit {
    color: @text3;
}

.card {
    box-shadow: 0px 2px 6px 0px rgba(200, 201, 204, 0.3);
    border-radius: 12px;
    margin: 16px;
}

.edit-btn {
    position: absolute;
    right: 16px;
    top: 16px;
    top: calc(var(--safe-top) + 16px);
    .flex();
    z-index: 20;
    img {
        width: 18px;
        height: 18px;
    }
    span {
        font-size: 12px;
        color: #ffffff;
        line-height: 12px;
        margin-left: 4px;
    }
    width: 72px;
    height: 24px;
    background: #272b2e;
    border-radius: 4px;
    justify-content: center;
}

.yinsi {
    position: absolute;
    background: #3ab200;
    border-radius: 4px;
    top: calc(var(--safe-top) + 16px);
    left: 16px;
    z-index: 3;
    padding: 0 11px;
    height: 24px;
    .flex();
    img {
        width: 18px;
        height: 18px;
    }
    span {
        font-size: 12px;
        color: #ffffff;
        line-height: 24px;
        margin-left: 3px;
    }

    &.not {
        background: #ff4f50;
    }
}
</style>
