| | |
| | | }; |
| | | |
| | | if (row.id) { |
| | | // 编辑模式 - 先删除再添加(因为只有 add 和 del 接口) |
| | | delNoticeType(row.id).then(res => { |
| | | // 编辑模式 - 传入id |
| | | data.id = row.id; |
| | | } |
| | | |
| | | addNoticeType(data).then(res => { |
| | | if (res.code === 200) { |
| | | addNoticeType(data).then(addRes => { |
| | | if (addRes.code === 200) { |
| | | ElMessage.success('编辑成功'); |
| | | ElMessage.success(row.id ? '编辑成功' : '新增成功'); |
| | | row.editing = false; |
| | | delete row.originalNoticeType; |
| | | fetchNoticeTypeList().then(() => { |
| | | // 如果当前选中的类型被编辑,需要重新获取数据 |
| | | if (activeNoticeTypeTab.value === String(row.id)) { |
| | | fetchNoticesByType(addRes.data?.id || row.id); |
| | | if (row.id && activeNoticeTypeTab.value === String(row.id)) { |
| | | fetchNoticesByType(res.data?.id || row.id); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } else { |
| | | // 新增模式 |
| | | addNoticeType(data).then(res => { |
| | | if (res.code === 200) { |
| | | ElMessage.success('新增成功'); |
| | | row.editing = false; |
| | | fetchNoticeTypeList(); |
| | | } |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | const handleDeleteNoticeType = (row) => { |