summary.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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. // ['累计油耗 (万升)', 'cumulativeFuelConsumption'],
  219. ['累计注气量 (万方)', 'cumulativeGasInjection'],
  220. // ['累计注气量 (万方)', 'cumulativeGasInjection'],
  221. ['累计用电量 (KWh)', 'cumulativePowerConsumption'],
  222. // ['累计用电量 (MWh)', 'cumulativePowerConsumption'],
  223. ['累计注水量 (方)', 'cumulativeWaterInjection'],
  224. // ['累计注水量 (万方)', 'cumulativeWaterInjection'],
  225. ['平均时效 (%)', 'transitTime']
  226. ])
  227. const chartData = ref<Record<string, number[]>>({
  228. cumulativeFuelConsumption: [],
  229. cumulativeGasInjection: [],
  230. cumulativePowerConsumption: [],
  231. cumulativeWaterInjection: [],
  232. transitTime: []
  233. })
  234. let chartLoading = ref(false)
  235. const getChart = useDebounceFn(async () => {
  236. chartLoading.value = true
  237. try {
  238. const res = await IotRhDailyReportApi.getIotRhDailyReportSummaryPolyline(query.value)
  239. chartData.value = {
  240. cumulativeFuelConsumption: res.map((item) => item.cumulativeFuelConsumption || 0),
  241. // cumulativeFuelConsumption: res.map((item) => (item.cumulativeFuelConsumption || 0) / 10000),
  242. cumulativeGasInjection: res.map((item) => (item.cumulativeGasInjection || 0) / 10000),
  243. cumulativePowerConsumption: res.map((item) => item.cumulativePowerConsumption || 0),
  244. // cumulativePowerConsumption: res.map((item) => (item.cumulativePowerConsumption || 0) / 1000),
  245. cumulativeWaterInjection: res.map((item) => item.cumulativeWaterInjection || 0),
  246. // cumulativeWaterInjection: res.map((item) => (item.cumulativeWaterInjection || 0) / 10000),
  247. transitTime: res.map((item) => (item.transitTime || 0) * 100)
  248. }
  249. xAxisData.value = res.map((item) => item.reportDate || '')
  250. } finally {
  251. chartLoading.value = false
  252. }
  253. }, 500)
  254. const resizer = () => {
  255. chart?.resize()
  256. }
  257. onUnmounted(() => {
  258. window.removeEventListener('resize', resizer)
  259. })
  260. const render = () => {
  261. if (!chartRef.value) return
  262. chart = echarts.init(chartRef.value, undefined, { renderer: 'canvas' })
  263. window.addEventListener('resize', resizer)
  264. const values: number[] = []
  265. for (const [_name, key] of legend.value) {
  266. values.push(...(chartData.value[key] || []))
  267. }
  268. const maxVal = values.length === 0 ? 10000 : Math.max(...values)
  269. const minVal = values.length === 0 ? 0 : Math.min(...values) > 0 ? 0 : Math.min(...values)
  270. const maxDigits = (Math.floor(maxVal) + '').length
  271. const minDigits = minVal === 0 ? 0 : (Math.floor(Math.abs(minVal)) + '').length
  272. const interval = Math.max(maxDigits, minDigits)
  273. const maxInterval = interval
  274. const minInterval = minDigits
  275. const intervalArr = [0]
  276. for (let i = 1; i <= interval; i++) {
  277. intervalArr.push(Math.pow(10, i))
  278. }
  279. chart.setOption({
  280. tooltip: {
  281. trigger: 'axis',
  282. axisPointer: {
  283. type: 'line'
  284. },
  285. formatter: (params) => {
  286. let d = `${params[0].axisValueLabel}<br>`
  287. let item = params.map((el) => {
  288. return `<div class="flex items-center justify-between mt-1 gap-1">
  289. <span>${el.marker} ${el.seriesName}</span>
  290. <span>${chartData.value[legend.value[el.componentIndex][1]][el.dataIndex].toFixed(2)} ${el.seriesName.split(' ')[1]}</span>
  291. </div>`
  292. })
  293. return d + item.join('')
  294. }
  295. },
  296. legend: {
  297. data: legend.value.map(([name]) => name),
  298. show: true
  299. },
  300. xAxis: {
  301. type: 'category',
  302. data: xAxisData.value
  303. },
  304. yAxis: {
  305. type: 'value',
  306. min: -minInterval,
  307. max: maxInterval,
  308. interval: 1,
  309. axisLabel: {
  310. formatter: (v) => {
  311. const num = v === 0 ? 0 : v > 0 ? Math.pow(10, v) : -Math.pow(10, -v)
  312. return num.toLocaleString()
  313. }
  314. }
  315. },
  316. series: legend.value.map(([name, key]) => ({
  317. name,
  318. type: 'line',
  319. smooth: true,
  320. showSymbol: true,
  321. data: chartData.value[key].map((value) => {
  322. // return value
  323. if (value === 0) return 0
  324. const isPositive = value > 0
  325. const absItem = Math.abs(value)
  326. const min_value = Math.max(...intervalArr.filter((v) => v <= absItem))
  327. const min_index = intervalArr.findIndex((v) => v === min_value)
  328. const new_value =
  329. (absItem - min_value) / (intervalArr[min_index + 1] - intervalArr[min_index]) + min_index
  330. return isPositive ? new_value : -new_value
  331. })
  332. }))
  333. })
  334. }
  335. const handleDeptNodeClick = (node: any) => {
  336. deptName.value = node.name
  337. handleQuery()
  338. }
  339. const handleQuery = (setPage = true) => {
  340. if (setPage) {
  341. query.value.pageNo = 1
  342. }
  343. getChart().then(() => {
  344. render()
  345. })
  346. getList()
  347. getTotal()
  348. }
  349. const resetQuery = () => {
  350. query.value = {
  351. pageNo: 1,
  352. pageSize: 10,
  353. deptId: deptId,
  354. contractName: '',
  355. taskName: '',
  356. createTime: []
  357. }
  358. handleQuery()
  359. }
  360. watch(
  361. () => query.value.createTime,
  362. (val) => {
  363. if (!val) {
  364. totalWork.value.totalCount = 0
  365. totalWork.value.notReported = 0
  366. totalWork.value.alreadyReported = 0
  367. }
  368. handleQuery(false)
  369. }
  370. )
  371. watch([() => query.value.contractName, () => query.value.taskName], () => {
  372. handleQuery(false)
  373. })
  374. onMounted(() => {
  375. handleQuery()
  376. })
  377. const exportChart = () => {
  378. if (!chart) return
  379. let img = new Image()
  380. img.src = chart.getDataURL({
  381. type: 'png',
  382. pixelRatio: 1,
  383. backgroundColor: '#fff'
  384. })
  385. img.onload = function () {
  386. let canvas = document.createElement('canvas')
  387. canvas.width = img.width
  388. canvas.height = img.height
  389. let ctx = canvas.getContext('2d')
  390. ctx?.drawImage(img, 0, 0)
  391. let dataURL = canvas.toDataURL('image/png')
  392. let a = document.createElement('a')
  393. let event = new MouseEvent('click')
  394. a.href = dataURL
  395. a.download = `瑞恒日报统计数据.png`
  396. a.dispatchEvent(event)
  397. }
  398. }
  399. const exportData = async () => {
  400. const res = await IotRhDailyReportApi.exportRhDailyReportStatistics(query.value)
  401. download.excel(res, '瑞恒日报统计数据.xlsx')
  402. }
  403. const exportAll = async () => {
  404. if (tab.value === '看板') exportChart()
  405. else exportData()
  406. }
  407. const message = useMessage()
  408. const unfilledDialogRef = ref()
  409. const openUnfilledDialog = () => {
  410. // 检查是否选择了创建时间
  411. if (!query.value.createTime || query.value.createTime.length === 0) {
  412. message.warning('请先选择创建时间范围')
  413. return
  414. }
  415. // 打开弹窗
  416. unfilledDialogRef.value?.open()
  417. }
  418. const router = useRouter()
  419. const tolist = (id: number) => {
  420. const { pageNo, pageSize, ...rest } = query.value
  421. router.push({
  422. path: '/iotdayilyreport/IotRhDailyReport',
  423. query: {
  424. ...rest,
  425. deptId: id
  426. }
  427. })
  428. }
  429. </script>
  430. <template>
  431. <div class="grid grid-cols-[16%_1fr] gap-5">
  432. <div class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow p-4">
  433. <!-- <DeptTree2 :deptId="id" @node-click="handleDeptNodeClick" /> -->
  434. <DeptTreeSelect
  435. :deptId="id"
  436. :top-id="157"
  437. v-model="query.deptId"
  438. @node-click="handleDeptNodeClick"
  439. />
  440. </div>
  441. <div class="grid grid-rows-[62px_164px_1fr] h-full gap-4">
  442. <el-form
  443. size="default"
  444. class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow px-8 gap-8 flex items-center justify-between"
  445. >
  446. <div class="flex items-center gap-8">
  447. <el-form-item label="项目">
  448. <el-input
  449. v-model="query.contractName"
  450. placeholder="请输入项目"
  451. clearable
  452. @keyup.enter="handleQuery()"
  453. class="!w-240px"
  454. />
  455. </el-form-item>
  456. <el-form-item label="任务">
  457. <el-input
  458. v-model="query.taskName"
  459. placeholder="请输入任务"
  460. clearable
  461. @keyup.enter="handleQuery()"
  462. class="!w-240px"
  463. />
  464. </el-form-item>
  465. <el-form-item label="创建时间">
  466. <el-date-picker
  467. v-model="query.createTime"
  468. value-format="YYYY-MM-DD HH:mm:ss"
  469. type="daterange"
  470. start-placeholder="开始日期"
  471. end-placeholder="结束日期"
  472. :shortcuts="rangeShortcuts"
  473. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  474. class="!w-220px"
  475. />
  476. </el-form-item>
  477. </div>
  478. <el-form-item>
  479. <el-button type="primary" @click="handleQuery()">
  480. <Icon icon="ep:search" class="mr-5px" /> 搜索
  481. </el-button>
  482. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  483. </el-form-item>
  484. </el-form>
  485. <div class="grid grid-cols-7 gap-8">
  486. <div
  487. v-for="info in totalWorkKeys"
  488. :key="info[0]"
  489. class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow p-1 flex flex-col items-center justify-center gap-1"
  490. >
  491. <div class="size-7.5" :class="info[3]"></div>
  492. <count-to
  493. class="text-2xl font-medium"
  494. :start-val="0"
  495. :end-val="totalWork[info[0]]"
  496. :decimals="info[4]"
  497. @click="info[2] === '未填报' ? openUnfilledDialog() : ''"
  498. >
  499. <span class="text-xs leading-8 text-[var(--el-text-color-regular)]">暂无数据</span>
  500. </count-to>
  501. <div class="text-xs font-medium text-[var(--el-text-color-regular)]">{{ info[1] }}</div>
  502. <div class="text-sm font-medium text-[var(--el-text-color-regular)]">{{ info[2] }}</div>
  503. </div>
  504. </div>
  505. <div
  506. class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow px-8 py-4 grid grid-rows-[48px_1fr] gap-2"
  507. >
  508. <div class="flex items-center justify-between">
  509. <el-button-group>
  510. <el-button
  511. size="default"
  512. :type="tab === '表格' ? 'primary' : 'default'"
  513. @click="handleSelectTab('表格')"
  514. >表格
  515. </el-button>
  516. <el-button
  517. size="default"
  518. :type="tab === '看板' ? 'primary' : 'default'"
  519. @click="handleSelectTab('看板')"
  520. >看板
  521. </el-button>
  522. </el-button-group>
  523. <h3 class="text-xl font-medium">{{ `${deptName}-${tab}` }}</h3>
  524. <el-button size="default" type="primary" @click="exportAll">导出</el-button>
  525. </div>
  526. <!-- <el-auto-resizer>
  527. <template #default="{ height, width }"> -->
  528. <Motion
  529. as="div"
  530. :style="{ position: 'relative', overflow: 'hidden' }"
  531. :animate="{ height: `${500}px`, width: `100%` }"
  532. :transition="{ type: 'spring', stiffness: 200, damping: 25, duration: 0.3 }"
  533. >
  534. <AnimatePresence :initial="false" mode="sync">
  535. <Motion
  536. :key="currentTab"
  537. as="div"
  538. :initial="{ x: direction === 'left' ? '-100%' : '100%', opacity: 0 }"
  539. :animate="{ x: '0%', opacity: 1 }"
  540. :exit="{ x: direction === 'left' ? '50%' : '-50%', opacity: 0 }"
  541. :transition="{ type: 'tween', stiffness: 300, damping: 30, duration: 0.3 }"
  542. :style="{ position: 'absolute', left: 0, right: 0, top: 0 }"
  543. >
  544. <div :style="{ width: `100%`, height: `${500}px` }">
  545. <el-table
  546. v-if="currentTab === '表格'"
  547. v-loading="listLoading"
  548. :data="list"
  549. :stripe="true"
  550. :max-height="500"
  551. show-overflow-tooltip
  552. >
  553. <template v-for="item in columns(type)" :key="item.prop">
  554. <el-table-column
  555. v-if="item.prop !== 'name'"
  556. :label="item.label"
  557. :prop="item.prop"
  558. align="center"
  559. :formatter="formatter"
  560. />
  561. <el-table-column v-else :label="item.label" :prop="item.prop" align="center">
  562. <template #default="{ row }">
  563. <el-button text type="primary" @click.prevent="tolist(row.id)">{{
  564. row.name
  565. }}</el-button>
  566. </template>
  567. </el-table-column>
  568. </template>
  569. </el-table>
  570. <div
  571. ref="chartRef"
  572. v-loading="chartLoading"
  573. :key="dayjs().valueOf()"
  574. v-else
  575. :style="{ width: `100%`, height: `${500}px` }"
  576. >
  577. </div>
  578. </div>
  579. </Motion>
  580. </AnimatePresence>
  581. </Motion>
  582. <!-- </template>
  583. </el-auto-resizer> -->
  584. </div>
  585. </div>
  586. </div>
  587. <UnfilledReportDialog ref="unfilledDialogRef" :query-params="query" />
  588. </template>
  589. <style scoped>
  590. :deep(.el-form-item) {
  591. margin-bottom: 0;
  592. }
  593. :deep(.el-table) {
  594. border-top-right-radius: 8px;
  595. border-top-left-radius: 8px;
  596. .el-table__cell {
  597. height: 40px;
  598. }
  599. .el-table__header-wrapper {
  600. .el-table__cell {
  601. background: var(--el-fill-color-light);
  602. }
  603. }
  604. }
  605. </style>