music-sheet-klx.tsx 19 KB

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