eight
2024-08-13 b10adc8a3fd000901836e2219fa83462694e9866
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<!-- 客户总量统计 -->
<template>
  <!-- Echarts图 -->
  <el-card shadow="never">
    <el-skeleton :loading="loading" animated>
      <Echart :height="500" :options="echartsOption" />
    </el-skeleton>
  </el-card>
 
  <!-- 统计列表 -->
  <el-card class="mt-16px" shadow="never">
    <el-table v-loading="loading" :data="list">
      <el-table-column align="center" fixed="left" label="序号" type="index" width="80" />
      <el-table-column align="center" fixed="left" label="商机名称" prop="name" width="160">
        <template #default="scope">
          <el-link :underline="false" type="primary" @click="openDetail(scope.row.id)">
            {{ scope.row.name }}
          </el-link>
        </template>
      </el-table-column>
      <el-table-column align="center" fixed="left" label="客户名称" prop="customerName" width="120">
        <template #default="scope">
          <el-link
            :underline="false"
            type="primary"
            @click="openCustomerDetail(scope.row.customerId)"
          >
            {{ scope.row.customerName }}
          </el-link>
        </template>
      </el-table-column>
      <el-table-column
        :formatter="erpPriceTableColumnFormatter"
        align="center"
        label="商机金额(元)"
        prop="totalPrice"
        width="140"
      />
      <el-table-column
        :formatter="dateFormatter"
        align="center"
        label="预计成交日期"
        prop="dealTime"
        width="180px"
      />
      <el-table-column align="center" label="备注" prop="remark" width="200" />
      <el-table-column
        :formatter="dateFormatter"
        align="center"
        label="下次联系时间"
        prop="contactNextTime"
        width="180px"
      />
      <el-table-column align="center" label="负责人" prop="ownerUserName" width="100px" />
      <el-table-column align="center" label="所属部门" prop="ownerUserDeptName" width="100px" />
      <el-table-column
        :formatter="dateFormatter"
        align="center"
        label="最后跟进时间"
        prop="contactLastTime"
        width="180px"
      />
      <el-table-column
        :formatter="dateFormatter"
        align="center"
        label="更新时间"
        prop="updateTime"
        width="180px"
      />
      <el-table-column
        :formatter="dateFormatter"
        align="center"
        label="创建时间"
        prop="createTime"
        width="180px"
      />
      <el-table-column align="center" label="创建人" prop="creatorName" width="100px" />
      <el-table-column
        align="center"
        fixed="right"
        label="商机状态组"
        prop="statusTypeName"
        width="140"
      />
      <el-table-column
        align="center"
        fixed="right"
        label="商机阶段"
        prop="statusName"
        width="120"
      />
    </el-table>
    <!-- 分页 -->
    <Pagination
      v-model:limit="queryParams0.pageSize"
      v-model:page="queryParams0.pageNo"
      :total="total"
      @pagination="getList"
    />
  </el-card>
</template>
<script lang="ts" setup>
import {
  CrmStatisticsBusinessInversionRateSummaryByDateRespVO,
  StatisticFunnelApi
} from '@/api/crm/statistics/funnel'
import { EChartsOption } from 'echarts'
import { erpCalculatePercentage, erpPriceTableColumnFormatter } from '@/utils'
import { dateFormatter } from '@/utils/formatTime'
 
defineOptions({ name: 'BusinessSummary' })
 
