summary.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <script setup lang="ts">
  2. import dayjs from 'dayjs'
  3. import { IotRhDailyReportApi } from '@/api/pms/iotrhdailyreport'
  4. import { useDebounceFn } from '@vueuse/core'
  5. import CountTo from '@/components/count-to1.vue'
  6. import * as echarts from 'echarts'
  7. import UnfilledReportDialog from './UnfilledReportDialog.vue'
  8. import { Motion, AnimatePresence } from 'motion-v'
  9. import { rangeShortcuts } from '@/utils/formatTime'
  10. import download from '@/utils/download'
  11. import { useUserStore } from '@/store/modules/user'
  12. const deptId = useUserStore().getUser.deptId
  13. interface Query {
  14. pageNo: number
  15. pageSize: number
  16. deptId: number
  17. contractName?: string
  18. taskName?: string
  19. createTime: string[]
  20. }
  21. const id = deptId
  22. const query = ref<Query>({
  23. pageNo: 1,
  24. pageSize: 10,
  25. deptId: deptId,
  26. createTime: [
  27. ...rangeShortcuts[2].value().map((item) => dayjs(item).format('YYYY-MM-DD HH:mm:ss'))
  28. ]
  29. })
  30. const totalWorkKeys: [string, string, string, string, number][] = [
  31. ['totalCount', '个', '总数', 'i-tabler:report-analytics text-sky', 0],
  32. [
  33. 'alreadyReported',
  34. '个',
  35. '已填报',
  36. 'i-material-symbols:check-circle-outline-rounded text-emerald',
  37. 0
  38. ],
  39. ['notReported', '个', '未填报', 'i-material-symbols:cancel-outline-rounded text-rose', 0],
  40. [
  41. 'totalFuelConsumption',
  42. 'L',
  43. '累计油耗',
  44. 'i-material-symbols:directions-car-outline-rounded text-sky',
  45. 2
  46. ],
  47. [
  48. 'totalPowerConsumption',
  49. 'KWH',
  50. '累计用电量',
  51. 'i-material-symbols:electric-bolt-outline-rounded text-sky',
  52. 2
  53. ],
  54. [
  55. 'totalWaterInjection',
  56. '方',
  57. '累计注水量',
  58. 'i-material-symbols:water-drop-outline-rounded text-sky',
  59. 2
  60. ],
  61. ['totalGasInjection', '万方', '累计注气量', 'i-material-symbols:cloud-outline text-sky', 4]
  62. ]
  63. const totalWork = ref({
  64. totalCount: 0,
  65. alreadyReported: 0,
  66. notReported: 0,
  67. totalFuelConsumption: 0,
  68. totalPowerConsumption: 0,
  69. totalWaterInjection: 0,
  70. totalGasInjection: 0
  71. })
  72. const totalLoading = ref(false)
  73. const getTotal = useDebounceFn(async () => {
  74. totalLoading.value = true
  75. const { pageNo, pageSize, ...other } = query.value
  76. try {
  77. let res1: any[]
  78. if (query.value.createTime && query.value.createTime.length === 2) {
  79. res1 = await IotRhDailyReportApi.rhDailyReportStatistics({
  80. createTime: query.value.createTime,
  81. deptId: query.value.deptId
  82. })
  83. totalWork.value.totalCount = res1[0].count
  84. totalWork.value.alreadyReported = res1[1].count
  85. totalWork.value.notReported = res1[2].count
  86. }
  87. const res2 = await IotRhDailyReportApi.totalWorkload(other)
  88. totalWork.value = {
  89. ...totalWork.value,
  90. totalFuelConsumption: 0,
  91. totalPowerConsumption: 0,
  92. totalWaterInjection: 0,
  93. ...res2,
  94. totalGasInjection: (res2.totalGasInjection || 0) / 10000
  95. }
  96. } finally {
  97. totalLoading.value = false
  98. }
  99. }, 500)
  100. interface List {
  101. id: number | null
  102. name: string | null
  103. type: '1' | '2' | '3'
  104. cumulativeGasInjection: number | null
  105. cumulativeWaterInjection: number | null
  106. cumulativePowerConsumption: number | null
  107. cumulativeFuelConsumption: number | null
  108. transitTime: number | null
  109. }
  110. const list = ref<List[]>([])
  111. const type = ref('2')
  112. const columns = (type: string) => {
  113. return [
  114. {
  115. label: type === '2' ? '项目部' : '队伍',
  116. prop: 'name'
  117. },
  118. {
  119. label: '累计注气量(万方)',
  120. prop: 'cumulativeGasInjection'
  121. },
  122. {
  123. label: '累计注水量(方)',
  124. prop: 'cumulativeWaterInjection'
  125. },
  126. {
  127. label: '累计用电量(KWH)',
  128. prop: 'cumulativePowerConsumption'
  129. },
  130. {
  131. label: '累计油耗(L)',
  132. prop: 'cumulativeFuelConsumption'
  133. }
  134. ]
  135. }
  136. const listLoading = ref(false)
  137. const formatter = (row: List, column: any) => {
  138. return row[column.property] ?? 0
  139. }
  140. const getList = useDebounceFn(async () => {
  141. listLoading.value = true
  142. try {
  143. const res = await IotRhDailyReportApi.getIotRhDailyReportSummary(query.value)
  144. const { list: reslist } = res
  145. type.value = reslist[0]?.type || '2'
  146. list.value = reslist.map(
  147. ({ id, projectDeptId, projectDeptName, teamId, teamName, sort, taskId, type, ...other }) => {
  148. return {
  149. id: type === '2' ? projectDeptId : teamId,
  150. name: type === '2' ? projectDeptName : teamName,
  151. ...other,
  152. cumulativeGasInjection: (other.cumulativeGasInjection || 0) / 10000
  153. }
  154. }
  155. )
  156. } finally {
  157. listLoading.value = false
  158. }
  159. }, 500)
  160. const tab = ref<'表格' | '看板'>('表格')
  161. const currentTab = ref<'表格' | '看板'>('表格')
  162. const deptName = ref('瑞恒兴域')
  163. const direction = ref<'left' | 'right'>('right')
  164. const handleSelectTab = (val: '表格' | '看板') => {
  165. tab.value = val
  166. direction.value = val === '看板' ? 'right' : 'left'
  167. nextTick(() => {
  168. currentTab.value = val
  169. setTimeout(() => {
  170. render()
  171. })
  172. })
  173. }
  174. const chartRef = ref<HTMLDivElement | null>(null)
  175. let chart: echarts.ECharts | null = null
  176. const xAxisData = ref<string[]>([])
  177. const legend = ref<string[][]>([
  178. ['累计油耗 (吨)', 'cumulativeFuelConsumption'],
  179. ['累计注气量 (万方)', 'cumulativeGasInjection'],
  180. ['累计用电量 (KWH)', 'cumulativePowerConsumption'],
  181. ['累计注水量 (方)', 'cumulativeWaterInjection'],
  182. ['平均时效 (%)', 'transitTime']
  183. ])
  184. const chartData = ref<Record<string, number[]>>({
  185. cumulativeFuelConsumption: [],
  186. cumulativeGasInjection: [],
  187. cumulativePowerConsumption: [],
  188. cumulativeWaterInjection: [],
  189. transitTime: []
  190. })
  191. let chartLoading = ref(false)
  192. const getChart = useDebounceFn(async () => {
  193. chartLoading.value = true
  194. try {
  195. const res = await IotRhDailyReportApi.getIotRhDailyReportSummaryPolyline(query.value)
  196. chartData.value = {
  197. cumulativeFuelConsumption: res.map((item) => item.cumulativeFuelConsumption || 0),
  198. cumulativeGasInjection: res.map((item) => (item.cumulativeGasInjection || 0) / 10000),
  199. cumulativePowerConsumption: res.map((item) => item.cumulativePowerConsumption || 0),
  200. cumulativeWaterInjection: res.map((item) => item.cumulativeWaterInjection || 0),
  201. transitTime: res.map((item) => (item.transitTime || 0) * 100)
  202. }
  203. xAxisData.value = res.map((item) => item.reportDate || '')
  204. } finally {
  205. chartLoading.value = false
  206. }
  207. }, 500)
  208. const resizer = () => {
  209. chart?.resize()
  210. }
  211. onUnmounted(() => {
  212. window.removeEventListener('resize', resizer)
  213. })
  214. const render = () => {
  215. if (!chartRef.value) return
  216. chart = echarts.init(chartRef.value, undefined, { renderer: 'canvas' })
  217. window.addEventListener('resize', resizer)
  218. const values: number[] = []
  219. for (const [_name, key] of legend.value) {
  220. values.push(...(chartData.value[key] || []))
  221. }
  222. const maxVal = values.length === 0 ? 10000 : Math.max(...values)
  223. const minVal = values.length === 0 ? 0 : Math.min(...values)
  224. const maxDigits = (Math.floor(maxVal) + '').length
  225. const minDigits = (Math.floor(Math.abs(minVal)) + '').length
  226. const interval = Math.max(maxDigits, minDigits)
  227. const maxInterval = interval
  228. const minInterval = minDigits
  229. const intervalArr = [0]
  230. for (let i = 1; i <= interval; i++) {
  231. intervalArr.push(Math.pow(10, i))
  232. }
  233. chart.setOption({
  234. tooltip: {
  235. trigger: 'axis',
  236. axisPointer: {
  237. type: 'line'
  238. },
  239. formatter: (params) => {
  240. let d = `${params[0].axisValueLabel}<br>`
  241. let item = params.map((el) => {
  242. return `<div class="flex items-center justify-between mt-1 gap-1">
  243. <span>${el.marker} ${el.seriesName}</span>
  244. <span>${chartData.value[legend.value[el.componentIndex][1]][el.dataIndex].toFixed(2)} ${el.seriesName.split(' ')[1]}</span>
  245. </div>`
  246. })
  247. return d + item.join('')
  248. }
  249. },
  250. legend: {
  251. data: legend.value.map(([name]) => name),
  252. show: true
  253. },
  254. xAxis: {
  255. type: 'category',
  256. data: xAxisData.value
  257. },
  258. yAxis: {
  259. type: 'value',
  260. min: minInterval,
  261. max: maxInterval,
  262. interval: 1,
  263. axisLabel: {
  264. formatter: (v) => {
  265. const num = v === 0 ? 0 : v > 0 ? Math.pow(10, v) : -Math.pow(10, -v)
  266. return num.toLocaleString()
  267. }
  268. }
  269. },
  270. series: legend.value.map(([name, key]) => ({
  271. name,
  272. type: 'line',
  273. smooth: true,
  274. showSymbol: true,
  275. data: chartData.value[key].map((value) => {
  276. // return value
  277. if (value === 0) return 0
  278. const isPositive = value > 0
  279. const absItem = Math.abs(value)
  280. const min_value = Math.max(...intervalArr.filter((v) => v <= absItem))
  281. const min_index = intervalArr.findIndex((v) => v === min_value)
  282. const new_value =
  283. (absItem - min_value) / (intervalArr[min_index + 1] - intervalArr[min_index]) + min_index
  284. return isPositive ? new_value : -new_value
  285. })
  286. }))
  287. })
  288. }
  289. const handleDeptNodeClick = (node: any) => {
  290. deptName.value = node.name
  291. handleQuery()
  292. }
  293. const handleQuery = (setPage = true) => {
  294. if (setPage) {
  295. query.value.pageNo = 1
  296. }
  297. getChart().then(() => {
  298. render()
  299. })
  300. getList()
  301. getTotal()
  302. }
  303. const resetQuery = () => {
  304. query.value = {
  305. pageNo: 1,
  306. pageSize: 10,
  307. deptId: deptId,
  308. contractName: '',
  309. taskName: '',
  310. createTime: []
  311. }
  312. handleQuery()
  313. }
  314. watch(
  315. () => query.value.createTime,
  316. (val) => {
  317. if (!val) {
  318. totalWork.value.totalCount = 0
  319. totalWork.value.notReported = 0
  320. totalWork.value.alreadyReported = 0
  321. }
  322. handleQuery(false)
  323. }
  324. )
  325. watch([() => query.value.contractName, () => query.value.taskName], () => {
  326. handleQuery(false)
  327. })
  328. onMounted(() => {
  329. handleQuery()
  330. })
  331. const exportChart = () => {
  332. if (!chart) return
  333. let img = new Image()
  334. img.src = chart.getDataURL({
  335. type: 'png',
  336. pixelRatio: 1,
  337. backgroundColor: '#fff'
  338. })
  339. img.onload = function () {
  340. let canvas = document.createElement('canvas')
  341. canvas.width = img.width
  342. canvas.height = img.height
  343. let ctx = canvas.getContext('2d')
  344. ctx?.drawImage(img, 0, 0)
  345. let dataURL = canvas.toDataURL('image/png')
  346. let a = document.createElement('a')
  347. let event = new MouseEvent('click')
  348. a.href = dataURL
  349. a.download = `瑞恒日报统计数据.png`
  350. a.dispatchEvent(event)
  351. }
  352. }
  353. const exportData = async () => {
  354. const res = await IotRhDailyReportApi.exportRhDailyReportStatistics(query.value)
  355. download.excel(res, '瑞恒日报统计数据.xlsx')
  356. }
  357. const exportAll = async () => {
  358. if (tab.value === '看板') exportChart()
  359. else exportData()
  360. }
  361. const message = useMessage()
  362. const unfilledDialogRef = ref()
  363. const openUnfilledDialog = () => {
  364. // 检查是否选择了创建时间
  365. if (!query.value.createTime || query.value.createTime.length === 0) {
  366. message.warning('请先选择创建时间范围')
  367. return
  368. }
  369. // 打开弹窗
  370. unfilledDialogRef.value?.open()
  371. }
  372. const router = useRouter()
  373. const tolist = (id: number) => {
  374. const { pageNo, pageSize, ...rest } = query.value
  375. router.push({
  376. path: '/iotdayilyreport/IotRhDailyReport',
  377. query: {
  378. ...rest,
  379. deptId: id
  380. }
  381. })
  382. }
  383. </script>
  384. <template>
  385. <div class="grid grid-cols-[16%_1fr] gap-5">
  386. <div class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow p-4">
  387. <!-- <DeptTree2 :deptId="id" @node-click="handleDeptNodeClick" /> -->
  388. <DeptTreeSelect
  389. :deptId="id"
  390. :top-id="157"
  391. v-model="query.deptId"
  392. @node-click="handleDeptNodeClick"
  393. />
  394. </div>
  395. <div class="grid grid-rows-[62px_164px_1fr] h-full gap-4">
  396. <el-form
  397. size="default"
  398. class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow px-8 gap-8 flex items-center justify-between"
  399. >
  400. <div class="flex items-center gap-8">
  401. <el-form-item label="项目">
  402. <el-input
  403. v-model="query.contractName"
  404. placeholder="请输入项目"
  405. clearable
  406. @keyup.enter="handleQuery()"
  407. class="!w-240px"
  408. />
  409. </el-form-item>
  410. <el-form-item label="任务">
  411. <el-input
  412. v-model="query.taskName"
  413. placeholder="请输入任务"
  414. clearable
  415. @keyup.enter="handleQuery()"
  416. class="!w-240px"
  417. />
  418. </el-form-item>
  419. <el-form-item label="创建时间">
  420. <el-date-picker
  421. v-model="query.createTime"
  422. value-format="YYYY-MM-DD HH:mm:ss"
  423. type="daterange"
  424. start-placeholder="开始日期"
  425. end-placeholder="结束日期"
  426. :shortcuts="rangeShortcuts"
  427. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  428. class="!w-220px"
  429. />
  430. </el-form-item>
  431. </div>
  432. <el-form-item>
  433. <el-button type="primary" @click="handleQuery()">
  434. <Icon icon="ep:search" class="mr-5px" /> 搜索
  435. </el-button>
  436. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  437. </el-form-item>
  438. </el-form>
  439. <div class="grid grid-cols-7 gap-8">
  440. <div
  441. v-for="info in totalWorkKeys"
  442. :key="info[0]"
  443. class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow p-1 flex flex-col items-center justify-center gap-1"
  444. >
  445. <div class="size-7.5" :class="info[3]"></div>
  446. <count-to
  447. class="text-2xl font-medium"
  448. :start-val="0"
  449. :end-val="totalWork[info[0]]"
  450. :decimals="info[4]"
  451. @click="info[2] === '未填报' ? openUnfilledDialog() : ''"
  452. >
  453. <span class="text-xs leading-8 text-[var(--el-text-color-regular)]">暂无数据</span>
  454. </count-to>
  455. <div class="text-xs font-medium text-[var(--el-text-color-regular)]">{{ info[1] }}</div>
  456. <div class="text-sm font-medium text-[var(--el-text-color-regular)]">{{ info[2] }}</div>
  457. </div>
  458. </div>
  459. <div
  460. class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow px-8 py-4 grid grid-rows-[48px_1fr] gap-2"
  461. >
  462. <div class="flex items-center justify-between">
  463. <el-button-group>
  464. <el-button
  465. size="default"
  466. :type="tab === '表格' ? 'primary' : 'default'"
  467. @click="handleSelectTab('表格')"
  468. >表格
  469. </el-button>
  470. <el-button
  471. size="default"
  472. :type="tab === '看板' ? 'primary' : 'default'"
  473. @click="handleSelectTab('看板')"
  474. >看板
  475. </el-button>
  476. </el-button-group>
  477. <h3 class="text-xl font-medium">{{ `${deptName}-${tab}` }}</h3>
  478. <el-button size="default" type="primary" @click="exportAll">导出</el-button>
  479. </div>
  480. <!-- <el-auto-resizer>
  481. <template #default="{ height, width }"> -->
  482. <Motion
  483. as="div"
  484. :style="{ position: 'relative', overflow: 'hidden' }"
  485. :animate="{ height: `${500}px`, width: `100%` }"
  486. :transition="{ type: 'spring', stiffness: 200, damping: 25, duration: 0.3 }"
  487. >
  488. <AnimatePresence :initial="false" mode="sync">
  489. <Motion
  490. :key="currentTab"
  491. as="div"
  492. :initial="{ x: direction === 'left' ? '-100%' : '100%', opacity: 0 }"
  493. :animate="{ x: '0%', opacity: 1 }"
  494. :exit="{ x: direction === 'left' ? '50%' : '-50%', opacity: 0 }"
  495. :transition="{ type: 'tween', stiffness: 300, damping: 30, duration: 0.3 }"
  496. :style="{ position: 'absolute', left: 0, right: 0, top: 0 }"
  497. >
  498. <div :style="{ width: `100%`, height: `${500}px` }">
  499. <el-table
  500. v-if="currentTab === '表格'"
  501. v-loading="listLoading"
  502. :data="list"
  503. :stripe="true"
  504. :max-height="500"
  505. show-overflow-tooltip
  506. >
  507. <template v-for="item in columns(type)" :key="item.prop">
  508. <el-table-column
  509. v-if="item.prop !== 'name'"
  510. :label="item.label"
  511. :prop="item.prop"
  512. align="center"
  513. :formatter="formatter"
  514. />
  515. <el-table-column v-else :label="item.label" :prop="item.prop" align="center">
  516. <template #default="{ row }">
  517. <el-button text type="primary" @click.prevent="tolist(row.id)">{{
  518. row.name
  519. }}</el-button>
  520. </template>
  521. </el-table-column>
  522. </template>
  523. </el-table>
  524. <div
  525. ref="chartRef"
  526. v-loading="chartLoading"
  527. :key="dayjs().valueOf()"
  528. v-else
  529. :style="{ width: `100%`, height: `${500}px` }"
  530. >
  531. </div>
  532. </div>
  533. </Motion>
  534. </AnimatePresence>
  535. </Motion>
  536. <!-- </template>
  537. </el-auto-resizer> -->
  538. </div>
  539. </div>
  540. </div>
  541. <UnfilledReportDialog ref="unfilledDialogRef" :query-params="query" />
  542. </template>
  543. <style scoped>
  544. :deep(.el-form-item) {
  545. margin-bottom: 0;
  546. }
  547. :deep(.el-table) {
  548. border-top-right-radius: 8px;
  549. border-top-left-radius: 8px;
  550. .el-table__cell {
  551. height: 40px;
  552. }
  553. .el-table__header-wrapper {
  554. .el-table__cell {
  555. background: var(--el-fill-color-light);
  556. }
  557. }
  558. }
  559. </style>