<!--
 * @Author: PoJun
 * @Date: 2023-05-15 19:59:55
 * @LastEditors: PoJun
 * @LastEditTime: 2024-01-09 16:19:14
 * @Message: Nothing
-->
<template>
    <view class="index">
        <view v-if="vuex_userInfo && vuex_userInfo.attr.BusinessRole">
            <view class="index-banner">
                <uv-image :src="BannerImg" height="300px" width="100%">
                    <template v-slot:loading>
                        <uv-loading-icon></uv-loading-icon>
                    </template>
                </uv-image>
            </view>
            <!-- 管理员角色 -->
            <view class="content" v-if="vuex_userInfo.attr.BusinessRole == 'orgMember'">
                <!-- 排名 -->
                <view class="content-container">
                    <supplier-list></supplier-list>
                </view>
                <!-- 统计图 -->
                <view class="content-container">
                    <home-chart></home-chart>
                </view>
            </view>
            <!-- 供应商角色 -->
            <view class="content" v-else-if="vuex_userInfo.attr.BusinessRole == 'supplier'">
                <!-- 合作记录 -->
                <view class="content-container">
                    <records-list></records-list>
                </view>
                <!-- 产品目录 -->
                <view class="content-container">
                    <products-list></products-list>
                </view>
            </view>
        </view>
        <!-- 未登录和未认证角色 -->
        <no-auth v-else :title="!vuex_userInfo ? '没有检测到您的登录状态' : '角色认证尚未完成'">
            <uv-button
                v-if="!vuex_userInfo || vuex_userInfo.attr.auditState != 1"
                :text="!vuex_userInfo ? '去登录' : '去认证'"
                @click="toLogin"
                size="small"
                :hairline="false"
                plain
                throttleTime="100"
                shape="circle"
            ></uv-button>
        </no-auth>

        <uv-textarea
            :value="iinfo"
            :autoHeight="true"
            :textStyle="{ fontSize: '14px', textAlign: 'right' }"
        ></uv-textarea>
    </view>
</template>

<script>
import supplierList from "./components/supplier-list.vue";
import homeChart from "./components/home-chart.vue";
import recordsList from "./components/records-list.vue";
import productsList from "./components/products-list.vue";
import NoAuth from "@/components/no-auth/index.vue";

import BannerImg from "@/static/banner.png";

export default {
    components: {
        supplierList,
        homeChart,
        recordsList,
        productsList,
        NoAuth,
    },
    data() {
        return {
            BannerImg,
            iinfo: null,
        };
    },
    methods: {
        toLogin() {
            if (!this.vuex_userInfo) {
                uni.$uv.route("/pages/login/index");
            } else {
                uni.$uv.route("/subpkg/setting/authentication");
            }

            // 主动创建通知栏在线消息
            // uni.createPushMessage({
            //     title: "消息通知",
            //     content: "下午开个小会",
            //     success: () => {
            //         console.log("success");
            //     },
            //     fail: () => {
            //         console.log("fail");
            //     },
            // });
        },
    },
    computed: {},
    onLoad() {},
    onShow() {},
    onReady() {
        setTimeout(() => {
            plus.push.getClientInfoAsync(info => {
                console.log(info);
                console.log(info);
                console.log(info);
                this.iinfo = JSON.stringify(info);
            });
        }, 2000);
    },
};
</script>

<style lang="scss">
page {
    background-color: $uni-bg-color-grey;
}
.index {
    .banner {
        height: 300px;
        min-height: 300px;
    }
    .content {
        padding: 24rpx;
        transform: translateY(-40px);
        /* 增加个边距吧具体放下来 */
        margin-bottom: -50px;
        &-container {
            background-color: #fff;
            border-radius: 14rpx;
            margin-top: 24rpx;
            overflow: hidden;
        }
    }
}
</style>
