业绩报表

This commit is contained in:
墨大叔 2024-10-09 09:07:33 +08:00
parent 8f3d733461
commit 13389a4344
3 changed files with 378 additions and 0 deletions

View File

@ -45,3 +45,13 @@ export function bonusMonthAmount(query) {
})
}
/**
* 获取业绩报表
*/
export function achievementByUser(params) {
return request({
url: '/system/dashboard/achievementByUser',
method: 'get',
params
})
}

View File

@ -485,6 +485,34 @@ export function getLastMonth(n) {
return date;
}
/**
* 获取月份起始日期
*/
export function getLastMonthStart(n) {
let date = getLastMonth(n);
return new Date(date.getFullYear(), date.getMonth(), 1);
}
/**
* 获取月份起始日期字符串
*/
export function getLastMonthStartStr(n) {
let date = getLastMonthStart(n);
return parseTime(date, "{y}-{m}-{d}");
}
/**
* 获取月份结束日期
*/
export function getLastMonthEnd(n) {
return new Date(getLastMonthStart(n).getFullYear(), getLastMonthStart(n).getMonth() + 1, 0);
}
// 获取月份结束日期字符串
export function getLastMonthEndStr(n) {
let date = getLastMonthEnd(n);
return parseTime(date, "{y}-{m}-{d}");
}
// 获取前n月的日期字符串
export function getLastMonthDateStr(n) {
let date = getLastMonth(n);

View File

@ -0,0 +1,340 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="日期范围" prop="dateRange">
<el-date-picker
v-model="queryParams.dateRange"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
@change="handleQuery"
:clearable="false"
:picker-options="pickerOptions"
></el-date-picker>
</el-form-item>
<el-form-item label="用户名称" prop="userName">
<el-input
v-model="queryParams.userName"
placeholder="请输入用户名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="用户角色" prop="userTypes">
<el-select v-model="queryParams.userTypes" placeholder="请选择用户角色" @change="handleQuery" multiple clearable>
<el-option
v-for="dict in dict.type.user_type"
:key="dict.value"
:label="dict.label"
:value="dict.value"
v-if="dict.value !== SmUserType.NORMAL && dict.value !== SmUserType.BUSINESS_PLACE"
></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="bindRecordList" @selection-change="handleSelectionChange" :default-sort="defaultSort" @sort-change="onSortChange">
<el-table-column type="index" width="55" align="center" label="#" />
<template v-for="column of showColumns">
<el-table-column
:key="column.key"
:label="column.label"
:prop="column.key"
:align="column.align"
:min-width="column.minWidth"
:sort-orders="orderSorts"
:sortable="column.sortable"
:show-overflow-tooltip="column.overflow"
:width="column.width"
>
<template slot-scope="d">
<template v-if="column.key === 'userId'">
<user-link :id="d.row.userId" :name="d.row.userName"/>
</template>
<template v-else-if="column.key === 'userType'">
<dict-tag :options="dict.type.user_type" :value="d.row.userType"/>
</template>
<template v-else-if="['bindCount', 'unbindCount', 'achievement'].includes(column.key)">
{{d.row[column.key]}}
</template>
<template v-else>
{{d.row[column.key]}}
</template>
</template>
</el-table-column>
</template>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
</div>
</template>
<script>
import { getBindRecord, delBindRecord, addBindRecord, updateBindRecord } from "@/api/system/bindRecord";
import { $showColumns, $view } from '@/utils/mixins'
import UserLink from '@/components/Business/SmUser/UserLink.vue'
import DeviceLink from '@/components/Business/Device/DeviceLink.vue'
import { achievementByUser } from '@/api/system/dashboard'
import {
getLastDate,
getLastDateStr,
getLastMonth,
getLastMonthDateStr,
getLastMonthEnd, getLastMonthEndStr,
getLastMonthStart, getLastMonthStartStr
} from '@/utils'
import { SmUserType } from '@/utils/constants'
//
const defaultSort = {
prop: "achievement",
order: "descending"
}
export default {
name: "BindDashboard",
computed: {
SmUserType() {
return SmUserType
}
},
mixins: [$showColumns, $view],
dicts: ['user_type'],
components: { DeviceLink, UserLink },
props: {
query: {
type: Object,
default: () => {
return {}
}
}
},
data() {
return {
//
columns: [
{ key: 'userId', visible: true, label: '用户', minWidth: null, sortable: true, overflow: false, align: 'center', width: null },
{ key: 'userType', visible: true, label: '角色', minWidth: null, sortable: true, overflow: false, align: 'center', width: null },
{ key: 'achievement', visible: true, label: '业绩', minWidth: null, sortable: true, overflow: false, align: 'center', width: null },
{ key: 'bindCount', visible: true, label: '绑定数量', minWidth: null, sortable: true, overflow: false, align: 'center', width: null },
{ key: 'unbindCount', visible: true, label: '解绑数量', minWidth: null, sortable: true, overflow: false, align: 'center', width: null },
],
//
orderSorts: ['ascending', 'descending', null],
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
bindRecordList: [],
//
title: "",
//
open: false,
defaultSort,
//
queryParams: {
pageNum: 1,
pageSize: 20,
userName: null,
dateRange: [ getLastMonthStartStr(0), getLastMonthEndStr(0)]
},
//
form: {},
//
rules: {
deviceId: [
{ required: true, message: "设备id不能为空", trigger: "blur" }
],
userId: [
{ required: true, message: "用户id不能为空", trigger: "blur" }
],
createTime: [
{ required: true, message: "创建时间不能为空", trigger: "blur" }
],
type: [
{ required: true, message: "类型不能为空", trigger: "change" }
]
},
pickerOptions: {
shortcuts: [{
text: '本月',
onClick(picker) {
const end = getLastMonthEnd(0);
const start = getLastMonthStart(0);
picker.$emit('pick', [start, end]);
}
}, {
text: '上月',
onClick(picker) {
const end = getLastMonthEnd(1);
const start = getLastMonthStart(1);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一周',
onClick(picker) {
const end = getLastDate(0);
const start = getLastDate(6);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一个月',
onClick(picker) {
const end = getLastDate(0);
const start = getLastMonth(1);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近三个月',
onClick(picker) {
const end = getLastDate(0);
const start = getLastMonth(3);
picker.$emit('pick', [start, end]);
}
}]
},
};
},
created() {
this.queryParams = {
...this.queryParams,
...this.query
}
this.getList();
},
methods: {
/** 当排序按钮被点击时触发 **/
onSortChange(column) {
if (column.order == null) {
this.queryParams.orderByColumn = defaultSort.prop;
this.queryParams.isAsc = defaultSort.order;
} else {
this.queryParams.orderByColumn = column.prop;
this.queryParams.isAsc = column.order;
}
this.getList();
},
/** 查询设备绑定记录列表 */
getList() {
this.loading = true;
achievementByUser(this.queryParams).then(response => {
this.bindRecordList = response.rows;
this.total = response.total;
this.loading = false;
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
recordId: null,
deviceId: null,
userId: null,
createTime: null,
type: null
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.recordId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加设备绑定记录";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const recordId = row.recordId || this.ids
getBindRecord(recordId).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改设备绑定记录";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.recordId != null) {
updateBindRecord(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addBindRecord(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const recordIds = row.recordId || this.ids;
this.$modal.confirm('是否确认删除设备绑定记录编号为"' + recordIds + '"的数据项?').then(function() {
return delBindRecord(recordIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {
});
},
/** 导出按钮操作 */
handleExport() {
this.download('system/bindRecord/export', {
...this.queryParams
}, `bindRecord_${new Date().getTime()}.xlsx`)
}
}
};
</script>