import { defineComponent, h, onMounted, reactive, ref } from 'vue'
import SaveForm from '@components/save-form'
import {
DataTableColumns,
DataTableRowKey,
NButton,
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 {
appKey,
musicSheetAvailableType,
musicSheetPaymentType,
musicSheetSourceType,
musicSheetType,
scoreType
} from '@/utils/constant'
import {
musicSheetApplicationExtendSaveBatch,
musicSheetApplicationExtendTagList,
musicSheetApplicationOwnerList,
musicSheetPage
} from '@views/music-library/api'
import deepClone from '@/utils/deep.clone'
import { getOwnerName } from '@views/music-library/musicUtil'
import TheTooltip from '@components/TheTooltip'
import { sysApplicationPage } from '@views/menu-manage/api'
export default defineComponent({
name: 'klx-addMusic',
props: {
appId: {
type: String,
required: true
},
subjectList: {
type: Array,
default: () => []
},
musicSheetTagList: {
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,
composer: null,
userId: null,
applicationId: null
},
subjectList: [] as any,
showAdd: false,
currentStep: 1,
dataList: [],
selectRowData: [] as any, // 选择的数据列表
musicSheetCategories: [] as any,
musicSheetTagList: [] as any,
useProjectData: [] as any, // 适用项目行数据
userIdDisable: true,
userIdData: [] as any,
globalStartSortNum: null as any, // 排序起始值
status: false as any, // 是否启用
isConvertibleScore: null as any, //是否支持转简谱
scoreType: null as any //默认谱面
})
onMounted(async () => {
state.searchForm.keyword = null
// state.searchForm.musicSheetType = null
state.searchForm.subjectId = null
state.searchForm.sourceType = null
state.searchForm.composer = null
state.searchForm.userId = null
state.searchForm.applicationId = null
state.loading = true
state.subjectList = props.subjectList
// state.musicSheetTagList = props.musicSheetTagList
// 加载曲目标签
try {
const { data } = await musicSheetApplicationExtendTagList({
applicationId: props.appId,
enable: true
})
if (data && data.length > 0) {
data.forEach((item: any) => {
state.musicSheetTagList.push({
...item,
label: item.name,
value: item.id
})
})
}
} catch (err) {}
await initUseAppList()
await getList()
})
const initUseAppList = async () => {
try {
const appKeys = Object.keys(appKey)
const { data } = await sysApplicationPage({ page: 1, rows: 999 })
const tempList = data.rows || []
state.useProjectData = []
const filter = tempList.filter((next: any) => {
return appKeys.includes(next.appKey)
})
filter.forEach((item: any) => {
state.useProjectData.push({
...item,
label: item.appName,
value: item.id
})
})
} catch {}
}
const getList = async () => {
try {
state.loading = true
const search = {
...state.searchForm,
userId:
state.searchForm.sourceType && state.searchForm.sourceType == 'PERSON'
? state.searchForm.userId
: null,
organizationRoleId:
state.searchForm.sourceType && state.searchForm.sourceType == 'ORG'
? state.searchForm.userId
: null
}
const { data } = await musicSheetPage({
...state.pagination,
...search,
addAppId: props.appId
})
state.pagination.pageTotal = Number(data.total)
state.dataList = data.rows || []
} catch {}
state.loading = false
}
const saveForm = ref()
const onSearch = () => {
checkedRowKeysRef.value = []
saveForm.value?.submit()
}
const onBtnReset = () => {
saveForm.value?.reset()
}
const onSubmit = () => {
state.pagination.page = 1
getList()
}
const updateUserIdData = async (sourceType: any) => {
if (!state.searchForm.applicationId) {
return
}
state.userIdData = []
state.searchForm.userId = null
if (sourceType && sourceType !== 'PLATFORM') {
const { data } = await musicSheetApplicationOwnerList({
page: 1,
rows: 9999,
sourceType: sourceType,
applicationId: state.searchForm.applicationId
})
const temp = data.rows || []
temp.forEach((next: any) => {
state.userIdData.push({
...next,
label: sourceType === 'PERSON' ? next.userName : next.organizationRole,
value: sourceType === 'PERSON' ? next.userId : next.organizationRoleId
})
})
}
}
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.scoreType == null) {
message.error('默认谱面不能为空')
return
}
if (item.isConvertibleScore == null) {
message.error('是否支持转谱不能为空')
return
}
params.push({
...item,
musicSheetId: item.id,
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