select-student.vue 8.4 KB

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