<template> <div class="common-page page-t1 module-config"> <div class="option page-row"> <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px"> <el-form-item label="创建时间"> <el-date-picker v-model="queryParams.range" @change="dateChange" value-format="yyyy-MM-dd" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"> </el-date-picker> </el-form-item> <!--el-button type="primary" @click="getList">查询</el-button--> </el-form> <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport">导入</el-button> </div> <!-- <div class="tongji">{{tongji}}</div> --> <div class="panel-bottom page-row"> <div class="ctin-box"> <div class="content-within"> <div class="content-fix"> <el-table v-loading="loading" :data="dataList" > <el-table-column label="姓名" align="center" prop="perName" /> <el-table-column label="性别" align="center" prop="perSex" > <template slot-scope="scope"> <div v-if="scope.row.perSex==1">男</div> <div v-else>女</div> </template> </el-table-column> <el-table-column label="部门" align="center" prop="perDept" /> <el-table-column label="职务" align="center" prop="perOffice" /> <el-table-column label="卡号" align="center" prop="phone" /> <el-table-column label="电话" align="center" prop="perTel" /> </el-table> <!-- 添加分页组件 --> <el-pagination v-show="total>0" class="pagination-container" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryParams.page" :page-sizes="[10, 20, 30, 50]" :page-size="queryParams.size" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination> </div> </div> </div> </div> <!-- 人员定位卡导入对话框 --> <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body> <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag> <i class="el-icon-upload"></i> <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div> <div class="el-upload__tip text-center" slot="tip"> <span>仅允许导入xls、xlsx格式文件。</span> <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link> </div> </el-upload> <div slot="footer" class="dialog-footer"> <el-button type="primary" @click="submitFileForm">确 定</el-button> <el-button @click="upload.open = false">取 消</el-button> </div> </el-dialog> </div> </template> <script> import { personCardGet } from '@/api/newApi' import { getToken } from "@/utils/auth"; import {Loading, Message} from 'element-ui' export default { name: "diBang", components: {}, props: [], data() { return { // 遮罩层 loading: true, // 查询参数 queryParams: { page: 1, size: 10, range: [], }, total: 0, // 总条数 dataList:[], value1:null, tongji:'', // 用户导入参数 upload: { // 是否显示弹出层(用户导入) open: false, // 弹出层标题(用户导入) title: "", // 是否禁用上传 isUploading: false, // 是否更新已经存在的用户数据 updateSupport: 0, // 设置上传的请求头部 headers: { Authorization: "Bearer " + getToken() }, // 上传的地址 url: process.env.VUE_APP_LOCAL_API + "/api/perInfo/import" }, }; }, watch: {}, created() { this.$nextTick(function () {}); }, mounted() { this.$nextTick(function () { this.getList() }); }, methods: { getList(){ personCardGet(this.queryParams).then(res=>{ this.dataList = res.body.list; // 改为使用分页数据 this.total = res.body.total; // 获取总条数 this.loading = false; this.loading = false; }) }, handleSizeChange(val) { this.queryParams.size = val; this.getList(); }, handleCurrentChange(val) { this.queryParams.page = val; this.getList(); }, dateChange(e){ console.log(e) this.getList() }, // 文件上传中处理 handleFileUploadProgress(event, file, fileList) { console.log(file, fileList,'1111') this.upload.isUploading = true; }, // 文件上传成功处理 handleFileSuccess(response, file, fileList) { console.log(response, file, fileList,'aaa') this.upload.open = false; this.upload.isUploading = false; this.$refs.upload.clearFiles(); if (response.code === 200) { this.$alert("导入成功", "提示", { confirmButtonText: "确定" }); // 导入成功后刷新列表 this.getList(); } else { this.$message.error(response.msg); } }, // 提交上传文件 submitFileForm() { this.$refs.upload.submit(); }, // 提交上传文件 submitFileForm() { this.$refs.upload.submit(); }, // 下载模板 importTemplate() { // 实际项目中需要替换为真实的模板下载地址 window.location.href = process.env.VUE_APP_LOCAL_API + '/api/perInfo/exportTemplate' }, beforeUpload(file) { const isExcel = file.type.includes('sheet'); if (!isExcel) { this.$message.error('只能上传excel文件'); return false; } return true; }, handleImport(){ this.upload.open = true }, }, }; </script>