index.uvue 19 KB

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