|
@@ -0,0 +1,502 @@
|
|
|
+<template>
|
|
|
+ <div class="app-container">
|
|
|
+ <addModal ref="addModel" @success="modalSuccess" />
|
|
|
+ <div class="search-layout">
|
|
|
+ <el-button
|
|
|
+ class="filter-item"
|
|
|
+ style="margin-right: 0"
|
|
|
+ type="primary"
|
|
|
+ icon="el-icon-plus"
|
|
|
+ @click="handleCreate"
|
|
|
+ >
|
|
|
+ 添加
|
|
|
+ </el-button>
|
|
|
+ <el-button type="primary" icon="el-icon-download" @click="download"
|
|
|
+ >下载模板</el-button
|
|
|
+ >
|
|
|
+ <!-- <el-button type="primary" plain @click="addOrUpdate">批量导入</el-button> -->
|
|
|
+ <a href="javascript:;" class="file"
|
|
|
+ >批量导入
|
|
|
+ <input type="file" name="file" ref="file" @change="uploadFun($event)"
|
|
|
+ /></a>
|
|
|
+ <el-input
|
|
|
+ clearable
|
|
|
+ v-model="form.uid"
|
|
|
+ placeholder="请输入alipayUid"
|
|
|
+ class="input"
|
|
|
+ />
|
|
|
+ <el-date-picker
|
|
|
+ v-model="form.startTime"
|
|
|
+ type="datetime"
|
|
|
+ placeholder="选择起始时间"
|
|
|
+ value-format="yyyy-MM-dd HH:mm:ss"
|
|
|
+ class="filter-item input"
|
|
|
+ >
|
|
|
+ </el-date-picker>
|
|
|
+ <el-date-picker
|
|
|
+ v-model="form.endTime"
|
|
|
+ type="datetime"
|
|
|
+ placeholder="选择结束时间"
|
|
|
+ value-format="yyyy-MM-dd HH:mm:ss"
|
|
|
+ class="filter-item"
|
|
|
+ >
|
|
|
+ </el-date-picker>
|
|
|
+ <!-- <el-date-picker
|
|
|
+ v-model="form.date"
|
|
|
+ value-format="yyyy-MM-dd"
|
|
|
+ type="daterange"
|
|
|
+ range-separator="至"
|
|
|
+ start-placeholder="开始日期"
|
|
|
+ end-placeholder="结束日期"
|
|
|
+ class="filter-item wid picker-left"
|
|
|
+ >
|
|
|
+ </el-date-picker> -->
|
|
|
+ <el-button
|
|
|
+ class="filter-item"
|
|
|
+ type="primary"
|
|
|
+ style="margin-left: 10px"
|
|
|
+ icon="el-icon-search"
|
|
|
+ @click="query"
|
|
|
+ >
|
|
|
+ 搜索
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ <!-- 主体表格 -->
|
|
|
+ <el-table
|
|
|
+ :data="tableData"
|
|
|
+ border
|
|
|
+ fit
|
|
|
+ highlight-current-row
|
|
|
+ class="table"
|
|
|
+ v-loading="loading"
|
|
|
+ >
|
|
|
+ <el-table-column align="center" width="200" label="序号">
|
|
|
+ <template v-slot="scope">
|
|
|
+ {{
|
|
|
+ (pagination.current - 1) * pagination.pageSize + (scope.$index + 1)
|
|
|
+ }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
+ <el-table-column align="center" prop="uid" label="alipayUid">
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column
|
|
|
+ align="center"
|
|
|
+ prop="employTime"
|
|
|
+ label="入职时间"
|
|
|
+ show-overflow-tooltip
|
|
|
+ >
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column
|
|
|
+ align="center"
|
|
|
+ prop="createTime"
|
|
|
+ label="创建时间"
|
|
|
+ show-overflow-tooltip
|
|
|
+ >
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column align="center" label="操作区" width="250">
|
|
|
+ <template slot-scope="{ row, $index }">
|
|
|
+ <el-button type="primary" size="mini" @click="handleUpdate(row)">
|
|
|
+ 编辑
|
|
|
+ </el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="danger"
|
|
|
+ @click="handleDelete(row, $index)"
|
|
|
+ >
|
|
|
+ 删除
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ <pagination
|
|
|
+ :total="pagination.total"
|
|
|
+ :page.sync="pagination.current"
|
|
|
+ :limit.sync="pagination.pageSize"
|
|
|
+ :page-sizes="pagination.pageSizeOptions"
|
|
|
+ :layout="pagination.layout"
|
|
|
+ @pagination="handleSizeChange"
|
|
|
+ />
|
|
|
+ <el-drawer
|
|
|
+ :title="hasCompleted ? '导入已完成' : '正在处理中..'"
|
|
|
+ :visible.sync="drawerVisible"
|
|
|
+ :wrapperClosable="false"
|
|
|
+ size="50%"
|
|
|
+ direction="rtl"
|
|
|
+ >
|
|
|
+ <div style="padding: 50px">
|
|
|
+ <div>
|
|
|
+ 已处理条数;{{ hasDealNumber }}; 待处理条数:{{ waitDealNumber }};
|
|
|
+ 总共文件数:{{ allNumber }}
|
|
|
+ </div>
|
|
|
+ <el-progress
|
|
|
+ style="margin-top: 10px"
|
|
|
+ :percentage="makePercent"
|
|
|
+ :format="formatProgress"
|
|
|
+ ></el-progress>
|
|
|
+ <el-table
|
|
|
+ class="table"
|
|
|
+ ref="batch_upload_result"
|
|
|
+ v-loading="false"
|
|
|
+ :data="batchUploadResultList"
|
|
|
+ element-loading-text="Loading"
|
|
|
+ border
|
|
|
+ fit
|
|
|
+ highlight-current-row
|
|
|
+ height="500"
|
|
|
+ >
|
|
|
+ <el-table-column label="错误序号" align="center" width="100px">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ {{ scope.$index + 1 }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="文件名" align="center">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ {{ scope.row.name | matchNull }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="错误描述" align="center">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ {{ scope.row.err | matchNull }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ <div style="text-align: center; margin: 20px 0" v-show="hasCompleted">
|
|
|
+ <el-button type="primary" @click="drawerVisible = false">
|
|
|
+ 我已知晓
|
|
|
+ </el-button>
|
|
|
+ <el-button
|
|
|
+ type="warning"
|
|
|
+ @click="downloadBatchUploadErrorList"
|
|
|
+ v-show="batchUploadResultList.length > 0"
|
|
|
+ >
|
|
|
+ 下载错误列表文件
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </el-drawer>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import AddModal from "./modal/AddModal.vue";
|
|
|
+import tableMixins from "@/mixins/tableMixins";
|
|
|
+import Pagination from "@/components/Pagination";
|
|
|
+import { getList, setTitleList, deleteTitleList } from "@/api/employeeList";
|
|
|
+import { defaultTime, checkTime, calculateTime } from "@/utils/defaultTime";
|
|
|
+import { parseTime } from "@/utils/index";
|
|
|
+import { readExcel } from "@/utils/getExcelList";
|
|
|
+
|
|
|
+export default {
|
|
|
+ components: { Pagination, AddModal },
|
|
|
+ filters: {
|
|
|
+ matchNull(str) {
|
|
|
+ if (!str) {
|
|
|
+ return "未填写";
|
|
|
+ } else {
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ mixins: [tableMixins],
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ form: {},
|
|
|
+ loading: false,
|
|
|
+ // 批量导入结果返回
|
|
|
+ resultVisible: false,
|
|
|
+ result_list: [],
|
|
|
+ //批量人员注册-处理提示值
|
|
|
+ hasDealNumber: 0,
|
|
|
+ waitDealNumber: 0,
|
|
|
+ allNumber: 0,
|
|
|
+ hasCompleted: false,
|
|
|
+ //批量注册人员-抽屉控制值
|
|
|
+ drawerVisible: false,
|
|
|
+ batchUploadResultList: [],
|
|
|
+ batchVisible: false, //批量注册人员-弹框
|
|
|
+ };
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ // 校验时间格式
|
|
|
+ checkTime,
|
|
|
+ initData() {
|
|
|
+ this.getTableList();
|
|
|
+ },
|
|
|
+ // 获取表格数据
|
|
|
+ async getTableList() {
|
|
|
+ this.loading = true;
|
|
|
+ const result = await getList(this.getFilterParams());
|
|
|
+ this.setDataList(result.data);
|
|
|
+ // console.log(result);
|
|
|
+ this.loading = false;
|
|
|
+ },
|
|
|
+ // 获取筛选信息
|
|
|
+ query() {
|
|
|
+ this.clearPageParams();
|
|
|
+ this.getTableList();
|
|
|
+ },
|
|
|
+ // 增加筛选条件
|
|
|
+ transformFilterForm() {
|
|
|
+ return {
|
|
|
+ uid: this.form.uid || undefined,
|
|
|
+ startTime: this.form.startTime || undefined,
|
|
|
+ endTime: this.form.endTime || undefined,
|
|
|
+ // startTime: this.form.date[0] || undefined,
|
|
|
+ // endTime: this.form.date[1] || undefined,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ modalSuccess() {
|
|
|
+ this.getTableList();
|
|
|
+ },
|
|
|
+ // 添加配置
|
|
|
+ handleCreate() {
|
|
|
+ this.$refs.addModel.open();
|
|
|
+ // console.log(this.$refs.addModel);
|
|
|
+ },
|
|
|
+ // 编辑配置
|
|
|
+ handleUpdate(row) {
|
|
|
+ this.$refs.addModel.open(row);
|
|
|
+ },
|
|
|
+ // 删除
|
|
|
+ handleDelete(row, index) {
|
|
|
+ const that = this;
|
|
|
+ this.$confirm("确定删除吗?", "提示", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ cancelButtonText: "取消",
|
|
|
+ showClose: false,
|
|
|
+ type: "warning",
|
|
|
+ beforeClose: async (action, instance, done) => {
|
|
|
+ if (action === "confirm") {
|
|
|
+ instance.confirmButtonLoading = true;
|
|
|
+ instance.cancelButtonLoading = true;
|
|
|
+ instance.confirmButtonText = "提交中...";
|
|
|
+ try {
|
|
|
+ await deleteTitleList(row.id);
|
|
|
+ this.$message({
|
|
|
+ type: "success",
|
|
|
+ message: "删除成功!",
|
|
|
+ });
|
|
|
+ that.getTableList();
|
|
|
+ } catch (e) {
|
|
|
+ } finally {
|
|
|
+ done();
|
|
|
+ setTimeout(() => {
|
|
|
+ instance.confirmButtonLoading = false;
|
|
|
+ instance.cancelButtonLoading = false;
|
|
|
+ }, 300);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ done();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .then(() => {})
|
|
|
+ .catch(() => {});
|
|
|
+ },
|
|
|
+ // 下载模版
|
|
|
+ download() {
|
|
|
+ window.location.href =
|
|
|
+ // process.env.VUE_APP_BASE_API + "/static/deviceListExcel.xlsx";
|
|
|
+ process.env.VUE_APP_BASE_API + "/static/导入模板.xlsx";
|
|
|
+ },
|
|
|
+ // 批量导入
|
|
|
+ // addOrUpdate() {},
|
|
|
+ // 批量导入
|
|
|
+ async uploadFun(e) {
|
|
|
+ this.loading = true;
|
|
|
+ var files = e.currentTarget.files;
|
|
|
+ if (!files.length) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let data = await readExcel(files[0]); //file指的是获取的excel文件对象,如e.file
|
|
|
+ let newData = [];
|
|
|
+ data.forEach((i) => {
|
|
|
+ for (let key in i) {
|
|
|
+ if (i[key]) {
|
|
|
+ newData.push(i);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ data = newData;
|
|
|
+ this.loading = false;
|
|
|
+ this.allNumber = data.length;
|
|
|
+ this.drawerVisible = true;
|
|
|
+ this.doUploadAddUserInfo(0, data);
|
|
|
+ this.$refs.file.value = "";
|
|
|
+ },
|
|
|
+ // 递归调用校验数据并请求
|
|
|
+ async doUploadAddUserInfo(i, data) {
|
|
|
+ if (i > data.length - 1) {
|
|
|
+ this.hasCompleted = true;
|
|
|
+ this.getTableList();
|
|
|
+ this.$message.success("导入已完成!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let form = {};
|
|
|
+ form.uid = data[i]["alipayUid"];
|
|
|
+ form.employTime = data[i]["入职时间"];
|
|
|
+ form.employTime = parseTime(form.employTime, "{y}-{m}-{d} {h}:{i}:{s}");
|
|
|
+ // console.log(form.employTime, "form.employTime");
|
|
|
+ await this.isPassFun(form, i).then(async (res) => {
|
|
|
+ let timeout = 0;
|
|
|
+ if (res.isOk) {
|
|
|
+ await this.addUserInfo(data, form, i);
|
|
|
+ } else {
|
|
|
+ this.getFileList1(data, i, res, form);
|
|
|
+ timeout = 0;
|
|
|
+ }
|
|
|
+ this.hasDealNumber = i + 1;
|
|
|
+ this.waitDealNumber = data.length - (i + 1);
|
|
|
+ setTimeout(() => {
|
|
|
+ this.doUploadAddUserInfo(++i, data);
|
|
|
+ }, timeout);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 校验模板数据内容
|
|
|
+ async isPassFun(form, i) {
|
|
|
+ let isPass = {
|
|
|
+ isOk: true,
|
|
|
+ incorrect: {
|
|
|
+ name: `第${i + 1}行`,
|
|
|
+ err: "",
|
|
|
+ },
|
|
|
+ };
|
|
|
+ if (!form.uid) {
|
|
|
+ isPass.incorrect.err = "alipayUid为必填项";
|
|
|
+ isPass.isOk = false;
|
|
|
+ return isPass;
|
|
|
+ }
|
|
|
+ if (form.employTime) {
|
|
|
+ if (!this.checkTime(form.employTime)) {
|
|
|
+ isPass.isOk = false;
|
|
|
+ isPass.incorrect.err = "入职时间格式有误";
|
|
|
+ return isPass;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ resolve(isPass);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 批量注册人员-保持滚动条在最底部
|
|
|
+ makeScrollDown() {
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs.batch_upload_result.$refs.bodyWrapper.scrollTop =
|
|
|
+ this.$refs.batch_upload_result.$refs.bodyWrapper.scrollHeight;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ //批量注册人员-返回进度条尾部显示值
|
|
|
+ formatProgress(percent) {
|
|
|
+ return percent == 100 ? "已完成" : "";
|
|
|
+ },
|
|
|
+ //批量注册人员-导出错误名单
|
|
|
+ downloadBatchUploadErrorList() {
|
|
|
+ let list = this.batchUploadResultList;
|
|
|
+ let string = "序号\t文件名\t错误原因\n";
|
|
|
+ for (let i = 0; i < this.batchUploadResultList.length; i++) {
|
|
|
+ string +=
|
|
|
+ (i + 1).toString() +
|
|
|
+ "\t" +
|
|
|
+ list[i].name +
|
|
|
+ "\t" +
|
|
|
+ list[i].err +
|
|
|
+ "\t" +
|
|
|
+ "\n";
|
|
|
+ }
|
|
|
+ let blob = new Blob([string], { type: "text/plain;charset=utf-8" });
|
|
|
+ let excel_url = window.URL.createObjectURL(blob);
|
|
|
+ let link = document.createElement("a");
|
|
|
+ link.href = excel_url;
|
|
|
+ link.download = "结果错误名单.xls";
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ document.body.removeChild(link);
|
|
|
+ },
|
|
|
+ // 批量导入-调用添加员工接口
|
|
|
+ async addUserInfo(data, form, i) {
|
|
|
+ // console.log(form);
|
|
|
+ await setTitleList(form)
|
|
|
+ .then((res) => {})
|
|
|
+ .catch((err) => {
|
|
|
+ this.batchUploadResultList.push({ name: `第${i + 1}行`, err: err });
|
|
|
+ this.makeScrollDown();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 批量导入-推入错误信息
|
|
|
+ getFileList1(data, i, isPass) {
|
|
|
+ // this.initAddress(this.user_form.contents);
|
|
|
+ this.batchUploadResultList.push(isPass.incorrect);
|
|
|
+ this.makeScrollDown();
|
|
|
+ },
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ drawerVisible(n) {
|
|
|
+ if (n) {
|
|
|
+ this.batchVisible = false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ //批量注册人员-返回向下取整,减少渲染次数
|
|
|
+ makePercent() {
|
|
|
+ // console.log(this.hasDealNumber);
|
|
|
+ return Math.floor((this.hasDealNumber / this.allNumber) * 100);
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+.search-layout {
|
|
|
+ margin-bottom: 20px;
|
|
|
+ margin-top: -10px;
|
|
|
+ .filter-item {
|
|
|
+ margin-right: 10px;
|
|
|
+ margin-top: 10px;
|
|
|
+ }
|
|
|
+ .input {
|
|
|
+ width: 200px;
|
|
|
+ margin-left: 10px;
|
|
|
+ }
|
|
|
+ .picker-left {
|
|
|
+ margin-left: 10px;
|
|
|
+ }
|
|
|
+}
|
|
|
+.search-layout .filter-item:last-of-type {
|
|
|
+ margin-right: 0;
|
|
|
+}
|
|
|
+/*批量导入按钮*/
|
|
|
+.file {
|
|
|
+ margin: 10px 0 0 10px;
|
|
|
+ position: relative;
|
|
|
+ background: #d0eeff;
|
|
|
+ border: 1px solid #99d3f5;
|
|
|
+ border-radius: 4px;
|
|
|
+ padding: 10px 20px;
|
|
|
+ box-sizing: border-box;
|
|
|
+ overflow: hidden;
|
|
|
+ color: #1e88c7;
|
|
|
+ text-decoration: none;
|
|
|
+ text-indent: 0;
|
|
|
+}
|
|
|
+.file input {
|
|
|
+ position: absolute;
|
|
|
+ font-size: 14px;
|
|
|
+ width: 106px;
|
|
|
+ height: 40px;
|
|
|
+ left: 0;
|
|
|
+ top: 0;
|
|
|
+ opacity: 0;
|
|
|
+ cursor: pointer;
|
|
|
+}
|
|
|
+// .file:hover {
|
|
|
+// background: #aadffd;
|
|
|
+// border-color: #78c3f3;
|
|
|
+// color: #004974;
|
|
|
+// text-decoration: none;
|
|
|
+// }
|
|
|
+.table {
|
|
|
+ margin-top: 15px;
|
|
|
+}
|
|
|
+</style>
|