xiangpei
2024-09-23 710a9bf11a76b7b2fb27ba99f772ecc46aeb99fa
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
<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryForm">
      <el-form-item label="课目名称">
        <el-input v-model="queryForm.name" clearable @input="page" @clear="page"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="page">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="handleAdd">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="name"
        label="课目名称"
        >
      </el-table-column>
      <el-table-column
        label="操作"
        >
        <template slot-scope="scope">
          <el-button @click="handleEdit(scope.row)" type="text" size="small" style="margin-right: 5px">修改</el-button>
          <el-popconfirm
            title="确定要删除该课目吗?,该课目管理的数据都将被删除!"
            @confirm="del(scope.row.id)"
          >
            <el-button slot="reference" type="text" size="small">删除</el-button>
          </el-popconfirm>
 
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryForm.pageIndex" :limit.sync="queryForm.pageSize"
                @pagination="page"/>
 
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      :visible.sync="editOpen"
      width="400px"
      :before-close="handleClose">
      <el-form :model="form" :rules="rules" ref="form">
        <el-form-item label="课目名称" prop="name">
          <el-input v-model="form.name" placeholder="课目名称"/>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editOpen = false">取 消</el-button>
        <el-button type="primary" @click="addOrUpdate">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import subjectApi from '@/api/subject'
import Pagination from '@/components/Pagination'
 
export default {
  name: "manager",
  components: {Pagination},
  data() {
    return {
      total: 0,
      queryForm: {
        name: '',
        pageIndex: 1,
        pageSize: 10,
      },
      tableData: [],
      title: '新增课目',
      editOpen: false,
      form: {
        id: null,
        name: ''
      },
      rules: {
        name: [
          {required: true, message: '请输入课目名称'}
        ]
      }
    }
  },
  mounted() {
    this.page();
  },
  methods: {
    del(id) {
      subjectApi.deleteSubject(id).then(res => {
        this.$message.success("删除成功")
        this.page()
      })
    },
    page() {
      subjectApi.page(this.queryForm).then(res => {
        this.tableData = res.response.list
        this.total = res.response.total
      })
    },
    addOrUpdate() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (this.form.id) {
            subjectApi.update(this.form).then(res => {
              this.editOpen = false
              this.$message.success("修改成功")
              this.page()
            })
          } else {
            subjectApi.save(this.form).then(res => {
              this.editOpen = false
              this.$message.success("添加成功")
              this.page()
            })
          }
 
        }
      })
    },
    handleAdd() {
      this.form = {
        id: null,
        name: ''
      }
      this.title = '新增课目'
      this.editOpen = true
    },
    handleEdit(row) {
      this.form.id = row.id
      this.form.name = row.name
      this.title = '修改课目'
      this.editOpen = true
    },
    handleClose() {
      this.editOpen = false
      this.form = {
        id: null,
        name: ''
      }
    }
  }
}
</script>
 
<style scoped>
 
</style>