updateMusic.tsx 4.8 KB

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