Files
lehuo/apps/miniprogram/miniprogram/pages/application-success/application-success.ts
T

62 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { ServiceApplicationDetail } from '@lehuo/contracts';
import { MiniProgramApiError } from '../../services/api-client';
import { fetchServiceApplication } from '../../services/service-applications';
import { formatChinaDateTime } from '../../utils/date';
type DisplayApplication = ServiceApplicationDetail & { submittedAtText: string };
Page({
data: {
loading: true,
errorMessage: '',
publicId: '',
application: null as DisplayApplication | null,
},
onLoad(options: Record<string, string | undefined>) {
this.setData({ publicId: options.publicId ?? '' });
void this.loadApplication();
},
async loadApplication() {
if (!this.data.publicId) {
this.setData({ loading: false, errorMessage: '帮扶信息不完整,请前往“我的帮扶服务”查看' });
return;
}
this.setData({ loading: true, errorMessage: '' });
try {
const result = await fetchServiceApplication(this.data.publicId);
this.setData({
application: {
...result.application,
submittedAtText: formatChinaDateTime(result.application.submittedAt),
},
loading: false,
});
} catch (error) {
const message =
error instanceof MiniProgramApiError && error.requestId
? `${error.message}(编号:${error.requestId})`
: error instanceof Error
? error.message
: '暂时无法读取帮扶信息';
this.setData({ loading: false, errorMessage: message });
}
},
retryLoad() {
void this.loadApplication();
},
viewProgress() {
void wx.redirectTo({
url: `/pages/application-detail/application-detail?publicId=${encodeURIComponent(this.data.publicId)}`,
});
},
backHome() {
void wx.reLaunch({ url: '/pages/index/index' });
},
});