diff --git a/src/api/user.js b/src/api/user.js index 33687dce..9bd81a1c 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -256,6 +256,11 @@ export function postCertification(payload) { return api.post(url, payload, { validateStatus: s => s === 201 }); } +export function patchCertification(payload) { + const url = "/user/certification"; + return api.patch(url, payload, { validateStatus: s => s === 201 }); +} + /** * 获取用户认证信息 * @author mutoe diff --git a/src/page/profile/Certificate.vue b/src/page/profile/Certificate.vue index f9923b32..477c3700 100644 --- a/src/page/profile/Certificate.vue +++ b/src/page/profile/Certificate.vue @@ -173,7 +173,7 @@ import ContentText from "@/page/post/components/ContentText.vue"; import ImagePoster from "@/components/ImagePoster.vue"; -import { postCertification } from "@/api/user.js"; +import * as api from "@/api/user.js"; const formInfo = { user: { @@ -203,6 +203,7 @@ export default { loading: false, step: 1, formInfo, + status: 0, // 认证状态 fields: { name: "", number: "", @@ -225,8 +226,15 @@ export default { * 认证类型. 必须是 (user|org) * @returns {string} */ - type() { + type: { + get() { return this.$route.query.type || "user"; + }, + set(val) { + const { path, query } = this.$route; + query.type = val; + this.$router.push({ path, query }); + } }, /** * 待提交表单 @@ -294,15 +302,24 @@ export default { }, mounted() { this.$store.dispatch("FETCH_USER_VERIFY").then(data => { - this.formData = data.data; + this.formData = data.data || {}; + this.type = data.certification_name; + this.status = data.status; }); }, methods: { onSubmit() { - postCertification(this.formData).then(({ data: { message } }) => { - this.$Message.success(message || "提交成功,请等待审核"); + if (this.status === 0) { + api.postCertification(this.formData).then(() => { + this.$Message.success("提交成功,请等待审核"); this.goBack(); }); + } else { + api.patchCertification(this.formData).then(() => { + this.$Message.success("提交成功,请等待审核"); + this.goBack(); + }); + } }, uploaded1(poster) { this.$set(this.fields.files, 0, poster.id);