xsummary.vue 20 KB

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