Files
mgm-daylight-mcrm-mobile-ios/pages/findPlayer/findPlayer.vue
T
2026-09-22 16:37:00 +08:00

376 lines
11 KiB
Vue

<template>
<view>
<u-navbar
:safeAreaInsetTop="true"
:placeholder="true"
:title="title"
:fixed="true"
:autoBack="false"
leftIconColor="#C39A4B"
bgColor="#C39A4B"
titleStyle="font-weight:bold;color:#ffffff;"
>
<view
v-if="showNotificationBell"
@click="goNotification"
class="notification-bell-wrap"
slot="left"
>
<u-icon name="bell" color="#FFFFFF" size="24"></u-icon>
<view v-if="notificationCount > 0" class="notification-badge">
<text class="notification-badge-text">{{ notificationBadgeText }}</text>
</view>
</view>
<view @click="logout"
style="margin-top:2px;margin-right:3px;"
slot="right"
>
<image src="../../static/images/ico_exit.png" style="width:24px;height:24px;"></image>
</view>
</u-navbar>
<view class="hz-text-center" style="margin-top:120rpx;">
<image src="/static/images/limo.png" class="mr-[40]" style="width: 58px; height: 58px;"></image>
<image src="/static/images/room_book.png" class="find-player-ico"></image>
</view>
<view class="hz-font-bolder hz-font-xl hz-text-center hz-font-color-primary">
{{$t('hotel.roombooking')}}
</view>
<view class="hz-font-bolder hz-font-xl hz-text-center hz-font-color-dark mt-[160]">
{{$t('findPlayer.title')}}
</view>
<view style="margin-top:30rpx;margin-right:60rpx;margin-left:60rpx;">
<u--input
v-model="searchPlayerId"
:placeholder="playerIdStr"
prefixIcon="search"
prefixIconStyle="font-size: 26px;color:#C39A4B;"
customStyle="border-radius:22px;"
type="number"
:clearable="true"
:maxlength="8"
></u--input>
<view style="margin-top:30rpx;">
<view @click="getProfileByPlayerId" class="hz-btn hz-font-color-white hz-font-lg hz-font-bold hz-text-center" >{{$t("common.search").toUpperCase()}}</view>
</view>
</view>
<u-modal :content="msgStr" :show="showMsg" :confirmText="yesText" :showCancelButton="false" closeOnClickOverlay @confirm="confirmMsg" confirmColor="#C39A4B" @cancel="confirmMsg" @close="confirmMsg"></u-modal>
</view>
</template>
<script>
import { getApprovalCount } from '../../api/approvalApi.js';
import {playerLookup} from '../../api/mgmApi.js'
import { countNotification } from '../../api/notificationApi.js'
import mgmHeader from '@/components/header/header.vue'
export default {
components: {
mgmHeader // 注册组件
},
data() {
return {
// 数据变量
playerIdStr: this.$t("common.playerId"),
searchPlayerId: '',
userData:null,
deviceData:null,
siteData:null,
// 界面变量
showMsg:false,
title: '',
msgStr:'',
yesText:this.$t("common.ok"),
notificationCount: 0,
approvalRoutingCount: 0,
limoNotificationCount: 0,
countAp: '',
// 定时器变量
approvalCountTimer: null,
notificationCountTimer: null,
// 页面激活态(避免残留定时器回调在非当前页继续请求)
isFindPlayerActive: false,
canViewApproval:false
}
},
onLoad() {
// 初始化界面
//uni.setLocale("en") //測試切換語言en or zh-Hant
this.initUI();
this.siteData = uni.getStorageSync("siteData");
},
onShow() {
this.isFindPlayerActive = true;
// this.getApporvalCount();
this.userData = uni.getStorageSync("userData");
this.searchPlayerId = '';
this.playerIdStr=this.$t("common.playerId");
if(this.userData!==null && this.userData!==undefined){
const realUserData = this.getEffectiveUserData(this.userData);
this.showTabbarByPermission(realUserData);
this.title = realUserData.userName+','+realUserData.userId;
}
this.isLogin();
this.fetchNotificationCount();
// 切回页面时,先停后启,避免存在残留定时器
this.stopNotificationCountTimer();
this.startNotificationCountTimer();
this.canViewApproval = this.effectiveUserData.canViewApproval === true;
},
onHide() {
this.isFindPlayerActive = false;
// 切到其他页面时立即停止定时器,避免后台持续调用
// this.stopApprovalCountTimer();
this.stopNotificationCountTimer();
},
onUnload() {
this.isFindPlayerActive = false;
// 页面销毁时兜底清理
// this.stopApprovalCountTimer();
this.stopNotificationCountTimer();
},
onReady(){
},
methods: {
getEffectiveUserData(userData) {
if (userData && userData.data && typeof userData.data === 'object') {
return userData.data;
}
return userData || {};
},
goNotification() {
const url = this.buildNotificationUrl();
uni.navigateTo({
url
});
},
buildNotificationUrl(extraParams = []) {
const params = extraParams.slice();
if (this.effectiveUserData.canViewNotification === true) {
params.push('notificationCount=' + encodeURIComponent(this.limoNotificationCount));
}
if (this.effectiveUserData.canViewApproval === true) {
params.push('approvalRoutingCount=' + encodeURIComponent(this.approvalRoutingCount));
}
return params.length
? '/limo/notification/notification?' + params.join('&')
: '/limo/notification/notification';
},
getUserIdFromUserData(userData) {
const realUserData = this.getEffectiveUserData(userData);
if (userData == null || userData === '') {
return '';
}
const userId = realUserData.userId != null && realUserData.userId !== ''
? realUserData.userId
: realUserData.UserId;
return userId != null && userId !== '' ? userId : '';
},
parseNotificationCounts(res) {
const data = res && res.data && typeof res.data === 'object' ? res.data : (res || {});
return {
count: Number(data.count ?? data.Count) || 0,
notificationCount: Number(data.notificationCount ?? data.NotificationCount) || 0,
approvalRoutingCount: Number(data.approvalRoutingCount ?? data.ApprovalRoutingCount) || 0,
};
},
async fetchNotificationCount() {
this.userData = uni.getStorageSync('userData');
const userId = this.getUserIdFromUserData(this.userData);
if (!userId) {
this.notificationCount = 0;
this.limoNotificationCount = 0;
this.approvalRoutingCount = 0;
return;
}
try {
const res = await countNotification({ userId });
const counts = this.parseNotificationCounts(res);
this.notificationCount = counts.count;
this.limoNotificationCount = counts.notificationCount;
this.approvalRoutingCount = counts.approvalRoutingCount;
} catch (error) {
console.error('[FindPlayer] countNotification failed', error);
this.notificationCount = 0;
this.limoNotificationCount = 0;
this.approvalRoutingCount = 0;
}
},
startNotificationCountTimer() {
if (!this.notificationCountTimer) {
this.notificationCountTimer = setInterval(() => {
if (this.isFindPlayerActive) {
this.fetchNotificationCount();
}
}, 30000);
}
},
stopNotificationCountTimer() {
if (this.notificationCountTimer) {
clearInterval(this.notificationCountTimer);
this.notificationCountTimer = null;
}
},
// startApprovalCountTimer() {
// if (!this.approvalCountTimer) {
// this.approvalCountTimer = setInterval(() => {
// // 双保险:非当前页不请求
// if (this.isFindPlayerActive) {
// // this.getApporvalCount();
// }
// }, 30000); // 30秒
// }
// },
// stopApprovalCountTimer() {
// if (this.approvalCountTimer) {
// clearInterval(this.approvalCountTimer);
// this.approvalCountTimer = null;
// }
// },
// 数据方法
async getProfileByPlayerId(){
if(!this.searchPlayerId){
uni.$u.toast(this.$t("findPlayer.alert"));
return;
}
uni.showLoading({
title: this.$t("common.loading")
});
try{
let params = {playerId:this.searchPlayerId,userId:this.effectiveUserData.userId};
const res = await playerLookup(params);
if(res.success == true){
if(res.data !== null){
if(res.data.codedFlag==1){
uni.setStorageSync("playerData",res.data);
uni.hideLoading();
this.navTo("/booking/bookingRecord/bookingRecord",0,false);
}else{
this.msgStr = this.$t("findPlayer.noPermission");
this.showMsg = true;
}
}
}else{
this.msgStr = res.message;
this.showMsg = true;
}
}catch(e){
console.error(e);
uni.$u.toast(e.errMsg,5000);
var request = e.config!=undefined?JSON.stringify(e.config):"";
var response = e.data!=undefined?JSON.stringify(e.data):"";
await this.writeLog(this.effectiveUserData.userId,"find_player","","[APP][findPlayer.vue][getProfileByPlayerId][Catch Exception]"+e.errMsg,request,response,1,false);
}finally{
uni.hideLoading();
}
},
// async getApporvalCount(){
// if (!this.isFindPlayerActive) return;
// try{
// let params = {};
// const res = await getApprovalCount(params);
// if(res.success == true){
// if(res.data !== null){
// this.countAp = res.data;
// }
// }
// }catch(e){
// console.error(e);
// uni.$u.toast(e.errMsg,5000);
// var request = e.config!=undefined?JSON.stringify(e.config):"";
// var response = e.data!=undefined?JSON.stringify(e.data):"";
// await this.writeLog(this.effectiveUserData.userId,"find_player","","[APP][findPlayer.vue][getProfileByPlayerId][Catch Exception]"+e.errMsg,request,response,1,false);
// }finally{
// uni.hideLoading();
// }
// },
// 界面方法
confirmMsg(){
this.msgStr = '';
this.showMsg = false;
},
toNotification(){
this.navTo(this.buildNotificationUrl(['tab=1']),0,false)
},
clearSearchInput(){
this.searchPlayerId = '';
uni.removeStorageSync("playerData");
},
initUI() {
this.deviceData = uni.getStorageSync("deviceData");
},
logoutWithADFSApp() {
var wv = plus.webview.create(ADFS_LOGOUT_URL,'IDP');
wv.show();
},
},
computed: {
effectiveUserData() {
return this.getEffectiveUserData(this.userData);
},
showNotificationBell() {
return !!(
this.effectiveUserData &&
(this.effectiveUserData.canViewApproval === true ||
this.effectiveUserData.canViewNotification === true)
);
},
notificationBadgeText() {
if (this.notificationCount > 99) {
return '99+';
}
return String(this.notificationCount);
}
}
}
</script>
<style>
.u-border {
border-width: 0.5px !important;
border-color: #434343 !important;
border-style: solid;
height:30px;
}
.notification-bell-wrap {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
margin-top: 2px;
margin-left: 3px;
width: 24px;
height: 24px;
overflow: visible;
}
.notification-badge {
position: absolute;
top: -4px;
right: -5px;
min-width: 16px;
height: 16px;
padding: 0 4px;
border-radius: 8px;
background-color: #fa3534;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
z-index: 10;
}
.notification-badge-text {
color: #ffffff;
font-size: 10px;
line-height: 1;
font-weight: bold;
}
</style>