music-sheet-klx.tsx 20 KB

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