zhengyiming
2025-02-10 0f686ea1fe4700a909a6159efcf1fcb0e1f88a17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<template>
  <PageLayout title="" class="toggleMatchMakingIdentity-page-wrapper" :need-auth="false">
    <ContentScrollView class="toggleMatchMakingIdentity-page-scroll-view">
      <img :src="OssAssets.setting.ToggleBg" class="toggleMatchMakingIdentity-page-bg" />
      <div class="toggleMatchMakingIdentity-page-title">
        您的当前身份为“{{ MatchMakingIdentityEnumText[matchMakingIdentity] }}”
      </div>
      <PageFooterBtn type="primary" class="toggleMatchMakingIdentity-page-btn" @click="handleSet"
        >切换为“{{ MatchMakingIdentityEnumText[toggledMatchMakingIdentity] }}”身份</PageFooterBtn
      >
      <PageFooterBtn class="toggleMatchMakingIdentity-page-btn cancel" @click="goBack"
        >暂不切换</PageFooterBtn
      >
    </ContentScrollView>
  </PageLayout>
</template>
 
<script setup lang="ts">
import { MatchMakingIdentityEnumText, MatchMakingIdentityEnum } from '@12333/constants';
import { useUser } from '@/hooks';
import Taro from '@tarojs/taro';
import { goBack, setMatchMakingIdentity } from '@/utils';
import { useUserStore } from '@/stores/modules/user';
import { Message } from '@12333/utils';
import { OssAssets } from '@/constants';
 
defineOptions({
  name: 'toggleMatchMakingIdentity',
});
 
const { matchMakingIdentity, userDetail, isSetMatchMakingIdentity } = useUser();
const userStore = useUserStore();
 
onMounted(() => {
  if (!isSetMatchMakingIdentity.value) {
    setMatchMakingIdentity(matchMakingIdentity.value);
    userStore.isSetMatchMakingIdentity = true;
  }
});
 
const toggledMatchMakingIdentity = computed(() =>
  matchMakingIdentity.value === MatchMakingIdentityEnum.Contributors
    ? MatchMakingIdentityEnum.Employing
    : MatchMakingIdentityEnum.Contributors
);
 
async function handleSet() {
  try {
    let res = await userStore.setMatchMakingIdentity({
      matchMakingIdentity: toggledMatchMakingIdentity.value,
      userId: userDetail.value?.userId,
    });
    if (res) {
      Message.success('切换成功', {
        onClosed: () => {
          goBack();
        },
      });
    }
  } catch (error) {}
}
</script>
 
<style lang="scss">
@import '@/styles/common.scss';
 
.toggleMatchMakingIdentity-page-wrapper {
  background-color: #fff;
 
  .toggleMatchMakingIdentity-page-scroll-view {
    background-color: #fff;
  }
 
  .toggleMatchMakingIdentity-page-bg {
    margin: 80px auto 60px;
  }
 
  .toggleMatchMakingIdentity-page-title {
    font-weight: bold;
    font-size: 36px;
    color: boleGetCssVar('text-color', 'primary');
    line-height: 50px;
    text-align: center;
    margin-bottom: 60px;
  }
 
  .toggleMatchMakingIdentity-page-btn {
    width: 542px;
    margin: 0 auto 40px;
    display: block;
    font-size: 28px;
 
    &.cancel {
      background: #f8f9fb;
      font-weight: bold;
      color: boleGetCssVar('text-color', 'primary');
    }
  }
}
</style>