index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="所属学校" prop="schoolId">
  5. <el-select v-model="queryParams.schoolId" placeholder="请选择学校" style="width: 100%;">
  6. <el-option v-for="dict in dictTables.schoolDict" :key="dict.value" :label="dict.label"
  7. :value="dict.value"></el-option>
  8. </el-select>
  9. </el-form-item>
  10. <el-form-item label="班级名称" prop="className">
  11. <el-input
  12. v-model="queryParams.className"
  13. placeholder="请输入班级名称"
  14. clearable
  15. @keyup.enter.native="handleQuery"
  16. />
  17. </el-form-item>
  18. <el-form-item label="班级人数" prop="classCount">
  19. <el-input
  20. v-model="queryParams.classCount"
  21. placeholder="请输入班级人数"
  22. clearable
  23. @keyup.enter.native="handleQuery"
  24. />
  25. </el-form-item>
  26. <el-form-item>
  27. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  28. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  29. </el-form-item>
  30. </el-form>
  31. <el-row :gutter="10" class="mb8">
  32. <el-col :span="1.5">
  33. <el-button
  34. type="primary"
  35. plain
  36. icon="el-icon-plus"
  37. size="mini"
  38. @click="handleAdd"
  39. v-hasPermi="['system:clazz:add']"
  40. >新增</el-button>
  41. </el-col>
  42. <el-col :span="1.5">
  43. <el-button
  44. type="success"
  45. plain
  46. icon="el-icon-edit"
  47. size="mini"
  48. :disabled="single"
  49. @click="handleUpdate"
  50. v-hasPermi="['system:clazz:edit']"
  51. >修改</el-button>
  52. </el-col>
  53. <el-col :span="1.5">
  54. <el-button
  55. type="danger"
  56. plain
  57. icon="el-icon-delete"
  58. size="mini"
  59. :disabled="multiple"
  60. @click="handleDelete"
  61. v-hasPermi="['system:clazz:remove']"
  62. >删除</el-button>
  63. </el-col>
  64. <el-col :span="1.5">
  65. <el-button
  66. type="warning"
  67. plain
  68. icon="el-icon-download"
  69. size="mini"
  70. @click="handleExport"
  71. v-hasPermi="['system:clazz:export']"
  72. >导出</el-button>
  73. </el-col>
  74. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  75. </el-row>
  76. <el-table v-loading="loading" :data="clazzList" @selection-change="handleSelectionChange">
  77. <el-table-column type="selection" width="55" align="center" />
  78. <el-table-column label="序号" type="index" align="center"/>
  79. <!-- todo 显示 学校名称 -->
  80. <el-table-column label="所属学校" align="center">
  81. <template slot-scope="scope">
  82. <dict-tag :options="dictTables.schoolDict" :value="scope.row.schoolId" />
  83. </template>
  84. </el-table-column>
  85. <el-table-column label="班级名称" align="center" prop="className" />
  86. <el-table-column label="班主任" align="center" prop="teacherName" />
  87. <el-table-column label="班级人数" align="center" prop="classCount" />
  88. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  89. <template slot-scope="scope">
  90. <el-button
  91. size="mini"
  92. type="text"
  93. icon="el-icon-edit"
  94. @click="handleUpdate(scope.row)"
  95. v-hasPermi="['system:clazz:edit']"
  96. >修改</el-button>
  97. <el-button
  98. size="mini"
  99. type="text"
  100. icon="el-icon-delete"
  101. @click="handleDelete(scope.row)"
  102. v-hasPermi="['system:clazz:remove']"
  103. >删除</el-button>
  104. <!-- 要弹出对话框 让其进行选择 -->
  105. <el-button
  106. v-if="scope.row.teacherMain === 'N' || scope.row.teacherMain === null"
  107. size="mini" type="text"
  108. @click="handleTeacherClassBind(scope.row)"
  109. >
  110. <i class="el-icon-bind"></i>
  111. 绑定班主任
  112. </el-button>
  113. <el-button
  114. v-if="scope.row.teacherMain === 'Y'"
  115. size="mini" type="text"
  116. @click="unbindTeacherMain(scope.row)"
  117. >
  118. <i class="el-icon-bind"></i>
  119. 解绑班主任
  120. </el-button>
  121. </template>
  122. </el-table-column>
  123. </el-table>
  124. <pagination
  125. v-show="total>0"
  126. :total="total"
  127. :page.sync="queryParams.pageNum"
  128. :limit.sync="queryParams.pageSize"
  129. @pagination="getList"
  130. />
  131. <!-- 新增 修改 班级信息 组件-->
  132. <clazz-form
  133. ref="clazzForm"
  134. @submit="submitForm"
  135. @cancel="cancel"
  136. ></clazz-form>
  137. <!-- 绑定班主任对话框 -->
  138. <bind-teacher-class ref="bindTeacherClass" @resetTable="getList"/>
  139. </div>
  140. </template>
  141. <script>
  142. import { listClazz, getClazz, delClazz, addClazz, updateClazz } from "@/api/system/clazz";
  143. import {updateTeacherClassRelation} from '@/api/system/teacher_class_relation'
  144. import ClazzForm from "./module/ClazzForm";
  145. import BindTeacherClass from "./module/BindTeacherClass";
  146. import Textyixia from "@/mixin/Textyixia"
  147. import { Loading } from 'element-ui';
  148. export default {
  149. name: "Clazz",
  150. mixins: [Textyixia],
  151. dicts: ['sys_yes_no'],
  152. components: {
  153. ClazzForm,
  154. BindTeacherClass,
  155. },
  156. data() {
  157. return {
  158. dictTables: {
  159. schoolDict: []
  160. },
  161. // 遮罩层
  162. loading: true,
  163. // 选中数组
  164. ids: [],
  165. // 非单个禁用
  166. single: true,
  167. // 非多个禁用
  168. multiple: true,
  169. // 显示搜索条件
  170. showSearch: true,
  171. // 总条数
  172. total: 0,
  173. // 班级管理表格数据
  174. clazzList: [],
  175. // 弹出层标题
  176. title: "",
  177. // 是否显示弹出层
  178. open: false,
  179. // 查询参数
  180. queryParams: {
  181. pageNum: 1,
  182. pageSize: 10,
  183. schoolId: null,
  184. className: null,
  185. classCount: null,
  186. phone: null,
  187. },
  188. // 表单参数
  189. form: {},
  190. };
  191. },
  192. created() {
  193. this.getList();
  194. this.dictTableData("tb_school,school_name,id").then(data => {
  195. this.dictTables.schoolDict = data
  196. })
  197. },
  198. methods: {
  199. /** 查询班级管理列表 */
  200. getList() {
  201. this.loading = true;
  202. listClazz(this.queryParams).then(response => {
  203. this.clazzList = response.rows;
  204. this.total = response.total;
  205. this.loading = false;
  206. });
  207. },
  208. // 取消按钮
  209. cancel() {
  210. this.$refs.clazzForm.open = false
  211. this.reset();
  212. },
  213. // 表单重置
  214. reset() {
  215. this.$refs.clazzForm.reset()
  216. },
  217. /** 搜索按钮操作 */
  218. handleQuery() {
  219. this.queryParams.pageNum = 1;
  220. this.getList();
  221. },
  222. /** 重置按钮操作 */
  223. resetQuery() {
  224. this.resetForm("queryForm");
  225. this.handleQuery();
  226. },
  227. // 多选框选中数据
  228. handleSelectionChange(selection) {
  229. this.ids = selection.map(item => item.id)
  230. this.single = selection.length!==1
  231. this.multiple = !selection.length
  232. },
  233. /** 新增按钮操作 */
  234. handleAdd() {
  235. this.reset();
  236. this.$refs.clazzForm.open = true
  237. this.$refs.clazzForm.title = "添加班级";
  238. },
  239. /** 修改按钮操作 */
  240. handleUpdate(row) {
  241. this.reset();
  242. const id = row.id || this.ids
  243. getClazz(id).then(response => {
  244. this.$refs.clazzForm.form = response.data;
  245. this.$refs.clazzForm.open = true
  246. this.$refs.clazzForm.title = "修改班级信息";
  247. this.$refs.clazzForm.searchTeacherOption(true);
  248. this.$refs.clazzForm.schoolOptions = this.dictTables.schoolDict
  249. });
  250. },
  251. /** 提交按钮 */
  252. submitForm(data) {
  253. if (data.id != null) {
  254. updateClazz(data).then(response => {
  255. this.$modal.msgSuccess("修改成功");
  256. this.$refs.clazzForm.open = false
  257. this.getList();
  258. });
  259. } else {
  260. addClazz(data).then(response => {
  261. this.$modal.msgSuccess("新增成功");
  262. this.$refs.clazzForm.open = false
  263. this.getList();
  264. });
  265. }
  266. },
  267. /** 删除按钮操作 */
  268. handleDelete(row) {
  269. const ids = row.id || this.ids;
  270. this.$modal.confirm('是否确认删除班级管理编号为"' + ids + '"的数据项?').then(function() {
  271. return delClazz(ids);
  272. }).then(() => {
  273. this.getList();
  274. this.$modal.msgSuccess("删除成功");
  275. }).catch(() => {});
  276. },
  277. /** 导出按钮操作 */
  278. handleExport() {
  279. this.download('system/clazz/export', {
  280. ...this.queryParams
  281. }, `clazz_${new Date().getTime()}.xlsx`)
  282. },
  283. /** 绑定班主任 */
  284. handleTeacherClassBind(row) {
  285. // 弹出对话框,并让用户设置对应的教师
  286. this.$refs.bindTeacherClass.form.schoolId = row.schoolId;
  287. this.$refs.bindTeacherClass.form.classId = row.id;
  288. this.$refs.bindTeacherClass.openDialog();
  289. },
  290. /** 解绑班主任 */
  291. unbindTeacherMain(row) {
  292. this.form = {
  293. schoolId: row.schoolId,
  294. classId: row.id,
  295. teacherMain: 'N',
  296. }
  297. // 解绑班主任关系
  298. this.$confirm('确定解绑班主任?', '提示', {
  299. confirmButtonText: '确定',
  300. cancelButtonText: '取消',
  301. type: 'warning'
  302. }).then(() => {
  303. const loadingInstance = Loading.service({fullscreen: true, text: '正在解绑班主任...', background: 'rgba(0, 0, 0, 0.8)'})
  304. updateTeacherClassRelation(this.form).then(res => {
  305. console.log(res);
  306. this.$message({
  307. type:'success',
  308. message: '解绑成功!'
  309. });
  310. }).finally(() => {
  311. setTimeout(() => {
  312. this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
  313. loadingInstance.close();
  314. });
  315. }, 500)
  316. this.getList();
  317. })
  318. })
  319. }
  320. }
  321. };
  322. </script>