long
2021-08-05 3dcc7cfd77cfdf04a7eeb614e81f378bfe428a67
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<template>
  <el-dialog v-el-drag-dialog :title="'('+name+')'+objectName+'列表'" width="60%" :visible.sync="isShow" :before-close="closeHandle" :close-on-click-modal="false">
    <!-- 搜索区 ↓↓↓↓↓↓↓↓↓↓ -->
    <el-form v-show="showSearch" ref="searchForm" :inline="true">
      <el-form-item label="老师名称">
        <el-input
          v-model="keyWord"
          placeholder="请输入老师名称"
          clearable
          size="small"
          style="width: 240px"
          maxlength="50"
          @keyup.enter.native="reGetList"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="reGetList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetHandle">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 搜索区 ↑↑↑↑↑↑↑↑↑↑ -->
 
    <!-- 操作区 ↓↓↓↓↓↓↓↓↓↓ -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="showAddDialog"
        >新增</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>
    <!-- 操作区 ↑↑↑↑↑↑↑↑↑↑ -->
 
    <el-table :data="list" max-height="420px">
      <el-table-column type="index" label="序号" align="center" width="60" />
      <el-table-column label="老师名称" prop="teacherName" align="center" min-width="120" />
      <el-table-column label="班级名称" prop="className" align="center" min-width="120" />
      <el-table-column label="创建时间" prop="createTime" align="center" width="160" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="showEditDialog(scope.row)"
          >编辑</el-button> -->
          <el-button
            size="mini"
            type="text warn"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
 
    <!-- 新增&编辑 -->
    <el-dialog v-el-drag-dialog :title="(dialogData.type=='add'?'新增':'编辑') + objectName" width="500px" :visible.sync="dialogVisible" append-to-body :before-close="hideDialog" :close-on-click-modal="false">
      <el-form ref="refDialog" :model="dialogData" label-width="110px" :rules="rules" size="small">
        <el-form-item label="绑定老师" prop="teacherIds">
          <el-select v-model="dialogData.teacherIds" clearable multiple placeholder="选择老师" style="width: 100%">
            <el-option
              v-for="item in teacherOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="hideDialog">取消</el-button>
        <el-button type="primary" @click="submitHandle">确定</el-button>
      </div>
    </el-dialog>
 
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="pageNum"
      :limit.sync="pageSize"
      @pagination="getList"
    />
  </el-dialog>
</template>
 
<script>
 
export default {
  data() {
    return {
      isShow: false,
      showSearch: true, // 是否显示搜索区
      keyWord: '',
 
      name: '',
      id: '',
      list: [],
 
      objectName: '绑定老师', // 对象名称,用于删除提示、启用提示、弹窗标题等
 
      // 老师配置下拉
      teacherOptions: [],
 
      // 弹窗数据
      dialogVisible: false,
      dialogData: {},
 
      // 分页 ↓↓↓↓↓↓↓↓↓↓
      total: 0,
      pageNum: 1,
      pageSize: 20,
      // 分页 ↑↑↑↑↑↑↑↑↑↑
 
      // 表单校验
      rules: {
        teacherIds: [
          { required: true, message: '绑定老师不能为空', trigger: 'change' }
        ]
      }
 
    }
  },
  methods: {
    // 初始化 this.$refs.xxx.openHandle(id)
    openHandle(item) {
      this.id = item.id
      this.name = item.name
      this.getList()
      this.isShow = true
    },
 
    // 关闭列表
    closeHandle() {
      this.id = ''
      this.list = []
      this.isShow = false
    },
 
    // 获取列表
    getList() {
      var { pageNum, pageSize, keyWord } = this
      this.postFN({
        url: 'admin/schoolClassTeacher/list',
        params: {
          pageNum: pageNum,
          pageSize: pageSize,
          schoolClassId: this.id,
          name: keyWord
        },
        mockData: {
          code: 100,
          msg: '',
          data: {
            list: [{
              createTime: '2021-04-02 10:21:52',
              teacherName: '崔某',
              className: '五年一班',
              id: '1'
            }],
            total: 100
          }
        }
      }, (inf) => {
        this.list = inf.list || []
        this.total = inf.total
      })
    },
    // 重新获取列表
    reGetList() {
      this.pageNum = 1
      this.getList()
    },
    // 重置
    resetHandle() {
      this.keyWord = ''
      this.reGetList()
    },
    // 删除
    handleDelete(item) {
      // 打开二次确认弹窗
      this.$confirm('是否确认删除该' + this.objectName + '?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 确定回调
        // TODO url
        this.postFN({
          url: 'admin/schoolClassTeacher/delete/one',
          params: {
            id: item.id
          },
          mockData: {
            code: 100,
            msg: '',
            data: {}
          }
        }, () => {
          this.getList()
          this.$messageSuc('删除成功')
        })
      }).catch(() => {})
    },
    // 修改是否上架
    handleUpChange(item) {
      const text = item.isUp === 1 ? '上架' : '下架'
      this.$confirm('确认要' + text + '该' + this.objectName + '吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // TODO url
        this.postFN({
          url: 'xxx',
          params: {
            id: item.id,
            isUp: item.isUp
          },
          mockData: {
            code: 100,
            msg: '',
            data: {}
          }
        }, () => {
          this.$messageSuc(text + '成功')
        }, (res) => {
          item.isUp = item.isUp === 1 ? 0 : 1
          this.$messageError(res.msg)
        })
      }).catch(() => {
        item.isUp = item.isUp === 1 ? 0 : 1
      })
    },
 
    // 获取老师列表
    getTeacherOptions(callback) {
      this.postFN({
        url: 'admin/common/select/teacher/list',
        params: {},
        mockData: {
          code: 100,
          msg: '',
          data: {
            list: [{
              name: '黄冈',
              id: 1
            }, {
              name: '表莲华',
              id: 2
            }, {
              name: '吴起是',
              id: 3
            }]
          }
        }
      }, (inf) => {
        this.teacherOptions = inf.list || []
        callback && callback()
      })
    },
    // 打开新增弹窗
    showAddDialog() {
      this.getTeacherOptions()
      var dialogData = {
        type: 'add',
        teacherIds: ''
      }
      this.dialogVisible = true
      this.$nextTick(() => {
        this.dialogData = dialogData
        this.$refs['refDialog'].resetFields()
      })
    },
    // 打开编辑弹框
    showEditDialog(item) {
      var dialogData = {
        ...item,
        type: 'edit'
      }
      console.log('dialogData', dialogData)
      this.dialogVisible = true
      this.$nextTick(() => {
        this.dialogData = dialogData
        this.$refs['refDialog'].resetFields()
      })
    },
    // 关闭编辑弹窗
    hideDialog() {
      this.dialogData = {}
      this.dialogVisible = false
    },
    // 提交新增&编辑
    submitHandle() {
      this.$refs['refDialog'].validate(valid => {
        if (valid) {
          this.submitReq()
        }
      })
    },
    // 提交接口
    submitReq() {
      var { dialogData } = this
      var params = {
        teacherIds: dialogData.teacherIds.join(','),
        schoolClassId: this.id
      }
 
      var isAdd = dialogData.type === 'add'
      var url = isAdd ? 'admin/schoolClassTeacher/add' : 'xxx'
 
      !isAdd && (params.id = dialogData.id)
 
      this.postFN({
        url: url,
        params: params,
        mockData: {
          code: 100,
          msg: '',
          data: {}
        }
      }, () => {
        this.$messageSuc('保存成功')
        this.hideDialog()
        isAdd ? this.reGetList() : this.getList()
      })
    }
 
  }
}
</script>
 
<style lang="scss" scoped>
 
</style>