const props = defineProps<{ queryParams: any }>() // 搜索参数
const queryParams0 = reactive({
  pageNo: 1,
  pageSize: 10
})
const loading = ref(false) // 加载中
const list = ref([]) // 列表的数据
const total = ref(0)
/** 将传进来的值赋值给 queryParams0 */
watch(
  () => props.queryParams,
  (data) => {
    if (!data) {
      return
    }
    const newObj = { ...queryParams0, ...data }
    Object.assign(queryParams0, newObj)
  },
  {
    immediate: true
  }
)
/** 柱状图配置:纵向 */
const echartsOption = reactive<EChartsOption>({
  color: ['#6ca2ff', '#6ac9d7', '#ff7474'],
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      // 坐标轴指示器,坐标轴触发有效
      type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
    }
  },
  legend: {
    data: ['赢单转化率', '商机总数', '赢单商机数'],
    bottom: '0px',
    itemWidth: 14
  },
  grid: {
    top: '40px',
    left: '40px',
    right: '40px',
    bottom: '40px',
    containLabel: true,
    borderColor: '#fff'
  },
  xAxis: [
    {
      type: 'category',
      data: [],
      axisTick: {
        alignWithLabel: true,
        lineStyle: { width: 0 }
      },
      axisLabel: {
        color: '#BDBDBD'
      },
      /** 坐标轴轴线相关设置 */
      axisLine: {
        lineStyle: { color: '#BDBDBD' }
      },
      splitLine: {
        show: false
      }
    }
  ],
  yAxis: [
    {
      type: 'value',
      name: '赢单转化率',
      axisTick: {
        alignWithLabel: true,
        lineStyle: { width: 0 }
      },
      axisLabel: {
        color: '#BDBDBD',
        formatter: '{value}%'
      },
      /** 坐标轴轴线相关设置 */
      axisLine: {
        lineStyle: { color: '#BDBDBD' }
      },
      splitLine: {
        show: false
      }
    },
    {
      type: 'value',
      name: '商机数',
      axisTick: {
        alignWithLabel: true,
        lineStyle: { width: 0 }
      },
      axisLabel: {
        color: '#BDBDBD',
        formatter: '{value}个'
      },
      /** 坐标轴轴线相关设置 */
      axisLine: {
        lineStyle: { color: '#BDBDBD' }
      },
      splitLine: {
        show: false
      }
    }
  ],
  series: [
    {
      name: '赢单转化率',
      type: 'line',
      yAxisIndex: 0,
      data: []
    },
    {
      name: '商机总数',
      type: 'bar',
      yAxisIndex: 1,
      barWidth: 15,
      data: []
    },
    {
      name: '赢单商机数',
      type: 'bar',
      yAxisIndex: 1,
      barWidth: 15,
      data: []
    }
  ]
}) as EChartsOption
 
/** 获取数据并填充图表 */
const fetchAndFill = async () => {
  // 1. 加载统计数据
  const businessSummaryByDate = await StatisticFunnelApi.getBusinessInversionRateSummaryByDate(
    props.queryParams
  )
  // 2.1 更新 Echarts 数据
  if (echartsOption.xAxis && echartsOption.xAxis[0] && echartsOption.xAxis[0]['data']) {
    echartsOption.xAxis[0]['data'] = businessSummaryByDate.map(
      (s: CrmStatisticsBusinessInversionRateSummaryByDateRespVO) => s.time
    )
  }
  if (echartsOption.series && echartsOption.series[0] && echartsOption.series[0]['data']) {
    echartsOption.series[0]['data'] = businessSummaryByDate.map(
      (s: CrmStatisticsBusinessInversionRateSummaryByDateRespVO) =>
        erpCalculatePercentage(s.businessWinCount, s.businessCount)
    )
  }
  if (echartsOption.series && echartsOption.series[1] && echartsOption.series[1]['data']) {
    echartsOption.series[1]['data'] = businessSummaryByDate.map(
      (s: CrmStatisticsBusinessInversionRateSummaryByDateRespVO) => s.businessCount
    )
  }
  if (echartsOption.series && echartsOption.series[2] && echartsOption.series[2]['data']) {
    echartsOption.series[2]['data'] = businessSummaryByDate.map(
      (s: CrmStatisticsBusinessInversionRateSummaryByDateRespVO) => s.businessWinCount
    )
  }
 
  // 2.2 更新列表数据
  await getList()
}
/** 获取商机列表 */
const getList = async () => {
  const data = await StatisticFunnelApi.getBusinessPageByDate(props.queryParams)
  list.value = data.list
  total.value = data.total
}
/** 打开客户详情 */
const { push } = useRouter()
const openDetail = (id: number) => {
  push({ name: 'CrmBusinessDetail', params: { id } })
}
 
/** 打开客户详情 */
const openCustomerDetail = (id: number) => {
  push({ name: 'CrmCustomerDetail', params: { id } })
}
 
/** 获取统计数据 */
const loadData = async () => {
  loading.value = true
  try {
    await fetchAndFill()
  } finally {
    loading.value = false
  }
}
 
defineExpose({ loadData })
 
/** 初始化 */
onMounted(() => {
  loadData()
})
</script>