龚焕茏
2024-07-19 9a2293ea12531e49bb183a1a98e7bc3b065fffa6
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
175
176
177
178
179
180
181
182
183
184
185
<template>
  <div class="app-container">
    <el-form :model="queryParam" ref="queryForm" :inline="true">
      <el-form-item label="查询条件:">
        <el-input v-model="queryParam.name" size="small"></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" size="small">查询</el-button>
        <!-- <router-link :to="{path:'/education/subject/edit'}" class="link-left">
          <el-button type="primary">添加</el-button>
        </router-link> -->
      </el-form-item>
    </el-form>
 
    <el-table
      v-loading="listLoading"
      :data="tableData"
      default-expand-all
      border fit highlight-current-row style="width: 100%"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      row-key="id"
    >
      <el-table-column prop="name" label="部门" />
      <el-table-column prop="subjectNames" label="课目"/>
      <el-table-column width="240px" label="操作" align="center">
        <template slot-scope="{row}">
          <el-button type="success" @click="addSubject(row.id, row.name)" size="mini">添加课目</el-button>
          <el-button type="primary" @click="editSubject(row.id, row.name, row.subjectIds)" size="mini">编辑</el-button>
<!--          <el-button   size="mini" type="danger" @click="delSubject(row)" class="link-left">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>
 
    <el-dialog
      :title="addTitle"
      :visible.sync="addShow"
      width="450px"
    >
      <el-input v-model="addForm.subjectName" placeholder="课目名称" required/>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelAdd">取 消</el-button>
        <el-button type="primary" @click="add">保 存</el-button>
      </span>
    </el-dialog>
 
    <el-dialog
      :title="editTitle"
      :visible.sync="editShow"
      width="450px"
    >
      <el-form label-position="top">
        <el-form-item label="部门">
          <el-input v-model="editForm.deptName" disabled required/>
        </el-form-item>
        <el-form-item label="课目">
          <el-select v-model="editForm.subjectIds" multiple placeholder="请选择该部门对应的课目">
            <el-option v-for="subject in subjectList" :key="subject.id" :value="subject.id" :label="subject.name"/>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelEdit">取 消</el-button>
        <el-button type="primary" @click="edit">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import { mapGetters, mapState } from 'vuex'
import Pagination from '@/components/Pagination'
import subjectApi from '@/api/subject'
 
export default {
  components: { Pagination },
  data () {
    return {
      subjectList: [],
      addForm: {
        deptId: null,
        subjectName: ''
      },
      editForm: {
        deptId: null,
        deptName: null,
        subjectIds: []
      },
      addTitle: '',
      editTitle: '',
      addShow: false,
      editShow: false,
      queryParam: {
        level: null,
        pageIndex: 1,
        pageSize: 10
      },
      listLoading: true,
      tableData: [],
      total: 0
    }
  },
  created () {
    this.search()
    this.getAllSubject()
  },
  methods: {
    getAllSubject() {
      subjectApi.list().then(res => {
        this.subjectList = res.response
      })
    },
    editSubject(deptId, deptName, subjectIds) {
      this.editTitle = "修改【" + deptName + "】的课目"
      this.editForm.deptId = deptId
      this.editForm.deptName = deptName
      this.editForm.subjectIds = subjectIds;
      this.editShow = true
    },
    addSubject(deptId, deptName) {
      this.addTitle = "为【" + deptName + "】添加课目";
      this.addShow = true;
      this.addForm.deptId = deptId
    },
    add() {
      subjectApi.add(this.addForm).then(res => {
        this.$message.success("添加成功")
        this.addShow = false
        this.search()
      })
    },
    edit() {
      subjectApi.edit(this.editForm).then(res => {
        this.$message.success("修改成功")
        this.editShow = false
        this.search()
      })
    },
    cancelEdit() {
      this.editShow = false
      this.editTitle = ""
      this.editForm.deptId = null
      this.editForm.deptName = ""
      this.editForm.subjectIds = []
    },
    cancelAdd() {
      this.addShow = false
      this.addTitle = ""
      this.addForm.subjectName = ""
    },
    search () {
      this.listLoading = true
      subjectApi.pageList(this.queryParam).then(data => {
        this.tableData = data.response
        this.listLoading = false
      })
    },
    submitForm () {
      this.queryParam.pageIndex = 1
      this.search()
    },
    delSubject (row) {
      let _this = this
      subjectApi.deleteSubject(row.id).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>