Files
art-design/src/views/crmpc/home/widget/CardList.vue
T
2025-07-30 17:23:09 +08:00

547 lines
14 KiB
Vue

<template>
<div class="homeheard">
您已陪伴领客 CRM
<span class="daynum"
><span class="day">{{ homestatistics.day }}</span
>天</span
>
</div>
<div class="boxshadow">
<div class="heard">
<div class="heard-title">数据简报</div>
<el-date-picker
v-model="selectedDate"
type="month"
format="YYYY-MM"
value-format="YYYY-MM"
placeholder="选择年月"
class="heard-date-picker"
/>
</div>
<el-row :gutter="20" class="card-list">
<el-col :sm="12" :md="6" :lg="4">
<div
class="card art-custom-card"
:style="{
backgroundImage: `url(${adduser})`,
backgroundSize: 'cover',
backgroundPosition: 'center'
}"
>
<CountTo
class="number box-title"
:endVal="homestatistics.customer"
:duration="1000"
separator=""
></CountTo>
<div class="change-box">
<span class="change-text">新增客户</span>
</div>
</div>
</el-col>
<el-col :sm="12" :md="6" :lg="4">
<div
class="card art-custom-card"
:style="{
backgroundImage: `url(${addbf})`,
backgroundSize: 'cover',
backgroundPosition: 'center'
}"
>
<CountTo
class="number box-title"
:endVal="homestatistics.visit"
:duration="1000"
separator=""
></CountTo>
<div class="change-box">
<span class="change-text">新增拜访</span>
</div>
</div>
</el-col>
<el-col :sm="12" :md="6" :lg="4">
<div
class="card art-custom-card"
:style="{
backgroundImage: `url(${addgj})`,
backgroundSize: 'cover',
backgroundPosition: 'center'
}"
>
<CountTo
class="number box-title"
:endVal="homestatistics.follow"
:duration="1000"
separator=""
></CountTo>
<div class="change-box">
<span class="change-text">新增跟进</span>
</div>
</div>
</el-col>
<el-col :sm="12" :md="6" :lg="4">
<div
class="card art-custom-card"
:style="{
backgroundImage: `url(${deal})`,
backgroundSize: 'cover',
backgroundPosition: 'center'
}"
>
<CountTo
class="number box-title"
:endVal="homestatistics.customer_init"
:duration="1000"
separator=""
>
</CountTo>
<div class="change-box">
<span class="change-text">跟进中</span>
</div>
</div>
</el-col>
<el-col :sm="12" :md="6" :lg="4">
<div
class="card art-custom-card"
:style="{
backgroundImage: `url(${gjing})`,
backgroundSize: 'cover',
backgroundPosition: 'center'
}"
>
<CountTo
class="number box-title"
:endVal="homestatistics.customero_fllow"
:duration="1000"
separator=""
>
</CountTo>
<div class="change-box">
<span class="change-text">已成交</span>
</div>
</div>
</el-col>
<el-col :sm="12" :md="6" :lg="4">
<div
class="card art-custom-card"
:style="{
backgroundImage: `url(${loss})`,
backgroundSize: 'cover',
backgroundPosition: 'center'
}"
>
<CountTo
class="number box-title"
:endVal="homestatistics.customer_deal"
:duration="1000"
separator=""
>
</CountTo>
<div class="change-box">
<span class="change-text">已丢失</span>
</div>
</div>
</el-col>
</el-row>
</div>
<div class="boxshadow">
<div class="heard">
<div class="heard-title">跟进提醒</div>
<el-select
v-model="remindRange"
placeholder="请选择"
class="heard-select"
style="min-width: 120px"
>
<el-option label="全部" value="" />
<el-option label="当天" value="0" />
<el-option label="近三天" value="1" />
<el-option label="近七天" value="2" />
</el-select>
</div>
<div class="table">
<ArtTable
ref="tableRef"
row-key="id"
:loading="loading"
:data="tableData"
:currentPage="pagination.currentPage"
:pageSize="pagination.pageSize"
:total="pagination.total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
lass="customer-table"
>
<template #default>
<el-table-column prop="contacts" label="客户名称" min-width="120"></el-table-column>
<el-table-column prop="phone" label="电话" min-width="120"></el-table-column>
<el-table-column
prop="follow_next"
label="下次跟进时间"
min-width="140"
></el-table-column>
<el-table-column label="状态" min-width="140">
<template #default="scope">
<span :class="getCountdownClass(scope.row.follow_next)">
<span class="custom-clock-icon" style="vertical-align: middle; margin-right: 4px">
<i class="iconfont-sys">&#xe7b1;</i>
</span>
{{ getCountdown(scope.row.follow_next) }}
</span>
</template>
</el-table-column>
<el-table-column label="操作" min-width="100">
<template #default="scope">
<div class="follow-action" @click="goAddFollow(scope.row)">
<span class="custom-clock-icon" style="vertical-align: middle; margin-right: 4px">
<i class="iconfont-sys">&#xe6bf;</i>
</span>
跟进
</div>
</template>
</el-table-column>
</template>
</ArtTable>
</div>
</div>
</template>
<script setup lang="ts">
import { reactive, ref, onMounted, onUnmounted } from 'vue'
import { CountTo } from 'vue3-count-to'
import adduser from '@/assets/img/crm/adduser.png'
import addbf from '@/assets/img/crm/addbf.png'
import addgj from '@/assets/img/crm/addgj.png'
import deal from '@/assets/img/crm/deal.png'
import gjing from '@/assets/img/crm/gjing.png'
import loss from '@/assets/img/crm/loss.png'
import dayjs from 'dayjs'
import { CrmService } from '@/api/crmApi'
const router = useRouter()
function getCurrentMonth() {
const d = new Date()
const month = d.getMonth() + 1
return `${d.getFullYear()}-${month < 10 ? '0' + month : month}`
}
const selectedDate = ref(getCurrentMonth())
const remindRange = ref('')
const loading = ref(false)
const pagination = reactive({
currentPage: 1,
pageSize: 10,
total: 0
})
const tableData = ref([])
watch([remindRange], () => {
pagination.currentPage = 1
gettableList()
})
watch(selectedDate, (val) => {
console.log('用户选择的时间:', val)
gethomestatistics(val)
})
//获取统计数据 homestatistics
interface CustomerInfo {
[key: string]: any
}
const homestatistics = ref<CustomerInfo>({})
const gethomestatistics = async (val: any) => {
loading.value = true
try {
const data = await CrmService.homestatistics({ created: val ? val : getCurrentMonth() })
homestatistics.value = data
} catch (error) {
console.error('获取用户列表失败:', error)
} finally {
loading.value = false
}
}
// 获取列表数据
const gettableList = async () => {
loading.value = true
try {
const { currentPage, pageSize } = pagination
const params: any = {
current: currentPage,
size: pageSize
}
if (remindRange.value) params.filter = remindRange.value
const { data, current, size, total } = await CrmService.waitFollow(params)
tableData.value = data.map((item: any) => ({
...item
}))
Object.assign(pagination, { currentPage: current, pageSize: size, total })
} catch (error) {
console.error('获取用户列表失败:', error)
} finally {
loading.value = false
}
}
// 处理表格分页变化
const handleSizeChange = (newPageSize: number) => {
pagination.pageSize = newPageSize
// getWorkList()
}
const handleCurrentChange = (newCurrentPage: number) => {
pagination.currentPage = newCurrentPage
// getWorkList()
}
const timer = ref(0)
const refreshKey = ref(0)
onMounted(() => {
gethomestatistics('')
gettableList()
timer.value = window.setInterval(() => {
refreshKey.value++
}, 1000)
})
onUnmounted(() => {
if (timer.value) {
clearInterval(timer.value)
}
})
function getCountdown(targetDate: string) {
// 让 refreshKey 成为依赖,确保每秒刷新
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
refreshKey.value
const now = dayjs()
const target = dayjs(targetDate, 'YYYY-MM-DD HH:mm:ss')
if (!target.isValid()) return '时间格式错误'
const diff = target.diff(now)
if (diff <= 0) return '已超时'
const days = Math.floor(diff / (1000 * 60 * 60 * 24))
const hours = Math.floor((diff / (1000 * 60 * 60)) % 24)
const minutes = Math.floor((diff / (1000 * 60)) % 60)
const seconds = Math.floor((diff / 1000) % 60)
return `${days > 0 ? days + '天' : ''}${hours}小时${minutes}分${seconds}秒`
}
function getCountdownClass(targetDate: string) {
const now = dayjs()
const target = dayjs(targetDate, 'YYYY-MM-DD HH:mm:ss')
if (!target.isValid() || target.diff(now) <= 0) {
return 'countdown-danger'
}
return 'countdown-success'
}
function goAddFollow(row: any) {
router.push({
path: '/crmpc/customer/followadd',
query: { id: row.id } // 可带客户名等参数
})
}
</script>
<style lang="scss" scoped>
.table {
::v-deep(.el-scrollbar__view) {
width: 100% !important;
}
:deep(.el-table__empty-block) {
height: 400px !important;
width: 100% !important;
}
}
.homeheard {
background:
url('@/assets/img/crm/hometop.png') no-repeat center/cover,
linear-gradient(90deg, #edf2ff 0%, #cbe5fc 72.55%);
padding: 10px 20px;
margin-bottom: 10px;
border-radius: 6px;
display: flex;
align-items: center;
/* 垂直居中 */
color: #333333;
}
.daynum {
margin-left: 20px;
color: #3471ff;
}
.day {
font-size: 70px;
font-weight: bold;
}
.card-list {
box-sizing: border-box;
display: flex;
flex-wrap: wrap;
background-color: var(--el-card-bg-color) !important;
.art-custom-card {
border: none !important;
position: relative;
box-sizing: border-box;
display: flex;
flex-direction: column;
justify-content: center;
width: 100%;
height: 120px;
align-items: end;
padding: 0 18px;
list-style: none;
transition: all 0.3s ease;
$icon-size: 52px;
.iconfont-sys {
position: absolute;
top: 0;
right: 20px;
bottom: 0;
width: $icon-size;
height: $icon-size;
margin: auto;
overflow: hidden;
font-size: 22px;
line-height: $icon-size;
color: var(--el-color-primary) !important;
text-align: center;
background-color: var(--el-color-primary-light-9);
border-radius: 12px;
}
.des {
display: block;
height: 14px;
font-size: 14px;
line-height: 14px;
}
.number {
display: block;
margin-top: 10px;
font-size: 28px;
font-weight: 400;
}
.change-box {
display: flex;
align-items: center;
margin-top: 10px;
.change-text {
display: block;
font-size: 13px;
// color: var(--art-text-gray-600);
}
.change {
display: block;
margin-left: 5px;
font-size: 13px;
font-weight: bold;
&.text-success {
color: var(--el-color-success);
}
&.text-danger {
color: var(--el-color-danger);
}
}
}
}
}
.heard {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
.heard-title {
font-size: 20px;
font-weight: bold;
color: #333;
border-left: 4px solid #3471ff;
padding-left: 12px;
height: 32px;
display: flex;
align-items: center;
}
.heard-select {
width: 120px;
}
}
.dark {
.card-list {
.art-custom-card {
.iconfont-sys {
background-color: #232323 !important;
}
}
}
}
.table {
::v-deep .custom-table-header {
background: #f7f9fa !important;
color: #333;
font-weight: bold;
}
::v-deep .el-table__body tr.custom-table-row td {
border-bottom: 1px solid #f7f9fa !important;
border-right: 1px solid #f7f9fa !important;
}
::v-deep .el-table__body tr td:last-child {
border-right: none !important;
}
::v-deep .el-table__body tr:last-child td {
border-bottom: none !important;
}
::v-deep .el-table__header-wrapper th {
border-bottom: 1px solid #f7f9fa !important;
border-right: 1px solid #f7f9fa !important;
}
::v-deep .el-table__header-wrapper th:last-child {
border-right: none !important;
}
::v-deep .el-table {
border: 1px solid #f7f9fa !important;
border-radius: 6px;
}
}
.countdown-danger {
color: #ff0000 !important;
}
.countdown-success {
color: #00a43f !important;
}
.follow-action {
display: inline-flex;
align-items: center;
cursor: pointer;
color: #409eff;
padding: 4px 10px;
border-radius: 4px;
transition: background 0.2s;
&:hover {
background: #f5f7fa;
}
}
</style>