Files
gxtyzx-uniapp/src/pages/user.vue
T
2025-03-20 10:58:18 +08:00

464 lines
18 KiB
Vue

<template>
<layout class="page" @done="onLayout">
<!-- 顶部距离 -->
<view class="header" :style="'margin-top: ' + statusBarHeight + 'px'"></view>
<!-- 用户信息 -->
<ws-user-card :data="userInfo" :users="users" :isLogin="isLogin" @openLogin="openLogin" @done="reload"/>
<block v-if="hideTools">
<uni-card :border="false" :padding="'18px 8px'">
<uv-skeleton rows="2" :loading="hideTools" :title="false"></uv-skeleton>
</uni-card>
<uni-card :border="false" :padding="'18px 8px'">
<uv-skeleton rows="9" :loading="hideTools" :title="false"></uv-skeleton>
</uni-card>
</block>
<block v-else>
<!-- 收藏|关注|足迹|作品 -->
<!-- <ws-user-collect></ws-user-collect> -->
<!-- 我的资产 -->
<ws-my-asset :data="userInfo" :users="users" :config="config" :is-login="isLogin" @done="openLogin"></ws-my-asset>
<!-- 我的订单 -->
<!-- <ws-user-order :order="order" :is-login="isLogin" @done="openLogin"></ws-user-order> -->
<!-- 其他功能 -->
<uni-card :border="false" :padding="0">
<!-- 场馆管理可见-->
<block v-if="hasMerchantRole || hasMerchantClerkRole">
<view class="card">
<block v-for="(item, index) in mpMenus" :key="index">
<block v-if="index === '1981'" v-for="(v, i) in item" :key="i">
<view class="flex justify-between items-center py-20 border-bottom" @click="navTo(v)">
<view class="flex justify-start items-center">
<uv-icon :name="v.avatar"/>
<text class="text-30 ml-20">{{ v.title }}</text>
</view>
<uv-icon name="arrow-right" size="24rpx"/>
</view>
</block>
</block>
<view class="flex justify-between items-center py-20 border-bottom" @click="showActionSheet">
<view class="flex justify-start items-center">
<uv-icon name="https://oss.wsdns.cn/20241126/92f728b3b4e146d6a916259bde11a209.png"/>
<text class="text-30 ml-20">扫码核销</text>
</view>
<uv-icon name="arrow-right" size="24rpx"/>
</view>
<!-- <button class="share-btn" open-type="contact">-->
<!-- <view class="flex justify-between items-center py-20 border-bottom">-->
<!-- <view class="flex justify-start items-center">-->
<!-- <uv-icon name="https://oss.wsdns.cn/20240806/670b965e729b4a92a60927bf51bc8afe.png"/>-->
<!-- <text class="text-30 ml-20" style="font-weight: normal!important;">联系客服</text>-->
<!-- </view>-->
<!-- <uv-icon name="arrow-right" size="24rpx"/>-->
<!-- </view>-->
<!-- </button>-->
</view>
<!-- <view class="server" style="min-height: 200px">-->
<!-- <uni-list :border="false">-->
<!-- <block v-for="(item, index) in mpMenus" :key="index">-->
<!-- <block v-if="index === '1981'" v-for="(v,i) in item">-->
<!-- <uni-list-item :thumb="v.avatar" link @click="navTo(v)">-->
<!-- <template v-slot:body>-->
<!-- <view class="slot-box">-->
<!-- <text class="slot-text" :style="{ color: v.color ? v.color : '#333333' }">{{-->
<!-- v.title-->
<!-- }}-->
<!-- </text>-->
<!-- </view>-->
<!-- </template>-->
<!-- </uni-list-item>-->
<!-- </block>-->
<!-- </block>-->
<!-- <uni-list-item thumb="https://oss.wsdns.cn/20240806/670b965e729b4a92a60927bf51bc8afe.png" link>-->
<!-- <template v-slot:body>-->
<!-- <view class="slot-box">-->
<!-- <button class="share-btn" open-type="contact">联系客服</button>-->
<!-- </view>-->
<!-- </template>-->
<!-- </uni-list-item>-->
<!-- </uni-list>-->
<!-- </view>-->
</block>
<block v-else>
<!-- 普通会员菜单 -->
<view class="server" style="min-height: 200px">
<view class="card">
<block v-for="(item, index) in mpMenus" :key="index">
<block v-if="index === '1981'" v-for="(v, i) in item" :key="i">
<view class="flex justify-between items-center py-20 border-bottom" @click="navTo(v)">
<view class="flex justify-start items-center">
<uv-icon :name="v.avatar"/>
<text class="text-30 ml-20">{{ v.title }}</text>
</view>
<uv-icon name="arrow-right" size="24rpx"/>
</view>
</block>
</block>
<!-- <button class="share-btn" open-type="contact">-->
<!-- <view class="flex justify-between items-center py-20 border-bottom">-->
<!-- <view class="flex justify-start items-center">-->
<!-- <uv-icon name="https://oss.wsdns.cn/20240806/670b965e729b4a92a60927bf51bc8afe.png"/>-->
<!-- <text class="text-30 ml-20" style="font-weight: normal!important;">联系客服</text>-->
<!-- </view>-->
<!-- <uv-icon name="arrow-right" size="24rpx"/>-->
<!-- </view>-->
<!-- </button>-->
</view>
<!-- <uni-list :border="false">-->
<!-- <block v-for="(item, index) in mpMenus" :key="index">-->
<!-- <block v-if="index === '1981'" v-for="(v,i) in item">-->
<!-- <uni-list-item :thumb="v.avatar" link @click="navTo(v)">-->
<!-- <template v-slot:body>-->
<!-- <view class="slot-box">-->
<!-- <text class="slot-text" :style="{ color: v.color ? v.color : '#333333' }">{{-->
<!-- v.title-->
<!-- }}-->
<!-- </text>-->
<!-- </view>-->
<!-- </template>-->
<!-- </uni-list-item>-->
<!-- </block>-->
<!-- </block>-->
<!-- <uni-list-item thumb="https://oss.wsdns.cn/20240806/670b965e729b4a92a60927bf51bc8afe.png" link>-->
<!-- <template v-slot:body>-->
<!-- <button class="share-btn" open-type="contact">联系客服</button>-->
<!-- </template>-->
<!-- </uni-list-item>-->
<!-- </uni-list>-->
</view>
</block>
</uni-card>
<!-- <block v-for="(item, index) in mpMenus" :key="index">-->
<!-- <block v-if="index === '1981'">-->
<!-- <uni-card :title="item[0].groupName" :border="false" :padding="0">-->
<!-- <uv-skeleton rows="1" rowsHeight="30" rowsWidth="100%" :loading="mpMenus.length === 0" :title="false">-->
<!-- <div class="flex space-around py-6 flex-wrap">-->
<!-- <block v-for="(item,index) in item" :key="index">-->
<!-- <div-->
<!-- class="service-item flex flex-col justify-center items-center web-cell-content web-text-center px-20"-->
<!-- @click="navTo(item)">-->
<!-- <uv-avatar :src="item.avatar" :size="24" mode="widthFix"></uv-avatar>-->
<!-- <text style="white-space: nowrap">{{ item.title }}</text>-->
<!-- </div>-->
<!-- </block>-->
<!-- </div>-->
<!-- <w-gap height="5"></w-gap>-->
<!-- </uv-skeleton>-->
<!-- </uni-card>-->
<!-- </block>-->
<!-- <block v-if="index === '1982' && (hasMerchantClerkRole || hasMerchantRole)">-->
<!-- <uni-card :title="item[0].groupName" :border="false" :padding="0">-->
<!-- <uv-skeleton rows="1" rowsHeight="30" rowsWidth="100%" :loading="mpMenus.length === 0" :title="false">-->
<!-- <div class="flex space-around py-6 flex-wrap">-->
<!-- <block v-for="(item,index) in item" :key="index">-->
<!-- <div-->
<!-- class="service-item flex flex-col justify-center items-center web-cell-content web-text-center px-20"-->
<!-- @click="navTo(item)">-->
<!-- <image :src="item.avatar" style="width: 30px; height: 30px;" mode="widthFix"></image>-->
<!-- <text style="white-space: nowrap">{{ item.title }}</text>-->
<!-- </div>-->
<!-- </block>-->
<!-- </div>-->
<!-- <w-gap height="5"></w-gap>-->
<!-- </uv-skeleton>-->
<!-- </uni-card>-->
<!-- </block>-->
<!-- </block>-->
<!-- <ws-personal :form="users" ref="personal" @done="reload" />-->
<!-- 登录组件 -->
<ws-login ref="login" :logo="logo" @done="reload"/>
<!-- 退出按钮 -->
<ws-logout v-if="isLogin" @done="reload"></ws-logout>
</block>
<uv-action-sheet
safeAreaInsetBottom
closeOnClickOverlay
round="15"
cancelText="取消"
ref="actionSheet"
:actions="[{name: '订单核销'}, {name: '游泳年/月卡使用'}]"
title="请选择操作"
@select="selectActionSheet">
</uv-action-sheet>
</layout>
</template>
<script>
import {useUserStore} from '@/store/modules/user';
import * as MpMenuApi from '@/api/cms/mp-menu';
import * as UserCardApi from '@/api/booking/userCard';
import {getThinkUsers, updateThinkUsers} from '@/api/think/thinkUsers';
import {openUrl} from '@/utils/common';
import {useMpStore} from "@/store/modules/mp";
import {getWxOpenId, loginByOpenId} from '@/api/passport/login';
import Layout from "@/components/layout.vue";
import {useTenantStore} from '@/store/modules/tenant';
import {authUser} from "@/api/user";
import UvAvatar from "@/uni_modules/uv-avatar/components/uv-avatar/uv-avatar.vue";
import {getThinkOrderByCode, thinkOrderCheckCode} from "@/api/think/thinkOrder";
const tenantStore = useTenantStore();
const mpStore = useMpStore();
const userStore = useUserStore();
export default {
components: {UvAvatar, Layout},
data() {
return {
statusBarHeight: 104,
isLogin: false,
userInfo: {},
fields: {},
logo: '',
config: {},
bookingUser: {},
merchantList: [],
server: [],
mpMenus: [],
ads: [],
order: [],
users: {},
hideTools: true,
// 是否拥有场馆管理员权限
hasMerchantRole: false,
// 是否拥有场馆职员权限
hasMerchantClerkRole: false,
// 是否拥有超级管理员权限
hasSuperAdminRole: false
};
},
onLoad() {
this.reload();
},
methods: {
async reload(e) {
const app = this;
// 获取系统信息
uni.getSystemInfo({
success(data) {
if (data) {
app.statusBarHeight = data.statusBarHeight + 50;
}
}
});
// 当前小程序信息
const info = await mpStore.fetchMpInfo();
// 配置信息
app.config = info.config
// 当前租户信息
const tenantInfo = await tenantStore.fetchTenantInfo();
app.logo = tenantInfo.websiteLogo;
if (tenantInfo.fields) {
tenantInfo.fields.map((d) => {
const key = d.name;
app.fields[key] = d.value;
});
}
if (uni.getStorageSync('phone')) {
app.isLogin = true;
}
// 获取旧系统用户信息
if (uni.getStorageSync('uid')) {
await getThinkUsers(uni.getStorageSync('uid')).then(data => {
app.users = data;
console.log(app.users, '>>>>')
})
}
// 当前登录用户信息
const userInfo = await userStore.fetchUserInfo();
if (Object.keys(userInfo).length > 0) {
app.userInfo = userInfo;
app.userInfo.avatarUrl = uni.getStorageSync('avatarUrl')
uni.setStorageSync('user_id', app.userInfo.userId);
// 更新第三方系统的用户ID
if (!userInfo.uid && uni.getStorageSync('uid')) {
await authUser({uid: uni.getStorageSync('uid')}).then(res => {
console.log('更新第三方系统的用户ID')
})
}
// 判断用户角色
app.hasMerchantRole = userInfo.roles.find((d) => d.roleCode === 'merchant');
app.hasMerchantClerkRole = userInfo.roles.find((d) => d.roleCode === 'merchantClerk');
app.hasSuperAdminRole = userInfo.roles.find((d) => d.roleCode === 'superAdmin');
// app.users = {
// uid: uni.getStorageSync('uid'),
// phone: uni.getStorageSync('phone'),
// username: uni.getStorageSync('username'),
// avatarUrl: uni.getStorageSync('avatarUrl'),
// openid: uni.getStorageSync('openid')
// }
// await UserApi.getByPhone({
// openId: userInfo.openid
// }).then((data) => {
// if (data) {
// app.users = data;
// uni.setStorageSync('uid', data.id);
// data.points = data.integral
// data.balance = data.money
// data.isAdmin = 2 === data.isAdmin
// data.idCardNo = data.idCard
// data.nickname = data.username
// data.avatar = data.avatarUrl
// data.createTime = uni.$uv.date(data.createTime,'yyyy-mm-dd hh:MM:ss')
// authUser(data)
//
// // app.userInfo = Object.assign({}, app.userInfo, data);
// // if (!data.openId) {
// // data.openId = app.userInfo.openid
// // updateUsers(data);
// // }
// }
// });
if (!uni.getStorageSync('openid')) {
// 更新openid
// #ifdef MP-WEIXIN
uni.login({
success: (res) => {
getWxOpenId({
code: res.code
}).then((response) => {
uni.setStorageSync('openid', response.openid);
updateUsers({
id: uni.getStorageSync('uid'),
openId: response.openid,
sessionKey: response.session_key,
unionid: response.unionid
});
});
}
});
// #endif
}
} else {
app.isLogin = false;
app.userInfo = {};
}
// 菜单数据
MpMenuApi.pageMpMenu({type: 0, limit: 100})
.then((res) => {
app.order = res.list.filter((d) => d.rows == 0);
app.server = res.list.filter((d) => d.rows == 1);
if (!app.hasMerchantRole && !app.hasMerchantClerkRole) {
app.server = res.list.filter((d) => d.rows == 1 && d.adminShow == 0);
}
app.hideTools = false;
})
.catch(() => {
uni.showToast({
title: '请检查您的网络.',
icon: 'none'
});
app.hideTools = false;
});
},
navTo(item) {
if (!this.isLogin) {
this.$refs.login.open('bottom');
return false;
} else {
openUrl(item);
}
},
onLayout({mpMenus, ads}) {
this.mpMenus = mpMenus;
this.ads = ads;
this.hideTools = false;
},
// 弹出登录提示框
openLogin(text) {
if (!this.isLogin) {
this.$refs.login.open('bottom');
return false;
}
if (text) {
uni.navigateTo({url: text})
}
},
scan() {
uni.scanCode({
onlyFromCamera: true,
success: async ({result}) => {
const res = await getThinkOrderByCode(result)
if (!res.res) return uni.showToast({
title: res.msg,
icon: 'none'
})
uni.navigateTo({url: `/package/order/check?id=${res.data.id}`})
},
fail: (err) => {
uni.showToast({
title: '扫码失败',
icon: 'none'
})
}
});
},
showActionSheet(){
this.$refs.actionSheet.open()
},
selectActionSheet({name}){
if (name === '订单核销') {
this.scan()
}
else if (name === '游泳年/月卡使用') {
this.useCard()
}
},
async useCard(){
uni.scanCode({
onlyFromCamera: true,
success: async ({result}) => {
const res = await thinkOrderCheckCode({qrcode: result}).catch(err => {
uni.showToast({
title: err.data,
icon: 'none'
})
})
if (res) {
uni.showToast({
title: '使用成功',
icon: 'success'
})
}
// if (!res.res) return uni.showToast({
// title: res.msg,
// icon: 'none'
// })
// uni.navigateTo({url: `/package/order/check?id=${res.data.id}`})
console.log(res)
},
fail: (err) => {
uni.showToast({
title: '扫码失败',
icon: 'none'
})
}
});
}
}
};
</script>
<style>
page {
background: url('https://oss.wsdns.cn/20240502/75fc744657544a38a32f83a825688286.png') no-repeat;
background-size: 100%;
background-repeat: no-repeat;
background-color: #f0f2f5;
width: 750rpx;
overflow-x: hidden;
}
</style>
<style lang="scss">
.service-item {
width: 130rpx !important;
margin-bottom: 30rpx;
}
</style>