2022-08-20 17:51:59 +08:00

200 lines
5.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div>
<!-- 筛选框 -->
<el-card class="box-card">
<div class="goods" style="margin: 20px">
<el-form ref="form" :inline="true" :model="form">
<el-form-item label="查询类别:">
<el-select v-model="form.targetField" placeholder="全部">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="操作用户">
<el-select v-model="form.userId" placeholder="输入操作用户">
<el-option
v-for="item in options1"
:key="item.id"
:label="item.name"
:value="item.id"
>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="操作时间:">
<el-date-picker
v-model="value1"
type="datetimerange"
range-separator="-"
start-placeholder=""
end-placeholder=""
value-format="yyyy-MM-dd HH:mm:ss"
>
</el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="query()">查询</el-button>
</el-form-item>
</el-form>
</div>
</el-card>
<!-- 表格 -->
<el-card style="margin-top: 30px" class="box-card">
<el-table :data="tableData" style="width: 100%">
<el-table-column prop="id" label="序号"> </el-table-column>
<el-table-column prop="created_at" label="时间"> </el-table-column>
<el-table-column prop="target_field" label="类别"> </el-table-column>
<el-table-column prop="before_update" label="操作前"> </el-table-column>
<el-table-column prop="after_update" label="操作后"> </el-table-column>
<el-table-column prop="user.name" label="操作人"> </el-table-column>
</el-table>
</el-card>
<!-- 分页功能 -->
<div class="block">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="current_page"
:page-sizes="[15, 50, 100]"
:page-size="per_page"
layout="total, sizes, prev, pager, next, jumper"
:total="Paginationdata.total"
>
</el-pagination>
</div>
</div>
</template>
<script>
import { recordList } from "../../api/record";
import { userList } from "../../api/user";
export default {
data() {
return {
options: [
{
value: "cost",
label: "成本",
},
{
value: "stock",
label: "库存",
},
{
value: "inventory",
label: "库存盘点",
},
{
value: "status",
label: "状态",
},
{
value: "set",
label: "设置",
},
], //查询类别
options1: [], //查询用户列表
form: {
targetField: "",
userId: "",
},
value1: "", //筛选时间变量
tableData: [], //列表数据
Paginationdata: {}, //分页相关数据
current_page: 1, //当前页
per_page: 15, //每页显示数量
};
},
methods: {
//请求列表数据
getList() {
// let token = localStorage.getItem("token");
let page = {
page: this.current_page,
per_page: this.per_page,
};
recordList(page).then((res) => {
this.tableData = res.data.data;
this.Paginationdata = res.data.meta;
});
},
// 获取用户列表
getUser() {
userList().then((res) => {
this.options1 = res.data.data;
console.log("我是用户", this.options1);
});
},
// 查询
query() {
console.log(this.form.userId, this.form.targetField);
let queryData = {
userId: this.form.userId,
target_field: this.form.targetField,
page: this.current_page,
per_page: this.per_page,
moudule: this.moudule,
target_id: this.$route.query.id,
startTime: this.value1[0],
endTime: this.value1[1],
};
// 对象值为空清除
const newObj = filterParams(queryData);
function filterParams(obj) {
const _newPar = {};
for (const key in obj) {
// 如果对象属性的值不为空就保存该属性这里我做了限制如果属性的值为0保存该属性。如果属性的值全部是空格属于为空。
if (
(obj[key] === 0 || obj[key]) &&
obj[key].toString().replace(/(^\s*)|(\s*$)/g, "") !== ""
) {
// 记录属性
_newPar[key] = obj[key];
}
}
// 返回对象
return _newPar;
}
recordList(newObj).then((res) => {
this.tableData = res.data.data;
this.Paginationdata = res.data.meta;
});
},
//分页功能
handleSizeChange(val) {
//当前条数
this.per_page = val;
this.query();
},
handleCurrentChange(val) {
//当前页
this.current_page = val;
this.query();
},
},
mounted() {
this.getList();
this.getUser();
},
};
</script>
<style>
.block {
margin-top: 30px;
}
</style>