import { defineComponent, h, onMounted, reactive, ref } from 'vue'
import SaveForm from '@components/save-form'
import {
DataTableColumns,
DataTableRowKey,
NButton,
NCascader,
NDataTable,
NFormItem,
NIcon,
NImage,
NInput,
NInputNumber,
NSelect,
NSpace,
NStep,
NSteps,
useDialog,
useMessage
} from 'naive-ui'
import Pagination from '@components/pagination'
import { getMapValueByKey, getSelectDataFromObj } from '@/utils/objectUtil'
import { musicSheetSourceType, musicSheetType } from '@/utils/constant'
import {musicSheetApplicationExtendCategoryList, musicSheetApplicationExtendSaveBatch, musicSheetPage} from '@views/music-library/api'
import deepClone from '@/utils/deep.clone'
import { getOwnerName } from '@views/music-library/musicUtil'
import TheTooltip from "@components/TheTooltip";
export default defineComponent({
name: 'gyt-addMusic',
props: {
appId: {
type: String,
required: true
},
subjectList: {
type: Array,
default: () => []
},
musicSheetCategories: {
type: Array,
default: () => []
}
},
emits: ['close', 'getList'],
setup(props, { slots, attrs, emit }) {
const dialogs = useDialog()
const message = useMessage()
const state = reactive({
loading: false,
pagination: {
page: 1,
rows: 5,
pageTotal: 0
},
stepPagination: {
page: 1,
rows: 5,
pageTotal: 0
},
searchForm: {
keyword: null,
musicSheetType: null,
subjectId: null,
sourceType: null
},
subjectList: [] as any,
showAdd: false,
currentStep: 1,
dataList: [],
selectRowData: [] as any, // 选择的数据列表
musicSheetCategories: [] as any,
startSortNum: null as any, // 排序起始值
projectMusicCategoryId: null as any // 曲目分类ID
})
onMounted(async () => {
state.loading = true
state.subjectList = props.subjectList
// state.musicSheetCategories = props.musicSheetCategories
//加载曲目分类列表
try {
const {data} = await musicSheetApplicationExtendCategoryList({
applicationIds: props.appId
})
if (data && data.length > 0) {
state.musicSheetCategories = data[0].musicSheetCategories
}
} catch {
}
await getList()
})
const getList = async () => {
try {
state.loading = true
const { data } = await musicSheetPage({
...state.pagination,
...state.searchForm,
addAppId: props.appId
})
state.pagination.pageTotal = Number(data.total)
state.dataList = data.rows || []
} catch {}
state.loading = false
}
const saveForm = ref()
const onSearch = () => {
saveForm.value?.submit()
}
const onBtnReset = () => {
saveForm.value?.reset()
}
const onSubmit = () => {
state.pagination.page = 1
getList()
}
const onSave = async () => {
if (state.selectRowData.length == 0) {
message.error('未选择曲目')
return
}
const params = [] as any[]
for (let i = 0; i < state.selectRowData.length; i++) {
const item = state.selectRowData[i]
if (!item.projectMusicCategoryId) {
message.error('曲目分类不能为空')
return
}
if (!item.sortNo || !item.projectMusicCategoryId) {
message.error('排序号不能为空')
return
}
params.push({
...item,
musicSheetId: item.id,
musicSheetCategoryId: item.projectMusicCategoryId,
applicationId: props.appId,
id: null
})
}
const res = (await musicSheetApplicationExtendSaveBatch(params)) as any
if (res && res.code == '200') {
message.success(`添加成功`)
emit('getList')
emit('close')
}
}
const columnsField = [
{
type: 'selection'
},
{
title: '曲目编号',
key: 'id'
},
{
title: '封面图',
key: 'titleImg',
render(row: any) {
return