music-sheet-klx.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. import { defineComponent, onMounted, reactive, ref } from 'vue'
  2. import SaveForm from '@components/save-form'
  3. import {
  4. DataTableRowKey,
  5. NButton,
  6. NDataTable,
  7. NDatePicker,
  8. NDescriptions,
  9. NDescriptionsItem,
  10. NFormItem,
  11. NImage,
  12. NInput,
  13. NModal,
  14. NSelect,
  15. NSpace,
  16. NTag,
  17. useDialog,
  18. useMessage
  19. } from 'naive-ui'
  20. import Pagination from '@components/pagination'
  21. import TheTooltip from '@components/TheTooltip'
  22. import AddMusic from '@views/music-library/project-music-sheet/module/klx/addMusic'
  23. import { getMapValueByKey, getSelectDataFromObj } from '@/utils/objectUtil'
  24. import {
  25. musicSheetAudioType,
  26. musicSheetAvailableType,
  27. musicSheetPaymentType,
  28. musicSheetSourceType,
  29. musicSheetType
  30. } from '@/utils/constant'
  31. import {
  32. musicSheetApplicationExtendStatus,
  33. musicSheetApplicationExtendTagList,
  34. musicSheetApplicationOwnerList,
  35. musicSheetPageByApplication
  36. } from '@views/music-library/api'
  37. import { subjectPage, sysApplicationPage } from '@views/system-manage/api'
  38. import { filterTimes } from '@/utils/dateUtil'
  39. import deepClone from '@/utils/deep.clone'
  40. import { getOwnerName } from '@views/music-library/musicUtil'
  41. import UpdateMusic from '@views/music-library/project-music-sheet/module/klx/updateMusic'
  42. export default defineComponent({
  43. name: 'music-sheet-KLX',
  44. props: {
  45. appKey: {
  46. type: String,
  47. default: 'KLX'
  48. }
  49. },
  50. setup(props) {
  51. const dialog = useDialog()
  52. const message = useMessage()
  53. const state = reactive({
  54. loading: false,
  55. appId: null as any,
  56. pagination: {
  57. page: 1,
  58. rows: 10,
  59. pageTotal: 0
  60. },
  61. searchForm: {
  62. keyword: null,
  63. musicSheetType: null, //曲目类型(SINGLE:单曲 CONCERT:合奏)
  64. subjectId: null, //声部ID
  65. subjectIds: null, //曲目声部ID集合
  66. status: null, //曲目状态(0:停用,1:启用)
  67. sourceType: null, //来源类型/作者属性(PLATFORM: 平台; ORG: 机构; PERSON: 个人)
  68. paymentType: null, //收费类型(FREE:免费;VIP:会员;CHARGE:单曲收费)
  69. userId: null, //所属人
  70. musicCategoryId: null, //曲目分类ID
  71. times: null, // 上传时间
  72. audioType: null, //音频类型(HOMEMODE: 自制 COMMON: 普通)
  73. exquisiteFlag: null, //精品标志
  74. topFlag: null, //是否置顶(0:否;1:是)
  75. availableType: null, //可用途径 ORG 机构 PLATFORM 平台
  76. appAuditFlag: null, //是否审核版本
  77. detailFlag: null, //是否查询详情
  78. musicTagIds: [] as any //曲目标签
  79. },
  80. subjectList: [],
  81. dataList: [] as any[],
  82. showAddDialog: false,
  83. showEditDialog: false,
  84. userIdDisable: true,
  85. userIdData: [] as any,
  86. updateRow: {} as any, // 修改选择的行
  87. musicTagList: [] as any, //曲目标签
  88. applicationId: null //应用ID
  89. })
  90. onMounted(async () => {
  91. state.loading = true
  92. // 获取应用APP信息
  93. try {
  94. const { data } = await sysApplicationPage({ page: 1, rows: 1, appKey: props.appKey })
  95. const tempList = data.rows || []
  96. if (!tempList || tempList.length == 0) {
  97. state.loading = false
  98. message.error('加载项目信息失败')
  99. return
  100. }
  101. state.appId = tempList[0].id
  102. state.applicationId = tempList[0].id
  103. } catch {}
  104. // 加载声部
  105. try {
  106. const { data } = await subjectPage({ page: 1, rows: 999 })
  107. const tempList = data.rows || []
  108. tempList.forEach((item: any) => {
  109. item.label = item.name
  110. item.value = item.id + ''
  111. })
  112. state.subjectList = tempList
  113. } catch {}
  114. // 加载曲目标签
  115. try {
  116. const { data } = await musicSheetApplicationExtendTagList({ applicationId: state.appId })
  117. if (data && data.length > 0) {
  118. data.forEach((item: any) => {
  119. state.musicTagList.push({
  120. ...item,
  121. label: item.name,
  122. value: item.id
  123. })
  124. })
  125. }
  126. } catch (err) {}
  127. // 加载表格数据
  128. getList()
  129. })
  130. const saveForm = ref()
  131. const onSearch = () => {
  132. saveForm.value?.submit()
  133. }
  134. const onBtnReset = () => {
  135. saveForm.value?.reset()
  136. }
  137. const onSubmit = () => {
  138. state.pagination.page = 1
  139. getList()
  140. }
  141. const checkedRowKeysRef = ref<DataTableRowKey[]>([])
  142. const handleCheck = (rowKeys: DataTableRowKey[]) => {
  143. checkedRowKeysRef.value = rowKeys
  144. }
  145. const getList = async () => {
  146. try {
  147. state.loading = true
  148. const sourceType = state.searchForm.sourceType
  149. let userId = state.searchForm.userId
  150. let organizationRoleId = null
  151. if (sourceType && sourceType === 'ORG') {
  152. organizationRoleId = deepClone(userId)
  153. userId = null
  154. }
  155. const { data } = await musicSheetPageByApplication({
  156. ...state.pagination,
  157. ...state.searchForm,
  158. userId: userId,
  159. organizationRoleId: organizationRoleId,
  160. musicTagIds: state.searchForm.musicTagIds?.join(','),
  161. ...filterTimes(state.searchForm.times, ['startTime', 'endTime']),
  162. applicationId: state.applicationId
  163. })
  164. state.pagination.pageTotal = Number(data.total)
  165. state.dataList = data.rows || []
  166. } catch {}
  167. state.loading = false
  168. }
  169. const onChangeStatus = (row: any) => {
  170. const statusStr = row.status ? '停用' : '启用'
  171. dialog.warning({
  172. title: '提示',
  173. content: `是否${statusStr}?`,
  174. positiveText: '确定',
  175. negativeText: '取消',
  176. onPositiveClick: async () => {
  177. try {
  178. await musicSheetApplicationExtendStatus({
  179. ids: row.applicationExtendId,
  180. status: !row.status
  181. })
  182. getList()
  183. message.success(`${statusStr}成功`)
  184. } catch {}
  185. }
  186. })
  187. }
  188. const onBatchChangeStatus = (status: boolean) => {
  189. const length = checkedRowKeysRef.value.length
  190. if (length == 0) {
  191. message.warning('未选择数据')
  192. }
  193. const statusStr = !status ? '停用' : '启用'
  194. dialog.warning({
  195. title: '提示',
  196. content: `是否${statusStr}` + length + `条数据?`,
  197. positiveText: '确定',
  198. negativeText: '取消',
  199. onPositiveClick: async () => {
  200. try {
  201. await musicSheetApplicationExtendStatus({
  202. ids: checkedRowKeysRef.value.join(','),
  203. status: status
  204. })
  205. getList()
  206. message.success(`${statusStr}成功`)
  207. } catch {}
  208. }
  209. })
  210. }
  211. const columns = (): any => {
  212. return [
  213. {
  214. type: 'selection'
  215. },
  216. {
  217. title: '曲目信息',
  218. key: 'id',
  219. render: (row: any) => (
  220. <>
  221. <NDescriptions labelPlacement="left" column={1}>
  222. <NDescriptionsItem label="曲目名称">
  223. <TheTooltip content={row.name} />{' '}
  224. </NDescriptionsItem>
  225. <NDescriptionsItem label="曲目编号">{row.id}</NDescriptionsItem>
  226. </NDescriptions>
  227. </>
  228. )
  229. },
  230. {
  231. title: '曲目来源',
  232. key: 'musicSheetCategoriesName',
  233. render: (row: any) => (
  234. <>
  235. <NDescriptions labelPlacement="left" column={1}>
  236. <NDescriptionsItem label="曲目来源">
  237. {getMapValueByKey(row.sourceType, new Map(Object.entries(musicSheetSourceType)))}
  238. </NDescriptionsItem>
  239. <NDescriptionsItem label="所属人">
  240. {getOwnerName(row.musicSheetExtend, row.sourceType)}
  241. </NDescriptionsItem>
  242. </NDescriptions>
  243. </>
  244. )
  245. },
  246. {
  247. title: '封面图',
  248. key: 'musicCover',
  249. render(row: any): JSX.Element {
  250. return <NImage width={60} height={60} src={row.musicCover} />
  251. }
  252. },
  253. {
  254. title: '曲目类型',
  255. key: 'musicSheetType',
  256. render: (row: any) => {
  257. return (
  258. <div>
  259. {getMapValueByKey(row.musicSheetType, new Map(Object.entries(musicSheetType)))}
  260. </div>
  261. )
  262. }
  263. },
  264. {
  265. title: '伴奏类型',
  266. key: 'audioType',
  267. render: (row: any) => {
  268. return (
  269. <div>
  270. {getMapValueByKey(row.audioType, new Map(Object.entries(musicSheetAudioType)))}
  271. </div>
  272. )
  273. }
  274. },
  275. {
  276. title: '可用声部',
  277. key: 'subjectNames'
  278. },
  279. {
  280. title: '曲目标签',
  281. key: 'musicTagNames'
  282. },
  283. {
  284. title: '可用途径',
  285. key: 'applicationAvailableType',
  286. render: (row: any) => {
  287. return (
  288. <div>
  289. {getMapValueByKey(
  290. row.applicationAvailableType,
  291. new Map(Object.entries(musicSheetAvailableType))
  292. )}
  293. </div>
  294. )
  295. }
  296. },
  297. {
  298. title: '是否置顶',
  299. key: 'topFlag',
  300. render: (row: any) => {
  301. return <div>{row.topFlag ? '是' : '否'}</div>
  302. }
  303. },
  304. {
  305. title: '是否精品',
  306. key: 'exquisiteFlag',
  307. render: (row: any) => {
  308. return <div>{row.topFlag ? '是' : '否'}</div>
  309. }
  310. },
  311. {
  312. title: '收费方式',
  313. key: 'paymentType',
  314. render: (row: any) => {
  315. return (
  316. <div>
  317. {getMapValueByKey(row.paymentType, new Map(Object.entries(musicSheetPaymentType)))}
  318. </div>
  319. )
  320. }
  321. },
  322. {
  323. title: '曲目价格',
  324. key: 'musicPrice'
  325. },
  326. {
  327. title: '上传人',
  328. key: 'createByName'
  329. },
  330. {
  331. title: '上传时间',
  332. key: 'createTime'
  333. },
  334. {
  335. title: '状态',
  336. key: 'status',
  337. render(row: any) {
  338. return (
  339. <NTag type={row.status ? 'primary' : 'default'}>{row.status ? '启用' : '停用'}</NTag>
  340. )
  341. }
  342. },
  343. {
  344. title: '操作',
  345. key: 'operation',
  346. fixed: 'right',
  347. render(row: any) {
  348. return (
  349. <NSpace>
  350. <NButton
  351. type="primary"
  352. size="small"
  353. text
  354. //v-auth="musicSheet/status1612431726029942786"
  355. onClick={() => onChangeStatus(row)}
  356. >
  357. {row.status ? '停用' : '启用'}
  358. </NButton>
  359. <NButton
  360. type="primary"
  361. size="small"
  362. text
  363. //v-auth="musicSheet/update1602302618558099458"
  364. onClick={() => {
  365. state.showEditDialog = true
  366. state.updateRow = row
  367. }}
  368. >
  369. 修改
  370. </NButton>
  371. </NSpace>
  372. )
  373. }
  374. }
  375. ]
  376. }
  377. return () => {
  378. return (
  379. <div class="system-menu-container">
  380. <SaveForm
  381. ref={saveForm}
  382. model={state.searchForm}
  383. onSubmit={onSubmit}
  384. saveKey="music-sheet-klx"
  385. onSetModel={(val: any) => (state.searchForm = val)}
  386. >
  387. <NFormItem label="关键词" path="keyword">
  388. <NInput
  389. placeholder="请输入曲目名称/编号"
  390. v-model:value={state.searchForm.keyword}
  391. clearable
  392. />
  393. </NFormItem>
  394. <NFormItem label="曲目来源" path="sourceType">
  395. <NSelect
  396. placeholder="请选择曲目来源"
  397. v-model:value={state.searchForm.sourceType}
  398. options={getSelectDataFromObj(musicSheetSourceType)}
  399. onUpdateValue={async (value: any) => {
  400. state.userIdData = []
  401. state.searchForm.userId = null
  402. if (value && value !== 'PLATFORM') {
  403. const { data } = await musicSheetApplicationOwnerList({
  404. page: 1,
  405. rows: 9999,
  406. sourceType: value,
  407. applicationId: state.appId
  408. })
  409. const temp = data.rows || []
  410. temp.forEach((next: any) => {
  411. state.userIdData.push({
  412. ...next,
  413. label: value === 'PERSON' ? next.userName : next.organizationRole,
  414. value: value === 'PERSON' ? next.userId : next.organizationRoleId
  415. })
  416. })
  417. state.userIdDisable = false
  418. } else {
  419. state.userIdDisable = true
  420. }
  421. }}
  422. clearable
  423. />
  424. </NFormItem>
  425. <NFormItem label="所属人" path="userId">
  426. <NSelect
  427. placeholder="请选择所属人"
  428. disabled={state.userIdDisable}
  429. v-model:value={state.searchForm.userId}
  430. options={state.userIdData}
  431. clearable
  432. ></NSelect>
  433. </NFormItem>
  434. <NFormItem label="曲目类型" path="subjectType">
  435. <NSelect
  436. placeholder="请选择曲目类型"
  437. v-model:value={state.searchForm.musicSheetType}
  438. options={getSelectDataFromObj(musicSheetType)}
  439. clearable
  440. />
  441. </NFormItem>
  442. <NFormItem label="伴奏类型" path="audioType">
  443. <NSelect
  444. placeholder="请选择伴奏类型"
  445. v-model:value={state.searchForm.audioType}
  446. options={getSelectDataFromObj(musicSheetAudioType)}
  447. clearable
  448. />
  449. </NFormItem>
  450. <NFormItem label="可用声部" path="subjectId">
  451. <NSelect
  452. placeholder="请选择可用声部"
  453. v-model:value={state.searchForm.subjectId}
  454. options={state.subjectList}
  455. clearable
  456. />
  457. </NFormItem>
  458. <NFormItem label="曲目标签" path="musicTagIds">
  459. <NSelect
  460. placeholder="请选择曲目标签"
  461. v-model:value={state.searchForm.musicTagIds}
  462. options={state.musicTagList}
  463. multiple
  464. maxTagCount={2}
  465. clearable
  466. />
  467. </NFormItem>
  468. {/*<NFormItem*/}
  469. {/* label="可用途径"*/}
  470. {/* path="availableType"*/}
  471. {/*>*/}
  472. {/* <NSelect*/}
  473. {/* placeholder="请选择可用途径"*/}
  474. {/* v-model:value={state.searchForm.availableType}*/}
  475. {/* options={getSelectDataFromObj(musicSheetAvailableType)}*/}
  476. {/* clearable*/}
  477. {/* >*/}
  478. {/* </NSelect>*/}
  479. {/*</NFormItem>*/}
  480. <NFormItem label="收费方式" path="paymentType">
  481. <NSelect
  482. placeholder="请选择收费方式"
  483. v-model:value={state.searchForm.paymentType}
  484. options={getSelectDataFromObj(musicSheetPaymentType)}
  485. clearable
  486. ></NSelect>
  487. </NFormItem>
  488. <NFormItem label="状态" path="status">
  489. <NSelect
  490. v-model:value={state.searchForm.status}
  491. placeholder="请选择状态"
  492. options={
  493. [
  494. {
  495. label: '启用',
  496. value: true
  497. },
  498. {
  499. label: '停用',
  500. value: false
  501. }
  502. ] as any
  503. }
  504. clearable
  505. />
  506. </NFormItem>
  507. <NFormItem label="上传时间" path="authorFrom">
  508. <NDatePicker
  509. v-model:value={state.searchForm.times}
  510. type="daterange"
  511. clearable
  512. value-format="yyyy.MM.dd"
  513. startPlaceholder="开始时间"
  514. endPlaceholder="结束时间"
  515. />
  516. </NFormItem>
  517. <NFormItem>
  518. <NSpace>
  519. <NButton type="primary" onClick={onSearch}>
  520. 搜索
  521. </NButton>
  522. <NButton type="default" onClick={onBtnReset}>
  523. 重置
  524. </NButton>
  525. </NSpace>
  526. </NFormItem>
  527. </SaveForm>
  528. <div class={['section-container']}>
  529. <NSpace style={{ paddingBottom: '12px' }}>
  530. <NButton
  531. type="primary"
  532. //v-auth="musicSheet/save1602302550719426561"
  533. onClick={() => {
  534. state.showAddDialog = true
  535. }}
  536. >
  537. 添加曲目
  538. </NButton>
  539. <NButton
  540. disabled={checkedRowKeysRef.value.length == 0}
  541. //v-auth="musicSheet/save1602302550719426561"
  542. onClick={() => {
  543. onBatchChangeStatus(false)
  544. }}
  545. >
  546. 批量停用
  547. </NButton>
  548. <NButton
  549. disabled={checkedRowKeysRef.value.length == 0}
  550. //v-auth="musicSheet/save1602302550719426561"
  551. onClick={() => {
  552. onBatchChangeStatus(true)
  553. }}
  554. >
  555. 批量启用
  556. </NButton>
  557. </NSpace>
  558. <NDataTable
  559. loading={state.loading}
  560. columns={columns()}
  561. data={state.dataList}
  562. rowKey={(row: any) => row.applicationExtendId}
  563. onUpdateCheckedRowKeys={handleCheck}
  564. scrollX={'1600'}
  565. ></NDataTable>
  566. <Pagination
  567. v-model:page={state.pagination.page}
  568. v-model:pageSize={state.pagination.rows}
  569. v-model:pageTotal={state.pagination.pageTotal}
  570. onList={getList}
  571. sync
  572. saveKey="music-sheet-klx"
  573. ></Pagination>
  574. </div>
  575. <NModal
  576. v-model:show={state.showAddDialog}
  577. preset="dialog"
  578. showIcon={false}
  579. title={'添加曲目'}
  580. style={{ width: '1200px' }}
  581. >
  582. <AddMusic
  583. onClose={() => (state.showAddDialog = false)}
  584. onGetList={onSubmit}
  585. subjectList={state.subjectList}
  586. appId={state.appId}
  587. musicSheetTagList={state.musicTagList}
  588. />
  589. </NModal>
  590. <NModal
  591. v-model:show={state.showEditDialog}
  592. preset="dialog"
  593. showIcon={false}
  594. title={'修改曲目'}
  595. style={{ width: '500px' }}
  596. >
  597. <UpdateMusic
  598. onClose={() => (state.showEditDialog = false)}
  599. onGetList={() => {
  600. state.pagination.page = 1
  601. getList()
  602. }}
  603. rowData={state.updateRow}
  604. appId={state.appId}
  605. musicSheetTagList={state.musicTagList}
  606. />
  607. </NModal>
  608. </div>
  609. )
  610. }
  611. }
  612. })