detailTalkTime.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div class="statistics-call-detail-talk-time-container layout-pd">
  3. <!-- 搜索 -->
  4. <el-card shadow="never" v-if="showSearch">
  5. <el-form :model="state.queryParams" ref="ruleFormRef" @submit.native.prevent inline>
  6. <el-form-item label="状态" prop="type">
  7. <el-select v-model="state.queryParams.type" placeholder="请选择状态" clearable @change="handleQuery">
  8. <el-option v-for="item in state.callForwardingType" :value="item.dicDataValue" :key="item.dicDataValue" :label="item.dicDataName" />
  9. </el-select>
  10. </el-form-item>
  11. <el-form-item label="来源" prop="source">
  12. <el-select v-model="state.queryParams.source" placeholder="请选择来源" clearable @change="handleQuery">
  13. <el-option v-for="item in state.callForwardingSource" :value="item.dicDataValue" :key="item.dicDataValue" :label="item.dicDataName" />
  14. </el-select>
  15. </el-form-item>
  16. <el-form-item label="时间段" prop="crTime">
  17. <el-date-picker
  18. v-model="state.queryParams.crTime"
  19. type="daterange"
  20. unlink-panels
  21. range-separator="至"
  22. start-placeholder="开始时间"
  23. end-placeholder="结束时间"
  24. :shortcuts="shortcuts"
  25. @change="handleQuery"
  26. value-format="YYYY-MM-DD"
  27. :clearable="false"
  28. />
  29. </el-form-item>
  30. <el-form-item label-width="0">
  31. <el-button type="primary" @click="handleQuery" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
  32. <el-button @click="resetQuery(ruleFormRef)" class="default-button" :loading="state.loading">
  33. <SvgIcon name="ele-Refresh" class="mr5" />重置
  34. </el-button>
  35. </el-form-item>
  36. </el-form>
  37. </el-card>
  38. <el-card shadow="never">
  39. <ProTable
  40. ref="proTableRef"
  41. :columns="columns"
  42. :data="state.tableData"
  43. @updateTable="queryList"
  44. :loading="state.loading"
  45. :total="state.total"
  46. v-model:page-index="state.queryParams.PageIndex"
  47. v-model:page-size="state.queryParams.PageSize"
  48. show-summary
  49. border
  50. :summary-method="getSummaries"
  51. >
  52. </ProTable>
  53. </el-card>
  54. </div>
  55. </template>
  56. <script setup lang="tsx" name="statisticsCallDetailTalkTime">
  57. import { computed, onMounted, reactive, ref } from 'vue';
  58. import { FormInstance } from 'element-plus';
  59. import { callPeriodBase, callPeriodDetail } from '@/api/statistics/call';
  60. import { defaultDate, shortcuts } from '@/utils/constants';
  61. import { formatDate } from '@/utils/formatTime';
  62. import { useRoute } from 'vue-router';
  63. const proTableRef = ref<RefType>(); // 表格ref
  64. // 表格配置项
  65. const columns = ref<any[]>([
  66. { type: 'index', fixed: 'left', width: 55, label: '序号', align: 'center' },
  67. { prop: 'cpn', label: '主叫号码', align: 'center' },
  68. {
  69. prop: 'cdpn',
  70. label: '被叫号码',
  71. align: 'center',
  72. },
  73. {
  74. prop: 'createdTime',
  75. label: '来电时间',
  76. align: 'center',
  77. render: (scope) => {
  78. return <span>{formatDate(scope.row.createdTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
  79. },
  80. },
  81. ]);
  82. // 定义变量内容
  83. const ruleFormRef = ref<RefType>(); // 表单ref
  84. const state = reactive({
  85. queryParams: {
  86. // 查询条件
  87. type: null,
  88. source: null,
  89. crTime: defaultDate,
  90. PageIndex: 1,
  91. PageSize: 10,
  92. },
  93. tableData: [], //表单
  94. loading: false, // 加载
  95. total: 0, // 总数
  96. callForwardingSource: [],
  97. callForwardingType: [],
  98. });
  99. /** 搜索按钮操作 */
  100. const handleQuery = () => {
  101. state.queryParams.PageIndex = 1;
  102. queryList();
  103. };
  104. /** 获取列表 */
  105. const queryList = () => {
  106. state.loading = true;
  107. if (historyParams.type) {
  108. state.queryParams.type = historyParams.type;
  109. }
  110. let beginDate = null;
  111. let endDate = null;
  112. if (historyParams.beginDate) {
  113. state.queryParams.crTime = [historyParams.beginDate, historyParams.endDate];
  114. }
  115. if (state.queryParams?.crTime) {
  116. beginDate = state.queryParams?.crTime[0];
  117. endDate = state.queryParams?.crTime[1];
  118. }
  119. state.loading = true;
  120. const request = {
  121. beginDate,
  122. endDate,
  123. PageIndex: state.queryParams.PageIndex,
  124. PageSize: state.queryParams.PageSize,
  125. type: state.queryParams.type,
  126. source: state.queryParams.source,
  127. };
  128. callPeriodDetail(request)
  129. .then((res: any) => {
  130. state.tableData = res.result?.data ?? [];
  131. state.total = res.result?.total ?? 0;
  132. state.loading = false;
  133. })
  134. .catch(() => {
  135. state.loading = false;
  136. });
  137. };
  138. /** 重置按钮操作 */
  139. const resetQuery = (formEl: FormInstance | undefined) => {
  140. if (!formEl) return;
  141. formEl.resetFields();
  142. queryList();
  143. };
  144. // 合计
  145. const getSummaries = (param: any) => {
  146. const { columns, data } = param;
  147. const sums: string[] = [];
  148. columns.forEach((column: { property: string }, index: number) => {
  149. if (index === 0) {
  150. sums[index] = '合计';
  151. return;
  152. }
  153. const values = data.map((item: { [x: string]: any }) => Number(item[column.property]));
  154. if (['callInConnectRate', 'effectiveRate', 'gateWay'].includes(column.property)) {
  155. //百分比不能计算
  156. sums[index] = '';
  157. return '';
  158. } else if (!values.every((value: unknown) => Number.isNaN(value))) {
  159. sums[index] = `${values.reduce((prev: any, curr: any) => {
  160. const value = Number(curr);
  161. if (!Number.isNaN(value)) {
  162. return prev + curr;
  163. } else {
  164. return prev;
  165. }
  166. }, 0)}`;
  167. } else {
  168. sums[index] = ' ';
  169. }
  170. });
  171. return sums;
  172. };
  173. // 获取基础信息
  174. const getBaseInfo = async () => {
  175. try {
  176. const { result } = await callPeriodBase();
  177. state.callForwardingSource = result.callForwardingSource ?? [];
  178. state.callForwardingType = result.callForwardingType ?? [];
  179. } catch (e) {
  180. console.log(e);
  181. }
  182. };
  183. // 是否展示查询条件
  184. const historyParams = history.state;
  185. const route = useRoute();
  186. const showSearch = computed(() => {
  187. return historyParams.showSearch;
  188. });
  189. onMounted(() => {
  190. getBaseInfo();
  191. queryList();
  192. });
  193. </script>