BindTeacherClass.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. element-loading-text="正在绑定中..."
  5. element-loading-spinner="el-icon-loading"
  6. element-loading-background="rgba(0, 0, 0, 0.8)"
  7. title="绑定班主任" width="450px"
  8. :visible.sync="open"
  9. @close="closeDialog"
  10. >
  11. <el-form
  12. :model="form"
  13. :rules="rules"
  14. ref="bindRuleForm"
  15. >
  16. <el-form-item label="教师" label-width="60px" prop="teacherId">
  17. <el-select
  18. v-model="form.teacherId"
  19. :loading="bindOptionLoding"
  20. loading-text="正在加载中~~~"
  21. reserve-keyword
  22. @visible-change="searchTeacherOption"
  23. placeholder="请选择该班级教师" style="width: 100%;">
  24. <el-option
  25. v-for="item in teacherOptions"
  26. :key="item.value"
  27. :label="item.label"
  28. :value="item.value"></el-option>
  29. </el-select>
  30. </el-form-item>
  31. </el-form>
  32. <div slot="footer" class="dialog-footer">
  33. <el-button @click="closeDialog">取 消</el-button>
  34. <el-button type="primary" @click="submitForm">确 定</el-button>
  35. </div>
  36. </el-dialog>
  37. </template>
  38. <script>
  39. import {updateTeacherClassRelation, getRelationInfoList} from '@/api/system/teacher_class_relation'
  40. export default {
  41. data() {
  42. return {
  43. loading: false,
  44. form: {},
  45. open: false,
  46. option: [],
  47. bindOptionLoding: false,
  48. teacherOptions: [],
  49. rules: {
  50. teacherId: [
  51. { required: true, message: '请选择教师', trigger: 'change' }
  52. ],
  53. }
  54. }
  55. },
  56. methods: {
  57. openDialog() {
  58. this.open = true;
  59. },
  60. closeDialog() {
  61. this.open = false;
  62. this.reset();
  63. this.$refs.bindRuleForm.resetFields()
  64. this.teacherOptions = []
  65. },
  66. dialogFormVisibleChange(val) {
  67. this.dialogFormVisible = val;
  68. },
  69. reset() {
  70. this.form = {};
  71. },
  72. searchTeacherOption(openSelect) {
  73. if (openSelect) {
  74. this.bindOptionLoding = true
  75. // 发送请求
  76. getRelationInfoList(this.form).then(res => {
  77. let data = res.data;
  78. this.teacherOptions = data.map(item => {
  79. let obj = {};
  80. obj.label = item.teacherName;
  81. obj.value = item.teacherId;
  82. return obj;
  83. })
  84. }).finally(() =>
  85. this.bindOptionLoding = false
  86. )
  87. }
  88. },
  89. submitForm() {
  90. this.$refs.bindRuleForm.validate(isOk => {
  91. if (isOk) {
  92. this.loading = true
  93. this.form.teacherMain = 'Y';
  94. updateTeacherClassRelation(this.form).then(res => {
  95. // 发送请求
  96. this.$message.success('绑定成功!');
  97. // 关闭表单
  98. this.closeDialog();
  99. // 重置列表
  100. this.$emit('resetTable');
  101. }).finally(() => {
  102. setTimeout(() => {
  103. this.loading = false;
  104. }, 500)
  105. })
  106. }
  107. })
  108. }
  109. },
  110. }
  111. </script>
  112. <style>
  113. </style>