liu
5 天以前 fe2d6627b8f1002af7a31b08f6f43bec034d04ee
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<script lang="ts" setup>
import type { UmsMemberProfileApi } from '#/api/ums/member/profile';
 
import { computed, onMounted, ref } from 'vue';
 
import { Page } from '@vben/common-ui';
 
import { Alert, Button, message } from 'ant-design-vue';
 
import { useVbenForm } from '#/adapter/form';
import {
  applyProfileChange,
  getMyLatestChange,
  getMyProfile,
} from '#/api/ums/member/profile';
 
import { useProfileSchema } from './data';
 
defineOptions({ name: 'UmsMemberProfile' });
 
const loading = ref(false);
const submitting = ref(false);
const latestChange = ref<UmsMemberProfileApi.ChangeRecord>();
 
/** 最近一次申请待审核时禁止重复提交 */
const pending = computed(() => latestChange.value?.status === 0);
 
const [Form, formApi] = useVbenForm({
  commonConfig: {
    componentProps: {
      class: 'w-full',
    },
    labelWidth: 130,
  },
  wrapperClass: 'grid-cols-2',
  layout: 'vertical',
  schema: useProfileSchema(),
  showDefaultActions: false,
});
 
/** 只提交允许会员维护的字段 */
async function buildSubmitData(): Promise<UmsMemberProfileApi.ApplyReq> {
  const values = (await formApi.getValues()) as UmsMemberProfileApi.ApplyReq;
  return {
    contactUser: values.contactUser,
    contactPhone: values.contactPhone,
    contactEmail: values.contactEmail,
    workUnit: values.workUnit,
    title: values.title,
    researchDirection: values.researchDirection,
    unitIntro: values.unitIntro,
    legalPerson: values.legalPerson,
    organizationCode: values.organizationCode,
    regionCode: values.regionCode,
    industry: values.industry,
  };
}
 
async function loadData() {
  loading.value = true;
  try {
    const [profile, latest] = await Promise.all([
      getMyProfile(),
      getMyLatestChange(),
    ]);
    latestChange.value = latest ?? undefined;
    await formApi.setValues(
      {
        no: profile.no,
        name: profile.name,
        memberType: profile.memberType,
        contactUser: profile.contactUser,
        contactPhone: profile.contactPhone,
        contactEmail: profile.contactEmail,
        workUnit: profile.workUnit,
        title: profile.title,
        researchDirection: profile.researchDirection,
        unitIntro: profile.unitIntro,
        legalPerson: profile.legalPerson,
        organizationCode: profile.organizationCode,
        regionCode: profile.regionCode,
        industry: profile.industry,
      },
      false,
    );
  } finally {
    loading.value = false;
  }
}
 
async function handleSubmit() {
  const { valid } = await formApi.validate();
  if (!valid) {
    return;
  }
  submitting.value = true;
  try {
    await applyProfileChange(await buildSubmitData());
    message.success('资料变更申请已提交,等待管理员审核');
    await loadData();
  } finally {
    submitting.value = false;
  }
}
 
const latestAlert = computed(() => {
  const latest = latestChange.value;
  if (!latest) {
    return null;
  }
  if (latest.status === 0) {
    return {
      type: 'info' as const,
      message: '资料变更申请审核中',
      description: `提交时间:${latest.createTime || '-'},请等待管理员审核。`,
    };
  }
  if (latest.status === 10) {
    return {
      type: 'success' as const,
      message: '最近一次资料变更已通过',
      description: `审核时间:${latest.auditTime || '-'}`,
    };
  }
  return {
    type: 'error' as const,
    message: '最近一次资料变更被驳回',
    description: `驳回原因:${latest.auditRemark || '-'};审核时间:${latest.auditTime || '-'}`,
  };
});
 
onMounted(loadData);
</script>
 
<template>
  <Page auto-content-height>
    <div class="mx-auto max-w-5xl p-4">
      <div class="mb-4 rounded-lg border border-border bg-background p-4">
        <div class="mb-1 text-base font-semibold">我的资料</div>
        <div class="text-sm text-gray-500">
          修改联系方式等资料后提交,管理员审核通过后生效;审核期间不可重复提交。
        </div>
      </div>
 
      <Alert
        v-if="latestAlert"
        class="mb-4"
        :type="latestAlert.type"
        show-icon
        :message="latestAlert.message"
        :description="latestAlert.description"
      />
 
      <div class="rounded-lg border border-border bg-background p-4">
        <Form class="mx-3" />
        <div class="mt-4 flex justify-end">
          <Button
            type="primary"
            :loading="submitting || loading"
            :disabled="pending"
            @click="handleSubmit"
          >
            {{ pending ? '审核中,暂不可提交' : '提交审核' }}
          </Button>
        </div>
      </div>
    </div>
  </Page>
</template>