534 lines
14 KiB
Vue
534 lines
14 KiB
Vue
<template>
|
||
<div class="app-container">
|
||
<el-form
|
||
:model="queryParams"
|
||
ref="queryRef"
|
||
:inline="true"
|
||
v-show="showSearch"
|
||
label-width="68px"
|
||
>
|
||
<!-- <el-form-item label="用户ID" prop="userId">
|
||
<el-input
|
||
v-model="queryParams.userId"
|
||
placeholder="请输入用户ID"
|
||
clearable
|
||
@keyup.enter="handleQuery"
|
||
/>
|
||
</el-form-item>-->
|
||
<el-form-item label="用户名称" prop="nickname">
|
||
<el-input
|
||
v-model="queryParams.nickname"
|
||
placeholder="请输入用户名称"
|
||
clearable
|
||
@keyup.enter="handleQuery"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="手机号" prop="phone">
|
||
<el-input
|
||
v-model="queryParams.phone"
|
||
placeholder="请输入手机号"
|
||
clearable
|
||
@keyup.enter="handleQuery"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" icon="Search" @click="handleQuery"
|
||
>搜索</el-button
|
||
>
|
||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
|
||
<el-row :gutter="10" class="mb8">
|
||
<el-col :span="1.5">
|
||
<el-button
|
||
type="primary"
|
||
plain
|
||
icon="Plus"
|
||
@click="handleAdd"
|
||
v-hasPermi="['employee:employee:add']"
|
||
>新增
|
||
</el-button>
|
||
</el-col>
|
||
<el-col :span="1.5">
|
||
<el-button type="primary" plain icon="Plus" @click="handleImport"
|
||
>导入员工
|
||
</el-button>
|
||
</el-col>
|
||
<!-- <el-col :span="1.5">
|
||
<el-button
|
||
type="success"
|
||
plain
|
||
icon="Edit"
|
||
:disabled="single"
|
||
@click="handleUpdate"
|
||
v-hasPermi="['employee:employee:edit']"
|
||
>修改
|
||
</el-button>
|
||
</el-col>-->
|
||
<el-col :span="1.5">
|
||
<el-button
|
||
type="danger"
|
||
plain
|
||
icon="Delete"
|
||
:disabled="multiple"
|
||
@click="handleDelete"
|
||
v-hasPermi="['employee:employee:remove']"
|
||
>删除
|
||
</el-button>
|
||
</el-col>
|
||
<right-toolbar
|
||
v-model:showSearch="showSearch"
|
||
@queryTable="getList"
|
||
></right-toolbar>
|
||
</el-row>
|
||
|
||
<el-table
|
||
@row-click="handleCancelEditPoint"
|
||
v-loading="loading"
|
||
:data="employeeList"
|
||
@selection-change="handleSelectionChange"
|
||
>
|
||
<el-table-column type="selection" width="55" align="center" />
|
||
<!-- <el-table-column label="用户ID" align="center" prop="userId"/>-->
|
||
<el-table-column label="用户名称" align="center" prop="nickname" />
|
||
<el-table-column label="手机号码" align="center" prop="phone" />
|
||
<el-table-column label="状态" align="center" prop="status">
|
||
<template #default="{ row }">
|
||
<el-switch
|
||
@click="handleUpdateStatus(row)"
|
||
inactive-value="0"
|
||
active-value="1"
|
||
:model-value="row.status"
|
||
/>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="总积分" align="center" prop="point" width="240">
|
||
<template #default="{ row }">
|
||
<el-row
|
||
justify="center"
|
||
v-if="pointEditing && form.userId === row.userId"
|
||
align="middle"
|
||
>
|
||
<el-col :span="12">
|
||
<el-input-number
|
||
style="width: 100%"
|
||
@click.stop
|
||
size="small"
|
||
v-model="form.point"
|
||
/>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-button
|
||
link
|
||
@click.stop="submitPoint"
|
||
icon="Check"
|
||
type="success"
|
||
/>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row v-else>
|
||
<el-col :span="12">
|
||
<div style="text-align: center">{{ row.point }}</div>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-button
|
||
link
|
||
icon="Edit"
|
||
@click.stop="handleUpdatePoint($event, row)"
|
||
type="primary"
|
||
/>
|
||
</el-col>
|
||
</el-row>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="创建时间" align="center" prop="createTime" />
|
||
<el-table-column
|
||
label="操作"
|
||
align="center"
|
||
class-name="small-padding fixed-width"
|
||
>
|
||
<template #default="scope">
|
||
<!-- <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
|
||
v-hasPermi="['employee:employee:edit']">修改
|
||
</el-button>-->
|
||
<el-button
|
||
link
|
||
type="primary"
|
||
icon="Delete"
|
||
@click="handleDelete(scope.row)"
|
||
v-hasPermi="['employee:employee:remove']"
|
||
>删除
|
||
</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"
|
||
/>
|
||
|
||
<!-- 添加或修改员工对话框 -->
|
||
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
|
||
<el-form
|
||
ref="employeeRef"
|
||
:model="form"
|
||
:rules="rules"
|
||
label-width="80px"
|
||
>
|
||
<el-form-item label="用户名称" prop="nickname">
|
||
<el-input v-model="form.nickname" placeholder="请输入用户名称" />
|
||
</el-form-item>
|
||
<el-form-item label="手机号码" prop="phone">
|
||
<el-input v-model="form.phone" placeholder="请输入手机号码" />
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<div class="dialog-footer">
|
||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||
<el-button @click="cancel">取 消</el-button>
|
||
</div>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 员工导入对话框 -->
|
||
<el-dialog
|
||
draggable
|
||
v-model="upload.open"
|
||
:title="upload.title"
|
||
append-to-body
|
||
width="400px"
|
||
>
|
||
<div v-show="upload.isUploading" class="upload-progress">
|
||
<el-progress type="circle" :percentage="50" :show-text="false" />
|
||
<p>正在导入员工数据,请耐心等待......</p>
|
||
</div>
|
||
<el-upload
|
||
v-show="!upload.isUploading"
|
||
ref="uploadRef"
|
||
:action="upload.url"
|
||
:auto-upload="false"
|
||
:disabled="upload.isUploading"
|
||
:headers="upload.headers"
|
||
:limit="1"
|
||
:on-progress="handleFileUploadProgress"
|
||
:on-success="handleFileSuccess"
|
||
accept=".xlsx, .xls"
|
||
drag
|
||
>
|
||
<el-icon class="el-icon--upload">
|
||
<upload-filled />
|
||
</el-icon>
|
||
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
||
<template #tip>
|
||
<div class="el-upload__tip text-center">
|
||
<ol style="text-align: start; margin-left: 20px">
|
||
<!-- <li>(*)为必填项</li>-->
|
||
<!-- <li>部门,角色,岗位请填数字编号</li>-->
|
||
<!-- <li>角色,岗位若存在多个,请以英文逗号隔开</li>-->
|
||
<!-- <li>禁止任何的换行或空格</li>-->
|
||
<!-- <li style="color: #f00; font-size: 13px">-->
|
||
<!-- 请手动更改单元格格式为文本格式-->
|
||
<!-- </li>-->
|
||
<li>
|
||
<span>仅允许导入xls、xlsx格式文件。</span>
|
||
<el-link
|
||
:underline="false"
|
||
style="font-size: 12px; vertical-align: baseline"
|
||
type="primary"
|
||
@click="importTemplate"
|
||
>下载模板
|
||
</el-link>
|
||
</li>
|
||
</ol>
|
||
</div>
|
||
</template>
|
||
</el-upload>
|
||
<template #footer>
|
||
<div class="dialog-footer">
|
||
<el-button type="primary" @click="submitFileForm">确 定</el-button>
|
||
<el-button @click="upload.open = false">取 消</el-button>
|
||
</div>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup name="Employee">
|
||
import {
|
||
listEmployee,
|
||
getEmployee,
|
||
delEmployee,
|
||
addEmployee,
|
||
updateEmployee,
|
||
downloadEmployeeTemplate,
|
||
updateEmployeePoint,
|
||
updateEmployeeStatus,
|
||
} from "@/api/employee/employee";
|
||
import { getToken } from "@/utils/auth";
|
||
import { saveAs } from "file-saver";
|
||
import modal from "@/plugins/modal";
|
||
|
||
const { proxy } = getCurrentInstance();
|
||
|
||
const employeeList = ref([]);
|
||
const open = ref(false);
|
||
const loading = ref(true);
|
||
const showSearch = ref(true);
|
||
const ids = ref([]);
|
||
const single = ref(true);
|
||
const multiple = ref(true);
|
||
const total = ref(0);
|
||
const title = ref("");
|
||
const pointEditing = ref(false);
|
||
const data = reactive({
|
||
form: {},
|
||
queryParams: {
|
||
pageNum: 1,
|
||
pageSize: 10,
|
||
userId: null,
|
||
nickname: null,
|
||
point: null,
|
||
},
|
||
rules: {
|
||
userId: [{ required: true, message: "用户ID不能为空", trigger: "blur" }],
|
||
nickname: [
|
||
{ required: true, message: "用户名称不能为空", trigger: "blur" },
|
||
],
|
||
point: [{ required: true, message: "总积分不能为空", trigger: "blur" }],
|
||
},
|
||
});
|
||
|
||
const { queryParams, form, rules } = toRefs(data);
|
||
|
||
/*** 用户导入参数 */
|
||
const upload = reactive({
|
||
// 是否显示弹出层(用户导入)
|
||
open: false,
|
||
// 弹出层标题(用户导入)
|
||
title: "",
|
||
// 是否禁用上传
|
||
isUploading: false,
|
||
// 是否更新已经存在的用户数据
|
||
updateSupport: 0,
|
||
// 设置上传的请求头部
|
||
headers: { Authorization: "Bearer " + getToken() },
|
||
// 上传的地址
|
||
url: import.meta.env.VITE_APP_BASE_API + "/employee/employee/importData",
|
||
});
|
||
|
||
/** 查询员工列表 */
|
||
function getList() {
|
||
loading.value = true;
|
||
listEmployee(queryParams.value).then((response) => {
|
||
employeeList.value = response.rows;
|
||
total.value = response.total;
|
||
loading.value = false;
|
||
});
|
||
}
|
||
|
||
// 取消按钮
|
||
function cancel() {
|
||
open.value = false;
|
||
reset();
|
||
}
|
||
|
||
// 表单重置
|
||
function reset() {
|
||
form.value = {
|
||
userId: null,
|
||
nickname: null,
|
||
point: null,
|
||
phone: null,
|
||
status: "0",
|
||
};
|
||
proxy.resetForm("employeeRef");
|
||
}
|
||
|
||
/** 搜索按钮操作 */
|
||
function handleQuery() {
|
||
queryParams.value.pageNum = 1;
|
||
getList();
|
||
}
|
||
|
||
/** 重置按钮操作 */
|
||
function resetQuery() {
|
||
proxy.resetForm("queryRef");
|
||
handleQuery();
|
||
}
|
||
|
||
// 多选框选中数据
|
||
function handleSelectionChange(selection) {
|
||
ids.value = selection.map((item) => item.userId);
|
||
single.value = selection.length != 1;
|
||
multiple.value = !selection.length;
|
||
}
|
||
|
||
/** 新增按钮操作 */
|
||
function handleAdd() {
|
||
reset();
|
||
open.value = true;
|
||
title.value = "添加员工";
|
||
}
|
||
|
||
/** 导入按钮操作 */
|
||
function handleImport() {
|
||
upload.title = "员工导入";
|
||
upload.open = true;
|
||
}
|
||
|
||
const importTemplate = async () => {
|
||
const blob = await downloadEmployeeTemplate();
|
||
saveAs(blob, `employee_${new Date().getTime()}.xlsx`);
|
||
};
|
||
|
||
/**文件上传中处理 */
|
||
const handleFileUploadProgress = (event, file, fileList) => {
|
||
upload.isUploading = true;
|
||
};
|
||
/** 文件上传成功处理 */
|
||
const handleFileSuccess = (response, file, fileList) => {
|
||
upload.open = false;
|
||
upload.isUploading = false;
|
||
proxy.$refs["uploadRef"].handleRemove(file);
|
||
proxy.$alert(
|
||
"<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
|
||
response.msg +
|
||
"</div>",
|
||
"导入结果",
|
||
{ dangerouslyUseHTMLString: true }
|
||
);
|
||
getList();
|
||
};
|
||
|
||
/** 提交上传文件 */
|
||
function submitFileForm() {
|
||
proxy.$refs["uploadRef"].submit();
|
||
}
|
||
|
||
/** 修改按钮操作 */
|
||
function handleUpdate(row) {
|
||
reset();
|
||
const _userId = row.userId || ids.value;
|
||
getEmployee(_userId).then((response) => {
|
||
form.value = response.data;
|
||
open.value = true;
|
||
title.value = "修改员工";
|
||
});
|
||
}
|
||
|
||
const handleUpdatePoint = (event, row) => {
|
||
event.stopPropagation();
|
||
reset();
|
||
form.value.userId = row.userId;
|
||
form.value.point = row.point;
|
||
pointEditing.value = true;
|
||
};
|
||
|
||
/** 提交按钮 */
|
||
function submitForm() {
|
||
proxy.$refs["employeeRef"].validate((valid) => {
|
||
if (valid) {
|
||
if (form.value.userId != null) {
|
||
updateEmployee(form.value).then((response) => {
|
||
proxy.$modal.msgSuccess("修改成功");
|
||
open.value = false;
|
||
getList();
|
||
});
|
||
} else {
|
||
addEmployee(form.value).then((response) => {
|
||
proxy.$modal.msgSuccess("新增成功");
|
||
open.value = false;
|
||
getList();
|
||
});
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
/** 删除按钮操作 */
|
||
function handleDelete(row) {
|
||
const _userIds = row.userId || ids.value;
|
||
proxy.$modal
|
||
.confirm('是否确认删除员工编号为"' + _userIds + '"的数据项?')
|
||
.then(function () {
|
||
return delEmployee(_userIds);
|
||
})
|
||
.then(() => {
|
||
getList();
|
||
proxy.$modal.msgSuccess("删除成功");
|
||
})
|
||
.catch(() => {});
|
||
}
|
||
|
||
const handleUpdateStatus = (row) => {
|
||
modal.confirm("是否确定要更改状态?").then(async () => {
|
||
let status;
|
||
if (row.status === "1") {
|
||
status = "0";
|
||
} else {
|
||
status = "1";
|
||
}
|
||
await updateEmployeeStatus({
|
||
userId: row.userId,
|
||
status,
|
||
});
|
||
getList();
|
||
modal.msgSuccess("修改状态成功");
|
||
});
|
||
};
|
||
|
||
const submitPoint = () => {
|
||
updateEmployeePoint({
|
||
userId: form.value.userId,
|
||
point: form.value.point,
|
||
})
|
||
.then(() => {
|
||
modal.msgSuccess("修改积分成功");
|
||
})
|
||
.finally(() => {
|
||
pointEditing.value = false;
|
||
getList();
|
||
});
|
||
};
|
||
|
||
const handleCancelEditPoint = () => {
|
||
reset();
|
||
pointEditing.value = false;
|
||
};
|
||
getList();
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.upload-progress {
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: center;
|
||
align-items: center;
|
||
width: 100%;
|
||
aspect-ratio: 360/185;
|
||
|
||
& > p {
|
||
text-align: center;
|
||
margin-top: 6px;
|
||
}
|
||
|
||
:deep(.el-progress-circle svg) {
|
||
animation: spin 1s linear infinite;
|
||
}
|
||
}
|
||
|
||
@keyframes spin {
|
||
from {
|
||
transform: rotate(0deg);
|
||
}
|
||
to {
|
||
transform: rotate(360deg);
|
||
}
|
||
}
|
||
</style>
|