import {NButton, NForm, NFormItem, NInput, NSelect, NSpace, useMessage} from 'naive-ui' import {defineComponent, onMounted, PropType, reactive, ref} from 'vue' import {subjectUpdate, subjectSave} from "@views/system-manage/subject-manage/api"; import UploadFile from "@components/upload-file"; export default defineComponent({ name: 'role-operation', props: { type: { type: String, default: 'add' }, data: { type: Object as PropType, default: () => { } }, categoryList: { type: Object as PropType, default: () => [] }, instrumentList: { type: Object as PropType, default: () => [] } }, emits: ['close', 'getList'], setup(props, {slots, attrs, emit}) { const state = reactive({ forms: { categoryId: null, name: null, img: null, musicalInstrumentIds: [], }, rowData: {}, categoryList: [], instrumentList: [], }) const btnLoading = ref(false) const formsRef = ref() const message = useMessage() const onSubmit = async () => { formsRef.value.validate(async (error: any) => { if (error) return false try { btnLoading.value = true if (props.type === 'add') { const params: any = { ...state.forms, musicalInstrumentIds: state.forms.musicalInstrumentIds?.join(',') || '' } await subjectSave(params) message.success('添加成功') } else if (props.type === 'edit') { const params: any = { ...state.forms, musicalInstrumentIds: state.forms.musicalInstrumentIds?.join(',') || '', id: props.data.id } await subjectUpdate(params) message.success('修改成功') } emit('close') emit('getList') } catch { } btnLoading.value = false }) } onMounted(async () => { if (props.type === 'edit') { const data = props.data state.forms.categoryId = data.categoryId state.forms.name = data.name state.forms.img = data.img state.forms.musicalInstrumentIds = data.musicalInstrumentIds?.split(',') || []; } console.log("pca", props.categoryList) props.categoryList.forEach((next: any) => { next.disabled = !next.enableFlag }) props.instrumentList.forEach((next: any) => { next.disabled = !next.enableFlag }) }) return () => (
emit('close')}> 取消 onSubmit()} loading={btnLoading.value}> 保存
) } })