select-student.vue 8.7 KB

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