CRM:优化合同金额排行、回款金额排行

This commit is contained in:
YunaiV
2024-02-03 01:14:24 +08:00
parent d6438943b8
commit 4549f8ed3c
8 changed files with 270 additions and 352 deletions

View File

@@ -0,0 +1,107 @@
<!-- 合同金额排行 -->
<template>
<!-- 柱状图 -->
<el-card shadow="never">
<el-skeleton :loading="loading" animated>
<Echart :height="500" :options="echartsOption" />
</el-skeleton>
</el-card>
<!-- 排行列表 -->
<el-card shadow="never" class="mt-16px">
<el-table v-loading="loading" :data="list">
<el-table-column label="公司排名" align="center" type="index" width="80" />
<el-table-column label="签订人" align="center" prop="nickname" min-width="200" />
<el-table-column label="部门" align="center" prop="deptName" min-width="200" />
<el-table-column
label="合同金额(元)"
align="center"
prop="count"
min-width="200"
:formatter="fenToYuanFormat"
/>
</el-table>
</el-card>
</template>
<script setup lang="ts">
import { RankApi, BiRankRespVO } from '@/api/crm/bi/rank'
import { EChartsOption } from 'echarts'
import { fenToYuanFormat } from '@/utils/formatter'
import { fenToYuan } from '@/utils'
import { clone } from 'unocss'
defineOptions({ name: 'ContractPriceRank' })
const props = defineProps<{ queryParams: any }>() // 搜索参数
const loading = ref(false) // 加载中
const list = ref<BiRankRespVO[]>([]) // 列表的数据
/** 柱状图配置:横向 */
const echartsOption = reactive<EChartsOption>({
dataset: {
dimensions: ['nickname', 'count'],
source: []
},
grid: {
left: 20,
right: 20,
bottom: 20,
containLabel: true
},
legend: {
top: 50
},
series: [
{
name: '合同金额排行',
type: 'bar'
}
],
toolbox: {
feature: {
dataZoom: {
yAxisIndex: false // 数据区域缩放Y 轴不缩放
},
brush: {
type: ['lineX', 'clear'] // 区域缩放按钮、还原按钮
},
saveAsImage: { show: true, name: '合同金额排行' } // 保存为图片
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
},
valueFormatter: fenToYuan
},
xAxis: {
type: 'value',
name: '合同金额(元)'
},
yAxis: {
type: 'category',
name: '签订人'
}
}) as EChartsOption
/** 获取合同金额排行 */
const loadData = async () => {
// 1. 加载排行数据
loading.value = true
const rankingList = await RankApi.getContractPriceRank(props.queryParams)
// 2.1 更新 Echarts 数据
if (echartsOption.dataset && echartsOption.dataset['source']) {
echartsOption.dataset['source'] = clone(rankingList).reverse()
}
// 2.2 更新列表数据
list.value = rankingList
loading.value = false
}
defineExpose({ loadData })
/** 初始化 */
onMounted(() => {
loadData()
})
</script>

View File

