updateMusic.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import {defineComponent, onMounted, reactive, ref} from "vue";
  2. import {NButton, NCascader, NForm, NFormItem, NInputNumber, NSpace, useMessage} from "naive-ui";
  3. import {musicSheetApplicationExtendCategoryApplicationExtendInfo, musicSheetApplicationExtendUpdate} from "@views/music-library/api";
  4. export default defineComponent({
  5. name: 'project-music-cooleshow-edu-updateMusic',
  6. props: {
  7. appId: {
  8. type: String,
  9. required: true
  10. },
  11. rowData: {
  12. type: Object,
  13. required: true
  14. },
  15. musicSheetCategories: {
  16. type: Array,
  17. default: () => []
  18. }
  19. },
  20. emits: ['close', 'getList'],
  21. setup(props, {slots, attrs, emit}) {
  22. const message = useMessage()
  23. const btnLoading = ref(false)
  24. const forms = reactive({
  25. musicSheetCategoryId: null as any,
  26. sortNo: null as any,
  27. })
  28. const formsRef = ref()
  29. const state = reactive({
  30. rowData: null as any,
  31. musicSheetCategories: [] as any,
  32. })
  33. onMounted(async () => {
  34. state.rowData = props.rowData
  35. state.musicSheetCategories = props.musicSheetCategories
  36. const {data} = await musicSheetApplicationExtendCategoryApplicationExtendInfo({musicSheetId: state.rowData.id, applicationId: props.appId}) as any
  37. if (!data) {
  38. message.error("加载应用失败")
  39. return
  40. }
  41. forms.musicSheetCategoryId = data[0].musicSheetCategoryId
  42. forms.sortNo = data[0].sortNo
  43. })
  44. const onSubmit = async () => {
  45. formsRef.value.validate(async (error: any) => {
  46. if (error) return false
  47. btnLoading.value = true
  48. try {
  49. const res = await musicSheetApplicationExtendUpdate(
  50. {
  51. ...forms,
  52. musicSheetId: state.rowData.id,
  53. applicationId: props.appId
  54. }
  55. ) as any;
  56. if (res && res.code === 200) {
  57. emit('close')
  58. emit('getList')
  59. }
  60. } catch (error) {
  61. }
  62. btnLoading.value = false
  63. })
  64. }
  65. return () => {
  66. return (
  67. <div style="background: #fff; padding-top: 12px">
  68. <NForm
  69. ref={formsRef}
  70. labelPlacement="top"
  71. model={forms}
  72. label-placement="left"
  73. label-width="auto"
  74. >
  75. <NFormItem
  76. label="乐谱教材"
  77. path="musicSheetCategoryId"
  78. rule={[
  79. {
  80. required: true,
  81. message: '请选择乐谱教材'
  82. }
  83. ]}
  84. >
  85. <NCascader
  86. valueField="id"
  87. labelField="name"
  88. children-field="children"
  89. placeholder="请选择乐谱教材"
  90. value={forms.musicSheetCategoryId}
  91. options={state.musicSheetCategories}
  92. checkStrategy={"child"}
  93. onUpdateValue={(value: any) => {
  94. forms.musicSheetCategoryId = value
  95. }}
  96. clearable
  97. />
  98. </NFormItem>
  99. <NFormItem
  100. label="排序值"
  101. path="sortNo"
  102. rule={[
  103. {
  104. required: true,
  105. message: '请输入排序值'
  106. }
  107. ]}
  108. >
  109. <NInputNumber
  110. v-model:value={forms.sortNo}
  111. placeholder="请输入排序值"
  112. clearable
  113. min={0}
  114. max={9999}
  115. style={{width: '100%'}}
  116. />
  117. </NFormItem>
  118. </NForm>
  119. <NSpace justify="end">
  120. <NButton onClick={() => emit('close')}>取消</NButton>
  121. <NButton type="primary" onClick={onSubmit}
  122. loading={btnLoading.value}
  123. disabled={btnLoading.value}
  124. >
  125. 保存
  126. </NButton>
  127. </NSpace>
  128. </div>
  129. )
  130. }
  131. }
  132. })