merge-music.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div class="merge-music">
  3. <el-button type="primary" @click="visible = true">选择乐团</el-button>
  4. <el-button type="primary" @click="studentsVisible = true">已合并学生</el-button>
  5. <empty v-if="isEmpty" desc="暂未选择乐团"/>
  6. <el-collapse v-model="active" @change="changeActive" class="items" v-else>
  7. <el-collapse-item class="item" v-for="(item, key) in items" :key="key" :name="key" >
  8. <template #title>
  9. <div class="header">
  10. <span class="title">
  11. <span>{{item.name}}</span>
  12. </span>
  13. <span style="width: 20%;">
  14. <span>学员人数:已选{{item.num}}人</span>
  15. <i @click.stop="remove(key)" class="icon el-icon-circle-close"></i>
  16. </span>
  17. </div>
  18. </template>
  19. <selectItem :active="active" :id="item.id" @selected="selected"/>
  20. </el-collapse-item>
  21. </el-collapse>
  22. <div class="btns">
  23. <el-button type="primary" @click="$emit('chiosetab', 1)">上一步</el-button>
  24. <el-button type="primary" @click="merge">确认合并</el-button>
  25. </div>
  26. <el-dialog
  27. title="选择乐团"
  28. :visible.sync="visible"
  29. width="700px"
  30. >
  31. <selectMusic
  32. :visible="visible"
  33. @close="visible = false"
  34. @submited="submited"
  35. />
  36. </el-dialog>
  37. <el-dialog
  38. title="查看已合并学生"
  39. :visible.sync="studentsVisible"
  40. width="700px"
  41. >
  42. <mergedStudents
  43. @close="studentsVisible = false"
  44. @submited="submited"
  45. />
  46. </el-dialog>
  47. </div>
  48. </template>
  49. <script>
  50. import { getTeamList, getPayType } from "@/api/teamServer";
  51. import { addMusicGroupRegs } from '../api'
  52. import selectMusic from './select-msic'
  53. import selectItem from './select-item'
  54. import mergedStudents from './merged-students'
  55. export default {
  56. components: {
  57. selectMusic,
  58. selectItem,
  59. mergedStudents,
  60. },
  61. data() {
  62. return {
  63. active: '',
  64. visible: false,
  65. studentsVisible: false,
  66. tableData: [],
  67. passed: [],
  68. items: {},
  69. studentsByMusicId: {}
  70. };
  71. },
  72. computed: {
  73. isEmpty() {
  74. return Object.keys(this.items).length === 0
  75. },
  76. },
  77. mounted() {
  78. // this.FetchList()
  79. },
  80. methods: {
  81. changeActive(val) {
  82. this.active = val
  83. },
  84. submited(vals) {
  85. const data = {}
  86. for (const item of vals) {
  87. if (!data[item.id]) {
  88. data[item.id] = {...item, num: 0}
  89. } else {
  90. data[item.id] = {
  91. ...data[item.id],
  92. ...item,
  93. }
  94. }
  95. }
  96. this.items = data
  97. },
  98. remove(key) {
  99. const data = {...this.items}
  100. const select = {...this.studentsByMusicId}
  101. delete data[key]
  102. delete select[key]
  103. this.items = {...data}
  104. this.studentsByMusicId = {...select}
  105. },
  106. selected(list, key) {
  107. const data = this.studentsByMusicId
  108. if (!data[key]) {
  109. data[key] = []
  110. }
  111. data[key] = list
  112. this.items[key].num = list.length
  113. this.items = this.items
  114. this.studentsByMusicId = data
  115. },
  116. async merge() {
  117. let allId = []
  118. for (const key in this.studentsByMusicId) {
  119. if (Object.hasOwnProperty.call(this.studentsByMusicId, key)) {
  120. const item = this.studentsByMusicId[key]
  121. allId = allId.concat(item)
  122. }
  123. }
  124. try {
  125. await this.$confirm('是否确认合并乐团?', '提示', {
  126. type: 'warning'
  127. })
  128. await addMusicGroupRegs({
  129. musicGroupId: this.$route.query.id,
  130. registerIds: allId
  131. })
  132. this.$message.success('合并成功')
  133. this.$emit('chiosetab', 2)
  134. } catch (error) {}
  135. },
  136. handleSelectionChange(arr) {
  137. const passed = [];
  138. for (let i in arr) {
  139. passed.push(arr[i].id);
  140. }
  141. this.passed = passed;
  142. },
  143. async FetchList() {
  144. try {
  145. const res = await getTeamList()
  146. this.tableData = res.data.rows
  147. } catch (error) {}
  148. },
  149. },
  150. };
  151. </script>
  152. <style lang="less" scoped>
  153. .merge-music{
  154. /deep/ .items{
  155. margin-top: 20px;
  156. }
  157. /deep/ .item{
  158. /deep/ .el-collapse-item__header.is-active {
  159. border-bottom-color: #EBEEF5;
  160. }
  161. >div:first-child{
  162. margin-bottom: 10px;
  163. }
  164. // margin-bottom: 10px;
  165. }
  166. /deep/ .header{
  167. display: flex;
  168. align-items: center;
  169. width: 98%;
  170. justify-content: space-between;
  171. // margin-bottom: 10px;
  172. >span:first-child{
  173. display: flex;
  174. &::before{
  175. content: '';
  176. display: inline-block;
  177. width: 5px;
  178. background-color: #14928A;
  179. margin-right: 10px;
  180. border-radius: 2px;
  181. height: 48px;
  182. position: absolute;
  183. }
  184. }
  185. .icon{
  186. font-size: 18px;
  187. font-weight: normal;
  188. margin-right: 20px;
  189. }
  190. }
  191. }
  192. .title{
  193. position: relative;
  194. display: block;
  195. max-width: 60%;
  196. >span{
  197. display: block;
  198. margin-left: 20px;
  199. font-weight: normal;
  200. flex: 1;
  201. overflow: hidden;
  202. text-overflow: ellipsis;
  203. overflow: hidden;
  204. text-overflow: ellipsis;
  205. height: 48px;
  206. line-height: 48px;
  207. white-space: pre;
  208. }
  209. }
  210. .btns{
  211. margin-top: 20px;
  212. text-align: right;
  213. }
  214. </style>