music-sheet-gym.tsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. minWidth: '150px',
  299. key: 'composer',
  300. render(row: any) {
  301. return (
  302. <NDescriptions labelPlacement="left" column={1}>
  303. <NDescriptionsItem label="上传人">{row.createByName}</NDescriptionsItem>
  304. <NDescriptionsItem label="上传时间">{row.createTime}</NDescriptionsItem>
  305. </NDescriptions>
  306. )
  307. }
  308. },
  309. {
  310. title: '状态',
  311. key: 'status',
  312. render(row: any) {
  313. return (
  314. <NTag type={row.status ? 'primary' : 'default'}>{row.status ? '启用' : '停用'}</NTag>
  315. )
  316. }
  317. },
  318. {
  319. title: '操作',
  320. key: 'operation',
  321. fixed: 'right',
  322. render(row: any) {
  323. return (
  324. <NSpace>
  325. <NButton
  326. type="primary"
  327. size="small"
  328. text
  329. //v-auth="musicSheet/status1612431726029942786"
  330. onClick={() => onChangeStatus(row)}
  331. >
  332. {row.status ? '停用' : '启用'}
  333. </NButton>
  334. <NButton
  335. type="primary"
  336. size="small"
  337. text
  338. //v-auth="musicSheet/update1602302618558099458"
  339. onClick={() => {
  340. state.showEditDialog = true
  341. state.updateRow = row
  342. }}
  343. >
  344. 修改
  345. </NButton>
  346. </NSpace>
  347. )
  348. }
  349. }
  350. ]
  351. }
  352. return () => {
  353. return (
  354. <div class="system-menu-container">
  355. <SaveForm
  356. ref={saveForm}
  357. model={state.searchForm}
  358. onSubmit={onSubmit}
  359. saveKey="music-sheet-gym"
  360. onSetModel={(val: any) => (state.searchForm = val)}
  361. >
  362. <NFormItem label="关键词" path="keyword">
  363. <NInput
  364. placeholder="请输入曲目名称/编号"
  365. v-model:value={state.searchForm.keyword}
  366. clearable
  367. />
  368. </NFormItem>
  369. <NFormItem label="曲目来源" path="sourceType">
  370. <NSelect
  371. placeholder="请选择曲目来源"
  372. v-model:value={state.searchForm.sourceType}
  373. options={getSelectDataFromObj(musicSheetSourceType)}
  374. onUpdateValue={async (value: any) => {
  375. state.userIdData = []
  376. state.searchForm.userId = null
  377. if (value && value !== 'PLATFORM') {
  378. const { data } = await musicSheetApplicationOwnerList({
  379. page: 1,
  380. rows: 9999,
  381. sourceType: value,
  382. applicationId: state.appId
  383. })
  384. const temp = data.rows || []
  385. temp.forEach((next: any) => {
  386. state.userIdData.push({
  387. ...next,
  388. label: value === 'PERSON' ? next.userName : next.organizationRole,
  389. value: value === 'PERSON' ? next.userId : next.organizationRoleId
  390. })
  391. })
  392. state.userIdDisable = false
  393. } else {
  394. state.userIdDisable = true
  395. }
  396. }}
  397. clearable
  398. />
  399. </NFormItem>
  400. <NFormItem label="所属人" path="userId">
  401. <NSelect
  402. placeholder="请选择所属人"
  403. disabled={state.userIdDisable}
  404. v-model:value={state.searchForm.userId}
  405. options={state.userIdData}
  406. clearable
  407. ></NSelect>
  408. </NFormItem>
  409. <NFormItem label="曲目类型" path="subjectType">
  410. <NSelect
  411. placeholder="请选择曲目类型"
  412. v-model:value={state.searchForm.musicSheetType}
  413. options={getSelectDataFromObj(musicSheetType)}
  414. clearable
  415. />
  416. </NFormItem>
  417. <NFormItem label="伴奏类型" path="audioType">
  418. <NSelect
  419. placeholder="请选择伴奏类型"
  420. v-model:value={state.searchForm.audioType}
  421. options={getSelectDataFromObj(musicSheetAudioType)}
  422. clearable
  423. />
  424. </NFormItem>
  425. <NFormItem label="可用声部" path="subjectId">
  426. <NSelect
  427. placeholder="请选择可用声部"
  428. v-model:value={state.searchForm.subjectId}
  429. options={state.subjectList}
  430. clearable
  431. />
  432. </NFormItem>
  433. <NFormItem label="曲目分类" path="musicCategoryId">
  434. <NCascader
  435. valueField="id"
  436. labelField="name"
  437. children-field="children"
  438. placeholder="请选择曲目分类"
  439. v-model:value={state.searchForm.musicCategoryId}
  440. options={state.musicSheetCategories}
  441. clearable
  442. />
  443. </NFormItem>
  444. {/*<NFormItem*/}
  445. {/* label="可用途径"*/}
  446. {/* path="availableType"*/}
  447. {/*>*/}
  448. {/* <NSelect*/}
  449. {/* placeholder="请选择可用途径"*/}
  450. {/* v-model:value={state.searchForm.availableType}*/}
  451. {/* options={getSelectDataFromObj(musicSheetAvailableType)}*/}
  452. {/* clearable*/}
  453. {/* >*/}
  454. {/* </NSelect>*/}
  455. {/*</NFormItem>*/}
  456. <NFormItem label="收费方式" path="paymentType">
  457. <NSelect
  458. placeholder="请选择收费方式"
  459. v-model:value={state.searchForm.paymentType}
  460. options={getSelectDataFromObj(musicSheetPaymentType)}
  461. clearable
  462. ></NSelect>
  463. </NFormItem>
  464. <NFormItem label="状态" path="status">
  465. <NSelect
  466. v-model:value={state.searchForm.status}
  467. placeholder="请选择状态"
  468. options={
  469. [
  470. {
  471. label: '启用',
  472. value: true
  473. },
  474. {
  475. label: '停用',
  476. value: false
  477. }
  478. ] as any
  479. }
  480. clearable
  481. />
  482. </NFormItem>
  483. <NFormItem label="上传时间" path="authorFrom">
  484. <NDatePicker
  485. v-model:value={state.searchForm.times}
  486. type="daterange"
  487. clearable
  488. value-format="yyyy.MM.dd"
  489. startPlaceholder="开始时间"
  490. endPlaceholder="结束时间"
  491. />
  492. </NFormItem>
  493. <NFormItem>
  494. <NSpace>
  495. <NButton type="primary" onClick={onSearch}>
  496. 搜索
  497. </NButton>
  498. <NButton type="default" onClick={onBtnReset}>
  499. 重置
  500. </NButton>
  501. </NSpace>
  502. </NFormItem>
  503. </SaveForm>
  504. <div class={['section-container']}>
  505. <NSpace style={{ paddingBottom: '12px' }}>
  506. <NButton
  507. type="primary"
  508. //v-auth="musicSheet/save1602302550719426561"
  509. onClick={() => {
  510. state.showAddDialog = true
  511. }}
  512. >
  513. 添加曲目
  514. </NButton>
  515. <NButton
  516. disabled={checkedRowKeysRef.value.length == 0}
  517. //v-auth="musicSheet/save1602302550719426561"
  518. onClick={() => {
  519. onBatchChangeStatus(false)
  520. }}
  521. >
  522. 批量停用
  523. </NButton>
  524. <NButton
  525. disabled={checkedRowKeysRef.value.length == 0}
  526. //v-auth="musicSheet/save1602302550719426561"
  527. onClick={() => {
  528. onBatchChangeStatus(true)
  529. }}
  530. >
  531. 批量启用
  532. </NButton>
  533. </NSpace>
  534. <NDataTable
  535. loading={state.loading}
  536. columns={columns()}
  537. data={state.dataList}
  538. rowKey={(row: any) => row.applicationExtendId}
  539. onUpdateCheckedRowKeys={handleCheck}
  540. scrollX={'2100'}
  541. ></NDataTable>
  542. <Pagination
  543. v-model:page={state.pagination.page}
  544. v-model:pageSize={state.pagination.rows}
  545. v-model:pageTotal={state.pagination.pageTotal}
  546. onList={getList}
  547. sync
  548. saveKey="music-sheet-gym"
  549. ></Pagination>
  550. </div>
  551. <NModal
  552. v-model:show={state.showAddDialog}
  553. preset="dialog"
  554. showIcon={false}
  555. title={'添加曲目'}
  556. style={{ width: '1200px' }}
  557. >
  558. <AddMusic
  559. onClose={() => (state.showAddDialog = false)}
  560. onGetList={() => {
  561. state.pagination.page = 1
  562. getList()
  563. }}
  564. subjectList={state.subjectList}
  565. appId={state.appId}
  566. musicSheetCategories={state.musicSheetCategories}
  567. />
  568. </NModal>
  569. <NModal
  570. v-model:show={state.showEditDialog}
  571. preset="dialog"
  572. showIcon={false}
  573. title={'修改曲目'}
  574. style={{ width: '500px' }}
  575. >
  576. <UpdateMusic
  577. onClose={() => (state.showEditDialog = false)}
  578. onGetList={() => {
  579. state.pagination.page = 1
  580. getList()
  581. }}
  582. rowData={state.updateRow}
  583. appId={state.appId}
  584. musicSheetCategories={state.musicSheetCategories}
  585. />
  586. </NModal>
  587. </div>
  588. )
  589. }
  590. }
  591. })