music-sheet-gym.tsx 19 KB

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