@@ -0,0 +1,108 @@
<!-- 回款金额排行 -->
<template>
<!-- 柱状图 -->
<el-card shadow="never">
<el-skeleton :loading="loading" animated>
<Echart :height="500" :options="echartsOption" />
</el-skeleton>
</el-card>
<!-- 排行列表 -->
<el-card shadow="never" class="mt-16px">
<el-table v-loading="loading" :data="list">
<el-table-column label="公司排名" align="center" type="index" width="80" />
<el-table-column label="签订人" align="center" prop="nickname" min-width="200" />
<el-table-column label="部门" align="center" prop="deptName" min-width="200" />
<el-table-column
label="回款金额(元)"
align="center"
prop="count"
min-width="200"
:formatter="fenToYuanFormat"
/>
</el-table>
</el-card>
</template>
<script setup lang="ts">
import { RankApi, BiRankRespVO } from '@/api/crm/bi/rank'
import { EChartsOption } from 'echarts'
import { fenToYuanFormat } from '@/utils/formatter'
import { fenToYuan } from '@/utils'
import { clone } from 'unocss'
defineOptions({ name: 'ReceivablePriceRank' })
const props = defineProps<{ queryParams: any }>() // 搜索参数
const loading = ref(false) // 加载中
const list = ref<BiRankRespVO[]>([]) // 列表的数据
/** 柱状图配置:横向 */
const echartsOption = reactive<EChartsOption>({
dataset: {
dimensions: ['nickname', 'count'],
source: []
},
grid: {
left: 20,
right: 20,
bottom: 20,
containLabel: true
},
legend: {
top: 50
},
series: [
{
name: '回款金额排行',
type: 'bar'
}
],
toolbox: {
feature: {
dataZoom: {
yAxisIndex: false // 数据区域缩放Y 轴不缩放
},
brush: {
type: ['lineX', 'clear'] // 区域缩放按钮、还原按钮
},
saveAsImage: { show: true, name: '回款金额排行' } // 保存为图片
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
},
valueFormatter: fenToYuan
},
xAxis: {
type: 'value',
name: '回款金额(元)'
},
yAxis: {
type: 'category',
name: '签订人',
nameGap: 30
}
}) as EChartsOption
/** 获取回款金额排行 */
const loadData = async () => {
// 1. 加载排行数据
loading.value = true
const rankingList = await RankApi.getReceivablePriceRank(props.queryParams)
// 2.1 更新 Echarts 数据
if (echartsOption.dataset && echartsOption.dataset['source']) {
echartsOption.dataset['source'] = clone(rankingList).reverse()
}
// 2.2 更新列表数据
list.value = rankingList
loading.value = false
}
defineExpose({ loadData })
/** 初始化 */
onMounted(() => {
loadData()
})
</script>

View File

@@ -0,0 +1,100 @@
<!-- BI 排行版 -->
<template>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="时间范围" prop="orderDate">
<el-date-picker
v-model="queryParams.times"
:shortcuts="defaultShortcuts"
class="!w-240px"
end-placeholder="结束日期"
start-placeholder="开始日期"
type="daterange"
value-format="YYYY-MM-DD HH:mm:ss"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
/>
</el-form-item>
<el-form-item label="归属部门" prop="deptId">
<el-tree-select
v-model="queryParams.deptId"
:data="deptList"
:props="defaultProps"
check-strictly
node-key="id"
placeholder="请选择归属部门"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 排行数据 -->
<el-col>
<el-tabs v-model="activeTab">
<!-- 合同金额排行 -->
<el-tab-pane label="合同金额排行" name="contractPriceRank" lazy>
<ContractPriceRank :query-params="queryParams" ref="contractPriceRankRef" />
</el-tab-pane>
<!-- 回款金额排行 -->
<el-tab-pane label="回款金额排行" name="receivablePriceRank" lazy>
<ReceivablePriceRank :query-params="queryParams" ref="receivablePriceRankRef" />
</el-tab-pane>
</el-tabs>
</el-col>
</template>
<script lang="ts" setup>
import ContractPriceRank from './ContractPriceRank.vue'
import ReceivablePriceRank from './ReceivablePriceRank.vue'
import { defaultProps, handleTree } from '@/utils/tree'
import * as DeptApi from '@/api/system/dept'
import { beginOfDay, defaultShortcuts, endOfDay, formatDate } from '@/utils/formatTime'
import { useUserStore } from '@/store/modules/user'
defineOptions({ name: 'CrmBiRank' })
const queryParams = reactive({
deptId: useUserStore().getUser.deptId,
times: [
// 默认显示最近一周的数据
formatDate(beginOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24 * 7))),
formatDate(endOfDay(new Date(new Date().getTime() - 3600 * 1000 * 24)))
]
})
const queryFormRef = ref() // 搜索的表单
const deptList = ref<Tree[]>([]) // 树形结构
const activeTab = ref('contractPriceRank')
const contractPriceRankRef = ref() // ContractPriceRank 组件的引用
const receivablePriceRankRef = ref() // ReceivablePriceRank 组件的引用
/** 搜索按钮操作 */
const handleQuery = () => {
if (activeTab.value === 'contractPriceRank') {
contractPriceRankRef.value.loadData()
} else if (activeTab.value === 'receivablePriceRank') {
receivablePriceRankRef.value.loadData()
}
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
// 加载部门树
onMounted(async () => {
deptList.value = handleTree(await DeptApi.getSimpleDeptList())
})
</script>
<style lang="scss" scoped></style>