xsummary.vue 18 KB

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