<template>
    <view class="container">
        <view class="my-container">
            <view class="user-info-pannel">
                <view class="head-img">
                    <image class="head-img-icon" :src="userInfo.type == 'group' && userInfo.info.headimg ? userInfo.info.headimg : '/resource/images/logo.png'"></image>
                </view>
                <view class="shop-info">
                    <view class="shop-name">{{ userInfo.info.name }}</view>
                </view>
            </view>

            <view class="pannel-gorup">
                <view class="form-item flex-row flex-between border-bottom">
                    <view class="form-label">
                        <image class="form-icon" src="/static/resource/images/info-icon.png"></image>
                        <text>当前版本</text>
                    </view>
                    <view class="form-value">{{ app_version }}</view>
                </view>

                <view class="form-item" @tap="bindQuit">
                    <view class="form-label">
                        <image class="form-icon" src="/static/resource/images/quit.png"></image>
                        <text>退出</text>
                    </view>
                    <view class="form-value"></view>
                </view>
            </view>
        </view>

        <view class="page-foot">
            <view class="app-support"></view>
        </view>
    </view>
</template>

<script>
// pages/my/my.js
var config = require('../../common/config.js');
var http = require('../../common/http.js');
var common = require('../../common/common.js');
var storage = require('../../common/storage.js');
export default {
    data() {
        return {
            userInfo: {
                type: '',

                info: {
                    headimg: '',
                    name: ''
                }
            },
            app_version: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        this.loadUserInfo();
        this.setData({
            app_version: config.APP_VERSION
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        const that = this;
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        loadUserInfo: function () {
            const userInfo = storage.getUserInfo();
            if (!userInfo) {
                http.postApi(config.API_USER_INFO, {}, (resp) => {
                    if (resp.data.code === 200) {
                        storage.setUserInfo(resp.data.data);
                        this.setData({
                            userInfo: resp.data.data
                        });
                    } else {
                        common.simpleToast(resp.data.msg);
                    }
                });
            } else {
                this.setData({
                    userInfo: userInfo
                });
            }
        },

        bindQuit: function () {
            uni.showModal({
                title: '',
                content: '确定退出？',
                showCancel: true,
                cancelText: '取消',
                confirmText: '确定',
                success: function (res) {
                    if (res.confirm) {
                        uni.clearStorage();
                        uni.reLaunch({
                            url: '/pages/login/login',
                            success: function (res) {},
                            fail: function (res) {},
                            complete: function (res) {}
                        });
                    }
                }
            });
        }
    }
};
</script>
<style>
@import './my.css';
</style>
