select-student.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <div>
  3. <el-form :model="form" ref="form" label-suffix=": " inline label-width="90px">
  4. <el-row>
  5. <el-col :span="10">
  6. <el-form-item
  7. label="主教老师"
  8. prop="coreTeacher"
  9. v-if="!isOnlyChangeUser"
  10. :rules="[{ required: true, message: '请选择主教老师' }]"
  11. >
  12. <el-select
  13. v-model.trim="form.coreTeacher"
  14. placeholder="请选择主教老师"
  15. clearable
  16. filterable
  17. >
  18. <el-option
  19. v-for="(item, index) in teacherList"
  20. :key="index"
  21. :label="item.realName"
  22. :value="String(item.id)"
  23. ></el-option>
  24. </el-select>
  25. <!-- <remote-search :commit="'setTeachers'" v-model="form.coreTeacher" /> -->
  26. </el-form-item>
  27. </el-col>
  28. <el-col :span="10" :offset="4">
  29. <el-form-item
  30. label="助教老师"
  31. prop="assistant"
  32. v-if="!isOnlyChangeUser && activeType!='HIGH'&&activeType!='HIGH_ONLINE'&&activeType!='MUSIC_NETWORK'"
  33. >
  34. <!-- <remote-search :commit="'setTeachers'" v-model="form.assistant" :multiple='true'/> -->
  35. <el-select
  36. v-model.trim="form.assistant"
  37. placeholder="请选择助教老师"
  38. filterable
  39. clearable
  40. collapse-tags
  41. multiple
  42. >
  43. <el-option
  44. v-for="(item, index) in cooperationList"
  45. :key="index"
  46. :label="item.realName"
  47. :value="item.id"
  48. ></el-option>
  49. </el-select>
  50. </el-form-item>
  51. </el-col>
  52. </el-row>
  53. <el-row>
  54. <el-col :span="10" v-if="showName">
  55. <el-form-item
  56. label="班级名称"
  57. prop="name"
  58. :rules="[
  59. { required: true, message: '请输入班级名称', trigger: 'blur' },
  60. ]"
  61. >
  62. <el-input
  63. v-model="form.name"
  64. style="width: 100%"
  65. placeholder="请输入班级名称"
  66. />
  67. </el-form-item>
  68. </el-col>
  69. <el-col :span="10" :offset="showName ? 4 : 0">
  70. <el-form-item label="声部" style="margin-right: 0;">
  71. <el-select
  72. v-model="sound"
  73. style="width: 100%"
  74. clearable
  75. multiple
  76. collapse-tags
  77. filterable
  78. placeholder="请选择声部"
  79. >
  80. <el-option
  81. v-for="(item, index) in soundList"
  82. :key="index"
  83. :label="item.name"
  84. :value="item.id"
  85. ></el-option>
  86. </el-select>
  87. </el-form-item>
  88. </el-col>
  89. </el-row>
  90. <el-transfer
  91. filterable
  92. :titles="['所有学员', '已选学员']"
  93. filter-placeholder="请输入学生姓名"
  94. :filter-method="filterStudent"
  95. v-model="seleched"
  96. :render-content="renderFunc"
  97. :data="data"
  98. :class="{hideReturn: !canDelUser}"
  99. >
  100. <template #left-footer>
  101. <div class="footer line">
  102. <span>姓名</span>
  103. <span>性别</span>
  104. <span>专业</span>
  105. </div>
  106. </template>
  107. <template #right-footer>
  108. <div class="footer line">
  109. <span>姓名</span>
  110. <span>性别</span>
  111. <span>专业</span>
  112. </div>
  113. </template>
  114. </el-transfer>
  115. </el-form>
  116. <div slot="footer" class="dialog-footer">
  117. <el-button @click="$listeners.close">取 消</el-button>
  118. <el-button type="primary" @click="submit">确 定</el-button>
  119. </div>
  120. </div>
  121. </template>
  122. <script>
  123. import { genderType } from "@/constant";
  124. import { updateClassGroupStudents } from '../../api'
  125. import { uniqBy } from 'lodash'
  126. export default {
  127. props: ["studentList", "soundList", "activeType", 'activeListStudent', 'isOnlyChangeUser', 'classGroupId', 'type', 'teacherList', 'cooperationList'],
  128. computed: {
  129. data() {
  130. return uniqBy([...this.studentList, ...this.activeListStudent], 'userId')
  131. .filter(item => {
  132. if (this.sound.length) {
  133. return this.sound.includes(item.actualSubjectId) || this.seleched.includes(item.userId)
  134. }
  135. return true
  136. })
  137. .map((item) => ({
  138. value: item.userId,
  139. key: item.userId,
  140. name: item.name,
  141. subjectName: item.subjectName,
  142. gender: genderType[item.gender],
  143. }));
  144. },
  145. showName() {
  146. return !this.isOnlyChangeUser && this.activeType != 'MUSIC_NETWORK'
  147. },
  148. canDelUser() {
  149. return this.$route.query.type !== 'resetTeam' || !this.isOnlyChangeUser
  150. }
  151. },
  152. data() {
  153. return {
  154. sound: [],
  155. form: {
  156. name: '',
  157. coreTeacher: '',
  158. assistant: '',
  159. },
  160. seleched: [],
  161. };
  162. },
  163. watch: {
  164. activeListStudent() {
  165. this.setSelectedUser()
  166. },
  167. },
  168. mounted() {
  169. this.setSelectedUser()
  170. },
  171. methods: {
  172. setSelectedUser() {
  173. const ids = this.activeListStudent.map(item => item.userId)
  174. this.seleched = [...ids]
  175. },
  176. filterStudent(query, item) {
  177. return (
  178. item.name.indexOf(query) > -1 ||
  179. item.subjectName.indexOf(query) > -1 ||
  180. item.gender.indexOf(query) > -1
  181. );
  182. },
  183. renderFunc(h, option) {
  184. return (
  185. <div class="line">
  186. <el-tooltip class="item" effect="dark" placement="top" open-delay={300}>
  187. <span slot="content">{option.name}</span>
  188. <span class="select-item">{option.name}</span>
  189. </el-tooltip>
  190. <span>{option.gender}</span>
  191. <el-tooltip class="item" effect="dark" placement="top" open-delay={300}>
  192. <span slot="content">{option.subjectName}</span>
  193. <span class="select-item">{option.subjectName}</span>
  194. </el-tooltip>
  195. </div>
  196. );
  197. },
  198. change(val) {
  199. this.$listeners.changeActiveChioseSound(val)
  200. this.$listeners.searchStudent()
  201. },
  202. submit() {
  203. if (!this.isOnlyChangeUser && this.activeType == 'HIGH_ONLINE' && (this.seleched.length < 3 || this.seleched.length > 5)) {
  204. return this.$message.error('线上技能班必须为3-5人')
  205. }
  206. if (this.seleched.length < 1) {
  207. return this.$message.error('请至少选择一名学生')
  208. }
  209. if (this.activeType == 'MUSIC_NETWORK' && this.seleched.length > 1) {
  210. return this.$message.error('乐团网管课仅可添加一名学生')
  211. }
  212. this.$refs.form.validate(async valid => {
  213. if (valid) {
  214. if (this.isOnlyChangeUser && this.type !== 'change') {
  215. try {
  216. await updateClassGroupStudents({
  217. classGroupId: this.classGroupId,
  218. studentIds: this.seleched.join(',')
  219. })
  220. this.$message.success('提交成功')
  221. } catch (error) {}
  222. this.$listeners.submited()
  223. this.$listeners.close()
  224. } else {
  225. this.$listeners.submited({
  226. seleched: this.seleched,
  227. ...this.form
  228. })
  229. }
  230. }
  231. })
  232. }
  233. },
  234. };
  235. </script>
  236. <style lang="less" scoped>
  237. /deep/ .el-transfer {
  238. display: flex;
  239. align-items: center;
  240. .el-transfer__buttons {
  241. display: flex;
  242. width: 110px;
  243. flex-direction: column;
  244. > button {
  245. &:last-child {
  246. margin-left: 0;
  247. }
  248. }
  249. }
  250. .el-transfer-panel {
  251. width: 300px;
  252. }
  253. }
  254. .footer {
  255. margin-left: 35px;
  256. margin-right: auto;
  257. height: 40px;
  258. line-height: 40px;
  259. }
  260. .hideReturn{
  261. /deep/ .el-transfer__buttons button:first-child{
  262. display: none;
  263. }
  264. }
  265. /deep/ .el-checkbox-group{
  266. padding-bottom: 40px;
  267. }
  268. /deep/ .line {
  269. width: 220px;
  270. display: flex;
  271. justify-content: space-around;
  272. .select-item{
  273. width: 33.33333%;
  274. white-space: nowrap;
  275. overflow: hidden;
  276. text-overflow: ellipsis;
  277. }
  278. }
  279. /deep/ .dialog-footer{
  280. margin-top: 20px;
  281. display: block;
  282. text-align: right;
  283. }
  284. </style>