summary.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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: 1
  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. ['totalFootage', 'M', '累计进尺', 'i-solar:ruler-bold text-sky', 2]
  57. ]
  58. const totalWork = ref({
  59. totalCount: 0,
  60. alreadyReported: 0,
  61. notReported: 0,
  62. totalFuelConsumption: 0,
  63. totalPowerConsumption: 0,
  64. totalFootage: 0
  65. })
  66. const totalLoading = ref(false)
  67. const getTotal = useDebounceFn(async () => {
  68. totalLoading.value = true
  69. const { pageNo, pageSize, ...other } = query.value
  70. try {
  71. let res1: any[]
  72. if (query.value.createTime && query.value.createTime.length === 2) {
  73. res1 = await IotRyDailyReportApi.ryDailyReportStatistics({
  74. createTime: query.value.createTime,
  75. projectClassification: query.value.projectClassification
  76. })
  77. totalWork.value.totalCount = res1[0].count
  78. totalWork.value.alreadyReported = res1[1].count
  79. totalWork.value.notReported = res1[2].count
  80. }
  81. const res2 = await IotRyDailyReportApi.totalWorkload(other)
  82. totalWork.value = {
  83. ...totalWork.value,
  84. totalFootage: 0,
  85. ...res2,
  86. totalPowerConsumption: (res2.totalPowerConsumption || 0) / 1000,
  87. totalGasInjection: (res2.totalGasInjection || 0) / 10000,
  88. totalFuelConsumption: (res2.totalFuelConsumption || 0) / 10000
  89. }
  90. } finally {
  91. totalLoading.value = false
  92. }
  93. }, 1000)
  94. interface List {
  95. id: number | null
  96. name: string | null
  97. type: '1' | '2' | '3'
  98. cumulativeGasInjection: number | null
  99. cumulativeWaterInjection: number | null
  100. cumulativePowerConsumption: number | null
  101. cumulativeFuelConsumption: number | null
  102. transitTime: number | null
  103. }
  104. const list = ref<List[]>([])
  105. const type = ref('2')
  106. const columns = (type: string) => {
  107. return [
  108. {
  109. label: type === '2' ? '项目部' : '队伍',
  110. prop: 'name'
  111. },
  112. {
  113. label: '累计进尺(M)',
  114. prop: 'cumulativeFootage'
  115. },
  116. {
  117. label: '累计用电量(MWh)',
  118. prop: 'cumulativePowerConsumption'
  119. },
  120. {
  121. label: '累计油耗(万升)',
  122. prop: 'cumulativeFuelConsumption'
  123. },
  124. {
  125. label: '平均时效(%)',
  126. prop: 'transitTime'
  127. }
  128. ]
  129. }
  130. const listLoading = ref(false)
  131. const formatter = (row: List, column: any) => {
  132. if (column.property === 'transitTime') {
  133. return (Number(row.transitTime ?? 0) * 100).toFixed(2) + '%'
  134. } else return row[column.property] ?? 0
  135. }
  136. const getList = useDebounceFn(async () => {
  137. listLoading.value = true
  138. try {
  139. const res = await IotRyDailyReportApi.getIotRyDailyReportSummary(query.value)
  140. const { list: reslist } = res
  141. type.value = reslist[0]?.type || '2'
  142. list.value = reslist.map(
  143. ({ id, projectDeptId, projectDeptName, teamId, teamName, sort, taskId, type, ...other }) => ({
  144. id: type === '2' ? projectDeptId : teamId,
  145. name: type === '2' ? projectDeptName : teamName,
  146. ...other,
  147. cumulativePowerConsumption: ((other.cumulativePowerConsumption || 0) / 1000).toFixed(4),
  148. cumulativeFuelConsumption: ((other.cumulativeFuelConsumption || 0) / 10000).toFixed(4)
  149. })
  150. )
  151. } finally {
  152. listLoading.value = false
  153. }
  154. }, 1000)
  155. const tab = ref<'表格' | '看板'>('表格')
  156. const currentTab = ref<'表格' | '看板'>('表格')
  157. const deptName = ref('瑞鹰国际钻井')
  158. const direction = ref<'left' | 'right'>('right')
  159. const handleSelectTab = (val: '表格' | '看板') => {
  160. tab.value = val
  161. direction.value = val === '看板' ? 'right' : 'left'
  162. nextTick(() => {
  163. currentTab.value = val
  164. setTimeout(() => {
  165. render()
  166. })
  167. })
  168. }
  169. const chartRef = ref<HTMLDivElement | null>(null)
  170. let chart: echarts.ECharts | null = null
  171. const xAxisData = ref<string[]>([])
  172. const legend = ref<string[][]>([
  173. // ['累计油耗 (万升)', 'cumulativeFuelConsumption'],
  174. ['累计油耗 (升)', 'cumulativeFuelConsumption'],
  175. ['累计进尺 (M)', 'cumulativeFootage'],
  176. ['累计用电量 (KWh)', 'cumulativePowerConsumption'],
  177. // ['累计用电量 (MWh)', 'cumulativePowerConsumption'],
  178. ['平均时效 (%)', 'transitTime']
  179. ])
  180. const chartData = ref<Record<string, number[]>>({
  181. cumulativeFuelConsumption: [],
  182. cumulativeFootage: [],
  183. cumulativePowerConsumption: [],
  184. transitTime: []
  185. })
  186. let chartLoading = ref(false)
  187. const getChart = useDebounceFn(async () => {
  188. chartLoading.value = true
  189. try {
  190. // 创建查询参数,如果 createTime 为空则不传
  191. const params: any = {
  192. deptId: query.value.deptId,
  193. projectClassification: query.value.projectClassification
  194. }
  195. // 只有 createTime 有值时才添加
  196. if (query.value.createTime && query.value.createTime.length === 2) {
  197. params.createTime = query.value.createTime
  198. }
  199. const res = await IotRyDailyReportApi.getIotRyDailyReportSummaryPolyline(query.value)
  200. chartData.value = {
  201. cumulativeFuelConsumption: res.map((item) => item.cumulativeFuelConsumption || 0),
  202. // cumulativeFuelConsumption: res.map((item) => (item.cumulativeFuelConsumption || 0) / 10000),
  203. cumulativeFootage: res.map((item) => item.cumulativeFootage || 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. handleQuery()
  297. }
  298. const handleQuery = (setPage = true) => {
  299. if (setPage) {
  300. query.value.pageNo = 1
  301. }
  302. getChart().then(() => {
  303. render()
  304. })
  305. getList()
  306. getTotal()
  307. }
  308. const resetQuery = () => {
  309. query.value = {
  310. pageNo: 1,
  311. pageSize: 10,
  312. deptId: deptId,
  313. createTime: [],
  314. projectClassification: 1
  315. }
  316. handleQuery()
  317. }
  318. watch(
  319. () => query.value.createTime,
  320. (val) => {
  321. if (!val) {
  322. totalWork.value.totalCount = 0
  323. totalWork.value.notReported = 0
  324. totalWork.value.alreadyReported = 0
  325. }
  326. handleQuery(false)
  327. }
  328. )
  329. onMounted(() => {
  330. handleQuery()
  331. })
  332. const exportChart = () => {
  333. if (!chart) return
  334. let img = new Image()
  335. img.src = chart.getDataURL({
  336. type: 'png',
  337. pixelRatio: 1,
  338. backgroundColor: '#fff'
  339. })
  340. img.onload = function () {
  341. let canvas = document.createElement('canvas')
  342. canvas.width = img.width
  343. canvas.height = img.height
  344. let ctx = canvas.getContext('2d')
  345. ctx?.drawImage(img, 0, 0)
  346. let dataURL = canvas.toDataURL('image/png')
  347. let a = document.createElement('a')
  348. let event = new MouseEvent('click')
  349. a.href = dataURL
  350. a.download = `瑞鹰钻井日报统计数据.png`
  351. a.dispatchEvent(event)
  352. }
  353. }
  354. const exportData = async () => {
  355. const res = await IotRyDailyReportApi.exportRyDailyReportStatistics(query.value)
  356. download.excel(res, '瑞鹰钻井日报统计数据.xlsx')
  357. }
  358. const exportAll = async () => {
  359. if (tab.value === '看板') exportChart()
  360. else exportData()
  361. }
  362. const message = useMessage()
  363. const unfilledDialogRef = ref()
  364. const openUnfilledDialog = () => {
  365. // 检查是否选择了创建时间
  366. if (!query.value.createTime || query.value.createTime.length === 0) {
  367. message.warning('请先选择创建时间范围')
  368. return
  369. }
  370. // 打开弹窗
  371. unfilledDialogRef.value?.open()
  372. }
  373. const router = useRouter()
  374. const tolist = (id: number) => {
  375. const { pageNo, pageSize, ...rest } = query.value
  376. router.push({
  377. path: '/iotdayilyreport/IotRyDailyReport',
  378. query: {
  379. ...rest,
  380. deptId: id
  381. }
  382. })
  383. }
  384. </script>
  385. <template>
  386. <div class="grid grid-cols-[16%_1fr] gap-5">
  387. <div class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow p-4">
  388. <!-- <DeptTree2 ref="deptTreeRef" :deptId="id" @node-click="handleDeptNodeClick" /> -->
  389. <DeptTreeSelect
  390. :deptId="id"
  391. :top-id="158"
  392. v-model="query.deptId"
  393. @node-click="handleDeptNodeClick"
  394. />
  395. </div>
  396. <div class="grid grid-rows-[62px_164px_1fr] h-full gap-5">
  397. <el-form
  398. size="default"
  399. class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow px-8 gap-8 flex items-center justify-between"
  400. >
  401. <div class="flex items-center gap-8">
  402. <el-form-item label="项目">
  403. <el-input
  404. v-model="query.contractName"
  405. placeholder="请输入项目"
  406. clearable
  407. @keyup.enter="handleQuery()"
  408. class="!w-240px"
  409. />
  410. </el-form-item>
  411. <el-form-item label="任务">
  412. <el-input
  413. v-model="query.taskName"
  414. placeholder="请输入任务"
  415. clearable
  416. @keyup.enter="handleQuery()"
  417. class="!w-240px"
  418. />
  419. </el-form-item>
  420. <el-form-item label="创建时间">
  421. <el-date-picker
  422. v-model="query.createTime"
  423. value-format="YYYY-MM-DD HH:mm:ss"
  424. type="daterange"
  425. start-placeholder="开始日期"
  426. end-placeholder="结束日期"
  427. :shortcuts="rangeShortcuts"
  428. class="!w-220px"
  429. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  430. />
  431. </el-form-item>
  432. </div>
  433. <el-form-item>
  434. <el-button type="primary" @click="handleQuery()">
  435. <Icon icon="ep:search" class="mr-5px" /> 搜索
  436. </el-button>
  437. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  438. </el-form-item>
  439. </el-form>
  440. <div class="grid grid-cols-6 gap-8">
  441. <div
  442. v-for="info in totalWorkKeys"
  443. :key="info[0]"
  444. class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow p-4 flex flex-col items-center justify-center gap-2"
  445. >
  446. <div class="size-7.5" :class="info[3]"></div>
  447. <count-to
  448. class="text-2xl font-medium"
  449. :start-val="0"
  450. :end-val="totalWork[info[0]]"
  451. :decimals="info[4]"
  452. @click="info[2] === '未填报' ? openUnfilledDialog() : ''"
  453. >
  454. <span class="text-xs leading-8 text-[var(--el-text-color-regular)]">暂无数据</span>
  455. </count-to>
  456. <div class="text-xs font-medium text-[var(--el-text-color-regular)]">{{ info[1] }}</div>
  457. <div class="text-sm font-medium text-[var(--el-text-color-regular)]">{{ info[2] }}</div>
  458. </div>
  459. </div>
  460. <div
  461. class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow px-8 py-4 grid grid-rows-[48px_1fr] gap-2"
  462. >
  463. <div class="flex items-center justify-between">
  464. <el-button-group>
  465. <el-button
  466. size="default"
  467. :type="tab === '表格' ? 'primary' : 'default'"
  468. @click="handleSelectTab('表格')"
  469. >表格
  470. </el-button>
  471. <el-button
  472. size="default"
  473. :type="tab === '看板' ? 'primary' : 'default'"
  474. @click="handleSelectTab('看板')"
  475. >看板
  476. </el-button>
  477. </el-button-group>
  478. <h3 class="text-xl font-medium">{{ `${deptName}-${tab}` }}</h3>
  479. <el-button size="default" type="primary" @click="exportAll">导出</el-button>
  480. </div>
  481. <!-- <el-auto-resizer>
  482. <template #default="{ height, width }"> -->
  483. <Motion
  484. as="div"
  485. :style="{ position: 'relative', overflow: 'hidden' }"
  486. :animate="{ height: `${500}px`, width: `100%` }"
  487. :transition="{ type: 'spring', stiffness: 200, damping: 25, duration: 0.3 }"
  488. >
  489. <AnimatePresence :initial="false" mode="sync">
  490. <Motion
  491. :key="currentTab"
  492. as="div"
  493. :initial="{ x: direction === 'left' ? '-100%' : '100%', opacity: 0 }"
  494. :animate="{ x: '0%', opacity: 1 }"
  495. :exit="{ x: direction === 'left' ? '50%' : '-50%', opacity: 0 }"
  496. :transition="{ type: 'tween', stiffness: 300, damping: 30, duration: 0.3 }"
  497. :style="{ position: 'absolute', left: 0, right: 0, top: 0 }"
  498. >
  499. <div :style="{ width: `100%`, height: `${500}px` }">
  500. <el-table
  501. v-if="currentTab === '表格'"
  502. v-loading="listLoading"
  503. :data="list"
  504. :stripe="true"
  505. :max-height="500"
  506. show-overflow-tooltip
  507. >
  508. <template v-for="item in columns(type)" :key="item.prop">
  509. <el-table-column
  510. v-if="item.prop !== 'name'"
  511. :label="item.label"
  512. :prop="item.prop"
  513. align="center"
  514. :formatter="formatter"
  515. />
  516. <el-table-column v-else :label="item.label" :prop="item.prop" align="center">
  517. <template #default="{ row }">
  518. <el-button text type="primary" @click.prevent="tolist(row.id)">{{
  519. row.name
  520. }}</el-button>
  521. </template>
  522. </el-table-column>
  523. </template>
  524. </el-table>
  525. <div
  526. ref="chartRef"
  527. v-loading="chartLoading"
  528. :key="dayjs().valueOf()"
  529. v-else
  530. :style="{ width: `100%`, height: `${500}px` }"
  531. >
  532. </div>
  533. </div>
  534. </Motion>
  535. </AnimatePresence>
  536. </Motion>
  537. <!-- </template>
  538. </el-auto-resizer> -->
  539. </div>
  540. </div>
  541. </div>
  542. <UnfilledReportDialog ref="unfilledDialogRef" :query-params="query" />
  543. </template>
  544. <style scoped>
  545. :deep(.el-form-item) {
  546. margin-bottom: 0;
  547. }
  548. :deep(.el-table) {
  549. border-top-right-radius: 8px;
  550. border-top-left-radius: 8px;
  551. .el-table__cell {
  552. height: 52px;
  553. }
  554. .el-table__header-wrapper {
  555. .el-table__cell {
  556. background: var(--el-fill-color-light);
  557. }
  558. }
  559. }
  560. </style>