zhouwx
2025-06-10 c8c99bf1f753e27c4d99a0ff6058ce16f973f9c4
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
<template>
  <div class="notice">
    <el-dialog
        v-model="dialogVisible"
        :title="title"
        width="800px"
        :before-close="handleClose"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
    >
      <div style="margin-bottom: 10px;margin-left: 30px">
        <el-checkbox v-model="state.bindBatchStu" @change="changeBind">绑定批次人员</el-checkbox>
        <el-select
            v-if="state.bindBatchStu"
            multiple
            collapse-tags
            collapse-tags-tooltip
            v-model="state.form.phaseIds"
            style="width: 160px;margin: 0 20px"
            v-loadMoreNew:[reselectExam]="handleScroll"
            :popper-class="reselectExam.name"
            class="item-width"
            placeholder="请选择批次"
        >
          <el-option
              v-for="item in state.batchList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
          />
        </el-select>
      </div>
      <div>
        <el-form :inline="true" style="display: flex;align-items: center;flex-wrap: wrap;" >
          <el-form-item >
            <!--            <el-checkbox v-model="state.DisableSelection">一键全选</el-checkbox>-->
          </el-form-item>
          <el-form-item label="姓名:" >
            <el-input v-model="state.queryParams.name" placeholder="请输入姓名"></el-input>
          </el-form-item>
          <el-form-item label="职务:" >
            <el-input v-model="state.queryParams.duty" placeholder="请输入职务"></el-input>
          </el-form-item>
          <el-form-item >
            <el-button
                type="primary"
                @click="getList"
            >查询</el-button>
            <el-button
                type="primary"
                plain
                @click="resetQuery"
            >重置</el-button>
          </el-form-item>
        </el-form>
      </div>
 
      <!-- 表格数据 -->
      <el-table
          ref="tableRef"
          v-loading="loading"
          :data="state.dataList"
          :border="true"
          :row-key="getRowKey"
          @selection-change="handleSelectionChange"
          v-model="state.selectRowKeys"
      >
        <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="empno" align="center" width="60"  />
        <el-table-column label="姓名" prop="name" align="center"  />
        <el-table-column label="性别" prop="sex" align="center" >
          <template #default="scope">
            <span>{{scope.row.sex == 0 ? '男':'女'}}</span>
          </template>
        </el-table-column>
        <el-table-column label="手机号" prop="phone" align="center" width="130"/>
        <el-table-column label="身份证" prop="idNo" align="center" width="200" :show-overflow-tooltip="true"/>
<!--        <el-table-column label="创建人" prop="createBy" align="center"/>-->
        <el-table-column label="工作岗位" prop="post" align="center"/>
        <el-table-column label="职务" prop="duty" align="center"/>
<!--        <el-table-column label="一人一档" prop="duty" align="center" width="120">-->
<!--          <template #default="scope">-->
<!--            <el-button link type="primary">培训考试记录</el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
 
      <pagination
          v-show="state.total> 0"
          :total="state.total"
          v-model:page="state.queryParams.pageNum"
          v-model:limit="state.queryParams.pageSize"
          @pagination="getList"
      />
      <template #footer>
        <span class="dialog-footer">
            <el-button @click="handleClose" size="default">取 消</el-button>
            <el-button type="primary"  @click="onSubmit" size="default" v-preReClick>确认</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import {nextTick, reactive, ref, toRefs} from 'vue'
import {ElMessage} from "element-plus";
import Cookies from "js-cookie";
import {
  addQuestionBank,
  checkQuestionBankName,
  editQuestionBank,
  getQuestionBank
} from "@/api/onlineEducation/questionBank";
import {getStudent} from "@/api/onlineEducation/student";
import {batchAddStudent, getBatch} from "@/api/onlineEducation/batch";
import {examAddStudent} from "@/api/onlineEducation/exam";
 
const dialogVisible = ref(false);
const title = ref("");
const tableRef = ref();
const length = ref()
const emit = defineEmits(["getList"]);
const startUsername = ref('');
const classifyRef = ref(null)
const state = reactive({
  form: {
    paperId: null,
    phaseIds: [],
    studentIds: []
  },
  isAdmin: false,
  total: 0,
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    name: '',
    duty: ''
  },
  dataList: [],
  totalItems: 0, // 总数据条数,从后端接口获取
  phaseId: null,
  chooseStu: [],
  companyId: null,
  selectRowKeys: [],
  batchList: [],
  batchPageNum: 1, // 当前页码
  batchPageSize: 10, // 每页显示的数量
  hasMoreItemsBatch: null, // 是否还有更多选项
  bindBatchStu: false
 
})
const loading = ref(false);
 
const reselectExam = reactive({
  name: 'ExamBatch'
})
const getRowKey = (row) => {
  return row.id
}
const openDialog = async (data) => {
  // state.selectRowKeys = [10,11]
 
  state.form.paperId = data.queryParams.paperId
  title.value = '学员选择';
  dialogVisible.value = true;
  await getList()
  await loadMoreBatchData()
}
 
const getList = async () => {
  loading.value = true
  const res = await getStudent(state.queryParams)
  if(res.code == 200){
    state.dataList = res.data.list
    state.total = res.data.total
    // await nextTick(() => {
    //   const currentIds = state.dataList.map(row => row.id)
    //   const selectIds = state.selectRowKeys.filter(id => currentIds.includes(id))
    //   state.dataList.forEach(row => {
    //     if (selectIds.includes(row.id)) {
    //       tableRef.value.toggleRowSelection(row, true);
    //     }
    //   })
    // });
  }else{
    ElMessage.warning(res.message)
  }
  loading.value = false
}
 
const onSubmit = async () => {
    const res = await examAddStudent(state.form)
    if(res.code === 200){
      ElMessage({
        type: 'success',
        message: '新增成功'
      });
    }else{
      ElMessage.warning(res.message)
    }
    emit("getList")
    reset();
    dialogVisible.value = false;
}
 
const handleClose = () => {
  reset();
  dialogVisible.value = false;
  emit("getList")
}
const reset = () => {
  state.form = {
    paperId: null,
    phaseIds: [],
    studentIds: []
  }
  state.bindBatchStu = false;
  state.batchList = [];
  state.batchPageNum = 1;
  state.batchPageSize = 10;
  state.hasMoreItemsBatch = null;
  tableRef.value.clearSelection();
  state.dataList = []
  state.total = 0
  state.queryParams ={
    pageNum: 1,
    pageSize: 10
  }
}
const handleSelectionChange = (val) => {
  state.form.studentIds = val.map(item => item.id)
  console.log("选中的行",  state.form.studentIds)
}
 
const handleScroll = () => {
  if(state.batchPageNum >= state.hasMoreItemsBatch) return
  state.batchPageNum++;
  loadMoreBatchData()
}
const loadMoreBatchData = async () => {
  console.log(' Bank');
  const queryParams = {
    pageNum: state.batchPageNum,
    pageSize: state.batchPageSize,
  }
  const res = await getBatch(queryParams)
  if (res.code == 200) {
    state.hasMoreItemsBatch = res.data.totalPage
    const data = res.data
    state.batchList = state.batchList.concat(data.list)
  }else{
    ElMessage.warning(res.message)
  }
}
const changeBind = (val) => {
  console.log('vv',val)
}
const resetQuery = () => {
  state.queryParams ={
    pageNum: 1,
    pageSize: 10,
    name: '',
    duty: ''
  }
  getList()
}
defineExpose({
  openDialog
});
 
</script>
 
<style scoped lang="scss">
.notice{
  :deep(.el-form .el-form-item__label) {
    font-size: 15px;
  }
  .file {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }
}
</style>