summary.vue 19 KB

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