addMusic.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. import { defineComponent, h, onMounted, reactive, ref } from 'vue'
  2. import SaveForm from '@components/save-form'
  3. import {
  4. DataTableColumns,
  5. DataTableRowKey,
  6. NButton,
  7. NCascader,
  8. NDataTable,
  9. NFormItem,
  10. NIcon,
  11. NImage,
  12. NInput,
  13. NInputNumber,
  14. NSelect,
  15. NSpace,
  16. NStep,
  17. NSteps,
  18. useDialog,
  19. useMessage
  20. } from 'naive-ui'
  21. import Pagination from '@components/pagination'
  22. import { getMapValueByKey, getSelectDataFromObj } from '@/utils/objectUtil'
  23. import { musicSheetPaymentType, musicSheetSourceType, musicSheetType } from '@/utils/constant'
  24. import { musicSheetApplicationExtendSaveBatch, musicSheetPage } from '@views/music-library/api'
  25. import deepClone from '@/utils/deep.clone'
  26. import { getOwnerName } from '@views/music-library/musicUtil'
  27. import TheTooltip from '@/components/TheTooltip'
  28. export default defineComponent({
  29. name: 'gym-addMusic',
  30. props: {
  31. appId: {
  32. type: String,
  33. required: true
  34. },
  35. subjectList: {
  36. type: Array,
  37. default: () => []
  38. },
  39. musicSheetCategories: {
  40. type: Array,
  41. default: () => []
  42. }
  43. },
  44. emits: ['close', 'getList'],
  45. setup(props, { slots, attrs, emit }) {
  46. const dialogs = useDialog()
  47. const message = useMessage()
  48. const state = reactive({
  49. loading: false,
  50. pagination: {
  51. page: 1,
  52. rows: 5,
  53. pageTotal: 0
  54. },
  55. stepPagination: {
  56. page: 1,
  57. rows: 5,
  58. pageTotal: 0
  59. },
  60. searchForm: {
  61. keyword: null,
  62. musicSheetType: null,
  63. subjectId: null,
  64. sourceType: null
  65. },
  66. subjectList: [] as any,
  67. showAdd: false,
  68. currentStep: 1,
  69. dataList: [],
  70. selectRowData: [] as any, // 选择的数据列表
  71. musicSheetCategories: [] as any,
  72. startSortNum: null as any, // 排序起始值
  73. projectMusicCategoryId: null as any, // 曲目分类ID
  74. globalPaymentType: null as any //收费方式
  75. })
  76. onMounted(() => {
  77. state.subjectList = props.subjectList
  78. state.musicSheetCategories = props.musicSheetCategories
  79. getList()
  80. })
  81. const getList = async () => {
  82. try {
  83. state.loading = true
  84. const { data } = await musicSheetPage({
  85. ...state.pagination,
  86. ...state.searchForm,
  87. addAppId: props.appId
  88. })
  89. state.pagination.pageTotal = Number(data.total)
  90. state.dataList = data.rows || []
  91. } catch {}
  92. state.loading = false
  93. }
  94. const saveForm = ref()
  95. const onSearch = () => {
  96. saveForm.value?.submit()
  97. }
  98. const onBtnReset = () => {
  99. saveForm.value?.reset()
  100. }
  101. const onSubmit = () => {
  102. state.pagination.page = 1
  103. getList()
  104. }
  105. const onSave = async () => {
  106. if (state.selectRowData.length == 0) {
  107. message.error('未选择曲目')
  108. return
  109. }
  110. const params = [] as any[]
  111. for (let i = 0; i < state.selectRowData.length; i++) {
  112. const item = state.selectRowData[i]
  113. if (!item.projectMusicCategoryId) {
  114. message.error('曲目分类不能为空')
  115. return
  116. }
  117. if (!item.sortNo || !item.projectMusicCategoryId) {
  118. message.error('排序号不能为空')
  119. return
  120. }
  121. params.push({
  122. ...item,
  123. musicSheetId: item.id,
  124. musicSheetCategoryId: item.projectMusicCategoryId,
  125. applicationId: props.appId,
  126. id: null
  127. })
  128. }
  129. const res = (await musicSheetApplicationExtendSaveBatch(params)) as any
  130. if (res && res.code == '200') {
  131. message.success(`添加成功`)
  132. emit('getList')
  133. emit('close')
  134. }
  135. }
  136. const columnsField = [
  137. {
  138. type: 'selection'
  139. },
  140. {
  141. title: '曲目编号',
  142. key: 'id'
  143. },
  144. {
  145. title: '封面图',
  146. key: 'titleImg',
  147. render(row: any) {
  148. return <NImage width={40} height={40} src={row.musicCover} />
  149. }
  150. },
  151. {
  152. title: '声部',
  153. key: 'subjectNames'
  154. },
  155. {
  156. title: '曲目名称',
  157. key: 'name'
  158. },
  159. {
  160. title: '音乐人',
  161. key: 'composer'
  162. },
  163. {
  164. title: '曲目类型',
  165. key: 'musicSheetType',
  166. render: (row: any) => {
  167. return (
  168. <div>
  169. {getMapValueByKey(row.musicSheetType, new Map(Object.entries(musicSheetType)))}
  170. </div>
  171. )
  172. }
  173. },
  174. {
  175. title: '作者属性',
  176. key: 'sourceType',
  177. render(row: any) {
  178. return getMapValueByKey(row.sourceType, new Map(Object.entries(musicSheetSourceType)))
  179. }
  180. },
  181. {
  182. title: '所属人',
  183. key: 'userName',
  184. width: 200,
  185. render: (row: any) => {
  186. return <TheTooltip content={getOwnerName(row.musicSheetExtend, row.sourceType)} />
  187. }
  188. }
  189. ]
  190. const columns = (): any => {
  191. return columnsField
  192. }
  193. const stepColumns = (): DataTableColumns => {
  194. const field = deepClone(columnsField)
  195. field.splice(0, 1)
  196. field.push({
  197. title(column: any) {
  198. return (
  199. <NSpace>
  200. 曲目分类
  201. <NButton
  202. type="primary"
  203. size="small"
  204. text
  205. onClick={() => {
  206. dialogs.create({
  207. title: '请选择曲目分类',
  208. showIcon: false,
  209. content: () => {
  210. return h(
  211. 'div',
  212. {
  213. class: 'flex flex-col justify-center items-center text-14px'
  214. },
  215. [
  216. // icon
  217. h(NCascader, {
  218. onUpdateValue(v) {
  219. state.projectMusicCategoryId = v
  220. },
  221. valueField: 'id',
  222. labelField: 'name',
  223. childrenField: 'children',
  224. placeholderField: '请选择曲目分类',
  225. options: state.musicSheetCategories
  226. })
  227. ]
  228. )
  229. },
  230. positiveText: '确定',
  231. negativeText: '取消',
  232. onPositiveClick: () => {
  233. for (let i = 0; i < state.selectRowData.length; i++) {
  234. const item = state.selectRowData[i]
  235. item.projectMusicCategoryId = state.projectMusicCategoryId
  236. }
  237. }
  238. })
  239. }}
  240. >
  241. <NIcon size={15} style="padding-left: 5px;margin-top:4px">
  242. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
  243. <path d="M2 26h28v2H2z" fill="currentColor"></path>
  244. <path
  245. d="M25.4 9c.8-.8.8-2 0-2.8l-3.6-3.6c-.8-.8-2-.8-2.8 0l-15 15V24h6.4l15-15zm-5-5L24 7.6l-3 3L17.4 7l3-3zM6 22v-3.6l10-10l3.6 3.6l-10 10H6z"
  246. fill="currentColor"
  247. ></path>
  248. </svg>
  249. </NIcon>
  250. </NButton>
  251. </NSpace>
  252. )
  253. },
  254. key: 'projectMusicCategoryId',
  255. width: 200,
  256. render: (row: any) => {
  257. // })
  258. return (
  259. <NCascader
  260. valueField="id"
  261. labelField="name"
  262. children-field="children"
  263. placeholder="请选择曲目分类"
  264. value={row.projectMusicCategoryId}
  265. options={state.musicSheetCategories}
  266. onUpdateValue={(value: any) => {
  267. row.projectMusicCategoryId = value
  268. }}
  269. clearable
  270. />
  271. )
  272. }
  273. })
  274. field.push({
  275. title(column: any) {
  276. return (
  277. <NSpace>
  278. 收费方式
  279. <NButton
  280. type="primary"
  281. size="small"
  282. text
  283. onClick={() => {
  284. dialogs.create({
  285. title: '请选择收费方式',
  286. showIcon: false,
  287. content: () => {
  288. return h(
  289. 'div',
  290. {
  291. class: 'flex flex-col justify-center items-center text-14px'
  292. },
  293. [
  294. h(NSelect, {
  295. onUpdateValue(v) {
  296. state.globalPaymentType = v
  297. },
  298. clearable: true,
  299. options: getSelectDataFromObj(musicSheetPaymentType)
  300. })
  301. ]
  302. )
  303. },
  304. positiveText: '确定',
  305. negativeText: '取消',
  306. onPositiveClick: () => {
  307. for (let i = 0; i < state.selectRowData.length; i++) {
  308. const item = state.selectRowData[i]
  309. item.paymentType = state.globalPaymentType
  310. }
  311. }
  312. })
  313. }}
  314. >
  315. <NIcon size={15} style="padding-left: 5px;margin-top:4px">
  316. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
  317. <path d="M2 26h28v2H2z" fill="currentColor"></path>
  318. <path
  319. d="M25.4 9c.8-.8.8-2 0-2.8l-3.6-3.6c-.8-.8-2-.8-2.8 0l-15 15V24h6.4l15-15zm-5-5L24 7.6l-3 3L17.4 7l3-3zM6 22v-3.6l10-10l3.6 3.6l-10 10H6z"
  320. fill="currentColor"
  321. ></path>
  322. </svg>
  323. </NIcon>
  324. </NButton>
  325. </NSpace>
  326. )
  327. },
  328. key: 'paymentType',
  329. width: 200,
  330. render: (row: any) => {
  331. return (
  332. <NSelect
  333. placeholder="请选择收费方式"
  334. value={row.paymentType}
  335. options={getSelectDataFromObj(musicSheetPaymentType)}
  336. clearable
  337. onUpdateValue={(value) => {
  338. row['paymentType'] = value
  339. }}
  340. />
  341. )
  342. }
  343. })
  344. field.push({
  345. title(column: any) {
  346. return (
  347. <NSpace>
  348. 排序
  349. <NButton
  350. type="primary"
  351. size="small"
  352. text
  353. onClick={() => {
  354. dialogs.create({
  355. title: '请输入排序起始值',
  356. showIcon: false,
  357. content: () => {
  358. return h(
  359. 'div',
  360. {
  361. class: 'flex flex-col justify-center items-center text-14px'
  362. },
  363. [
  364. // icon
  365. h(NInputNumber, {
  366. onUpdateValue(v) {
  367. state.startSortNum = v
  368. },
  369. min: 0,
  370. max: 9999
  371. })
  372. ]
  373. )
  374. },
  375. positiveText: '确定',
  376. negativeText: '取消',
  377. onPositiveClick: () => {
  378. if (state.startSortNum) {
  379. for (let i = 0; i < state.selectRowData.length; i++) {
  380. const item = state.selectRowData[i]
  381. item.sortNo = state.startSortNum + i
  382. }
  383. }
  384. }
  385. })
  386. }}
  387. >
  388. <NIcon size={15} style="padding-left: 5px;margin-top:4px">
  389. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
  390. <path d="M2 26h28v2H2z" fill="currentColor"></path>
  391. <path
  392. d="M25.4 9c.8-.8.8-2 0-2.8l-3.6-3.6c-.8-.8-2-.8-2.8 0l-15 15V24h6.4l15-15zm-5-5L24 7.6l-3 3L17.4 7l3-3zM6 22v-3.6l10-10l3.6 3.6l-10 10H6z"
  393. fill="currentColor"
  394. ></path>
  395. </svg>
  396. </NIcon>
  397. </NButton>
  398. </NSpace>
  399. )
  400. },
  401. key: 'sortNo',
  402. width: 150,
  403. render: (row: any) => {
  404. return h(NInputNumber, {
  405. value: row.sortNo,
  406. min: 0,
  407. max: 9999,
  408. onUpdateValue(value: any) {
  409. row.sortNo = value
  410. }
  411. })
  412. }
  413. })
  414. field.push({
  415. title: '操作',
  416. key: 'operation',
  417. fixed: 'right',
  418. render(row: any) {
  419. return (
  420. <NSpace>
  421. <NButton
  422. type="primary"
  423. size="small"
  424. text
  425. //v-auth="musicSheet/update1602302618558099458"
  426. onClick={() => {
  427. dialogs.warning({
  428. title: '警告',
  429. content: `是否删除该数据?`,
  430. positiveText: '确定',
  431. negativeText: '取消',
  432. onPositiveClick: async () => {
  433. try {
  434. const index = state.selectRowData.findIndex((item: any) => {
  435. if (item.id == row.id) {
  436. return true
  437. }
  438. })
  439. if (index > -1) {
  440. state.selectRowData.splice(index, 1)
  441. }
  442. const index1 = checkedRowKeysRef.value.findIndex((item: any) => {
  443. if (item == row.id) {
  444. return true
  445. }
  446. })
  447. if (index1 > -1) {
  448. checkedRowKeysRef.value.splice(index, 1)
  449. }
  450. } catch {}
  451. }
  452. })
  453. }}
  454. >
  455. 移除
  456. </NButton>
  457. </NSpace>
  458. )
  459. }
  460. })
  461. return field
  462. }
  463. const checkedRowKeysRef = ref<DataTableRowKey[]>([])
  464. const handleCheck = (rowKeys: DataTableRowKey[]) => {
  465. checkedRowKeysRef.value = rowKeys
  466. // 添加行更新值
  467. state.dataList.forEach((next: any) => {
  468. if (checkedRowKeysRef.value.includes(next.id)) {
  469. const find = state.selectRowData.find((row: any) => {
  470. return row.id === next.id
  471. })
  472. if (!find) {
  473. state.selectRowData.push(next)
  474. }
  475. }
  476. })
  477. // 去掉行更新值
  478. state.selectRowData = state.selectRowData.filter((next: any) => {
  479. return checkedRowKeysRef.value.includes(next.id)
  480. })
  481. }
  482. return () => {
  483. return (
  484. <div class="system-menu-container">
  485. <NSpace vertical size="medium">
  486. <NSteps
  487. current={state.currentStep}
  488. // onUpdateCurrent={()=>{
  489. // state.currentStep = val
  490. // }}
  491. style={'margin-bottom: 10px;margin-top: 10px'}
  492. >
  493. <NStep title="选择曲目" description=""></NStep>
  494. <NStep title="设置曲目信息" description=""></NStep>
  495. </NSteps>
  496. </NSpace>
  497. {state.currentStep === 1 && (
  498. <div class="system-menu-container">
  499. <SaveForm
  500. ref={saveForm}
  501. model={state.searchForm}
  502. onSubmit={onSubmit}
  503. // saveKey="cooleshow-edu-addMusic"
  504. onSetModel={(val: any) => (state.searchForm = val)}
  505. >
  506. <NFormItem label="关键词" path="keyword">
  507. <NInput
  508. v-model:value={state.searchForm.keyword}
  509. placeholder="请输入曲目名称/编号"
  510. clearable
  511. />
  512. </NFormItem>
  513. <NFormItem label="曲目类型" path="musicSheetType">
  514. <NSelect
  515. placeholder="请选择曲目类型"
  516. v-model:value={state.searchForm.musicSheetType}
  517. options={getSelectDataFromObj(musicSheetType)}
  518. clearable
  519. />
  520. </NFormItem>
  521. <NFormItem label="声部" path="musicSubject">
  522. <NSelect
  523. placeholder="请选择声部"
  524. v-model:value={state.searchForm.subjectId}
  525. options={state.subjectList}
  526. clearable
  527. />
  528. </NFormItem>
  529. <NFormItem label="曲目来源" path="sourceType">
  530. <NSelect
  531. placeholder="请选择曲目来源"
  532. v-model:value={state.searchForm.sourceType}
  533. options={getSelectDataFromObj(musicSheetSourceType)}
  534. // onUpdateValue={async (value: any) => {
  535. // }}
  536. clearable
  537. />
  538. </NFormItem>
  539. <NFormItem>
  540. <NSpace>
  541. <NButton type="primary" onClick={onSearch}>
  542. 搜索
  543. </NButton>
  544. <NButton type="default" onClick={onBtnReset}>
  545. 重置
  546. </NButton>
  547. </NSpace>
  548. </NFormItem>
  549. </SaveForm>
  550. <p style={{ paddingBottom: '12px' }}>
  551. 你选择了<span style={'color:red;padding:0 8px'}>{state.selectRowData.length}</span>
  552. 条曲目
  553. </p>
  554. <NDataTable
  555. loading={state.loading}
  556. columns={columns()}
  557. data={state.dataList}
  558. rowKey={(row: any) => row.id}
  559. onUpdateCheckedRowKeys={handleCheck}
  560. ></NDataTable>
  561. <Pagination
  562. v-model:page={state.pagination.page}
  563. v-model:pageSize={state.pagination.rows}
  564. v-model:pageTotal={state.pagination.pageTotal}
  565. onList={getList}
  566. sync
  567. // saveKey="cooleshow-edu-addMusic"
  568. ></Pagination>
  569. </div>
  570. )}
  571. {state.currentStep === 2 && (
  572. <div class="system-menu-container" style={'margin-top: 15px;'}>
  573. <NDataTable
  574. loading={state.loading}
  575. columns={stepColumns()}
  576. data={state.selectRowData}
  577. rowKey={(row: any) => row.id}
  578. maxHeight={500}
  579. scrollX={1800}
  580. ></NDataTable>
  581. </div>
  582. )}
  583. <NSpace justify="end" style={'margin-top:10px'}>
  584. <NButton
  585. type="default"
  586. onClick={() => {
  587. if (state.currentStep > 1) {
  588. state.currentStep = state.currentStep - 1
  589. } else {
  590. emit('close')
  591. }
  592. }}
  593. >
  594. {state.currentStep === 1 ? '取消' : '上一步'}
  595. </NButton>
  596. <NButton
  597. type="primary"
  598. onClick={() => {
  599. if (state.currentStep < 2) {
  600. if (state.selectRowData.length == 0) {
  601. message.warning('请选择曲目')
  602. return
  603. }
  604. state.currentStep = state.currentStep + 1
  605. } else {
  606. onSave()
  607. }
  608. }}
  609. // loading={btnLoading.value}
  610. // disabled={btnLoading.value}
  611. >
  612. {state.currentStep === 2 ? '确定' : '下一步'}
  613. </NButton>
  614. </NSpace>
  615. </div>
  616. )
  617. }
  618. }
  619. })