music-sheet-kt.tsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. // 获取应用APP信息
  83. {
  84. const {data} = await sysApplicationPage({page: 1, rows: 1, appKey: props.appKey})
  85. const tempList = data.rows || []
  86. if (!tempList || tempList.length == 0) {
  87. message.error("加载项目信息失败");
  88. return
  89. }
  90. state.appId = tempList[0].id
  91. state.searchForm.applicationId = tempList[0].id
  92. }
  93. // 加载声部
  94. {
  95. try {
  96. const {data} = await subjectPage({page: 1, rows: 999})
  97. const tempList = data.rows || []
  98. tempList.forEach((item: any) => {
  99. item.label = item.name
  100. item.value = item.id + ''
  101. })
  102. state.subjectList = tempList
  103. } catch {
  104. }
  105. }
  106. //加载曲目分类列表
  107. {
  108. const {data} = await musicSheetApplicationExtendCategoryList({applicationIds: state.appId})
  109. if (data && data.length > 0) {
  110. state.musicSheetCategories = data[0].musicSheetCategories
  111. }
  112. }
  113. // 加载表格数据
  114. {
  115. getList()
  116. }
  117. })
  118. const saveForm = ref()
  119. const onSearch = () => {
  120. saveForm.value?.submit()
  121. }
  122. const onBtnReset = () => {
  123. saveForm.value?.reset()
  124. }
  125. const onSubmit = () => {
  126. state.pagination.page = 1
  127. getList()
  128. }
  129. const checkedRowKeysRef = ref<DataTableRowKey[]>([])
  130. const handleCheck = (rowKeys: DataTableRowKey[]) => {
  131. checkedRowKeysRef.value = rowKeys
  132. }
  133. const getList = async () => {
  134. try {
  135. state.loading = true
  136. const {data} = await musicSheetPageByApplication({
  137. ...state.pagination,
  138. ...state.searchForm,
  139. ...filterTimes(state.searchForm.times, ['startTime', 'endTime']),
  140. })
  141. state.pagination.pageTotal = Number(data.total)
  142. state.dataList = data.rows || []
  143. } catch {
  144. }
  145. state.loading = false
  146. }
  147. const onChangeStatus = (row: any) => {
  148. const statusStr = row.status ? '停用' : '启用'
  149. dialog.warning({
  150. title: '警告',
  151. content: `是否${statusStr}?`,
  152. positiveText: '确定',
  153. negativeText: '取消',
  154. onPositiveClick: async () => {
  155. try {
  156. await musicSheetApplicationExtendStatus({
  157. ids: row.id,
  158. status: !row.status
  159. })
  160. getList()
  161. message.success(`${statusStr}成功`)
  162. } catch {
  163. }
  164. }
  165. })
  166. }
  167. const onBatchChangeStatus = (status: boolean) => {
  168. const length = checkedRowKeysRef.value.length;
  169. if (length == 0) {
  170. message.warning("未选择数据")
  171. }
  172. const statusStr = !status ? '停用' : '启用'
  173. dialog.warning({
  174. title: '警告',
  175. content: `是否${statusStr}` + length + `条数据?`,
  176. positiveText: '确定',
  177. negativeText: '取消',
  178. onPositiveClick: async () => {
  179. try {
  180. await musicSheetApplicationExtendStatus({
  181. ids: checkedRowKeysRef.value.join(','),
  182. status: status
  183. })
  184. getList()
  185. message.success(`${statusStr}成功`)
  186. } catch {
  187. }
  188. }
  189. })
  190. }
  191. const columns = (): any => {
  192. return [
  193. {
  194. type: 'selection'
  195. },
  196. {
  197. title: '曲目信息',
  198. key: 'id',
  199. render: (row: any) => (
  200. <>
  201. <NDescriptions labelPlacement="left" column={1}>
  202. <NDescriptionsItem label="曲目名称">
  203. <TheTooltip content={row.name}/>{' '}
  204. </NDescriptionsItem>
  205. <NDescriptionsItem label="曲目编号">{row.id}</NDescriptionsItem>
  206. </NDescriptions>
  207. </>
  208. )
  209. },
  210. {
  211. title: '曲目来源',
  212. key: 'musicSheetCategoriesName',
  213. render: (row: any) => (
  214. <>
  215. <NDescriptions labelPlacement="left" column={1}>
  216. <NDescriptionsItem label="曲目来源">
  217. {getMapValueByKey(row.sourceType, new Map(Object.entries(musicSheetSourceType)))}
  218. </NDescriptionsItem>
  219. <NDescriptionsItem label="所属人">{row.userName}</NDescriptionsItem>
  220. </NDescriptions>
  221. </>
  222. )
  223. },
  224. {
  225. title: '封面图',
  226. key: 'musicCover',
  227. render(row: any): JSX.Element {
  228. return <NImage width={60} height={60} src={row.musicCover}/>
  229. }
  230. },
  231. {
  232. title: '曲目类型',
  233. key: 'musicSheetType',
  234. render: (row: any) => {
  235. return <div>{getMapValueByKey(row.musicSheetType, new Map(Object.entries(musicSheetType)))}</div>
  236. }
  237. },
  238. {
  239. title: '伴奏类型',
  240. key: 'audioType',
  241. render: (row: any) => {
  242. return <div>{getMapValueByKey(row.audioType, new Map(Object.entries(musicSheetAudioType)))}</div>
  243. }
  244. },
  245. {
  246. title: '可用声部',
  247. key: 'subjectIdNames'
  248. },
  249. {
  250. title: '曲目分类',
  251. key: 'musicSheetCategoryName'
  252. },
  253. // {
  254. // title: '可用途径',
  255. // key: 'availableType',
  256. // render: (row: any) => {
  257. // return <div>{getMapValueByKey(row.availableType, new Map(Object.entries(musicSheetAvailableType)))}</div>
  258. // }
  259. // },
  260. // {
  261. // title: '收费方式',
  262. // key: 'paymentType',
  263. // render: (row: any) => {
  264. // return <div>{getMapValueByKey(row.paymentType, new Map(Object.entries(musicSheetPaymentType)))}</div>
  265. // }
  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="cooleshow-edu"
  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="musicCategoryId">
  396. <NCascader
  397. valueField="id"
  398. labelField="name"
  399. children-field="children"
  400. placeholder="请选择曲目分类"
  401. v-model:value={state.searchForm.musicCategoryId}
  402. options={state.musicSheetCategories}
  403. clearable
  404. />
  405. </NFormItem>
  406. {/*<NFormItem*/}
  407. {/* label="可用途径"*/}
  408. {/* path="availableType"*/}
  409. {/*>*/}
  410. {/* <NSelect*/}
  411. {/* placeholder="请选择可用途径"*/}
  412. {/* v-model:value={state.searchForm.availableType}*/}
  413. {/* options={getSelectDataFromObj(musicSheetAvailableType)}*/}
  414. {/* clearable*/}
  415. {/* >*/}
  416. {/* </NSelect>*/}
  417. {/*</NFormItem>*/}
  418. <NFormItem label="状态" path="status">
  419. <NSelect
  420. v-model:value={state.searchForm.status}
  421. placeholder="请选择状态"
  422. options={
  423. [
  424. {
  425. label: '启用',
  426. value: true
  427. },
  428. {
  429. label: '停用',
  430. value: false
  431. }
  432. ] as any
  433. }
  434. clearable
  435. />
  436. </NFormItem>
  437. <NFormItem label="上传时间" path="authorFrom">
  438. <NDatePicker
  439. v-model:value={state.searchForm.times}
  440. type="daterange"
  441. clearable
  442. value-format="yyyy.MM.dd"
  443. startPlaceholder="开始时间"
  444. endPlaceholder="结束时间"
  445. />
  446. </NFormItem>
  447. <NFormItem>
  448. <NSpace>
  449. <NButton type="primary" onClick={onSearch}>
  450. 搜索
  451. </NButton>
  452. <NButton type="default" onClick={onBtnReset}>
  453. 重置
  454. </NButton>
  455. </NSpace>
  456. </NFormItem>
  457. </SaveForm>
  458. <div class={['section-container']}>
  459. <NSpace style={{paddingBottom: '12px'}}>
  460. <NButton
  461. type="primary"
  462. //v-auth="musicSheet/save1602302550719426561"
  463. onClick={() => {
  464. state.showAddDialog = true
  465. }}
  466. >
  467. 新增
  468. </NButton>
  469. <NButton
  470. disabled={checkedRowKeysRef.value.length == 0}
  471. //v-auth="musicSheet/save1602302550719426561"
  472. onClick={() => {
  473. onBatchChangeStatus(false)
  474. }}
  475. >
  476. 批量禁用
  477. </NButton>
  478. <NButton
  479. disabled={checkedRowKeysRef.value.length == 0}
  480. //v-auth="musicSheet/save1602302550719426561"
  481. onClick={() => {
  482. onBatchChangeStatus(true)
  483. }}
  484. >
  485. 批量启用
  486. </NButton>
  487. </NSpace>
  488. <NDataTable
  489. loading={state.loading}
  490. columns={columns()}
  491. data={state.dataList}
  492. rowKey={(row: any) => row.applicationExtendId}
  493. onUpdateCheckedRowKeys={handleCheck}
  494. ></NDataTable>
  495. <Pagination
  496. v-model:page={state.pagination.page}
  497. v-model:pageSize={state.pagination.rows}
  498. v-model:pageTotal={state.pagination.pageTotal}
  499. onList={getList}
  500. sync
  501. saveKey="cooleshow-edu"
  502. ></Pagination>
  503. </div>
  504. <NModal
  505. v-model:show={state.showAddDialog}
  506. preset="dialog"
  507. showIcon={false}
  508. title={'添加曲目'}
  509. style={{width: '1200px'}}
  510. >
  511. <AddMusic
  512. onClose={() => (state.showAddDialog = false)}
  513. onGetList={() => {
  514. state.pagination.page = 1
  515. getList()
  516. }}
  517. subjectList={state.subjectList}
  518. appId={state.appId}
  519. musicSheetCategories={state.musicSheetCategories}
  520. />
  521. </NModal>
  522. <NModal
  523. v-model:show={state.showEditDialog}
  524. preset="dialog"
  525. showIcon={false}
  526. title={'修改曲目'}
  527. style={{width: '500px'}}
  528. >
  529. <UpdateMusic
  530. onClose={() => (state.showEditDialog = false)}
  531. onGetList={() => {
  532. state.pagination.page = 1
  533. getList()
  534. }}
  535. rowData={state.updateRow}
  536. appId={state.appId}
  537. musicSheetCategories={state.musicSheetCategories}
  538. />
  539. </NModal>
  540. </div>
  541. )
  542. }
  543. }
  544. })