zhouwx
2024-07-17 c1823a7f91775fd157d4e4683b597d7e426cd2ed
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
<template>
  <div class="app-container">
    <div style="margin-bottom: 10px;display: flex;align-items: center;justify-content: space-between">
      <div>
        <el-button
            type="primary"
            plain
            icon="Plus"
            @click="openDialog()"
        >选择学员</el-button>
        <el-button
            type="primary"
            plain
            @click="back"
        >返回</el-button>
      </div>
      <el-button
          type="danger"
          plain
          icon="Delete"
          @click="handleDeleteBatch"
      >批量删除</el-button>
    </div>
    <!-- 表格数据 -->
    <el-table ref="tableRef" v-loading="loading" :data="dataList" :border="true" :row-key="getRowKey"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" :reserve-selection="true" width="55" align="center" />
      <el-table-column label="序号" type="index" align="center" width="80" />
      <el-table-column label="批次名称" prop="phaseName" align="center"  />
      <el-table-column label="学员名称" prop="studentName" align="center"  />
      <el-table-column label="手机号" prop="studentPhone" align="center"  />
      <el-table-column label="总进度" prop="totalProgress" align="center"  />
      <el-table-column label="开始学习时间" prop="startTime" align="center"  />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  width="180">
        <template #default="scope">
          <el-button link type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
 
    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
 
    <choose-stu-dialog ref="dialogRef" @getList=getList></choose-stu-dialog>
  </div>
</template>
 
<script setup>
import {getCurrentInstance, onMounted, onUnmounted, reactive, ref, toRefs} from "vue";
import {ElMessage, ElMessageBox} from "element-plus";
import chooseStuDialog from './chooseStudent.vue'
import Cookies from "js-cookie";
import {delQuestionBank, getQuestionBank} from "@/api/onlineEducation/questionBank";
import {batchDelStudent, delBatchStu, getBatchStudent} from "@/api/onlineEducation/batch";
import {useRoute, useRouter} from 'vue-router'
const route = useRoute()
 
 
const { proxy } = getCurrentInstance();
const loading = ref(false);
const dialogRef = ref();
const tableRef = ref();
const router = useRouter();
const data = reactive({
  queryParams: {
    pageId: null,
    phaseId: null,
    pageNum: 1,
    pageSize: 10,
  },
  total: 0,
  dataList: [],
  isAdmin: false,
  chooseStu: []
 
});
 
const { queryParams, total, dataList } = toRefs(data);
 
onMounted(async ()=>{
  const userInfo = JSON.parse(Cookies.get('userInfo'))
  console.log("userInfo",userInfo)
  if(userInfo.userType === 0){
    data.isAdmin = true;
  }else {
    data.isAdmin = false;
  }
  const val = JSON.parse(route.query.val)
  // data.queryParams.pageId = val.id
  data.queryParams.phaseId = val.id
  await getList()
})
onUnmounted(()=>{
 
})
 
const getRowKey = (row) => {
  return row.id
}
const getList = async () => {
  loading.value = true
  const res = await getBatchStudent(data.queryParams)
  if(res.code == 200){
    data.dataList = res.data.list
    data.total = res.data.total
  }else{
    ElMessage.warning(res.message)
  }
  loading.value = false
}
 
const openDialog = () => {
  dialogRef.value.openDialog(data);
}
 
/** 重置新增的表单以及其他数据  */
function reset() {
  proxy.resetForm("roleRef");
}
const handleSelectionChange = (val) => {
 
  console.log("选中的行", val)
  data.chooseStu = val.map(item => item.id)
}
const handleDelete = (val) => {
  ElMessageBox.confirm(
      '确定删除此条数据?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then( async() => {
        const res = await delBatchStu(val.id)
        if(res.code == 200){
          ElMessage.success('数据删除成功')
          await getList()
          tableRef.value.clearSelection();
        }else{
          ElMessage.warning(res.message)
        }
      })
}
const handleDeleteBatch = () => {
  if(data.chooseStu && data.chooseStu.length <=0){
    ElMessage.warning('请选择要删除的学员');
    return false;
  }
  ElMessageBox.confirm(
      '确定删除选择的所有数据?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then( async() => {
        // const param = {
        //   phaseStudentIds: data.chooseStu
        // }
        const res = await batchDelStudent(data.chooseStu)
        if(res.code == 200){
          ElMessage.success('数据删除成功')
          await getList()
        }else{
          ElMessage.warning(res.message)
        }
      })
}
const back = () => {
  router.push("/class");
}
 
 
</script>