Files
pj_h5_cloud/src/pages/user/userRole.vue
T

104 lines
3.4 KiB
Vue

<template>
<view class="flex-col min-h-screen bg-gray-100">
<view class="text-center py-12">
<view class="main-text-40 mb-2">请选择您的身份</view>
</view>
<view class="px-6">
<view
class="card mb-6 overflow-hidden relative border-8 border-solid border-white duration-200"
:class="{ 'border-8 border-solid border-blue!': userRole === 'user' }"
@click="selectRole('user')"
>
<view class="flex-row items-center p-6">
<view class="w-64 h-64 rounded-full flex-col-center mr-8">
<image src="@/static/page/userRole.svg" />
</view>
<view class="main-text-32 mb-1">我是用户</view>
</view>
</view>
<view
class="card mb-6 overflow-hidden relative border-8 border-solid border-white duration-200"
:class="{ 'border-8 border-solid border-blue!': userRole === 'merchant' }"
@click="selectRole('merchant')"
>
<view class="flex-row items-center p-6">
<view class="w-64 h-64 rounded-full flex-col-center mr-8">
<image src="@/static/page/merchantRole.svg" />
</view>
<view class="main-text-32 mb-1">我是商户</view>
</view>
</view>
<view
class="card overflow-hidden relative border-8 border-solid border-white duration-200"
:class="{ 'border-8 border-solid border-blue!': userRole === 'doorAdmin' }"
@click="selectRole('doorAdmin')"
>
<view class="flex-row items-center p-6">
<view class="w-64 h-64 rounded-full flex-col-center mr-8">
<image src="@/static/page/doorAdminRole.svg" />
</view>
<view class="main-text-32 mb-1">我是智能柜管理员</view>
</view>
</view>
</view>
<view class="flex-row-center px-10 mt-auto pb-10 font-bold">
<tm-button block @click="confirmRole">确 定</tm-button>
</view>
</view>
</template>
<script setup lang="ts">
import { ref } from "vue"
import { userApi } from "@/sheep/api"
import getLaunchParam from "@/sheep/utils/getLaunchParam"
const userRole = ref("user")
const selectRole = (role: "user" | "merchant" | "doorAdmin") => (userRole.value = role)
// 确认选择
const confirmRole = async () => {
switch (userRole.value) {
case "user":
uni.setStorageSync("userRole", userRole.value)
if (getLaunchParam() === "selfMerchant") return uni.reLaunch({ url: "/pages/tabbar/selfMerchant" })
if (getLaunchParam() === "coopMerchant") return uni.reLaunch({ url: "/pages/tabbar/coopMerchant" })
break
case "merchant":
uni.showLoading({ title: "正在验证身份", mask: true })
const res1: any = await userApi.userRole().finally(() => uni.hideLoading())
if (res1.code == 0) {
if (res1.data.isMch) {
uni.setStorageSync("userRole", userRole.value)
uni.reLaunch({ url: "/pages/tabbar/individualOrder" })
} else {
uni.showToast({ title: "您不是商户", icon: "none" })
}
} else {
uni.showToast({ title: "身份验证失败", icon: "none" })
}
break
case "doorAdmin":
uni.showLoading({ title: "正在验证身份", mask: true })
const res2: any = await userApi.userRole().finally(() => uni.hideLoading())
if (res2.code == 0) {
if (res2.data.isHardDoorAdmin) {
uni.setStorageSync("userRole", userRole.value)
uni.reLaunch({ url: "/pages/tabbar/cabinet" })
} else {
uni.showToast({ title: "您不是智能柜管理员", icon: "none" })
}
} else {
uni.showToast({ title: "身份验证失败", icon: "none" })
}
break
default:
uni.showToast({ title: "请选择您的身份", icon: "none" })
}
}
</script>