马宇豪
2024-12-19 9cbd3ec7007bac8b7ae5d49d2e521889fda28822
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
<template>
    <div class="home-container">
        <div style="height: 100%">
          <div class="homeCard">
            <div class="main-card">
            <el-row class="cardTop">
              <el-col :span="12" class="mainCardBtn">
                <el-button type="primary" icon="Plus" size="default" @click="openDialog('add',{})">新增</el-button>
              </el-col>
            </el-row>
            <el-table :data="reportData" style="width: 100%" height="calc(100% - 48px)" :header-cell-style="{ background: '#fafafa' }">
              <el-table-column prop="id" label="id" show-overflow-tooltip></el-table-column>
              <el-table-column prop="planName" label="培训计划名称" show-overflow-tooltip></el-table-column>
              <el-table-column prop="planMode" label="培训形式" show-overflow-tooltip>
                <template #default="scope">
                  {{ scope.row.planMode == 1? '线上':scope.row.planMode == 2? '线下':'--' }}
                </template>
              </el-table-column>
              <el-table-column prop="offlineFile" label="印证照片" show-overflow-tooltip>
                <template #default="scope">
                  <div v-if="scope.row.offlineFile && scope.row.offlineFile !== ''">
                    <el-image
                        v-for="(item,index) in scope.row.offlineFile.split(',')"
                        style="width: 50px; height: 50px"
                        :src="item"
                        fit="cover"
                        :preview-teleported= true
                    />
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="planBeginTime" label="培训开始时间" show-overflow-tooltip></el-table-column>
              <el-table-column prop="planEndTime" label="培训结束时间" show-overflow-tooltip></el-table-column>
              <el-table-column prop="createDate" label="创建时间" show-overflow-tooltip></el-table-column>
              <el-table-column prop="updateDate" label="修改时间" show-overflow-tooltip></el-table-column>
              <el-table-column label="操作" width="140">
                  <template #default="scope">
                    <el-button size="small" text type="primary" @click="openDialog('update',scope.row)">重新上报</el-button>
                    <el-button style="color: red" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>
                  </template>
              </el-table-column>
            </el-table>
            <div class="pageBtn">
              <el-pagination @size-change="onHandleSizeChange" small="false" @current-change="onHandleCurrentChange" class="page-position" :pager-count="5" :page-sizes="[10, 20, 30]" v-model:current-page="listQuery.pageIndex" background v-model:page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
            </div>
            </div>
          </div>
        </div>
        <add-report ref="reportRef" @refresh="getData"></add-report>
    </div>
</template>
 
<script lang="ts">
import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
import addReport from "./components/addReport.vue"
import {judgeReportApi} from "/@/api/dataUpload/saftyBaseInfo/judgeReport";
import axios from "axios";
import Cookies from "js-cookie";
import {educateTrainApi} from "/@/api/dataUpload/educateTrain";
 
// 定义接口来定义对象的类型
interface TableDataRow {
  id: number|null
  updateDate: string
  createDate: string
  planName: string
  planMode: number|null
  offlineFile: string
  planBeginTime: string
  planEndTime: string
}
interface TableDataState {
  reportData: [],
  listQuery: {
    searchParams: {}
    pageIndex: number
    pageSize: number
  }
  total: null | number
  baseUrl: string
}
 
export default defineComponent({
    name: 'trainPlan',
    components: {addReport },
    setup() {
      const reportRef= ref();
      const state = reactive<TableDataState>({
        reportData: [],
        listQuery: {
          searchParams: {},
          pageIndex: 1,
          pageSize: 10
        },
        total: null,
        baseUrl: import.meta.env.VITE_API_URL
      });
 
      // 页面加载时
      onMounted(() => {
        getData()
        console.log(state.baseUrl)
      });
 
      const getData = async ()=>{
        const res = await educateTrainApi().getTrainPlanList(state.listQuery)
        if(res.data.code == 200){
          state.reportData = res.data.data
          state.total = res.data.total
        }else{
          ElMessage({
            type: 'warning',
            message: res.data.msg
          })
        }
      }
 
      const openDialog=(type:string,data:object)=>{
        reportRef.value.open(type,data)
      }
 
      // 删除用户
      const onRowDel = (row: TableDataRow) => {
          ElMessageBox.confirm(`此操作将永久删除计划名称:“${row.planName}”,是否继续?`, '提示', {
              confirmButtonText: '确认',
              cancelButtonText: '取消',
              type: 'warning'
          })
              .then(async () => {
                const res = await educateTrainApi().delTrainPlan({ids: [row.id]})
                if(res.data.code == 200){
                  ElMessage({
                    type: 'success',
                    message: '删除成功'
                  })
                  await getData()
                }else{
                  ElMessage({
                    type: 'warning',
                    message: res.data.msg
                  })
                }
              })
              .catch(() => {});
      };
      // 分页改变
      const onHandleSizeChange = (val: number) => {
          state.listQuery.pageSize = val;
          getData()
      };
      // 分页改变
      const onHandleCurrentChange = (val: number) => {
          state.listQuery.pageIndex = val;
          getData()
      };
 
      const openFile=(file: string)=>{
        axios.get(import.meta.env.VITE_API_URL + file,{headers:{'Content-Type': 'application/json','Authorization': `${Cookies.get('token')}`,'uid':`${Cookies.get('uid')}`},responseType: 'blob'}).then(res=>{
          if (res) {
            const link = document.createElement('a')
            let blob = new Blob([res.data],{type: res.data.type})
            link.style.display = "none";
            link.href = URL.createObjectURL(blob); // 创建URL
            window.open(link.href)
          } else {
            ElMessage({
              type: 'warning',
              message: '文件读取失败'
            });
          }
        })
      }
 
      return {
        reportRef,
        openDialog,
        openFile,
        getData,
        onRowDel,
        onHandleSizeChange,
        onHandleCurrentChange,
        ...toRefs(state)
      };
    }
});
</script>
<style lang="scss" scoped>
.home-container {
  height: calc(100vh - 144px);
  box-sizing: border-box;
  overflow: hidden;
  .demo-tabs {
    width: 100%;
    height: 100%;
 
    &::v-deep(.el-tabs__content) {
      height: calc(100% - 60px);
    }
 
    .el-tab-pane {
      height: 100%;
    }
  }
  .homeCard {
    width: 100%;
    padding: 20px;
    box-sizing: border-box;
    background: #fff;
    border-radius: 4px;
 
    .main-card {
      width: 100%;
      height: 100%;
      .cardTop {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 20px;
        .mainCardBtn {
          margin: 0;
        }
      }
      .pageBtn {
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: right;
 
        .demo-pagination-block + .demo-pagination-block {
          margin-top: 10px;
        }
        .demo-pagination-block .demonstration {
          margin-bottom: 16px;
        }
      }
    }
    &:last-of-type {
      height: calc(100% - 100px);
    }
  }
  .el-row {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
    .grid-content {
      align-items: center;
      min-height: 36px;
    }
 
    .topInfo {
      display: flex;
      align-items: center;
      font-size: 16px;
      font-weight: bold;
 
      & > div {
        white-space: nowrap;
        margin-right: 20px;
      }
    }
  }
  .el-card {
    border: 0;
  }
}
</style>