import Pagination from '@/components/pagination' import { NButton, NDataTable, NDatePicker, NFormItem, NInput, NModal, NSelect, NSpace, NTag, useDialog, useMessage } from 'naive-ui' import { defineComponent, onMounted, reactive, ref } from 'vue' import SaveForm from '@components/save-form' import { musicalInstrumentPage, musicalInstrumentUpdateStatus } from '@views/system-manage/subject-manage/api' import { getMapValueByKey } from '@/utils/filters' import { defaultScore } from '@/utils/constant' import { getSelectDataFromObj } from '@/utils/objectUtil' import InstrumentSave from '@views/system-manage/subject-manage/instrument/modal/instrument-save' import { filterTimes } from '@/utils/dateUtil' export default defineComponent({ name: 'instrument-list', setup() { const dialog = useDialog() const message = useMessage() const state = reactive({ loading: false, pagination: { page: 1, rows: 10, pageTotal: 0 }, searchForm: { keyword: '', timer: null, startTime: null, endTime: null, defaultScore: null, //默认谱面 code: null, //编码 operatorKeyword: null //操作人 }, dataList: [] as any, showSave: false, saveMode: 'add', rowData: {} }) const saveForm = ref() const onSubmit = () => { state.pagination.page = 1 getList() } const onSearch = () => { saveForm.value?.submit() } const onChangeStatus = (row: any) => { const statusStr = row.enableFlag ? '停用' : '启用' dialog.warning({ title: '提示', content: `是否${statusStr}?`, positiveText: '确定', negativeText: '取消', onPositiveClick: async () => { try { await musicalInstrumentUpdateStatus({ id: row.id }) getList() message.success(`${statusStr}成功`) } catch {} } }) } const onBtnReset = () => { saveForm.value?.reset() } const columns = () => { return [ { title: '编号', key: 'id' }, { title: '乐器名称', key: 'name' }, { title: '乐器编码', key: 'code' }, { title: '声部', key: 'subjectName' }, { title: '默认谱面', key: 'defaultScore', render(row: any) { return getMapValueByKey(row.defaultScore, new Map(Object.entries(defaultScore))) } }, { title: '操作人', key: 'operator', render(row: any) { return (
{row.operatorName}
{row.updateTime}
) } }, { title: '状态', key: 'enableFlag', render(row: any) { return ( {row.enableFlag ? '启用' : '停用'} ) } }, { title: '操作', key: 'operation', render(row: any) { return ( { state.rowData = row state.showSave = true state.saveMode = 'edit' }} > 修改 onChangeStatus(row)} > {row.enableFlag ? '停用' : '启用'} ) } } ] } const getList = async () => { try { state.loading = true const { data } = await musicalInstrumentPage({ ...state.pagination, ...state.searchForm, ...filterTimes(state.searchForm.timer, ['startTime', 'endTime']) }) state.loading = false state.pagination.pageTotal = Number(data.total) state.dataList = data.rows || [] } catch { state.loading = false } } onMounted(() => { getList() }) return () => (
Object.assign(state.searchForm, val)} saveKey="instrument-list" > 搜索 重置 { state.rowData = {} state.showSave = true state.saveMode = 'add' }} > 添加 row.id} >
(state.showSave = false)} onGetList={getList} />
) } })