index.uvue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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">{{getLabel(detailData)}}</text>
  32. <text class="info-value">{{ getDisplayTime(detailData) }}</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. <text @click="toggleFlowList" v-if="detailData.workOrderFlowList != null && detailData.workOrderFlowList.length > 1" class="toggle-btn">{{ isFlowListExpanded ? '收起' : '展开' }}</text>
  41. </view>
  42. <view class="info-card" v-if="detailData.workOrderFlowList != null && detailData.workOrderFlowList.length > 0">
  43. <view class="flow-item" v-for="(flow, index) in displayedFlowList" :key="index">
  44. <view class="flow-header">
  45. <text class="flow-operator">{{ flow.operatorName ?? '未知操作人' }}</text>
  46. <text class="flow-time">{{ flow.actionTime ?? '' }}</text>
  47. </view>
  48. <view class="flow-content">
  49. <text class="flow-action">{{ getActionTypeName(flow.actionType) }}</text>
  50. <!-- <text class="flow-remark" v-if="flow.actionRemark">{{ flow.actionRemark }}</text> -->
  51. </view>
  52. </view>
  53. </view>
  54. <view class="info-card" v-else>
  55. <view class="no-data">暂无流转记录</view>
  56. </view>
  57. </view>
  58. </scroll-view>
  59. <!-- 加载中状态 -->
  60. <view v-if="loading" class="loading-mask">
  61. <text class="loading-text">加载中...</text>
  62. </view>
  63. </view>
  64. </template>
  65. <script setup lang="uts">
  66. import { ref, computed } from 'vue'
  67. import type { acceptOrderInfo } from '../../../types/order'
  68. import type { WorkOrderFlow } from '../../../types/flow'
  69. import { getOrderInfoById, getRepairOrderInfoById } from '../../../api/order/detail'
  70. import type { SysDictData } from '../../../types/dict'
  71. import { getDictDataByType } from '../../../api/dict/index'
  72. const statusDictList = ref<SysDictData[]>([]) // 工单状态字典列表
  73. // 添加字典加载状态
  74. const dictLoaded = ref<boolean>(false)
  75. const formatDate = (dateString: string): string => {
  76. if (dateString == '' || dateString == null) return ''
  77. const date = new Date(dateString)
  78. const year = date.getFullYear()
  79. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  80. const day = date.getDate().toString().padStart(2, '0')
  81. const hours = date.getHours().toString().padStart(2, '0')
  82. const minutes = date.getMinutes().toString().padStart(2, '0')
  83. return `${year}-${month}-${day} ${hours}:${minutes}`
  84. }
  85. // 根据状态显示不同的时间label
  86. const getLabel = (item : acceptOrderInfo): string|null => {
  87. if (item == null) return null
  88. // 如果是"待接单"状态,显示派单时间
  89. if (item.workOrderStatus == 'assigned') {
  90. return '下发时间'
  91. } else if(item.workOrderStatus == 'to_finish') {
  92. if(item.workEndTime != null) {
  93. return '结束时间'
  94. }
  95. return '接单时间'
  96. } else if(item.workOrderStatus == 'to_approve') {
  97. return '申请挂起时间'
  98. } else if(item.workOrderStatus == 'suspended') {
  99. return '审批通过时间'
  100. } else if(item.workOrderStatus == 'return' || item.workOrderStatus == 'accept_return') {
  101. return '退回时间'
  102. } else if(item.workOrderStatus == 'completed') {
  103. return '结单时间'
  104. } else if(item.workOrderStatus == "archived") {
  105. return '归档时间'
  106. }
  107. // 默认显示创建时间
  108. return '创建时间'
  109. }
  110. // 根据状态显示不同的时间
  111. const getDisplayTime = (item : acceptOrderInfo): string|null => {
  112. if (item == null) return null
  113. let showTime = ref<string|null>('')
  114. // 如果是"待接单"状态,显示派单时间
  115. if (item.workOrderStatus == 'assigned') {
  116. showTime.value = item.assignTime
  117. } else if(item.workOrderStatus == 'to_finish') {
  118. showTime.value = item.acceptTime
  119. } else if(item.workOrderStatus == 'to_approve') {
  120. showTime.value = item.updateTime
  121. } else if(item.workOrderStatus == 'suspended') {
  122. showTime.value = item.updateTime
  123. } else if(item.workOrderStatus == 'return' || item.workOrderStatus == 'accept_return') {
  124. showTime.value = item.updateTime
  125. } else if(item.workOrderStatus == 'completed') {
  126. showTime.value = item.updateTime
  127. } else if(item.workOrderStatus == "archived") {
  128. showTime.value = item.updateTime
  129. } else {
  130. if (item.createTime != null && item.createTime.length >= 3) {
  131. showTime.value = item.createTime.slice(0, -3);
  132. } else {
  133. showTime.value = item.createTime != null ? item.createTime : '';
  134. }
  135. }
  136. return showTime.value
  137. // return formatDate(showTime.value ?? '')
  138. }
  139. // 获取工单状态字典列表
  140. const loadStatusDictList = async (): Promise<void> => {
  141. try {
  142. const result = await getDictDataByType('gxt_repair_order_flow_action_type')
  143. const resultObj = result as UTSJSONObject
  144. if (resultObj['code'] == 200) {
  145. const data = resultObj['data'] as any[]
  146. const dictData: SysDictData[] = []
  147. if (data.length > 0) {
  148. for (let i = 0; i < data.length; i++) {
  149. const item = data[i] as UTSJSONObject
  150. // 只提取需要的字段
  151. const dictItem: SysDictData = {
  152. dictValue: item['dictValue'] as string | null,
  153. dictLabel: item['dictLabel'] as string | null,
  154. dictCode: null,
  155. dictSort: null,
  156. dictType: null,
  157. cssClass: null,
  158. listClass: null,
  159. isDefault: null,
  160. status: null,
  161. default: null,
  162. createTime: null,
  163. remark: null
  164. }
  165. dictData.push(dictItem)
  166. }
  167. }
  168. statusDictList.value = dictData
  169. dictLoaded.value = true
  170. }
  171. } catch (e: any) {
  172. console.error('获取工单状态字典失败:', e.message)
  173. dictLoaded.value = true
  174. }
  175. }
  176. // 详情数据
  177. const detailData = ref<acceptOrderInfo>({
  178. orderType: 0,
  179. id: 0,
  180. teamLeaderId: 0,
  181. acceptUserId: 0,
  182. teamLeaderName: null,
  183. acceptUserName: null,
  184. acceptTime: null,
  185. assignTime: null,
  186. assignUserName: null,
  187. status: 0,
  188. workOrderProjectNo: null,
  189. workOrderStatus: null,
  190. gxtCenterId: 0,
  191. gxtCenter: null,
  192. pcsStationId: 0,
  193. pcsStationName: null,
  194. pcsDeviceId: 0,
  195. pcsDeviceName: null,
  196. brand: null,
  197. model: null,
  198. createTime: null,
  199. workOrderFlowList: null,
  200. suspendReason: null,
  201. rejectionReason: null,
  202. updateTime: null, // 新增字段
  203. workEndTime: null // 新增字段
  204. })
  205. const loading = ref<boolean>(false)
  206. // 控制工单流转列表是否展开
  207. const isFlowListExpanded = ref<boolean>(false)
  208. // 计算显示的工单流转列表
  209. const displayedFlowList = computed(() => {
  210. if (detailData.value.workOrderFlowList == null) return []
  211. // 如果已经展开,则显示全部
  212. if (isFlowListExpanded.value) {
  213. return detailData.value.workOrderFlowList
  214. }
  215. // 默认只显示最后一条
  216. const length = detailData.value.workOrderFlowList.length
  217. return length > 0 ? [detailData.value.workOrderFlowList[length - 1]] : []
  218. })
  219. // 切换工单流转列表的展开/收起状态
  220. const toggleFlowList = () => {
  221. isFlowListExpanded.value = !isFlowListExpanded.value
  222. }
  223. // 获取操作类型名称
  224. const getActionTypeName = (item: string | null): string | null => {
  225. if (item == null) return ''
  226. // const orderInfoItem = item as orderInfo
  227. const rawStatus = item
  228. if (rawStatus==null) return ''
  229. // 如果字典尚未加载,返回原始值
  230. if (dictLoaded.value == false) {
  231. return rawStatus
  232. }
  233. // 查找字典中对应的标签
  234. const dictItem = statusDictList.value.find(dict => dict.dictValue == rawStatus)
  235. return dictItem!=null ? dictItem.dictLabel : rawStatus
  236. }
  237. // 加载详情数据
  238. const loadDetail = async (id: string, orderType?: number): Promise<void> => {
  239. try {
  240. loading.value = true
  241. let result: any;
  242. // 根据orderType决定调用哪个API
  243. if (orderType == 1) {
  244. // 维修工单
  245. result = await getRepairOrderInfoById(id)
  246. } else {
  247. // 维保工单
  248. result = await getOrderInfoById(id)
  249. }
  250. // 提取响应数据
  251. const resultObj = result as UTSJSONObject
  252. const code = resultObj['code'] as number
  253. const data = resultObj['data'] as UTSJSONObject | null
  254. if (code == 200 && data != null) {
  255. // 处理工单流转列表
  256. let workOrderFlowList: WorkOrderFlow[] | null = null
  257. let flowList: UTSJSONObject[] = []
  258. if (orderType == 1) {
  259. // 维修工单
  260. flowList = data['repairOrderFlowList'] as UTSJSONObject[]
  261. } else {
  262. // 维保工单
  263. flowList = data['workOrderFlowList'] as UTSJSONObject[]
  264. }
  265. if (flowList != null) {
  266. workOrderFlowList = []
  267. for (let i = 0; i < flowList.length; i++) {
  268. const flowItem = flowList[i]
  269. const flow: WorkOrderFlow = {
  270. id: flowItem['id'] as Number,
  271. orderId: flowItem['orderId'] as Number,
  272. orderCode: flowItem['orderCode'] as string,
  273. actionType: flowItem['actionType'] as string,
  274. fromStatus: flowItem['fromStatus'] as string | null,
  275. toStatus: flowItem['toStatus'] as string,
  276. operatorId: flowItem['operatorId'] as Number | null,
  277. operatorName: flowItem['operatorName'] as string | null,
  278. actionTime: flowItem['actionTime'] as string,
  279. actionRemark: flowItem['actionRemark'] as string | null,
  280. createBy: flowItem['createBy'] as string | null,
  281. createTime: flowItem['createTime'] as string | null
  282. }
  283. workOrderFlowList.push(flow)
  284. }
  285. }
  286. // 转换数据
  287. const orderDtail: acceptOrderInfo = {
  288. orderType: data['orderType'] as Number,
  289. id: data['id'] as Number,
  290. teamLeaderId: data['teamLeaderId'] != null ? (data['teamLeaderId'] as Number) : 0,
  291. acceptUserId: data['acceptUserId'] != null ? (data['acceptUserId'] as Number) : 0,
  292. teamLeaderName: data['teamLeaderName'] as string | null,
  293. acceptUserName: data['acceptUserName'] as string | null,
  294. acceptTime: data['acceptTime'] as string | null,
  295. assignTime: data['assignTime'] as string | null,
  296. assignUserName: data['assignUserName'] as string | null,
  297. status: (data['status']==null)?0:data['status'] as Number,
  298. workOrderProjectNo: data['workOrderProjectNo'] as string | null,
  299. workOrderStatus: data['workOrderStatus'] as string | null,
  300. gxtCenterId: data['gxtCenterId'] as Number | 0,
  301. gxtCenter: data['gxtCenter'] as string | null,
  302. pcsStationId: data['pcsStationId'] as Number | 0,
  303. pcsStationName: data['pcsStationName'] as string | null,
  304. pcsDeviceId: data['pcsDeviceId'] as Number | 0,
  305. pcsDeviceName: data['pcsDeviceName'] as string | null,
  306. brand: data['brand'] as string | null,
  307. model: data['model'] as string | null,
  308. createTime: data['createTime'] as string | null,
  309. workOrderFlowList: workOrderFlowList,
  310. suspendReason: data['suspendReason'] as string | null,
  311. rejectionReason: data['rejectionReason'] as string | null,
  312. updateTime: data['updateTime'] as string | null, // 新增字段
  313. workEndTime: data['workEndTime'] as string | null // 新增字段
  314. }
  315. detailData.value = orderDtail
  316. } else {
  317. const msg = resultObj['msg'] as string | null
  318. uni.showToast({
  319. title: msg ?? '加载失败',
  320. icon: 'none'
  321. })
  322. }
  323. } catch (e: any) {
  324. uni.showToast({
  325. title: e.message ?? '加载失败',
  326. icon: 'none'
  327. })
  328. } finally {
  329. loading.value = false
  330. }
  331. }
  332. // 页面加载
  333. onLoad((options: any) => {
  334. const params = options as UTSJSONObject
  335. const id = params['id'] as string | null
  336. const orderTypeParam = params['orderType'] as string | null
  337. if (id != null && orderTypeParam != null) {
  338. // 先尝试从参数中获取orderType
  339. const orderTypeNumber = parseInt(orderTypeParam)
  340. loadDetail(id, orderTypeNumber)
  341. }
  342. })
  343. // 初始化
  344. onMounted(() => {
  345. loadStatusDictList()
  346. })
  347. </script>
  348. <style lang="scss">
  349. .detail-page {
  350. flex: 1;
  351. background-color: #e8f0f9;
  352. }
  353. .detail-content {
  354. flex: 1;
  355. padding: 20rpx 0;
  356. }
  357. .info-section {
  358. margin: 0 30rpx 24rpx;
  359. .section-title {
  360. position: relative;
  361. padding-left: 20rpx;
  362. margin-bottom: 20rpx;
  363. flex-direction: row;
  364. justify-content: space-between;
  365. align-items: center;
  366. &::before {
  367. // content: '';
  368. position: absolute;
  369. left: 0;
  370. top: 50%;
  371. transform: translateY(-50%);
  372. width: 8rpx;
  373. height: 32rpx;
  374. background-color: #007aff;
  375. border-radius: 4rpx;
  376. }
  377. &-text {
  378. font-size: 32rpx;
  379. font-weight: bold;
  380. color: #333333;
  381. }
  382. .toggle-btn {
  383. padding-right: 20rpx;
  384. font-size: 28rpx;
  385. color: #165dff;
  386. }
  387. }
  388. .info-card {
  389. background-color: #ffffff;
  390. border-radius: 16rpx;
  391. padding: 30rpx;
  392. .info-item {
  393. flex-direction: row;
  394. padding: 20rpx 0;
  395. border-bottom: 1rpx solid #f0f0f0;
  396. &:last-child {
  397. border-bottom: none;
  398. }
  399. &.full-width {
  400. flex-direction: column;
  401. .info-label {
  402. margin-bottom: 12rpx;
  403. }
  404. .info-value {
  405. line-height: 44rpx;
  406. }
  407. }
  408. .info-label {
  409. width: 240rpx;
  410. font-size: 28rpx;
  411. color: #666666;
  412. white-space: nowrap;
  413. }
  414. .info-value {
  415. flex: 1;
  416. font-size: 28rpx;
  417. color: #333333;
  418. text-align: right;
  419. &.highlight {
  420. color: #007aff;
  421. font-weight: bold;
  422. }
  423. }
  424. }
  425. .flow-item {
  426. padding: 20rpx 0;
  427. border-bottom: 1rpx solid #f0f0f0;
  428. &:last-child {
  429. border-bottom: none;
  430. }
  431. .flow-header {
  432. flex-direction: row;
  433. justify-content: space-between;
  434. margin-bottom: 10rpx;
  435. .flow-operator {
  436. font-size: 28rpx;
  437. color: #333333;
  438. font-weight: bold;
  439. }
  440. .flow-time {
  441. font-size: 24rpx;
  442. color: #999999;
  443. }
  444. }
  445. .flow-content {
  446. flex-direction: column;
  447. .flow-action {
  448. font-size: 26rpx;
  449. color: #666666;
  450. margin-bottom: 8rpx;
  451. }
  452. .flow-remark {
  453. font-size: 24rpx;
  454. color: #999999;
  455. background-color: #f5f5f5;
  456. padding: 10rpx;
  457. border-radius: 8rpx;
  458. }
  459. }
  460. }
  461. .no-data {
  462. text-align: center;
  463. padding: 40rpx 0;
  464. font-size: 28rpx;
  465. color: #999999;
  466. }
  467. }
  468. }
  469. .loading-mask {
  470. position: absolute;
  471. top: 0;
  472. left: 0;
  473. right: 0;
  474. bottom: 0;
  475. justify-content: center;
  476. align-items: center;
  477. background-color: rgba(0, 0, 0, 0.3);
  478. .loading-text {
  479. padding: 30rpx 60rpx;
  480. background-color: rgba(0, 0, 0, 0.7);
  481. color: #ffffff;
  482. font-size: 28rpx;
  483. border-radius: 12rpx;
  484. }
  485. }
  486. </style>