353 lines
8.4 KiB
Vue
353 lines
8.4 KiB
Vue
<template>
|
||
<view class="personal-center">
|
||
<view class="status_bar">
|
||
</view>
|
||
<!-- 资料卡 -->
|
||
<view class="profile-card" @click="navigateTo('profile')">
|
||
<u-avatar :src="userInfo.avatar" size="60" mode="aspectFill"></u-avatar>
|
||
<view class="user-info">
|
||
<text class="user-name">{{ userInfo.employees_name }}</text>
|
||
<text class="user-id" @click.stop="showStoreSelector">
|
||
{{ userInfo.store_name }}
|
||
<u-icon style="display:inline-block; margin-left: 10rpx;" name="arrow-right" color="#FFF" size="12" v-if="userInfo.employees.length > 1"></u-icon>
|
||
</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 操作列表 - 使用数据循环 -->
|
||
<view class="operation-list">
|
||
<u-cell-group :border="false">
|
||
<!-- 使用 v-for 循环渲染列表项 -->
|
||
<u-cell
|
||
v-for="(item, index) in operationList"
|
||
:key="index"
|
||
:title="item.title"
|
||
:icon="item.icon"
|
||
:icon-color="item.iconColor"
|
||
@click="handleOperationClick(item)"
|
||
>
|
||
</u-cell>
|
||
</u-cell-group>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import { goLogin } from '@/core/utils/auth-guard'
|
||
|
||
export default {
|
||
data() {
|
||
return {
|
||
// 用户信息
|
||
userInfo: {},
|
||
|
||
// 操作列表数据
|
||
operationList: [
|
||
{
|
||
title: '问题报障',
|
||
icon: 'order',
|
||
iconColor: '#4cd964',
|
||
pageName: 'problemGuarantee',
|
||
url: '/pages/personal/problemGuarantee',
|
||
needLogin: true
|
||
},
|
||
{
|
||
title: '意见反馈',
|
||
icon: 'email',
|
||
iconColor: '#dd524d',
|
||
pageName: 'feedback',
|
||
url: '/pages/personal/feedback'
|
||
},
|
||
{
|
||
title: '帮助手册',
|
||
icon: 'bookmark',
|
||
iconColor: '#007aff',
|
||
pageName: 'helpManual',
|
||
url: '/pages/personal/helpManual'
|
||
},
|
||
{
|
||
title: '操作信息',
|
||
icon: 'info-circle',
|
||
iconColor: '#f0ad4e',
|
||
pageName: 'operationInfo',
|
||
url: '/pages/personal/operationInfo',
|
||
badge: 3
|
||
},
|
||
{
|
||
title: '网络检测',
|
||
icon: 'wifi',
|
||
iconColor: '#10aeff',
|
||
pageName: 'networkTest',
|
||
url: '/pages/settings/networkTest'
|
||
},
|
||
{
|
||
title: '设置',
|
||
icon: 'setting',
|
||
iconColor: '#808080',
|
||
pageName: 'settings',
|
||
url: '/pages/settings/index'
|
||
}
|
||
],
|
||
|
||
// 当前选中的组织
|
||
currentOrg: null
|
||
}
|
||
},
|
||
onLoad() {
|
||
// 页面显示时更新数据
|
||
this.loadUserInfo();
|
||
},
|
||
onShow() {
|
||
// 页面显示时更新数据
|
||
this.loadUserInfo();
|
||
},
|
||
methods: {
|
||
// 加载用户信息
|
||
async loadUserInfo() {
|
||
if(!this.$store.getters.user){
|
||
setTimeout(() => this.loadUserInfo(), 100);
|
||
}
|
||
this.userInfo = this.$store.getters.user;
|
||
this.updateBadgeCount();
|
||
this.loadCurrentOrg();
|
||
},
|
||
|
||
// 从缓存加载当前组织
|
||
loadCurrentOrg() {
|
||
const savedOrg = uni.getStorageSync('pda_current_org');
|
||
if (savedOrg) {
|
||
this.currentOrg = savedOrg;
|
||
}
|
||
},
|
||
|
||
// 显示店铺选择器 - 使用 ActionSheet
|
||
showStoreSelector() {
|
||
// 从 userInfo.employees 生成选项列表
|
||
if (!this.userInfo.employees || this.userInfo.employees.length <= 1) {
|
||
return;
|
||
}
|
||
|
||
// 提取店铺名称列表
|
||
const storeList = this.userInfo.employees.map(emp => emp.store_name);
|
||
|
||
uni.showActionSheet({
|
||
itemList: storeList,
|
||
success: (res) => {
|
||
const selectedIndex = res.tapIndex;
|
||
if (selectedIndex >= 0 && selectedIndex < this.userInfo.employees.length) {
|
||
const selectedEmployee = this.userInfo.employees[selectedIndex];
|
||
this.handleStoreSwitch(selectedEmployee);
|
||
}
|
||
},
|
||
fail: (err) => {
|
||
console.log('用户取消选择', err);
|
||
}
|
||
});
|
||
},
|
||
|
||
// 处理店铺切换
|
||
async handleStoreSwitch(selectedEmployee) {
|
||
try {
|
||
// 显示加载中
|
||
uni.showLoading({
|
||
title: '切换中...',
|
||
mask: true
|
||
});
|
||
|
||
// 调用 store 的 action 切换员工
|
||
const result = await this.$store.dispatch('changeEmployee', selectedEmployee.id);
|
||
this.loadUserInfo();
|
||
|
||
} catch (error) {
|
||
console.error('切换失败:', error);
|
||
|
||
// 隐藏加载提示
|
||
uni.hideLoading();
|
||
|
||
// 显示错误提示
|
||
uni.showToast({
|
||
title: '切换失败,请重试',
|
||
icon: 'error',
|
||
duration: 2000
|
||
});
|
||
}
|
||
},
|
||
|
||
// 切换主体的函数(您需要实现的API函数)
|
||
async switchStore(employeeId) {
|
||
console.log('开始切换到员工ID:', employeeId);
|
||
|
||
// 这里调用您的后端API
|
||
// 示例:
|
||
// try {
|
||
// const response = await this.$api.store.switch({ employee_id: employeeId });
|
||
// return response.success || response.code === 200;
|
||
// } catch (error) {
|
||
// throw error;
|
||
// }
|
||
|
||
// 模拟API调用
|
||
return new Promise((resolve, reject) => {
|
||
setTimeout(() => {
|
||
console.log(`API: 已切换到员工ID: ${employeeId}`);
|
||
// 模拟成功
|
||
resolve(true);
|
||
|
||
// 如果需要模拟失败
|
||
// reject(new Error('切换失败'));
|
||
}, 800);
|
||
});
|
||
},
|
||
|
||
// 更新 store 中的用户信息
|
||
async updateStoreUserInfo(selectedEmployee) {
|
||
// 方法1: 调用 store 的 action
|
||
// await this.$store.dispatch('updateCurrentStore', selectedEmployee);
|
||
|
||
// 方法2: 直接更新(如果有相应 mutation)
|
||
// this.$store.commit('SET_CURRENT_STORE', selectedEmployee);
|
||
|
||
// 方法3: 更新本地用户信息对象
|
||
const updatedUser = {
|
||
...this.$store.getters.user,
|
||
store_name: selectedEmployee.store_name,
|
||
store_id: selectedEmployee.store_id,
|
||
current_employee_id: selectedEmployee.id
|
||
};
|
||
|
||
// 如果您有相应的 mutation
|
||
// this.$store.commit('UPDATE_USER_INFO', updatedUser);
|
||
|
||
console.log('更新用户信息为:', updatedUser);
|
||
},
|
||
|
||
// 重新加载页面数据(可选)
|
||
reloadPageData() {
|
||
console.log('重新加载页面数据...');
|
||
// 这里可以调用其他需要重新加载数据的方法
|
||
// 例如:this.loadOrders();
|
||
// this.loadStatistics();
|
||
},
|
||
|
||
// 其他方法保持不变...
|
||
updateBadgeCount() {
|
||
const unreadCount = 3;
|
||
this.operationList.forEach(item => {
|
||
if (item.pageName === 'operationInfo') {
|
||
item.badge = unreadCount;
|
||
}
|
||
});
|
||
},
|
||
|
||
handleOperationClick(item) {
|
||
console.log('点击了:', item.title);
|
||
|
||
if (item.needLogin && !this.checkLogin()) {
|
||
uni.showToast({
|
||
title: '请先登录',
|
||
icon: 'none'
|
||
});
|
||
goLogin();
|
||
return;
|
||
}
|
||
|
||
this.navigateTo(item.pageName, item.url);
|
||
},
|
||
|
||
checkLogin() {
|
||
const token = uni.getStorageSync('token');
|
||
return !!token;
|
||
},
|
||
|
||
navigateTo(pageName, customUrl = null) {
|
||
const routeMap = {
|
||
profile: '/pages/personal/profile',
|
||
problemGuarantee: '/pages/personal/problemGuarantee',
|
||
feedback: '/pages/personal/feedback',
|
||
helpManual: '/pages/personal/helpManual',
|
||
operationInfo: '/pages/personal/operationInfo',
|
||
networkTest: '/pages/personal/networkTest',
|
||
settings: '/pages/personal/settings'
|
||
};
|
||
|
||
const url = customUrl || routeMap[pageName];
|
||
|
||
if (!url) {
|
||
console.error('未找到页面路由:', pageName);
|
||
uni.showToast({
|
||
title: '页面不存在',
|
||
icon: 'error'
|
||
});
|
||
return;
|
||
}
|
||
|
||
console.log('跳转到:', url);
|
||
uni.navigateTo({
|
||
url: url,
|
||
fail: (err) => {
|
||
console.error('跳转失败:', err);
|
||
uni.showToast({
|
||
title: '页面跳转失败',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.personal-center {
|
||
background-color: #f8f8f8;
|
||
|
||
// 资料卡样式
|
||
.profile-card {
|
||
display: flex;
|
||
align-items: center;
|
||
padding: 40rpx 30rpx;
|
||
background: linear-gradient(135deg, #4cd964, #5ac8fa);
|
||
color: #fff;
|
||
position: relative;
|
||
|
||
.user-info {
|
||
flex: 1;
|
||
margin-left: 30rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
|
||
.user-name {
|
||
font-size: 36rpx;
|
||
font-weight: bold;
|
||
margin-bottom: 10rpx;
|
||
}
|
||
|
||
.user-id {
|
||
font-size: 30rpx;
|
||
opacity: 0.9;
|
||
margin-top: 8rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
|
||
&:active {
|
||
opacity: 0.7;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 操作列表样式
|
||
.operation-list {
|
||
margin-top: 20rpx;
|
||
background-color: #fff;
|
||
|
||
::v-deep .u-cell {
|
||
padding: 10rpx 20rpx !important;
|
||
}
|
||
|
||
::v-deep .u-cell_title {
|
||
font-size: 32rpx !important;
|
||
}
|
||
}
|
||
}
|
||
</style> |