index.uvue 21 KB

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