music-sheet-kt.tsx 19 KB

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