<template>
    <view class="container" :class="[`${themeInfo.theme}-theme`, `${themeInfo.language}`]">
        <nav-bar></nav-bar>
        <view class="content">
            <view class="openId-box">
                <view class="row">
                    <text class="label">openId</text>
                    <uni-easyinput v-model="openId" placeholder="请输入 openId" :inputBorder="true" />
                </view>
                <view class="btn-row">
                    <uv-button @click="saveOpenId">写入 openId</uv-button>
                    <uv-button type="warning" @click="clearOpenId">清空 openId</uv-button>
                </view>
            </view>
        </view>
    </view>
</template>

<script setup>
import { ref, reactive, onMounted } from "vue";
import navBar from "@/components/navBar.vue";
import { useMainStore } from "@/store/index.js";
import { useI18n } from "vue-i18n";
import { useLoginApi } from "@/Apis/login.js";
import { useLoginApi as homeApi } from "/Apis/home.js";
import { ClientSite } from "@/Apis/book.js";

const { themeInfo } = useMainStore();
const { t } = useI18n();

const getLoginApi = useLoginApi();
const getHomeApi = homeApi();
const getSiteApi = ClientSite();

const regionPickerRef = ref();
const typeSelectRef = ref();
const openId = ref("");
const state = reactive({
    contentTips: t("reserve.contentTips"), // 验证成功提示
    formData: {
        tag: 2,
        userName: "",
        phone: "",
        type: "",
        region: "",     // 区域
    },
    showTypeSelectModal: false,
    columns: [],
});

const localOpenId = uni.getStorageSync("openId");
openId.value = localOpenId || "";
const saveOpenId = () => {
    uni.setStorageSync("openId", openId.value || "");
    if (openId.value) {
        uni.showLoading({ title: "登录中..." });
        getLoginApi.AuthorizedLogin({
            openId: openId.value,
        })
            .then((res) => {
                uni.hideLoading();
                if (res.code == 200) {
                    uni.setStorageSync("token", res.data.token);
                    uni.setStorageSync("openId", res.data.openId);
                    uni.showToast({ title: "登录成功", icon: "none" });
                } else {
                    uni.showToast({ title: res.msg, icon: "none" });
                }
            }).catch((err) => {
            })
    } else {
        uni.showToast({ title: "请输入 openId", icon: "none" });
    }

};
const clearOpenId = () => {
    openId.value = "";
    uni.setStorageSync("openId", "");
    uni.showToast({ title: "已清空 openId", icon: "none" });
};
</script>

<style lang="scss" scoped>
@import "@/static/style/theme.scss";

.typeSelectBox {
    button {
        font-size: 32rpx;
        padding: 12rpx 0;
        font-size: 32rpx;
        padding: 12rpx 0;
        color: var(--text-color);
        background: var(--active-color);
        border-radius: 10rpx;
        box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.13);
    }
}

.container {
    margin: 0;
    padding: 0 20upx;
    width: 100%;
    min-height: 100vh;
    padding-bottom: 80rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: linear-gradient(to bottom,
            var(--right-linear),
            var(--left-linear2));
    background-attachment: fixed;

    .content {
        width: 100%;

        .infobox {
            width: 100%;
            padding: 10upx 6% 60upx;
            background-color: #ffffff;
            position: relative;

            &::before {
                content: "";
                z-index: 9;
                position: absolute;
                bottom: -7px;
                left: 0;
                width: 100%;
                height: 14px;
                background: radial-gradient(var(--left-linear2) 0px,
                        var(--left-linear2) 5px,
                        transparent 5px,
                        transparent);
                background-size: 14px 14px;
            }
        }

        .btn {
            margin-top: 60rpx;
            margin-bottom: 20rpx;

            button {
                font-size: 28rpx;
                padding: 12rpx 0;
                color: var(--text-color);
                background: var(--active-color);
                border-radius: 10rpx;
                box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.13);
            }
        }

        .select {
            border-bottom: 1px solid #bec2ce;
            margin: 30rpx 0;

            .label {
                color: #bec2ce;
                font-size: 26rpx;
                font-weight: bold;
            }

            .info {
                color: #242e42;
                font-size: 22rpx;
                display: flex;
                justify-content: space-between;
                font-weight: bold;
                padding: 0 18rpx;
                opacity: 0.7;

                &.Total {
                    margin-top: 10rpx;
                    color: #242e42;
                    opacity: 1;
                }
            }

            .garyBox {
                background-color: rgba(216, 216, 216, 0.3);
                border-radius: 8rpx;
                padding: 2rpx 10rpx;
                font-size: 20rpx;
                font-weight: bold;
                color: rgb(36, 46, 66);
                display: flex;
                align-items: center;
                justify-content: space-between;
                margin: 10rpx 4rpx;
            }

            .inputBox {
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding: 10rpx;
                margin-left: 5px;

                .ImgUpload {
                    display: flex;
                    margin: 10upx 0;

                    ::v-deep .uv-upload {
                        margin-right: 40rpx;
                        border-radius: 18rpx;
                        border: 2px solid #9797974f;

                        .uv-upload__wrap__preview {
                            margin: 0;
                        }
                    }

                    .upLoadText {
                        font-size: 28upx;
                        text-align: center;
                        padding: 10upx 0;
                        background: var(--active-color);
                        border-radius: 0 0 18upx 18upx;
                        margin: -1px;
                    }
                }

                .value {
                    flex: 1;
                    display: flex;
                    flex-wrap: wrap;
                    color: #242e42;
                    font-size: 30rpx;
                    font-weight: bold;
                }

                .arrow {
                    width: auto;
                    font-size: 24rpx;

                    .codeBtn {
                        font-size: 24rpx;
                        background-color: #d1cbcb2d;
                    }
                }

                image {
                    width: 20rpx;
                    height: 12rpx;
                }
            }
        }
    }

    .openId-box {
        width: 100%;
        background: #ffffff;
        border-radius: 16rpx;
        padding: 24rpx;
        box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
        margin-top: 20rpx;

        .row {
            display: grid;
            grid-template-columns: 140rpx 1fr;
            align-items: center;
            gap: 16rpx;

            .label {
                font-size: 28rpx;
                color: #666;
                font-weight: 700;
            }
        }

        .btn-row {
            display: flex;
            gap: 20rpx;
            margin-top: 20rpx;

            ::v-deep .uv-button {
                flex: 1;
            }
        }
    }

    .i-header {
        position: relative;

        &::before {
            content: "";
            position: absolute;
            top: -7px;
            left: 0;
            width: 100%;
            height: 14px;
            background: radial-gradient(var(--right-linear) 0px,
                    var(--right-linear) 5px,
                    transparent 5px,
                    transparent);
            background-size: 14px 14px;
            z-index: 9;
        }

        padding: 40upx 0;
        width: 100%;
        background-color: #f7f7f7;
        color: #242e42;

        .tabbox {
            position: relative;
            padding-top: 10upx;
            display: flex;
            justify-content: space-around;

            .li {
                width: 50%;
                background-color: transparent;
                font-size: 34upx;
                outline: none;
                text-align: center;
            }

            .li.active {
                font-weight: bold;
            }

            .bottom-line {
                position: absolute;
                left: calc(50% - 220rpx);
                bottom: 0;
                width: 160rpx;
                height: 2.5px;
                border-radius: 20px;
                background: var(--main-color);
                transition: left 0.5s ease;

                &.right {
                    left: calc(50% + 60rpx);
                }
            }
        }
    }
}
</style>
