import SaveForm from '@/components/save-form'
import Pagination from '@/components/pagination'
import {
DataTableRowKey,
NButton,
NCascader,
NDataTable,
NDescriptions,
NDescriptionsItem,
NFormItem,
NIcon,
NImage,
NInput,
NModal,
NSelect,
NSpace,
NTag,
NTooltip,
useDialog,
useMessage
} from 'naive-ui'
import { defineComponent, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
import {
musicSheetApplicationOwnerList,
musicSheetPage,
musicSheetRemove,
musicSheetImg,
musicSheetStatusList,
musicTagPage,
musicSheetCategoriesQueryTree
} from '../../api'
import MusicOperation from '../modal/music-operation'
import { subjectPage } from '@/views/system-manage/api'
import MusicPreView from '../modal/musicPreView'
import UseProject from '@views/music-library/music-sheet/modal/use-project'
import { getMapValueByKey } from '@/utils/filters'
import { appKey, musicSheetSourceType, musicSheetType } from '@/utils/constant'
import { getSelectDataFromObj } from '@/utils/objectUtil'
import { sysApplicationPage } from '@views/menu-manage/api'
import { getOwnerName } from '@views/music-library/musicUtil'
import styles from './music-list.module.less'
import { api_uploadFile } from '@/plugins/uploadFile'
import MusicCreateImg from '../modal/music-create-img'
import TheTooltip from '@components/TheTooltip'
export default defineComponent({
name: 'music-list',
props: ['searchId', 'musicCategoryId'],
setup(props, { emit }) {
const dialog = useDialog()
const message = useMessage()
const state = reactive({
loading: false,
pagination: {
page: 1,
rows: 10,
pageTotal: 0
},
searchForm: {
keyword: null,
musicSheetType: null,
subjectId: null, //声部ID
sourceType: null, //来源类型/作者属性(PLATFORM: 平台; ORG: 机构; PERSON: 个人
composer: null, //作曲人/音乐人
userId: null, //所属人
useAppId: null, //适用项目ID
status: null, //曲目状态(0:停用,1:启用)
appAuditFlag: null, //是否审核版本
categoriesId: null, //是否审核版本
musicCategoryId: null //曲目分类
},
dataList: [] as any,
subjectList: [] as any,
tagList: [] as any,
visiableMusic: false,
musicOperation: 'add',
musicData: {} as any,
musicSheetCategories: [] as any,
musicPreview: false,
musicScore: null as any,
showUseProject: false, // 适用项目
useProjectData: [] as any, // 适用项目行数据
showUseProjectId: null as any, // 适用项目行数据
detailReadonly: false, // 新增、修改、详情是否可编辑
userIdDisable: true, // 所属人
userIdData: [] as any, // 所属人数据列表
productOpen: false,
productItem: {} as any
})
const columns = (): any => {
return [
{
type: 'selection'
},
{
title: '曲目名称',
minWidth: '200px',
key: 'id',
render(row: any) {
return (
{row.id}
)
}
},
{
title: '封面图',
key: 'titleImg',
render(row: any): JSX.Element {
return
}
},
{
title: '曲目信息',
minWidth: '150px',
key: 'composer',
render(row: any) {
return (
{row.composer}
{getMapValueByKey(row.musicSheetType, new Map(Object.entries(musicSheetType)))}
{row.musicCategoryName}
)
}
},
{
title: '曲目分类',
minWidth: '100px',
key: 'musicCategoryName'
},
{
title: '可用声部',
minWidth: '100px',
maxWidth: '300px',
key: 'subjectNames'
},
{
title: '作者属性',
minWidth: '250px',
key: 'sourceType',
render(row: any) {
return (
{getMapValueByKey(row.sourceType, new Map(Object.entries(musicSheetSourceType)))}
{getOwnerName(row.musicSheetExtend, row.sourceType)
? getOwnerName(row.musicSheetExtend, row.sourceType)
: '--'}
)
}
},
{
title: '适用项目',
width: '300px',
key: 'projectName',
render(row: any) {
return (
{
state.showUseProject = true
state.showUseProjectId = row.id
}}
>
{row.musicSheetExtend && row.musicSheetExtend.useApplicationNames
? row.musicSheetExtend.useApplicationNames
: ''}
)
}
},
{
title: '更新信息',
minWidth: '250px',
key: 'updateBy',
render(row: any) {
return (
{row.updateByName}
{row.updateTime}
)
}
},
{
title: '可用声部',
minWidth: '100px',
maxWidth: '300px',
key: 'subjectNames',
render(row: any) {
return
}
},
{
title: '审核版本',
minWidth: '100px',
key: 'appAuditFlag',
render(row: any) {
return
{row.appAuditFlag ? '是' : '否'}
}
},
{
title: '状态',
minWidth: '50px',
key: 'status',
render(row: any) {
return (
{row.status ? '启用' : '停用'}
)
}
},
{
title: '操作',
key: 'operation',
fixed: 'right',
width: '300px',
render(row: any) {
return (
{
state.musicPreview = true
state.musicScore = row
}}
>
预览
{
state.visiableMusic = true
state.musicOperation = 'preview'
state.musicData = row
state.detailReadonly = true
}}
>
查看
{
state.visiableMusic = true
state.musicOperation = 'edit'
state.musicData = row
state.detailReadonly = true
}}
>
修改
onChangeStatus(row)}
>
{row.status ? '停用' : '启用'}
{
state.productOpen = true
state.productItem = row
// handleAutoProduct(row)
}}
>
生成图片
onRmove(row)}
v-auth="musicSheet/save1751241178962984962"
>
删除
)
}
}
]
}
const checkedRowKeysRef = ref([])
const handleCheck = (rowKeys: DataTableRowKey[]) => {
checkedRowKeysRef.value = rowKeys
}
const onChangeStatus = (row: any) => {
const statusStr = row.status ? '停用' : '启用'
dialog.warning({
title: '提示',
content: `是否${statusStr}?`,
positiveText: '确定',
negativeText: '取消',
onPositiveClick: async () => {
try {
await musicSheetStatusList({
ids: new Array(row.id),
status: !row.status
})
getList()
message.success(`${statusStr}成功`)
} catch {}
}
})
}
const onBatchChangeStatus = (status: boolean) => {
const length = checkedRowKeysRef.value.length
if (length == 0) {
message.warning('未选择数据')
}
const statusStr = !status ? '停用' : '启用'
dialog.warning({
title: '提示',
content: `是否${statusStr}` + length + `条数据?`,
positiveText: '确定',
negativeText: '取消',
onPositiveClick: async () => {
try {
await musicSheetStatusList({
ids: checkedRowKeysRef.value,
status: status
})
getList()
message.success(`${statusStr}成功`)
} catch {}
}
})
}
const updateUserIdData = async (sourceType: any) => {
if (!state.searchForm.useAppId) {
return
}
state.userIdData = []
state.searchForm.userId = null
if (sourceType && sourceType !== 'PLATFORM') {
const { data } = await musicSheetApplicationOwnerList({
page: 1,
rows: 9999,
sourceType: sourceType,
applicationId: state.searchForm.useAppId
})
const temp = data.rows || []
temp.forEach((next: any) => {
state.userIdData.push({
...next,
label: next.userName,
value: next.userId
})
})
}
}
const onRmove = (row: any): void => {
dialog.warning({
title: '警告',
content: `删除"${row.name}",是否继续?`,
positiveText: '确定',
negativeText: '取消',
onPositiveClick: async () => {
try {
await musicSheetRemove({ id: row.id })
getList()
message.success('删除成功')
} catch {}
}
})
}
const getList = async () => {
try {
state.loading = true
const { data } = await musicSheetPage({ ...state.pagination, ...state.searchForm })
state.pagination.pageTotal = Number(data.total)
state.dataList = data.rows || []
} catch {}
state.loading = false
}
// 获取标签
const getTagList = async () => {
try {
const { data } = await musicTagPage({ page: 1, rows: 999 })
const tempList = data.rows || []
tempList.forEach((item: any) => {
item.label = item.name
item.value = item.id
})
state.tagList = tempList
} catch {}
}
// 获取分类
const getMusicSheetCategorieList = async () => {
try {
const { data } = await musicSheetCategoriesQueryTree({})
// state.musicSheetCategories = filterPointCategory(data, 'musicSheetCategoriesList')
state.musicSheetCategories = data || []
} catch (e) {}
}
// 获取声部
const initSubjectList = async () => {
try {
const { data } = await subjectPage({ page: 1, rows: 999 })
const tempList = data.rows || []
tempList.forEach((item: any) => {
item.label = item.name
item.value = item.id + ''
})
state.subjectList = tempList
} catch {}
}
// app列表
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 saveForm = ref()
const onSubmit = () => {
state.pagination.page = 1
getList()
}
watch(
() => props.searchId,
(val) => {
console.log(val, 'searchId')
}
)
const onSearch = () => {
saveForm.value?.submit()
}
const onBtnReset = () => {
saveForm.value?.reset()
}
onMounted(async () => {
state.loading = true
// getTagList()
if (props.searchId) {
state.searchForm.categoriesId = props.searchId || null
}
if (props.musicCategoryId) {
state.searchForm.musicCategoryId = props.musicCategoryId || null
}
initSubjectList()
initUseAppList()
getMusicSheetCategorieList()
getList()
})
return () => (
)
}
})