NonProductionEfficiency.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <script setup lang="ts">
  2. import { IotRyDailyReportApi } from '@/api/pms/iotrydailyreport'
  3. import { useTableComponents } from '@/components/ZmTable/useTableComponents'
  4. import { useDebounceFn } from '@vueuse/core'
  5. import * as echarts from 'echarts'
  6. interface Query {
  7. pageNo: number
  8. pageSize: number
  9. deptId: number
  10. contractName?: string
  11. taskName?: string
  12. createTime: string[]
  13. projectClassification: 1
  14. }
  15. const props = defineProps<{
  16. query: Query
  17. deptName: string
  18. refreshKey: number
  19. }>()
  20. interface ListItem {
  21. id?: number | null
  22. name?: string | null
  23. type?: string
  24. teamId?: number
  25. projectDeptId?: number
  26. teamName?: string
  27. projectDeptName?: string
  28. accidentTime: number
  29. repairTime: number
  30. selfStopTime: number
  31. complexityTime: number
  32. relocationTime: number
  33. rectificationTime: number
  34. waitingStopTime: number
  35. winterBreakTime: number
  36. partyaDesign: number
  37. partyaPrepare: number
  38. partyaResource: number
  39. otherNptTime: number
  40. nptTotal: number
  41. nptRate: number
  42. calendarTime: number
  43. }
  44. const list = ref<ListItem[]>([])
  45. const loading = ref(false)
  46. const tab = ref<'表格' | '看板'>('表格')
  47. const chartRef = ref<HTMLDivElement | null>(null)
  48. let chart: echarts.ECharts | null = null
  49. const router = useRouter()
  50. const nonProductionTimeFields: [keyof ListItem, string][] = [
  51. ['accidentTime', '工程质量'],
  52. ['repairTime', '设备故障'],
  53. ['selfStopTime', '设备保养'],
  54. ['complexityTime', '技术受限'],
  55. ['relocationTime', '生产配合'],
  56. ['rectificationTime', '生产组织'],
  57. ['waitingStopTime', '不可抗力'],
  58. ['winterBreakTime', '待命'],
  59. ['partyaDesign', '甲方设计'],
  60. ['partyaPrepare', '甲方准备'],
  61. ['partyaResource', '甲方资源'],
  62. ['otherNptTime', '其它']
  63. ]
  64. const getQueryWithoutPage = () => {
  65. const { pageNo: _pageNo, pageSize: _pageSize, ...query } = props.query
  66. void _pageNo
  67. void _pageSize
  68. return {
  69. ...query,
  70. projectClassification: 1
  71. }
  72. }
  73. const normalizeListData = (data: any) => {
  74. const rows = Array.isArray(data) ? data : data?.list || data?.records || []
  75. return rows.map(({ projectDeptId, projectDeptName, teamId, teamName, type, ...other }) => ({
  76. ...other,
  77. type,
  78. projectDeptId,
  79. projectDeptName,
  80. teamId,
  81. teamName,
  82. id: type === '2' ? projectDeptId : teamId,
  83. name: type === '2' ? projectDeptName : teamName
  84. }))
  85. }
  86. const loadList = useDebounceFn(async function () {
  87. loading.value = true
  88. try {
  89. const data = await IotRyDailyReportApi.nptStatistics(getQueryWithoutPage())
  90. list.value = normalizeListData(data)
  91. if (tab.value === '看板') {
  92. nextTick(renderChart)
  93. }
  94. } finally {
  95. loading.value = false
  96. }
  97. }, 500)
  98. function handleQuery() {
  99. loadList()
  100. }
  101. watch(
  102. () => [
  103. props.refreshKey,
  104. props.query.deptId,
  105. props.query.contractName,
  106. props.query.taskName,
  107. props.query.createTime?.[0],
  108. props.query.createTime?.[1],
  109. props.query.projectClassification
  110. ],
  111. () => {
  112. handleQuery()
  113. },
  114. { immediate: true }
  115. )
  116. const handleSelectTab = (val: '表格' | '看板') => {
  117. tab.value = val
  118. if (val === '看板') {
  119. nextTick(renderChart)
  120. } else {
  121. chart?.dispose()
  122. chart = null
  123. }
  124. }
  125. const formatNumber = (value: unknown) => {
  126. const num = Number(value || 0)
  127. return Number.isInteger(num) ? `${num}` : num.toFixed(2)
  128. }
  129. const getFieldTotal = (field: keyof ListItem) => {
  130. return list.value.reduce((total, row) => total + Number(row[field] || 0), 0)
  131. }
  132. const getSummaryRate = () => {
  133. const nptTotal = getFieldTotal('nptTotal')
  134. const calendarTime = getFieldTotal('calendarTime')
  135. if (!calendarTime) return '0.00%'
  136. return `${((nptTotal / calendarTime) * 100).toFixed(2)}%`
  137. }
  138. const getSummaries = ({ columns }: { columns: Array<{ property?: keyof ListItem | string }> }) => {
  139. const nonSummaryFields = ['id', 'name', 'teamName', 'projectDeptName']
  140. return columns.map((column, index) => {
  141. if (index === 0) return '合计'
  142. const property = column.property as keyof ListItem | undefined
  143. if (!property) return ''
  144. if (property === 'nptRate') return getSummaryRate()
  145. if (nonSummaryFields.includes(property)) return ''
  146. return formatNumber(getFieldTotal(property))
  147. })
  148. }
  149. const formatTeamName = (row: ListItem) => {
  150. return row.name || '-'
  151. }
  152. const formatRate = (row: ListItem) => {
  153. return `${(Number(row.nptRate || 0) * 100).toFixed(2)}%`
  154. }
  155. const handleRowClick = (row: ListItem) => {
  156. if (!row.id) return
  157. router.push({
  158. name: 'IotRyDailyReport',
  159. query: {
  160. deptId: row.id,
  161. createTime: props.query.createTime,
  162. projectClassification: 1
  163. }
  164. })
  165. }
  166. const getClickableRowClassName = () => 'summary-clickable-row'
  167. const getPieData = () => {
  168. return list.value
  169. .map((row) => ({
  170. name: formatTeamName(row),
  171. value: Number(row.nptTotal || 0)
  172. }))
  173. .filter((item) => item.value > 0)
  174. }
  175. const getNptFieldPieData = () => {
  176. const excludedFields: Array<keyof ListItem> = ['selfStopTime', 'relocationTime', 'winterBreakTime']
  177. return nonProductionTimeFields
  178. .filter(([field]) => !excludedFields.includes(field))
  179. .map(([field, label]) => ({
  180. name: label,
  181. value: getFieldTotal(field)
  182. }))
  183. .filter((item) => item.value > 0)
  184. }
  185. const resizeChart = useDebounceFn(() => {
  186. renderChart()
  187. }, 150)
  188. const renderChart = () => {
  189. if (!chartRef.value) return
  190. chart?.dispose()
  191. chart = echarts.init(chartRef.value, undefined, { renderer: 'canvas' })
  192. window.removeEventListener('resize', resizeChart)
  193. window.addEventListener('resize', resizeChart)
  194. const projectPieData = getPieData()
  195. const nptFieldPieData = getNptFieldPieData()
  196. const chartWidth = chart.getWidth()
  197. const chartHeight = chart.getHeight()
  198. const projectCenter = chartWidth * 0.25
  199. const nptFieldCenter = chartWidth * 0.73
  200. const pieCenterY = chartHeight * 0.55
  201. const graphic: any[] = [
  202. {
  203. type: 'text',
  204. x: projectCenter,
  205. y: 32,
  206. style: {
  207. text: '项目NPT占比',
  208. fill: '#303133',
  209. fontSize: 14,
  210. fontWeight: 500,
  211. textAlign: 'center',
  212. textVerticalAlign: 'middle'
  213. }
  214. },
  215. {
  216. type: 'text',
  217. x: nptFieldCenter,
  218. y: 32,
  219. style: {
  220. text: 'NPT各项时间占比',
  221. fill: '#303133',
  222. fontSize: 14,
  223. fontWeight: 500,
  224. textAlign: 'center',
  225. textVerticalAlign: 'middle'
  226. }
  227. }
  228. ]
  229. if (projectPieData.length === 0) {
  230. graphic.push({
  231. type: 'text',
  232. x: projectCenter,
  233. y: pieCenterY,
  234. style: {
  235. text: '暂无项目NPT数据',
  236. fill: '#909399',
  237. fontSize: 14,
  238. textAlign: 'center'
  239. }
  240. })
  241. }
  242. if (nptFieldPieData.length === 0) {
  243. graphic.push({
  244. type: 'text',
  245. x: nptFieldCenter,
  246. y: pieCenterY,
  247. style: {
  248. text: '暂无NPT项数据',
  249. fill: '#909399',
  250. fontSize: 14,
  251. textAlign: 'center'
  252. }
  253. })
  254. }
  255. chart.setOption({
  256. tooltip: {
  257. trigger: 'item',
  258. formatter: (params: any) =>
  259. `${params.seriesName}<br/>${params.name}: ${formatNumber(params.value)} H<br/>占比: ${params.percent}%`
  260. },
  261. legend: [
  262. {
  263. type: 'scroll',
  264. orient: 'vertical',
  265. left: 16,
  266. top: 64,
  267. bottom: 24,
  268. data: projectPieData.map((item) => item.name)
  269. },
  270. {
  271. type: 'scroll',
  272. orient: 'vertical',
  273. right: 16,
  274. top: 64,
  275. bottom: 24,
  276. data: nptFieldPieData.map((item) => item.name)
  277. }
  278. ],
  279. graphic,
  280. series: [
  281. {
  282. name: '项目NPT占比',
  283. type: 'pie',
  284. radius: ['34%', '56%'],
  285. center: ['25%', '55%'],
  286. avoidLabelOverlap: true,
  287. itemStyle: {
  288. borderRadius: 4,
  289. borderColor: '#fff',
  290. borderWidth: 2
  291. },
  292. label: {
  293. formatter: '{b}: {d}%'
  294. },
  295. data: projectPieData
  296. },
  297. {
  298. name: 'NPT各项时间占比',
  299. type: 'pie',
  300. radius: ['34%', '56%'],
  301. center: ['73%', '55%'],
  302. avoidLabelOverlap: true,
  303. itemStyle: {
  304. borderRadius: 4,
  305. borderColor: '#fff',
  306. borderWidth: 2
  307. },
  308. label: {
  309. formatter: '{b}: {d}%'
  310. },
  311. data: nptFieldPieData
  312. }
  313. ]
  314. })
  315. }
  316. onUnmounted(() => {
  317. window.removeEventListener('resize', resizeChart)
  318. chart?.dispose()
  319. })
  320. const { ZmTable, ZmTableColumn } = useTableComponents<ListItem>()
  321. </script>
  322. <template>
  323. <div class="bg-white dark:bg-[#1d1e1f] rounded-lg shadow flex flex-col p-4 gap-2 h-full min-h-0">
  324. <div class="flex h-12 items-center justify-between">
  325. <el-button-group>
  326. <el-button
  327. size="default"
  328. :type="tab === '表格' ? 'primary' : 'default'"
  329. @click="handleSelectTab('表格')"
  330. >表格
  331. </el-button>
  332. <el-button
  333. size="default"
  334. :type="tab === '看板' ? 'primary' : 'default'"
  335. @click="handleSelectTab('看板')"
  336. >看板
  337. </el-button>
  338. </el-button-group>
  339. <!-- <h3 class="text-xl font-medium">{{ `${deptName}-${tab}` }}</h3> -->
  340. <div class="w-80px"></div>
  341. </div>
  342. <div class="flex-1 relative min-h-0">
  343. <el-auto-resizer class="absolute">
  344. <template #default="{ width, height }">
  345. <zm-table
  346. v-if="tab === '表格'"
  347. :data="list"
  348. :loading="loading"
  349. :width="width"
  350. :max-height="height"
  351. :height="height"
  352. show-border
  353. show-summary
  354. :summary-method="getSummaries"
  355. :row-class-name="getClickableRowClassName"
  356. @row-click="handleRowClick"
  357. >
  358. <zm-table-column
  359. prop="name"
  360. label="队伍"
  361. min-width="120"
  362. fixed="left"
  363. cover-formatter
  364. :real-value="formatTeamName"
  365. />
  366. <zm-table-column
  367. v-for="[prop, label] in nonProductionTimeFields"
  368. :key="prop"
  369. :prop="prop"
  370. :label="label"
  371. min-width="92"
  372. cover-formatter
  373. :real-value="(row: ListItem) => formatNumber(row[prop])"
  374. />
  375. <zm-table-column label="npt合计" is-parent>
  376. <zm-table-column
  377. prop="nptTotal"
  378. label="时长(H)"
  379. min-width="92"
  380. cover-formatter
  381. :real-value="(row: ListItem) => formatNumber(row.nptTotal)"
  382. />
  383. <zm-table-column
  384. prop="nptRate"
  385. label="占比"
  386. min-width="92"
  387. cover-formatter
  388. :real-value="formatRate"
  389. />
  390. </zm-table-column>
  391. <zm-table-column
  392. prop="calendarTime"
  393. label="自然时间"
  394. min-width="92"
  395. cover-formatter
  396. action
  397. :real-value="(row: ListItem) => formatNumber(row.calendarTime)"
  398. />
  399. </zm-table>
  400. <div
  401. v-else
  402. ref="chartRef"
  403. v-loading="loading"
  404. class="npt-board-container"
  405. :style="{ width: `${width}px`, height: `${height}px` }"
  406. >
  407. </div>
  408. </template>
  409. </el-auto-resizer>
  410. </div>
  411. </div>
  412. </template>
  413. <style scoped>
  414. :deep(.npt-cell-highlight) {
  415. background-color: #fff566 !important;
  416. }
  417. :deep(.summary-clickable-row) {
  418. cursor: pointer;
  419. }
  420. .npt-board-container {
  421. background: var(--el-bg-color);
  422. border: 1px solid var(--el-border-color-lighter);
  423. border-radius: 4px;
  424. }
  425. </style>