music-sheet-klx.tsx 19 KB

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