updateMusic.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 {scoreType} from "@/utils/constant";
  6. import {formatTree} from "@views/music-library/musicUtil";
  7. export default defineComponent({
  8. name: 'project-music-cooleshow-edu-updateMusic',
  9. props: {
  10. appId: {
  11. type: String,
  12. required: true
  13. },
  14. rowData: {
  15. type: Object,
  16. required: true
  17. },
  18. musicSheetCategories: {
  19. type: Array,
  20. default: () => []
  21. }
  22. },
  23. emits: ['close', 'getList'],
  24. setup(props, {slots, attrs, emit}) {
  25. const message = useMessage()
  26. const btnLoading = ref(false)
  27. const forms = reactive({
  28. musicSheetCategoryId: null as any,
  29. sortNo: null as any,
  30. availableType: null as any,
  31. isConvertibleScore: null as any,//是否支持转简谱
  32. status: false, // 是否启用
  33. scoreType: null as any,//默认谱面
  34. })
  35. const formsRef = ref()
  36. const state = reactive({
  37. rowData: null as any,
  38. musicSheetCategories: [] as any,
  39. })
  40. onMounted(async () => {
  41. state.rowData = props.rowData
  42. formatTree(props.musicSheetCategories)
  43. state.musicSheetCategories = props.musicSheetCategories
  44. const {data} = await musicSheetApplicationExtendCategoryApplicationExtendInfo({musicSheetId: state.rowData.id, applicationId: props.appId}) as any
  45. if (!data) {
  46. message.error("加载应用失败")
  47. return
  48. }
  49. forms.musicSheetCategoryId = data[0].musicSheetCategoryId
  50. forms.sortNo = data[0].sortNo
  51. forms.availableType = data[0].availableType
  52. forms.isConvertibleScore = data[0].isConvertibleScore
  53. forms.scoreType = data[0].scoreType
  54. forms.status = data[0].clientStatus
  55. })
  56. const onSubmit = async () => {
  57. formsRef.value.validate(async (error: any) => {
  58. if (error) return false
  59. btnLoading.value = true
  60. try {
  61. const res = await musicSheetApplicationExtendUpdate(
  62. {
  63. ...forms,
  64. musicSheetId: state.rowData.id,
  65. applicationId: props.appId
  66. }
  67. ) as any;
  68. if (res && res.code === 200) {
  69. emit('close')
  70. emit('getList')
  71. }
  72. } catch (error) {
  73. }
  74. btnLoading.value = false
  75. })
  76. }
  77. return () => {
  78. return (
  79. <div style="background: #fff; padding-top: 12px">
  80. <NForm
  81. ref={formsRef}
  82. labelPlacement="top"
  83. model={forms}
  84. label-placement="left"
  85. label-width="auto"
  86. >
  87. <NFormItem
  88. label="曲目分类"
  89. path="musicSheetCategoryId"
  90. rule={[
  91. {
  92. required: true,
  93. message: '请选择曲目分类'
  94. }
  95. ]}
  96. >
  97. <NCascader
  98. valueField="id"
  99. labelField="name"
  100. children-field="children"
  101. placeholder="请选择曲目分类"
  102. disabledField={'disabled'}
  103. value={forms.musicSheetCategoryId}
  104. options={state.musicSheetCategories}
  105. onUpdateValue={(value: any) => {
  106. forms.musicSheetCategoryId = value
  107. }}
  108. clearable
  109. />
  110. </NFormItem>
  111. <NFormItem
  112. label="可用途径"
  113. path="availableType"
  114. rule={[
  115. {
  116. required: true,
  117. message: '请选择可用途径'
  118. }
  119. ]}
  120. >
  121. <NSelect
  122. placeholder="请选择可用途径"
  123. options={[
  124. {
  125. label: '学校',
  126. value: 'ORG'
  127. },
  128. {
  129. label: '平台',
  130. value: 'PLATFORM'
  131. },
  132. ]}
  133. v-model:value={forms.availableType}
  134. clearable
  135. />
  136. </NFormItem>
  137. <NFormItem
  138. label="默认谱面"
  139. path="scoreType"
  140. rule={[
  141. {
  142. required: true,
  143. message: '请选择默认谱面'
  144. }
  145. ]}
  146. >
  147. <NSelect
  148. v-model:value={forms.scoreType}
  149. placeholder="请选择默认谱面"
  150. options={getSelectDataFromObj(scoreType)}
  151. clearable
  152. />
  153. </NFormItem>
  154. <NFormItem
  155. label="支持转谱"
  156. path="isConvertibleScore"
  157. rule={[
  158. {
  159. required: true,
  160. message: '请选择是否支持转谱',
  161. trigger: ['input', 'blur'],
  162. type: 'boolean'
  163. }
  164. ]}
  165. >
  166. <NSelect
  167. v-model:value={forms.isConvertibleScore}
  168. options={
  169. [
  170. {
  171. label: '是',
  172. value: true
  173. },
  174. {
  175. label: '否',
  176. value: false
  177. }
  178. ] as any
  179. }
  180. placeholder="请选择是否支持转谱"
  181. onUpdateValue={async (value: any) => {
  182. if (!value) {
  183. //如果不支持,修改默认谱面
  184. // forms.scoreType = 'STAVE'
  185. }
  186. }}
  187. clearable
  188. ></NSelect>
  189. </NFormItem>
  190. <NFormItem
  191. label="是否启用"
  192. path="status"
  193. rule={[
  194. {
  195. required: true,
  196. message: '请选择是否启用'
  197. }
  198. ]}
  199. >
  200. <NSelect
  201. placeholder="请选择是否启用"
  202. options={[
  203. {
  204. label: '是',
  205. value: true
  206. },
  207. {
  208. label: '否',
  209. value: false
  210. }
  211. ] as any}
  212. v-model:value={forms.status}
  213. clearable
  214. />
  215. </NFormItem>
  216. <NFormItem
  217. label="排序值"
  218. path="sortNo"
  219. >
  220. <NInputNumber
  221. v-model:value={forms.sortNo}
  222. placeholder="请输入排序值"
  223. clearable
  224. min={0}
  225. max={9999}
  226. style={{width: '100%'}}
  227. />
  228. </NFormItem>
  229. </NForm>
  230. <NSpace justify="end">
  231. <NButton onClick={() => emit('close')}>取消</NButton>
  232. <NButton type="primary" onClick={onSubmit}
  233. loading={btnLoading.value}
  234. disabled={btnLoading.value}
  235. >
  236. 保存
  237. </NButton>
  238. </NSpace>
  239. </div>
  240. )
  241. }
  242. }
  243. })