index.uvue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <template>
  2. <view class="detail-page">
  3. <scroll-view class="detail-content" :scroll-y="true">
  4. <!-- 工单信息 -->
  5. <view class="info-section">
  6. <view class="section-title">
  7. <text class="section-title-text">工单信息</text>
  8. </view>
  9. <view class="info-card">
  10. <view class="info-item">
  11. <text class="info-label">工单编码</text>
  12. <text class="info-value">{{ detailData.workOrderProjectNo ?? '' }}</text>
  13. </view>
  14. <view class="info-item">
  15. <text class="info-label">工单类型</text>
  16. <text class="info-value">{{ detailData.orderType == 1 ? '维修工单' : '维保工单' }}</text>
  17. </view>
  18. <view class="info-item">
  19. <text class="info-label">风机编号</text>
  20. <text class="info-value">{{ detailData.pcsDeviceName ?? '' }}</text>
  21. </view>
  22. <view class="info-item">
  23. <text class="info-label">场站</text>
  24. <text class="info-value">{{ detailData.pcsStationName ?? '' }}</text>
  25. </view>
  26. <view class="info-item">
  27. <text class="info-label">机型</text>
  28. <text class="info-value">{{ (detailData.brand ?? '') + ' ' + (detailData.model ?? '') }}</text>
  29. </view>
  30. <!-- <view class="info-item">
  31. <text class="info-label">创建时间</text>
  32. <text class="info-value">{{ detailData.createTime ?? '' }}</text>
  33. </view> -->
  34. </view>
  35. </view>
  36. <!-- 工时构成 -->
  37. <view class="info-section">
  38. <view class="section-title">
  39. <text class="section-title-text">工时构成</text>
  40. </view>
  41. <view class="info-card">
  42. <view class="chart-container">
  43. <view style="width: 320rpx; height: 320rpx;">
  44. <l-echart ref="chartRef" @finished="init"></l-echart>
  45. </view>
  46. <view class="chart-legend">
  47. <view v-for="(item, index) in chartLegendData" :key="index" class="legend-item">
  48. <view class="legend-left">
  49. <view class="legend-color" :style="{ backgroundColor: item.color }"></view>
  50. <text class="legend-name">{{ item.name }}</text>
  51. </view>
  52. <view class="legend-right">
  53. <text class="legend-value">{{ formatHours(item.value) }}h</text>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <view v-if="showCombinedLabel" class="combined-legend">
  59. <view class="legend-left">
  60. <view class="legend-color" :style="{ backgroundColor: colorMap.get('下发时长+准备时长') }"></view>
  61. <text class="legend-name">下发时长+准备时长</text>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <!-- 工时明细 -->
  67. <!-- <view class="info-section">
  68. <view class="section-title">
  69. <text class="section-title-text">工时明细</text>
  70. </view>
  71. <view class="info-card">
  72. <view class="info-item">
  73. <text class="info-label">下发时长</text>
  74. <text class="info-value">{{ formatHours(detailData.issueHour) }}小时</text>
  75. </view>
  76. <view class="info-item">
  77. <text class="info-label">接单时长</text>
  78. <text class="info-value">{{ formatHours(detailData.acceptHour) }}小时</text>
  79. </view>
  80. <view class="info-item">
  81. <text class="info-label">准备时长</text>
  82. <text class="info-value">{{ formatHours(detailData.prepareHour) }}小时</text>
  83. </view>
  84. <view class="info-item">
  85. <text class="info-label">作业时长</text>
  86. <text class="info-value">{{ formatHours(detailData.workHour) }}小时</text>
  87. </view>
  88. <view class="info-item">
  89. <text class="info-label">复运时长</text>
  90. <text class="info-value">{{ formatHours(detailData.restartHour) }}小时</text>
  91. </view>
  92. <view class="info-item">
  93. <text class="info-label">处理时长</text>
  94. <text class="info-value">{{ formatHours(detailData.handleHour) }}小时</text>
  95. </view>
  96. <view class="info-item">
  97. <text class="info-label">挂起时长</text>
  98. <text class="info-value">{{ formatHours(detailData.suspendHour) }}小时</text>
  99. </view>
  100. </view>
  101. </view> -->
  102. </scroll-view>
  103. <!-- 加载中状态 -->
  104. <view v-if="loading" class="loading-mask">
  105. <text class="loading-text">加载中...</text>
  106. </view>
  107. </view>
  108. </template>
  109. <script setup lang="uts">
  110. import { ref } from 'vue'
  111. import { getOrderHourDetail } from '../../../api/worktime/index'
  112. import type { orderInfo } from '../../../types/order'
  113. // #ifdef MP
  114. // 引入小程序依赖包,require只能是当前文件的相对路径
  115. const echarts = require('../../../../static/echarts.min.js')
  116. // #endif
  117. // #ifndef MP
  118. // 非小程序不需要引入
  119. const echarts = null
  120. // #endif
  121. // 详情数据
  122. const detailData = ref<orderInfo>({
  123. orderType: 0 as Number,
  124. id: 0 as Number,
  125. teamLeaderName: null,
  126. acceptUserName: null,
  127. acceptTime: null,
  128. assignTime: null,
  129. assignUserName: null,
  130. status: 0 as Number,
  131. workOrderProjectNo: null,
  132. workOrderStatus: null,
  133. gxtCenterId: 0 as Number,
  134. gxtCenter: null,
  135. pcsStationId: 0 as Number,
  136. pcsStationName: null,
  137. pcsDeviceId: 0 as Number,
  138. pcsDeviceName: null,
  139. brand: null,
  140. model: null,
  141. createTime: null,
  142. workOrderFlowList: null,
  143. // 工时相关字段
  144. issueHour: 0 as Number,
  145. acceptHour: 0 as Number,
  146. prepareHour: 0 as Number,
  147. workHour: 0 as Number,
  148. restartHour: 0 as Number,
  149. handleHour: 0 as Number,
  150. suspendHour: 0 as Number,
  151. downtimeHour: 0 as Number,
  152. } as orderInfo)
  153. const loading = ref<boolean>(false)
  154. const chartData = ref<UTSJSONObject[]>([])
  155. const chartRef = ref<LEchartComponentPublicInstance | null>(null)
  156. const showCombinedLabel = ref<boolean>(false)
  157. // 图例数据类型
  158. type ChartLegendItem = {
  159. name: string
  160. value: number
  161. color: string
  162. }
  163. const chartLegendData = ref<ChartLegendItem[]>([])
  164. // 颜色配置
  165. //const chartColors = ['#5B9BF3', '#4DD4C0', '#FF9966', '#FF6B96', '#9B7FE8', '#FFD700', '#8A2BE2']
  166. const chartColors = ['#5B9BF3', '#4DD4C0', '#FF9966', '#FF6B96', '#9B7FE8', '#FFD700']
  167. // 固定颜色映射
  168. const colorMap = new Map<string, string>([
  169. ['下发时长', '#5B9BF3'],
  170. ['接单时长', '#4DD4C0'],
  171. ['准备时长', '#FF9966'],
  172. ['挂起时长', '#FF6B96'],
  173. ['作业时长', '#9B7FE8'],
  174. ['复运时长', '#FFD700'],
  175. ['下发时长+准备时长', '#ff0000']
  176. ])
  177. // 格式化小时数
  178. const formatHours = (hourValue: number | null): string => {
  179. if (hourValue == null) return '0.0'
  180. return (hourValue as number).toFixed(2)
  181. }
  182. const init = async () => {
  183. if(chartRef.value == null) return
  184. const chart = await chartRef.value!.init(echarts)
  185. // 检查数据是否有效
  186. if (chartData.value == null || chartData.value.length == 0) {
  187. return
  188. }
  189. // 计算总值用于百分比计算,只累加正值以确保百分比计算准确
  190. const total = chartData.value.reduce((sum, currentItem) => {
  191. const value = currentItem.get('value') as number;
  192. return sum + (value > 0 ? value : 0);
  193. }, 0);
  194. // 构建图表数据数组
  195. const seriesData = chartData.value.map((item: UTSJSONObject, index: number) => {
  196. const value = item.get('value') as number;
  197. const percent = total > 0 ? (value / total * 100) : 0;
  198. const name = item.get('name') as string;
  199. return {
  200. name: name,
  201. value: item.get('value'),
  202. label: {
  203. // 如果百分比小于10%,不显示标签
  204. show: percent >= 5
  205. },
  206. itemStyle: {
  207. color: colorMap.get(name) != null ? colorMap.get(name) : chartColors[index % chartColors.length]
  208. }
  209. }
  210. })
  211. // 构建完整的图表选项对象
  212. const option = {
  213. legend: {
  214. show: false
  215. },
  216. series: [{
  217. type: 'pie',
  218. radius: ['30%', '90%'],
  219. center: ['50%', '50%'],
  220. label: {
  221. show: true,
  222. formatter: '{d}%',
  223. position: 'inside',
  224. color: '#fff',
  225. fontSize: 12,
  226. fontWeight: 'bold',
  227. textShadow: '0 1px 3px rgba(0,0,0,0.5)'
  228. },
  229. data: seriesData
  230. }]
  231. } as UTSJSONObject
  232. // 使用正确的API调用来设置图表选项
  233. chart.setOption(option)
  234. }
  235. // 准备图表数据
  236. const prepareChartData = (data: orderInfo): void => {
  237. const chartItems = [] as UTSJSONObject[]
  238. const legendItems = [] as ChartLegendItem[]
  239. // 添加各项工时数据
  240. if (data.issueHour != null) {
  241. if (data.orderType != null && data.orderType == 1) {
  242. if (data.prepareHour != null && data.prepareHour < 0) {
  243. const item = {
  244. name: '下发时长+准备时长',
  245. value: data.issueHour + data.prepareHour
  246. } as UTSJSONObject
  247. chartItems.push(item)
  248. if((data.issueHour + data.prepareHour) > 0){
  249. showCombinedLabel.value = true
  250. }else{
  251. showCombinedLabel.value = false
  252. }
  253. }else{
  254. const item = {
  255. name: '下发时长',
  256. value: data.issueHour
  257. } as UTSJSONObject
  258. chartItems.push(item)
  259. showCombinedLabel.value = false
  260. }
  261. const color = colorMap.get('下发时长')
  262. legendItems.push({
  263. name: '下发时长',
  264. value: data.issueHour,
  265. color: color != null ? color : '#5B9BF3'
  266. } as ChartLegendItem)
  267. }
  268. }
  269. if (data.acceptHour != null) {
  270. if (data.orderType != null && data.orderType == 1) {
  271. /* const item = {name: '接单时长', value: data.acceptHour} as UTSJSONObject
  272. chartItems.push(item) */
  273. const color = colorMap.get('接单时长')
  274. legendItems.push({
  275. name: '接单时长',
  276. value: data.acceptHour,
  277. color: color != null ? color : '#4DD4C0'
  278. } as ChartLegendItem)
  279. }
  280. }
  281. if (data.prepareHour != null) {
  282. if (data.orderType != null && data.orderType == 1) {
  283. if (data.prepareHour >= 0) {
  284. const item = {name: '准备时长', value: data.prepareHour} as UTSJSONObject
  285. chartItems.push(item)
  286. }
  287. const color = colorMap.get('准备时长')
  288. legendItems.push({
  289. name: '准备时长',
  290. value: data.prepareHour,
  291. color: color != null ? color : '#FF9966'
  292. } as ChartLegendItem)
  293. }
  294. }
  295. if (data.suspendHour != null) {
  296. const item = {name: '挂起时长', value: data.suspendHour} as UTSJSONObject
  297. chartItems.push(item)
  298. const color = colorMap.get('挂起时长')
  299. legendItems.push({
  300. name: '挂起时长',
  301. value: data.suspendHour,
  302. color: color != null ? color : '#FF6B96'
  303. } as ChartLegendItem)
  304. }
  305. if (data.workHour != null) {
  306. const item = {name: '作业时长', value: data.workHour} as UTSJSONObject
  307. chartItems.push(item)
  308. const color = colorMap.get('作业时长')
  309. legendItems.push({
  310. name: '作业时长',
  311. value: data.workHour,
  312. color: color != null ? color : '#9B7FE8'
  313. } as ChartLegendItem)
  314. }
  315. if (data.restartHour != null) {
  316. const item = {name: '复运时长', value: data.restartHour} as UTSJSONObject
  317. chartItems.push(item)
  318. const color = colorMap.get('复运时长')
  319. legendItems.push({
  320. name: '复运时长',
  321. value: data.restartHour,
  322. color: color != null ? color : '#FFD700'
  323. } as ChartLegendItem)
  324. }
  325. /* if (data.handleHour != null) {
  326. const item = {name: '处理时长', value: data.handleHour} as UTSJSONObject
  327. chartItems.push(item)
  328. legendItems.push({
  329. name: '处理时长',
  330. value: data.handleHour,
  331. color: chartColors[legendItems.length % chartColors.length]
  332. } as ChartLegendItem)
  333. } */
  334. if (data.downtimeHour != null) {
  335. /* const item = {name: '停运时长', value: data.downtimeHour} as UTSJSONObject
  336. chartItems.push(item) */
  337. legendItems.push({
  338. name: '停运时长',
  339. value: data.downtimeHour,
  340. //color: chartColors[legendItems.length % chartColors.length]
  341. color: '#ffffff'
  342. } as ChartLegendItem)
  343. }
  344. chartData.value = chartItems
  345. chartLegendData.value = legendItems
  346. // 如果图表已经初始化,则直接绘制
  347. if (chartRef.value != null && chartItems.length > 0) {
  348. init()
  349. }
  350. }
  351. // 加载详情数据
  352. const loadDetail = async (id: string, orderType: string): Promise<void> => {
  353. try {
  354. loading.value = true
  355. const result = await getOrderHourDetail(orderType, id)
  356. // 提取响应数据
  357. const resultObj = result as UTSJSONObject
  358. const code = resultObj.get('code') as number
  359. const data = resultObj.get('data') as UTSJSONObject | null
  360. if (code == 200 && data != null) {
  361. // 转换数据
  362. const orderDetail: orderInfo = {
  363. orderType: data.get('orderType') as Number,
  364. id: data.get('id') as Number,
  365. teamLeaderName: data.get('teamLeaderName') as string | null,
  366. acceptUserName: data.get('acceptUserName') as string | null,
  367. acceptTime: data.get('acceptTime') as string | null,
  368. assignTime: data.get('assignTime') as string | null,
  369. assignUserName: data.get('assignUserName') as string | null,
  370. status: (data.get('status') == null) ? (0 as Number) : (data.get('status') as Number),
  371. workOrderProjectNo: data.get('workOrderProjectNo') as string | null,
  372. workOrderStatus: data.get('workOrderStatus') as string | null,
  373. gxtCenterId: (data.get('gxtCenterId') ?? 0) as Number,
  374. gxtCenter: data.get('gxtCenter') as string | null,
  375. pcsStationId: (data.get('pcsStationId') ?? 0) as Number,
  376. pcsStationName: data.get('pcsStationName') as string | null,
  377. pcsDeviceId: (data.get('pcsDeviceId') ?? 0) as Number,
  378. pcsDeviceName: data.get('pcsDeviceName') as string | null,
  379. brand: data.get('brand') as string | null,
  380. model: data.get('model') as string | null,
  381. createTime: data.get('createTime') as string | null,
  382. workOrderFlowList: null,
  383. // 工时相关字段
  384. issueHour: (data.get('issueHour') as number | null) ?? 0,
  385. acceptHour: (data.get('acceptHour') as number | null) ?? 0,
  386. prepareHour: (data.get('prepareHour') as number | null) ?? 0,
  387. workHour: (data.get('workHour') as number | null) ?? 0,
  388. restartHour: (data.get('restartHour') as number | null) ?? 0,
  389. handleHour: (data.get('handleHour') as number | null) ?? 0,
  390. suspendHour: (data.get('suspendHour') as number | null) ?? 0,
  391. downtimeHour: (data.get('downtimeHour') as number | null) ?? 0,
  392. } as orderInfo
  393. detailData.value = orderDetail
  394. // 准备图表数据
  395. prepareChartData(orderDetail)
  396. } else {
  397. const msg = (resultObj.get('msg') as string | null) ?? '加载失败'
  398. uni.showToast({
  399. title: msg,
  400. icon: 'none'
  401. })
  402. }
  403. } catch (e: any) {
  404. uni.showToast({
  405. title: e.message ?? '加载失败',
  406. icon: 'none'
  407. })
  408. } finally {
  409. loading.value = false
  410. }
  411. }
  412. // 返回上一页
  413. const goBack = (): void => {
  414. uni.navigateBack()
  415. }
  416. // 页面加载
  417. onLoad((options: any) => {
  418. const params = options as UTSJSONObject
  419. const id = params.get('id') as string | null
  420. const orderType = params.get('orderType') as string | null
  421. if (id != null && orderType != null) {
  422. loadDetail(id, orderType)
  423. }
  424. })
  425. </script>
  426. <style lang="scss">
  427. .detail-page {
  428. flex: 1;
  429. background-color: #e8f0f9;
  430. }
  431. .detail-content {
  432. flex: 1;
  433. padding: 20rpx 0;
  434. }
  435. .info-section {
  436. margin: 0 30rpx 24rpx;
  437. .section-title {
  438. position: relative;
  439. padding-left: 20rpx;
  440. margin-bottom: 20rpx;
  441. &::before {
  442. position: absolute;
  443. left: 0;
  444. top: 50%;
  445. transform: translateY(-50%);
  446. width: 8rpx;
  447. height: 32rpx;
  448. background-color: #007aff;
  449. border-radius: 4rpx;
  450. }
  451. &-text {
  452. font-size: 32rpx;
  453. font-weight: bold;
  454. color: #333333;
  455. }
  456. }
  457. .info-card {
  458. background-color: #ffffff;
  459. border-radius: 16rpx;
  460. padding: 30rpx;
  461. .info-item {
  462. flex-direction: row;
  463. padding: 20rpx 0;
  464. border-bottom: 1rpx solid #f0f0f0;
  465. &:last-child {
  466. border-bottom: none;
  467. }
  468. &.full-width {
  469. flex-direction: column;
  470. .info-label {
  471. margin-bottom: 12rpx;
  472. }
  473. .info-value {
  474. line-height: 44rpx;
  475. }
  476. }
  477. .info-label {
  478. width: 240rpx;
  479. font-size: 28rpx;
  480. color: #666666;
  481. white-space: nowrap;
  482. }
  483. .info-value {
  484. flex: 1;
  485. font-size: 28rpx;
  486. color: #333333;
  487. text-align: right;
  488. &.highlight {
  489. color: #007aff;
  490. font-weight: bold;
  491. }
  492. }
  493. }
  494. .chart-container {
  495. flex-direction: row;
  496. align-items: center;
  497. justify-content: space-between;
  498. margin: 5rpx 0;
  499. padding: 5rpx 0;
  500. }
  501. .chart-legend {
  502. flex: 1;
  503. padding-left: 20rpx;
  504. }
  505. .legend-item {
  506. flex-direction: row;
  507. align-items: center;
  508. justify-content: space-between;
  509. margin-bottom: 8rpx;
  510. &:last-child {
  511. margin-bottom: 0;
  512. }
  513. .legend-left {
  514. flex-direction: row;
  515. align-items: center;
  516. }
  517. .legend-right {
  518. flex-direction: row;
  519. align-items: center;
  520. }
  521. }
  522. .legend-color {
  523. width: 20rpx;
  524. height: 20rpx;
  525. border-radius: 4rpx;
  526. margin-right: 12rpx;
  527. }
  528. .legend-name {
  529. font-size: 24rpx;
  530. color: #333333;
  531. margin-right: 8rpx;
  532. }
  533. .legend-value {
  534. font-size: 24rpx;
  535. color: #666666;
  536. font-weight: bold;
  537. }
  538. .no-data {
  539. text-align: center;
  540. padding: 40rpx 0;
  541. font-size: 28rpx;
  542. color: #999999;
  543. }
  544. .combined-legend {
  545. flex-direction: row;
  546. align-items: center;
  547. margin-top: 20rpx;
  548. padding-top: 20rpx;
  549. border-top: 1rpx dashed #eee;
  550. .legend-left {
  551. flex-direction: row;
  552. align-items: center;
  553. }
  554. }
  555. }
  556. }
  557. .loading-mask {
  558. position: absolute;
  559. top: 0;
  560. left: 0;
  561. right: 0;
  562. bottom: 0;
  563. justify-content: center;
  564. align-items: center;
  565. background-color: rgba(0, 0, 0, 0.3);
  566. .loading-text {
  567. padding: 30rpx 60rpx;
  568. background-color: rgba(0, 0, 0, 0.7);
  569. color: #ffffff;
  570. font-size: 28rpx;
  571. border-radius: 12rpx;
  572. }
  573. }
  574. </style>