merge-music.vue 5.4 KB

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