From fe285713f52314ced23d1a5aa2654d8eaab522f9 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期五, 08 三月 2024 14:47:05 +0800 Subject: [PATCH] 部门增加管理员,管理员修改 --- src/api/department.js | 8 ++ src/views/education/department/edit.vue | 70 ++++++++++++++--------- src/views/education/department/list.vue | 75 +++++++++++++++++++++--- 3 files changed, 114 insertions(+), 39 deletions(-) diff --git a/src/api/department.js b/src/api/department.js index 5bb8fc0..28876c9 100644 --- a/src/api/department.js +++ b/src/api/department.js @@ -1,4 +1,4 @@ -import { post } from '@/utils/request' +import { post, get } from '@/utils/request' export default { list: query => post('/api/admin/education/department/list'), @@ -8,5 +8,9 @@ selectUser: id => post('/api/admin/department/getUserByDepartment/' + id), selectDepartmentUser: id => post('/api/admin/department/getDepartmentUser'), deleteSubject: id => post('/api/admin/education/department/delete/' + id), - addData:query=>post('/api/admin/department/add',query) + addData: query => post('/api/admin/department/add', query), + // 鑾峰彇閮ㄩ棬鐢ㄦ埛涓嬫媺鍒楄〃 + getDeptUserList: id => get('/api/admin/department/' + id + '/user-list'), + // 淇敼閮ㄩ棬绠$悊鍛� + updateDeptAdmin: data => post('/api/admin/department/update-admin', data) } diff --git a/src/views/education/department/edit.vue b/src/views/education/department/edit.vue index 9cf1ea9..ea06fa2 100644 --- a/src/views/education/department/edit.vue +++ b/src/views/education/department/edit.vue @@ -10,6 +10,16 @@ <!-- <el-option v-for="item in levelEnum" :key="item.key" :value="item.key" :label="item.value"></el-option>--> <!-- </el-select>--> <!-- </el-form-item>--> + <el-form-item label="绠$悊鍛橈細" required> + <el-select v-model="form.adminId" filterable placeholder="閫夋嫨绠$悊鍛�"> + <el-option + v-for="item in deptUserList" + :key="item.id" + :label="item.value" + :value="item.id"> + </el-option> + </el-select> + </el-form-item> <el-form-item> <el-button type="primary" @click="submitForm">鎻愪氦</el-button> <el-button @click="resetForm">閲嶇疆</el-button> @@ -20,16 +30,17 @@ <script> import { mapGetters, mapState, mapActions } from 'vuex' -import subjectApi from '@/api/subject' import departmentApi from '@/api/department' -import enumItem from '@/store/modules/enumItem' export default { data () { return { - depart:[], + // 閮ㄩ棬浜哄憳 + deptUserList: [], + depart: [], form: { id: null, name: '', + adminId: null // level: 1, // levelName: '' }, @@ -39,7 +50,6 @@ }, created () { let id = this.$route.query.id - console.log(id) let _this = this if (id && parseInt(id) !== 0) { _this.formLoading = true @@ -47,43 +57,49 @@ _this.form = re.response _this.formLoading = false }) + // 鑾峰彇閮ㄩ棬浜哄憳 + _this.getUserSelect(id) } - if (id == undefined) { - _this.fig = 1 //鏄柊澧� + if (id === undefined) { + _this.fig = 1 // 鏄柊澧� } else { - _this.fig = 0 //鏄紪杈� + _this.fig = 0 // 鏄紪杈� } }, methods: { + getUserSelect (id) { + departmentApi.getDeptUserList(id).then(res => { + this.deptUserList = res.response + }) + }, submitForm () { let _this = this this.formLoading = true // this.form.levelName = this.enumFormat(this.levelEnum, this.form.level) - let obj = { - name:this.form.name - } - if (_this.fig==1){ - departmentApi.addData(this.form.name).then(res=>{ + // let obj = { + // name: this.form.name + // } + if (_this.fig === 1) { + departmentApi.addData(this.form.name).then(res => { console.log(res) - if (res.code ==1){ - - _this.$message.success(res.message) - _this.delCurrentView(_this).then(() => { - _this.$router.push('/education/department/list') - }) - }else { - _this.$message.error(res.message) - } - }) - }else { - departmentApi.edit(this.form).then(res=>{ - console.log(res) - if (res.code ==1){ + if (res.code === 1) { _this.$message.success(res.message) _this.delCurrentView(_this).then(() => { _this.$router.push('/education/department/list') }) - }else { + } else { + _this.$message.error(res.message) + } + }) + } else { + departmentApi.edit(this.form).then(res => { + console.log(res) + if (res.code === 1) { + _this.$message.success(res.message) + _this.delCurrentView(_this).then(() => { + _this.$router.push('/education/department/list') + }) + } else { _this.$message.error(res.message) } }) diff --git a/src/views/education/department/list.vue b/src/views/education/department/list.vue index 2821948..12a8c18 100644 --- a/src/views/education/department/list.vue +++ b/src/views/education/department/list.vue @@ -15,34 +15,60 @@ </el-form-item> </el-form> - <el-table v-loading="listLoading" :data="tableData" border fit highlight-current-row style="width: 100%"> + <el-table v-loading="listLoading" :data="tableData" stripe border fit highlight-current-row style="width: 100%"> <el-table-column prop="name" label="閮ㄩ棬"/> + <el-table-column prop="adminName" label="閮ㄩ棬璐熻矗浜�"/> <!-- <el-table-column prop="levelName" label="閮ㄩ棬" />--> - <el-table-column width="220px" label="鎿嶄綔" align="center"> + <el-table-column width="400px" label="鎿嶄綔" align="center"> <template slot-scope="{row}"> + <el-button type="success" size="mini" @click="updateDeptAdmin(row)" class="link-left" plain>淇敼閮ㄩ棬璐熻矗浜�</el-button> <router-link :to="{path:'/education/department/edit', query:{id:row.id}}" class="link-left"> - <el-button size="mini">缂栬緫</el-button> + <el-button size="mini" plain>缂栬緫</el-button> </router-link> - <el-button size="mini" type="danger" @click="delSubject(row)" class="link-left">鍒犻櫎</el-button> + <el-button size="mini" type="danger" plain @click="delSubject(row)" class="link-left">鍒犻櫎</el-button> </template> </el-table-column> </el-table> <pagination v-show="total>0" :total="total" :page.sync="queryParam.pageIndex" :limit.sync="queryParam.pageSize" @pagination="search"/> + + <el-dialog + :title="title" + :visible.sync="dialogVisible" + width="400px" + :before-close="handleClose"> + <el-select v-model="updateAdminForm.adminId" filterable placeholder="閫夋嫨绠$悊鍛�"> + <el-option + v-for="item in deptUserList" + :key="item.id" + :label="item.value" + :value="item.id"> + </el-option> + </el-select> + <span slot="footer" class="dialog-footer"> + <el-button @click="dialogVisible = false">鍙� 娑�</el-button> + <el-button type="primary" @click="submitUpdate">纭� 瀹�</el-button> + </span> + </el-dialog> + </div> </template> <script> import { mapGetters, mapState } from 'vuex' import Pagination from '@/components/Pagination' -import subjectApi from '@/api/subject' import departmentApi from '@/api/department' import enumItem from '@/store/modules/enumItem' export default { components: { Pagination }, data () { return { - depart:[], + // 閮ㄩ棬浜哄憳 + deptUserList: [], + dialogVisible: false, + title: '', + updateAdminForm: {}, + depart: [], queryParam: { level: null, pageIndex: 1, @@ -57,6 +83,36 @@ this.search() }, methods: { + handleClose () { + this.dialogVisible = false + this.title = '' + }, + submitUpdate () { + if (!this.updateAdminForm.adminId) { + this.$message.warning('璇烽�夋嫨閮ㄩ棬璐熻矗浜�') + return + } + departmentApi.updateDeptAdmin(this.updateAdminForm).then(res => { + if (res.code === 1) { + this.$message.success('淇敼鎴愬姛') + this.dialogVisible = false + this.title = '' + this.search() + } + }) + }, + updateDeptAdmin (row) { + this.updateAdminForm.id = row.id + this.updateAdminForm.adminId = row.adminId + this.title = row.name + '--绠$悊鍛樹慨鏀�' + this.getUserSelect(row.id) + this.dialogVisible = true + }, + getUserSelect (id) { + departmentApi.getDeptUserList(id).then(res => { + this.deptUserList = res.response + }) + }, search () { this.listLoading = true departmentApi.pageList(this.queryParam).then(data => { @@ -68,12 +124,11 @@ this.depart = data.response.list console.log(this.depart) - this.depart.map(item=>{ + this.depart.map(item => { item.key = item.id item.value = item.name }) enumItem.state.user.levelEnum = this.depart - }) }, submitForm () { @@ -83,8 +138,8 @@ delSubject (row) { let _this = this let obj = { - id :row.id, - deleted:1 + id: row.id, + deleted: 1 } departmentApi.edit(obj).then(re => { if (re.code === 1) { -- Gitblit v1.8.0