music-sheet-gyt.tsx 19 KB

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