|
|
@@ -105,7 +105,7 @@
|
|
|
<script setup lang="ts">
|
|
|
import { computed, ref } from 'vue'
|
|
|
|
|
|
-import { onLoad } from '@dcloudio/uni-app'
|
|
|
+import { onLoad, onShow } from '@dcloudio/uni-app'
|
|
|
|
|
|
import {
|
|
|
batchChannelCertApi,
|
|
|
@@ -200,7 +200,11 @@ const showSubmit = computed(() => {
|
|
|
})
|
|
|
|
|
|
const canSubmit = computed(() => {
|
|
|
- return Boolean(selectedChannel.value?.selectable) && !isSubmitting.value
|
|
|
+ return (
|
|
|
+ Boolean(selectedChannel.value?.selectable) &&
|
|
|
+ !isSubmitting.value &&
|
|
|
+ !settlementSignStore.processingSignTraceId
|
|
|
+ )
|
|
|
})
|
|
|
|
|
|
const showToast = (title: string): void => {
|
|
|
@@ -239,7 +243,10 @@ const findCertItem = (subjectLocation: string): CertItem | undefined => {
|
|
|
const isSelectableChannel = (certItem?: CertItem): boolean => {
|
|
|
if (!certItem) return true
|
|
|
|
|
|
- return SELECTABLE_CERT_STATUS.has(certItem.commonCertStatus ?? '')
|
|
|
+ return (
|
|
|
+ SELECTABLE_CERT_STATUS.has(certItem.commonCertStatus ?? '') ||
|
|
|
+ (certItem.commonCertStatus === 'SIGN' && certItem.needContinue === true)
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
const getCertStatusText = (certItem?: CertItem): string => {
|
|
|
@@ -438,24 +445,35 @@ const certFn = async (): Promise<void> => {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ const userInfo = await userStore.getUserInfoByCode()
|
|
|
+ if (!userInfo?.userId || !userInfo.certToken) {
|
|
|
+ showToast('认证信息获取失败,请重试')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
const accountInfo = wx.getAccountInfoSync()
|
|
|
const appId = accountInfo.miniProgram.appId
|
|
|
+ const context = settlementSignStore.createContext(subjectLocation)
|
|
|
|
|
|
const signRedirectUrl = `/pages-auth/settlement-channel-sign/index?subjectLocationByUrl=${encodeURIComponent(
|
|
|
subjectLocation
|
|
|
- )}`
|
|
|
+ )}&signTraceId=${encodeURIComponent(context.signTraceId)}`
|
|
|
|
|
|
const data = {
|
|
|
- userId: currentUserInfo.value?.userId || '',
|
|
|
+ userId: userInfo.userId,
|
|
|
subjectLocation,
|
|
|
- token: currentUserInfo.value?.certToken || '',
|
|
|
+ token: userInfo.certToken,
|
|
|
signRedirectUrl,
|
|
|
wxMiniAppId: appId,
|
|
|
}
|
|
|
|
|
|
- const res = await batchChannelCertApi(data)
|
|
|
+ const res = await batchChannelCertApi(data).catch((error) => {
|
|
|
+ settlementSignStore.clearContext(context.signTraceId)
|
|
|
+ throw error
|
|
|
+ })
|
|
|
|
|
|
if (res.code === 0 && res.data?.errMsg) {
|
|
|
+ settlementSignStore.clearContext(context.signTraceId)
|
|
|
authErrorMessage.value = res.data.errMsg
|
|
|
authErrorDialogVisible.value = true
|
|
|
isSubmitting.value = false
|
|
|
@@ -463,6 +481,7 @@ const certFn = async (): Promise<void> => {
|
|
|
}
|
|
|
|
|
|
if (res.data.commonCertStatus === 'FAIL_SIGN') {
|
|
|
+ settlementSignStore.clearContext(context.signTraceId)
|
|
|
showToast(res.msg || res.data.errMsg || '签约失败')
|
|
|
return
|
|
|
}
|
|
|
@@ -470,14 +489,16 @@ const certFn = async (): Promise<void> => {
|
|
|
const h5SignUrl = res.data?.h5SignUrl
|
|
|
|
|
|
if (h5SignUrl) {
|
|
|
- const context = settlementSignStore.createContext(subjectLocation)
|
|
|
-
|
|
|
uni.navigateTo({
|
|
|
url: `/pages-auth/web-view/index?url=${encodeURIComponent(
|
|
|
h5SignUrl
|
|
|
)}&subjectLocation=${encodeURIComponent(
|
|
|
subjectLocation
|
|
|
)}&signTraceId=${encodeURIComponent(context.signTraceId)}`,
|
|
|
+ fail: () => {
|
|
|
+ settlementSignStore.clearContext(context.signTraceId)
|
|
|
+ showToast('签约页面打开失败,请重试')
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
return
|
|
|
@@ -486,37 +507,66 @@ const certFn = async (): Promise<void> => {
|
|
|
await handleCertSuccess()
|
|
|
}
|
|
|
|
|
|
-const signRedirect = async (subjectLocation: string): Promise<boolean> => {
|
|
|
+const signRedirect = async (subjectLocation: string, signTraceId = ''): Promise<boolean> => {
|
|
|
if (!subjectLocation) {
|
|
|
showToast('参数异常')
|
|
|
return false
|
|
|
}
|
|
|
+
|
|
|
+ if (!settlementSignStore.beginSignRedirect(subjectLocation, signTraceId)) return false
|
|
|
+
|
|
|
+ isSubmitting.value = true
|
|
|
+
|
|
|
try {
|
|
|
- await signRedirectApi({
|
|
|
+ await userStore.getUserInfoByCode()
|
|
|
+
|
|
|
+ const res = await signRedirectApi({
|
|
|
subjectLocation,
|
|
|
})
|
|
|
- settlementSignStore.clearContext()
|
|
|
- uni.showToast({
|
|
|
- title: '签约成功',
|
|
|
- icon: 'success',
|
|
|
- })
|
|
|
+
|
|
|
+ if (res.data?.commonCertStatus === 'SIGN' && res.data.needContinue === true) {
|
|
|
+ selectedSubjectLocation.value = subjectLocation
|
|
|
+ await certFn()
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ if (SELECTABLE_CERT_STATUS.has(res.data?.commonCertStatus ?? '')) {
|
|
|
+ settlementSignStore.clearContext()
|
|
|
+ await userStore.getUserInfoByCode()
|
|
|
+ showToast(res.data.commonCertStatus === 'FAIL_SIGN' ? '签约失败,请重试' : '签约尚未完成')
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ await handleCertSuccess()
|
|
|
return true
|
|
|
} catch (error) {
|
|
|
console.error('signRedirect error:', error)
|
|
|
return false
|
|
|
+ } finally {
|
|
|
+ settlementSignStore.finishSignRedirect()
|
|
|
+ isSubmitting.value = false
|
|
|
}
|
|
|
}
|
|
|
|
|
|
onLoad(async (query) => {
|
|
|
const subjectLocation = query?.subjectLocationByUrl?.trim() || ''
|
|
|
+ const signTraceId = query?.signTraceId?.trim() || ''
|
|
|
|
|
|
if (subjectLocation) {
|
|
|
- await signRedirect(subjectLocation)
|
|
|
+ await signRedirect(subjectLocation, signTraceId)
|
|
|
+ } else {
|
|
|
+ await userStore.getUserInfoByCode()
|
|
|
}
|
|
|
|
|
|
- await userStore.getUserInfoByCode()
|
|
|
await getSubjectLocationDict()
|
|
|
})
|
|
|
+
|
|
|
+onShow(() => {
|
|
|
+ const context = settlementSignStore.returnedContext
|
|
|
+ if (!context) return
|
|
|
+
|
|
|
+ void signRedirect(context.subjectLocation, context.signTraceId)
|
|
|
+})
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|