index.uvue 21 KB

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