form.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <div>
  3. <el-form ref="form" :model="form" label-width="100px">
  4. <el-form-item
  5. prop="sysExamSong.name"
  6. label="曲名"
  7. :rules="[{required: true, message: '请输入曲名'}]"
  8. >
  9. <el-input placeholder="请输入曲名" v-model="form.sysExamSong.name"/>
  10. </el-form-item>
  11. <el-form-item
  12. label="原音"
  13. prop="sysExamSong.url"
  14. :rules="[{required: true, message: '请选择原音'}]"
  15. >
  16. <singe-file-upload
  17. tips="仅支持上传 mp3/aac 格式音频文件"
  18. accept=".mp3, .aac"
  19. v-model="form.sysExamSong.url"
  20. />
  21. </el-form-item>
  22. <div class="files" v-for="(song, index) in form.sysExamSongAccompaniments" :key="index">
  23. <el-row>
  24. <el-col :span="12">
  25. <el-form-item
  26. :prop="`sysExamSongAccompaniments.${index}.subjectId`"
  27. label="声部"
  28. :rules="[{required: true, message: '请选择声部'}]"
  29. >
  30. <el-select style="width: 100%!important;" v-model="song.subjectId" placeholder="请选择声部">
  31. <el-option
  32. v-for="item in selects.subjects"
  33. :value="String(item.id)"
  34. :label="item.name"
  35. :key="item.id"
  36. :disabled="hasSubjectId(String(item.id))"
  37. ></el-option>
  38. </el-select>
  39. </el-form-item>
  40. </el-col>
  41. <el-col :span="12">
  42. <el-form-item
  43. :prop="`sysExamSongAccompaniments.${index}.speed`"
  44. label="速度"
  45. :rules="[{required: true, message: '请输入速度'}]"
  46. >
  47. <el-input type="number" placeholder="请输入速度" v-model="song.speed"/>
  48. </el-form-item>
  49. </el-col>
  50. <el-col :span="12">
  51. <el-form-item
  52. label="mp3文件"
  53. :prop="`sysExamSongAccompaniments.${index}.mp3Url`"
  54. :rules="[{required: true, message: '请选择mp3文件'}]"
  55. >
  56. <singe-file-upload
  57. tips="仅支持上传 mp3/aac 格式音频文件"
  58. accept=".mp3, .aac"
  59. v-model="song.mp3Url"
  60. />
  61. </el-form-item>
  62. </el-col>
  63. <el-col :span="12">
  64. <el-form-item
  65. label="MusicXML"
  66. :prop="`sysExamSongAccompaniments.${index}.xmlUrl`"
  67. :rules="[{required: true, message: '请选择MusicXML文件'}]"
  68. >
  69. <singe-file-upload
  70. tips="仅支持上传 xml 格式文件"
  71. accept=".xml"
  72. v-model="song.xmlUrl"
  73. />
  74. </el-form-item>
  75. </el-col>
  76. </el-row>
  77. <el-button class="file-remove" type="text" @click="removeSys" :disabled="form.sysExamSongAccompaniments.length == 1">删除</el-button>
  78. </div>
  79. <el-button @click="createSys" type="info" style="width: 100%;margin-bottom: 20px;" plain>添加伴奏</el-button>
  80. <div class="btns">
  81. <el-button type="primary" @click="submit">提交</el-button>
  82. <el-button @click="$listeners.close">取消</el-button>
  83. </div>
  84. </el-form>
  85. </div>
  86. </template>
  87. <script>
  88. import { Add, Update, queryPageSysExam } from '../api'
  89. export default {
  90. props: ['detail', 'type'],
  91. data() {
  92. return {
  93. form: {
  94. sysExamSong: {
  95. name: '',
  96. url: '',
  97. },
  98. sysExamSongAccompaniments: [
  99. {
  100. subjectId: '',
  101. speed: '',
  102. mp3Url: '',
  103. xmlUrl: ''
  104. },
  105. ],
  106. delExamSongAccompanimentIds: []
  107. }
  108. }
  109. },
  110. mounted() {
  111. this.$store.dispatch('setSubjects')
  112. if (this.detail) {
  113. this.$set(this.form, 'sysExamSong', {
  114. name: this.detail.name,
  115. url: this.detail.url,
  116. })
  117. this.FeatchDetailList()
  118. }
  119. },
  120. methods: {
  121. async FeatchDetailList() {
  122. try {
  123. const res = await queryPageSysExam({
  124. sysExamSongId: this.detail.id
  125. })
  126. this.$set(this.form, 'sysExamSongAccompaniments', res.data.rows.map(item => {
  127. item.subjectId = String(item.subjectId)
  128. return item
  129. }))
  130. } catch (error) {}
  131. },
  132. createSys() {
  133. this.form.sysExamSongAccompaniments.push({
  134. subjectId: '',
  135. speed: '',
  136. mp3Url: '',
  137. xmlUrl: ''
  138. })
  139. },
  140. async removeSys(index) {
  141. try {
  142. await this.$confirm('是否确认删除此伴奏?', '提示', {
  143. type: 'warning'
  144. })
  145. if (this.form.sysExamSongAccompaniments[index]) {
  146. this.form.delExamSongAccompanimentIds.push(this.form.sysExamSongAccompaniments[index].id)
  147. }
  148. this.form.sysExamSongAccompaniments.splice(index, 1)
  149. } catch (error) {}
  150. },
  151. hasSubjectId(id) {
  152. const ids = []
  153. for (const item of this.form.sysExamSongAccompaniments) {
  154. ids.push(item.subjectId)
  155. }
  156. return ids.includes(id)
  157. },
  158. async submit() {
  159. this.$refs.form.validate(async (valid) => {
  160. if (valid) {
  161. if (!this.detail) {
  162. await Add({
  163. ...this.form,
  164. sysExamSong: {
  165. ...this.form.sysExamSong,
  166. type: 'COMMON',
  167. }
  168. })
  169. this.$message.success('提交成功')
  170. } else {
  171. await Update({
  172. ...this.form,
  173. sysExamSong: {
  174. ...this.form.sysExamSong,
  175. type: 'COMMON',
  176. id: this.detail.id
  177. }
  178. })
  179. this.$message.success('修改成功')
  180. }
  181. this.$listeners.close()
  182. this.$listeners.submited()
  183. }
  184. })
  185. }
  186. }
  187. }
  188. </script>
  189. <style lang="less" scoped>
  190. .btns{
  191. text-align: right;
  192. }
  193. .files{
  194. background-color: #f8f8f8;
  195. padding: 20px 0;
  196. padding-right: 20px;
  197. margin-bottom: 20px;
  198. border-radius: 5px;
  199. position: relative;
  200. .file-remove{
  201. position: absolute;
  202. right: 20px;
  203. bottom: 10px;
  204. }
  205. }
  206. </style>