import { addPlanFile, addPlanItem, deletePlanItem, editPlanItem, getPlanItem, getPlanList, GetPlanListParams, PlanFilePatams, PlanItemDetail, PlanItemParams, PlanListResponse, } from '@/api/plan'; import { ElMessage } from 'element-plus'; import { defineStore } from 'pinia'; export interface IncidentStateType { plans: PlanListResponse; planItemDetail: PlanItemDetail; loading: boolean; } export interface IncidentActionsType { toggleLoading(): void; getPlanList(params: GetPlanListParams): void; getPlanItem(id: string): void; addPlanItem(params: PlanItemParams): Promise; editPlanItem(params: PlanItemParams): Promise; deletePlanItem(id: string): Promise; addPlanFile(params: PlanFilePatams): Promise; } export default defineStore<'plan', IncidentStateType, {}, IncidentActionsType>( 'plan', { state: () => ({ plans: { rows: [], total: 0, }, planItemDetail: {}, loading: false, }), actions: { toggleLoading() { this.loading = !this.loading; }, async getPlanList(params) { try { this.toggleLoading(); this.plans = await getPlanList(params); } finally { this.toggleLoading(); } }, async getPlanItem(id) { try { this.toggleLoading(); const { data } = await getPlanItem(id); if (data) this.planItemDetail = data; } finally { this.toggleLoading(); } }, async addPlanItem(id) { try { this.toggleLoading(); await addPlanItem(id); ElMessage.success({ message: '保存成功' }); return true; } finally { this.toggleLoading(); } }, async editPlanItem(params) { try { this.toggleLoading(); await editPlanItem(params); ElMessage.success({ message: '修改成功' }); return true; } catch { ElMessage.error({ message: '修改失败' }); return false; } finally { this.toggleLoading(); } }, async deletePlanItem(params) { try { this.toggleLoading(); await deletePlanItem(params); ElMessage.success({ message: '删除成功' }); return true; } catch { ElMessage.error({ message: '删除失败' }); return false; } finally { this.toggleLoading(); } }, async addPlanFile(id) { try { await addPlanFile(id); ElMessage.success({ message: '导入成功' }); return true; } finally { } }, }, }, );