Files
danyang-match/miniapp/pages/service-program/service-program.js
T

65 lines
1.9 KiB
JavaScript
Raw Normal View History

/**
* U61 专项公益服务介绍
*
* Phase 19:此前项目文案写死、申请只弹说明(无任何后端交互)。
* 现接入 GET /service-programs + POST /service-programs/{id}/apply。
*
* 边界:项目成员身份只用于服务办理,**不得**成为用户价值标签;
* 项目主办/协作关系也不会自动获得用户资料访问权限。
*/
const { serviceProgramService } = require('../../services');
const STATUS_LABEL = {
draft: '筹备中',
active: '进行中',
ended: '已结束',
cancelled: '已取消',
};
Page({
data: {
loading: true,
error: '',
programs: [],
},
onShow() {
this.load();
},
async load() {
this.setData({ loading: true, error: '' });
try {
const list = await serviceProgramService.getPrograms();
const programs = (list || []).map((item) => ({
id: item.id,
name: item.name,
description: item.description || '',
status: STATUS_LABEL[item.status] || item.status || '',
applicable: item.status === 'active' || item.status === 'draft',
}));
this.setData({ programs, loading: false });
} catch (error) {
this.setData({ loading: false, error: '加载失败,请稍后重试' });
}
},
apply(event) {
const id = event.currentTarget.dataset.id;
wx.showModal({
title: '申请说明',
content: '请先完成基本资料,符合项目条件后工作人员会与你联系。',
confirmText: '提交申请',
success: async (res) => {
if (!res.confirm) {
return;
}
try {
await serviceProgramService.applyToProgram(id);
wx.showToast({ title: '申请已提交', icon: 'success' });
this.load();
} catch (error) {
wx.showToast({ title: '申请失败,请稍后重试', icon: 'none' });
}
},
});
},
});