ykt-wxapp/store/team.js

51 lines
1.7 KiB
JavaScript
Raw Normal View History

2026-02-02 08:52:42 +08:00
import { computed, ref } from "vue";
2026-01-29 10:45:50 +08:00
import { defineStore, storeToRefs } from "pinia";
import api from '@/utils/api';
import { toast } from '@/utils/widget';
import useAccountStore from "./account";
export default defineStore("teamStore", () => {
const { account, doctorInfo } = storeToRefs(useAccountStore());
const teams = ref([]);
2026-02-02 08:52:42 +08:00
const chargeTeams = computed(() => {
const userid = doctorInfo.value?.userid;
return teams.value.filter(team => {
const memberLeaderList = Array.isArray(team.memberLeaderList) ? team.memberLeaderList : [];
return memberLeaderList.includes(userid);
});
})
2026-01-29 10:45:50 +08:00
async function getTeam(teamId) {
if (!teamId || !account.value?.corpId) return;
const res = await api('getTeamData', { teamId, corpId: account.value.corpId });
if (res && res.data) {
return res.data;
} else {
toast(res?.message || '获取团队信息失败')
}
}
async function getTeams() {
const corpId = account.value?.corpId;
2026-01-30 10:26:11 +08:00
const mateId = doctorInfo.value?.userid;
2026-01-29 10:45:50 +08:00
if (!corpId || !mateId) return;
const res = await api('getJoinedTeams', { corpId, mateId });
teams.value = res && Array.isArray(res.data) ? res.data : [];
}
2026-02-03 14:21:50 +08:00
// 获取团队成员头像和名称映射
2026-02-03 14:17:37 +08:00
async function getTeamMemberAvatarsAndName(teamId) {
2026-02-02 14:12:46 +08:00
if (!teamId || !account.value?.corpId) return {};
2026-02-03 14:17:37 +08:00
const res = await api('getTeamMemberAvatarsAndName', {
teamId,
corpId: account.value.corpId
2026-02-02 14:12:46 +08:00
});
if (res && res.success && res.data) {
2026-02-03 14:21:50 +08:00
return res.data; // 返回 { userId: { avatar: "url", name: "医生名称" } } 的映射对象
2026-02-02 14:12:46 +08:00
}
return {};
}
2026-02-03 14:17:37 +08:00
return { teams, chargeTeams, getTeam, getTeams, getTeamMemberAvatarsAndName }
2026-01-29 10:45:50 +08:00
})