merge-music.vue 5.4 KB

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