diff --git a/src/api/system/dashboard.js b/src/api/system/dashboard.js index 9065fb1..f21cb2e 100644 --- a/src/api/system/dashboard.js +++ b/src/api/system/dashboard.js @@ -45,3 +45,13 @@ export function bonusMonthAmount(query) { }) } +/** + * 获取业绩报表 + */ +export function achievementByUser(params) { + return request({ + url: '/system/dashboard/achievementByUser', + method: 'get', + params + }) +} diff --git a/src/utils/index.js b/src/utils/index.js index 4c5d465..8a6b09d 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -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); diff --git a/src/views/dashboard/achievement/index.vue b/src/views/dashboard/achievement/index.vue new file mode 100644 index 0000000..be50879 --- /dev/null +++ b/src/views/dashboard/achievement/index.vue @@ -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>