xsummary.vue 17 KB

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