updateMusic.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import {defineComponent, onMounted, reactive, ref} from "vue";
  2. import {NButton, NCascader, NForm, NFormItem, NInputNumber, NSelect, 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. paymentType: null as any,
  28. })
  29. const formsRef = ref()
  30. const state = reactive({
  31. rowData: null as any,
  32. musicSheetCategories: [] as any,
  33. })
  34. onMounted(async () => {
  35. state.rowData = props.rowData
  36. state.musicSheetCategories = props.musicSheetCategories
  37. const {data} = await musicSheetApplicationExtendCategoryApplicationExtendInfo({musicSheetId: state.rowData.id, applicationId: props.appId}) as any
  38. if (!data) {
  39. message.error("加载应用失败")
  40. return
  41. }
  42. forms.musicSheetCategoryId = data[0].musicSheetCategoryId
  43. forms.sortNo = data[0].sortNo
  44. forms.paymentType = data[0].paymentType
  45. })
  46. const onSubmit = async () => {
  47. formsRef.value.validate(async (error: any) => {
  48. if (error) return false
  49. btnLoading.value = true
  50. try {
  51. const res = await musicSheetApplicationExtendUpdate(
  52. {
  53. ...forms,
  54. musicSheetId: state.rowData.id,
  55. applicationId: props.appId
  56. }
  57. ) as any;
  58. if (res && res.code === 200) {
  59. emit('close')
  60. emit('getList')
  61. }
  62. } catch (error) {
  63. }
  64. btnLoading.value = false
  65. })
  66. }
  67. return () => {
  68. return (
  69. <div style="background: #fff; padding-top: 12px">
  70. <NForm
  71. ref={formsRef}
  72. labelPlacement="top"
  73. model={forms}
  74. label-placement="left"
  75. label-width="auto"
  76. >
  77. <NFormItem
  78. label="乐谱教材"
  79. path="musicSheetCategoryId"
  80. rule={[
  81. {
  82. required: true,
  83. message: '请选择乐谱教材'
  84. }
  85. ]}
  86. >
  87. <NCascader
  88. valueField="id"
  89. labelField="name"
  90. children-field="children"
  91. placeholder="请选择乐谱教材"
  92. value={forms.musicSheetCategoryId}
  93. options={state.musicSheetCategories}
  94. onUpdateValue={(value: any) => {
  95. forms.musicSheetCategoryId = value
  96. }}
  97. clearable
  98. />
  99. </NFormItem>
  100. <NFormItem
  101. label="收费方式"
  102. path="paymentType"
  103. rule={[
  104. {
  105. required: true,
  106. message: '请选择收费方式'
  107. }
  108. ]}
  109. >
  110. <NSelect
  111. placeholder="请选择收费方式"
  112. options={[
  113. {
  114. label:'免费',
  115. value:'FREE'
  116. },
  117. {
  118. label:'会员',
  119. value:'VIP'
  120. }
  121. ]}
  122. v-model:value={forms.paymentType}
  123. clearable
  124. />
  125. </NFormItem>
  126. <NFormItem
  127. label="排序值"
  128. path="sortNo"
  129. rule={[
  130. {
  131. required: true,
  132. message: '请输入排序值'
  133. }
  134. ]}
  135. >
  136. <NInputNumber
  137. v-model:value={forms.sortNo}
  138. placeholder="请输入排序值"
  139. clearable
  140. min={0}
  141. max={9999}
  142. style={{width: '100%'}}
  143. />
  144. </NFormItem>
  145. </NForm>
  146. <NSpace justify="end">
  147. <NButton onClick={() => emit('close')}>取消</NButton>
  148. <NButton type="primary" onClick={onSubmit}
  149. loading={btnLoading.value}
  150. disabled={btnLoading.value}
  151. >
  152. 保存
  153. </NButton>
  154. </NSpace>
  155. </div>
  156. )
  157. }
  158. }
  159. })