xsummary.vue 18 KB

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