addMusic.tsx 18 KB

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