import { NButton, NDataTable, NModal, NSpace, NTag, useDialog, useMessage } from 'naive-ui' import { defineComponent, onMounted, reactive } from 'vue' import CategorizeSave from '@views/system-manage/subject-manage/subject-categorize/modal/categorize-save' import { subjectCategoryPage, subjectCategoryUpdateStatus } from '@views/system-manage/subject-manage/api' import { getTimes } from '@/utils/dateUtil' import Pagination from '@components/pagination' export default defineComponent({ name: 'category-list', setup() { const dialog = useDialog() const message = useMessage() const state = reactive({ loading: false, pagination: { page: 1, rows: 10, pageTotal: 0 }, dataList: [] as any, saveMode: 'add', showSaveDialog: false, rowData: {} }) const searchForm = reactive({ keyword: '', times: null as any, operatorKeyword: '' //创建人 }) const columns = (): any => { return [ { title: '分类编号', key: 'id' }, { title: '分类名称', key: 'name' }, { title: '操作人', key: 'operator', render(row: any) { return (
{row.operatorName}
{row.updateTime}
) } }, { title: '操作', key: 'operation', fixed: 'right', width: 180, render(row: any) { return ( { state.saveMode = 'edit' state.showSaveDialog = true state.rowData = row }} > 修改 ) } } ] } const getList = async () => { try { state.loading = true const { times, ...reset } = searchForm const body = { ...reset, ...getTimes(times, ['startTime', 'endTime']), page: state.pagination.page, rows: state.pagination.rows } const { data } = await subjectCategoryPage(body) state.loading = false state.pagination.pageTotal = Number(data.total) state.dataList = data.rows || [] } catch { state.loading = false } } const onChangeStatus = (row: any) => { const statusStr = row.enableFlag ? '停用' : '启用' dialog.warning({ title: '警告', content: `是否${statusStr}?`, positiveText: '确定', negativeText: '取消', onPositiveClick: async () => { try { await subjectCategoryUpdateStatus({ id: row.id }) getList() message.success(`${statusStr}成功`) } catch {} } }) } onMounted(() => { getList() }) return () => (
{ state.saveMode = 'add' state.showSaveDialog = true }} disabled={state.loading} > 添加 row.id} >
(state.showSaveDialog = false)} onGetList={getList} />
) } })