xiangpei
2024-05-09 a40ff20ea396e1b7395451e3820ae77d46aa299b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<template>
  <div class="app-container">
    <el-form :model="queryParam" ref="queryForm" :inline="true">
      <el-form-item label="部门:">
        <el-input v-model="queryParam.name"></el-input>
<!--        <el-select v-model="queryParam.level" placeholder="部门" clearable="">-->
<!--          <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>
        <el-button type="primary" @click="submitForm">查询</el-button>
        <router-link :to="{path:'/education/department/edit'}" class="link-left">
          <el-button type="primary">添加</el-button>
        </router-link>
      </el-form-item>
    </el-form>
 
    <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="adminNames" label="部门负责人"/>
<!--      <el-table-column prop="levelName" label="部门" />-->
      <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" plain>编辑</el-button>
          </router-link>
          <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.adminIds" @change="changSelect" multiple 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 departmentApi from '@/api/department'
import enumItem from '@/store/modules/enumItem'
export default {
  components: { Pagination },
  data () {
    return {
      // 部门人员
      deptUserList: [],
      dialogVisible: false,
      title: '',
      updateAdminForm: {
        id: null,
        adminIds: []
      },
      depart: [],
      queryParam: {
        level: null,
        pageIndex: 1,
        pageSize: 10
      },
      listLoading: true,
      tableData: [],
      total: 0
    }
  },
  created () {
    this.search()
  },
  methods: {
    changSelect( value ) {
      this.updateAdminForm.adminId = value
    },
    handleClose () {
      this.dialogVisible = false
      this.title = ''
    },
    submitUpdate () {
      if (!this.updateAdminForm.adminIds) {
        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.adminIds = row.adminIds
      console.log(this.updateAdminForm.adminIds, "dd")
      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 => {
        const re = data.response
        this.tableData = re.list
        this.tableData.map(item => {
          if (item.adminNames) {
            item.adminNames = item.adminNames.join("、")
          }
        })
        this.total = re.total
        this.queryParam.pageIndex = re.pageNum
        this.listLoading = false
 
        this.depart = data.response.list
        this.depart.map(item => {
          item.key = item.id
          item.value = item.name
        })
        enumItem.state.user.levelEnum = this.depart
      })
    },
    submitForm () {
      this.queryParam.pageIndex = 1
      this.search()
    },
    delSubject (row) {
      let _this = this
      let obj = {
        id: row.id,
        deleted: 1
      }
      departmentApi.edit(obj).then(re => {
        if (re.code === 1) {
          _this.search()
          _this.$message.success(re.message)
        } else {
          _this.$message.error(re.message)
        }
      })
    }
  },
  computed: {
    ...mapGetters('enumItem', [
      'enumFormat'
    ]),
    ...mapState('enumItem', {
      levelEnum: state => state.user.levelEnum
    })
  }
}
</script>