pendingOrder.uvue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <template>
  2. <uni-navbar-lite :showLeft=true title="待处理工单"></uni-navbar-lite>
  3. <view class="list-page">
  4. <!-- 搜索栏 -->
  5. <view class="search-bar">
  6. <view class="search-box">
  7. <image class="search-icon" src="/static/images/workbench/list/1.png" mode="aspectFit"></image>
  8. <input class="search-input" type="text" placeholder="搜索工单编码、风机编号" v-model="keyword" @confirm="handleSearch" @blur="handleSearch" />
  9. <text v-if="keyword.length > 0" class="clear-icon" @click="clearSearch">✕</text>
  10. </view>
  11. </view>
  12. <!-- 列表内容 -->
  13. <common-list
  14. :dataList="dataList"
  15. :loading="loading"
  16. :refreshing="refreshing"
  17. :hasMore="hasMore"
  18. @refresh="handleRefresh"
  19. @loadMore="loadMore"
  20. @itemClick="handleItemClick"
  21. >
  22. <template #default="{ item, index }">
  23. <view class="list-item">
  24. <view class="item-container">
  25. <view class="item-header">
  26. <text class="item-title">{{ getWorkOrderProjectNo(item) }}-{{ getPcsDeviceName(item) }}{{ getOrderType(item) }}</text>
  27. <text class="status-tag" :class="getStatusClass(item)">{{ getWorkOrderStatus(item) }}</text>
  28. </view>
  29. <view class="info-row">
  30. <view class="info-label">
  31. <text class="text-gray">{{ getDisplayTime(item) }}</text>
  32. </view>
  33. <view class="info-value">
  34. <button
  35. v-if="getOrderStatus(item) == 'assigned' && canHandleOrder(item)"
  36. class="btn-primary info-value"
  37. @click.stop="handleItemClick(item)"
  38. >
  39. 接单
  40. </button>
  41. <button
  42. v-else-if="getOrderStatus(item) == 'to_approve' && canHandleOrder(item)"
  43. class="btn-primary info-value"
  44. @click.stop="handleItemClick(item)"
  45. >
  46. 审批
  47. </button>
  48. <!-- <button
  49. v-else-if="getOrderStatus(item) == 'to_finish' && canHandleOrder(item)"
  50. class="btn-primary info-value"
  51. @click.stop="handleItemClick(item)"
  52. >
  53. 挂起
  54. </button> -->
  55. <button
  56. v-else-if="getOrderStatus(item) == 'suspended' && canHandleOrder(item)"
  57. class="btn-primary info-value"
  58. @click.stop="handleItemClick(item)"
  59. >
  60. 恢复
  61. </button>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. </common-list>
  68. </view>
  69. </template>
  70. <script setup lang="uts">
  71. import { ref, onBeforeUnmount, onMounted } from 'vue'
  72. import type { acceptOrderInfo } from '../../types/order'
  73. import type { SysDictData } from '../../types/dict'
  74. import { pendingList } from '../../api/order/list'
  75. import { getDictDataByType } from '../../api/dict/index'
  76. import {checkPermi} from '../../utils/storage'
  77. // 列表数据
  78. const dataList = ref<acceptOrderInfo[]>([])
  79. let keyword = ref<string>("")
  80. const page = ref<number>(1)
  81. const pageSize: number = 10
  82. const hasMore = ref<boolean>(true)
  83. const loading = ref<boolean>(false)
  84. const refreshing = ref<boolean>(false)
  85. const total = ref<number>(0)
  86. const statusDictList = ref<SysDictData[]>([]) // 工单状态字典列表
  87. // 添加字典加载状态
  88. const dictLoaded = ref<boolean>(false)
  89. const getOrderStatus = (item: any | null): string => {
  90. if (item == null) return ''
  91. const orderItem = item as acceptOrderInfo
  92. return orderItem.workOrderStatus ?? ''
  93. }
  94. // 方法:判断当前工单是否显示操作按钮(基于 orderType)
  95. const canHandleOrder = (item: any | null): boolean => {
  96. if (item == null) return false
  97. let permit: string[] = []
  98. const orderItem = item as acceptOrderInfo
  99. if(orderItem.workOrderStatus == 'assigned') {
  100. // 接单
  101. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:accept'] : ['gxt:repairOrder:accept']
  102. // } else if(orderItem.workOrderStatus == 'to_finish') {
  103. // // 挂起
  104. // permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:suspend'] : ['gxt:repairOrder:suspend']
  105. } else if(orderItem.workOrderStatus == 'to_approve') {
  106. // 审批
  107. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:approve'] : ['gxt:repairOrder:approve']
  108. } else if(orderItem.workOrderStatus == 'suspended') {
  109. // 恢复
  110. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:resume'] : ['gxt:repairOrder:resume']
  111. }
  112. // const orderType = (item as acceptOrderInfo).orderType
  113. return checkPermi(permit)
  114. }
  115. // 获取工单状态字典列表
  116. const loadStatusDictList = async (): Promise<void> => {
  117. try {
  118. const result = await getDictDataByType('gxt_work_order_status')
  119. const resultObj = result as UTSJSONObject
  120. if (resultObj['code'] == 200) {
  121. const data = resultObj['data'] as any[]
  122. const dictData: SysDictData[] = []
  123. if (data.length > 0) {
  124. for (let i = 0; i < data.length; i++) {
  125. const item = data[i] as UTSJSONObject
  126. // 只提取需要的字段
  127. const dictItem: SysDictData = {
  128. dictValue: item['dictValue'] as string | null,
  129. dictLabel: item['dictLabel'] as string | null,
  130. dictCode: null,
  131. dictSort: null,
  132. dictType: null,
  133. cssClass: null,
  134. listClass: null,
  135. isDefault: null,
  136. status: null,
  137. default: null,
  138. createTime: null,
  139. remark: null
  140. }
  141. dictData.push(dictItem)
  142. }
  143. }
  144. statusDictList.value = dictData
  145. dictLoaded.value = true
  146. }
  147. } catch (e: any) {
  148. console.error('获取工单状态字典失败:', e.message)
  149. dictLoaded.value = true
  150. }
  151. }
  152. // 加载列表数据
  153. const loadData = async (isRefresh: boolean | null): Promise<void> => {
  154. if (loading.value) {
  155. // 如果正在加载,直接重置刷新状态
  156. refreshing.value = false
  157. return
  158. }
  159. try {
  160. loading.value = true
  161. // 处理默认值
  162. const shouldRefresh = isRefresh != null ? isRefresh : false
  163. if (shouldRefresh) {
  164. page.value = 1
  165. }
  166. // 调用 API,传递关键字参数
  167. const searchKeyword = keyword.value.length > 0 ? keyword.value : null
  168. const result = await pendingList(page.value, pageSize, searchKeyword)
  169. // 提取响应数据
  170. const resultObj = result as UTSJSONObject
  171. const code = resultObj['code'] as number
  172. const responseData = resultObj['rows'] as any[]
  173. const responseTotal = resultObj['total'] as number
  174. if (code == 200) {
  175. // 将 any[] 转换为 acceptOrderInfo[]
  176. const newData: acceptOrderInfo[] = []
  177. for (let i = 0; i < responseData.length; i++) {
  178. const item = responseData[i] as UTSJSONObject
  179. const orderItem: acceptOrderInfo = {
  180. orderType: item['orderType'] as Number,
  181. id: item['id'] as Number,
  182. teamLeaderId: item['teamLeaderId'] != null ? (item['teamLeaderId'] as Number) : 0,
  183. acceptUserId: item['acceptUserId'] != null ? (item['acceptUserId'] as Number) : 0,
  184. teamLeaderName: item['teamLeaderName'] as string | null,
  185. acceptUserName: item['acceptUserName'] as string | null,
  186. acceptTime: item['acceptTime'] as string | null,
  187. assignTime: item['assignTime'] as string | null,
  188. assignUserName: item['assignUserName'] as string | null,
  189. status: (item['status']==null)?0:item['status'] as Number,
  190. workOrderProjectNo: item['workOrderProjectNo'] as string | null,
  191. workOrderStatus: item['workOrderStatus'] as string | null,
  192. gxtCenterId: item['gxtCenterId'] as Number | 0,
  193. gxtCenter: item['gxtCenter'] as string | null,
  194. pcsStationId: item['pcsStationId'] as Number | 0,
  195. pcsStationName: item['pcsStationName'] as string | null,
  196. pcsDeviceId: item['pcsDeviceId'] as Number | 0,
  197. pcsDeviceName: item['pcsDeviceName'] as string | null,
  198. brand: item['brand'] as string | null,
  199. model: item['model'] as string | null,
  200. createTime: item['createTime'] as string | null,
  201. suspendReason: item['suspendReason'] as string | null,
  202. rejectionReason: item['rejectionReason'] as string | null,
  203. updateTime: item['updateTime'] as string | null, // 新增字段
  204. workEndTime: item['workEndTime'] as string | null // 新增字段
  205. }
  206. newData.push(orderItem)
  207. }
  208. if (shouldRefresh) {
  209. dataList.value = newData
  210. } else {
  211. dataList.value = [...dataList.value, ...newData]
  212. }
  213. total.value = responseTotal
  214. hasMore.value = dataList.value.length < responseTotal
  215. } else {
  216. const msg = resultObj['msg'] as string | null
  217. uni.showToast({
  218. title: msg ?? '加载失败',
  219. icon: 'none'
  220. })
  221. }
  222. } catch (e: any) {
  223. uni.showToast({
  224. title: e.message ?? '加载失败',
  225. icon: 'none'
  226. })
  227. } finally {
  228. loading.value = false
  229. // #ifdef WEB
  230. // Web 平台立即重置
  231. refreshing.value = false
  232. // #endif
  233. // #ifndef WEB
  234. // App 平台延迟重置刷新状态,确保 UI 更新
  235. setTimeout(() => {
  236. refreshing.value = false
  237. }, 100)
  238. // #endif
  239. }
  240. // #ifdef WEB
  241. // Web 平台额外确保重置
  242. refreshing.value = false
  243. // #endif
  244. }
  245. // 辅助函数:从 any 类型提取属性
  246. const getOrderType = (item: any | null): string => {
  247. if (item == null) return ''
  248. const orderInfoItem = item as acceptOrderInfo
  249. return orderInfoItem.orderType == 1?"维修工单":"维保工单";
  250. }
  251. const getWorkOrderProjectNo = (item: any | null): string | null => {
  252. if (item == null) return ''
  253. const orderInfoItem = item as acceptOrderInfo
  254. return orderInfoItem.workOrderProjectNo
  255. }
  256. const getPcsDeviceName = (item: any | null): string | null=> {
  257. if (item == null) return ''
  258. const orderInfoItem = item as acceptOrderInfo
  259. return orderInfoItem.pcsDeviceName
  260. }
  261. // 根据状态显示不同的时间
  262. const getDisplayTime = (item: any | null): string|null => {
  263. if (item == null) return null
  264. const orderInfoItem = item as acceptOrderInfo
  265. // 如果是"待接单"状态,显示派单时间
  266. if (orderInfoItem.workOrderStatus == 'assigned') {
  267. return '下发时间:' + orderInfoItem.assignTime
  268. } else if(orderInfoItem.workOrderStatus == 'to_finish') {
  269. if(orderInfoItem.workEndTime != null) {
  270. return '结束时间:' + orderInfoItem.workEndTime
  271. }
  272. return '接单时间:' + orderInfoItem.acceptTime
  273. } else if(orderInfoItem.workOrderStatus == 'to_approve') {
  274. return '申请挂起时间:' + orderInfoItem.updateTime
  275. } else if(orderInfoItem.workOrderStatus == 'suspended') {
  276. return '审批通过时间:' + orderInfoItem.updateTime
  277. } else if(orderInfoItem.workOrderStatus == 'return' || orderInfoItem.workOrderStatus == 'accept_return') {
  278. return '退回时间:' + orderInfoItem.updateTime
  279. } else if(orderInfoItem.workOrderStatus == 'completed') {
  280. return '结单时间:' + orderInfoItem.updateTime
  281. }
  282. // 默认显示创建时间
  283. return '创建时间:' + orderInfoItem.createTime
  284. }
  285. const getWorkOrderStatus = (item: any | null): string | null => {
  286. if (item == null) return ''
  287. const orderInfoItem = item as acceptOrderInfo
  288. const rawStatus = orderInfoItem.workOrderStatus
  289. if (rawStatus==null) return ''
  290. // 如果字典尚未加载,返回原始值
  291. if (!dictLoaded.value) {
  292. return rawStatus
  293. }
  294. // 查找字典中对应的标签
  295. const dictItem = statusDictList.value.find(dict => dict.dictValue == rawStatus)
  296. return dictItem!=null ? dictItem.dictLabel : rawStatus
  297. }
  298. const getStatusClass = (item: any | null): string => {
  299. if (item == null) return ''
  300. const orderInfoItem = item as acceptOrderInfo
  301. const rawStatus = orderInfoItem.workOrderStatus
  302. if (rawStatus==null) return ''
  303. // const status = rawStatus
  304. // 返回对应的状态类名
  305. return `status-${rawStatus}`
  306. }
  307. // 下拉刷新
  308. const handleRefresh = async (): Promise<void> => {
  309. refreshing.value = true
  310. await loadData(true as boolean | null)
  311. }
  312. // 加载更多
  313. const loadMore = (): void => {
  314. if (!hasMore.value || loading.value) {
  315. return
  316. }
  317. page.value++
  318. loadData(false as boolean | null)
  319. }
  320. // 搜索
  321. const handleSearch = (): void => {
  322. page.value = 1
  323. loadData(true as boolean | null)
  324. }
  325. // 点击列表项
  326. const handleItemClick = (item: any | null): void => {
  327. if (item == null) return
  328. const orderItem = item as acceptOrderInfo
  329. if(orderItem.workOrderStatus == 'assigned') {
  330. uni.navigateTo({
  331. url: `/pages/order/detail/acceptIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  332. })
  333. } else if(orderItem.workOrderStatus == 'to_approve') {
  334. // 跳转到待审批页面
  335. uni.navigateTo({
  336. url: `/pages/order/detail/approveIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  337. })
  338. } else if(orderItem.workOrderStatus == 'suspended') {
  339. // 跳转到恢复页面
  340. uni.navigateTo({
  341. url: `/pages/order/detail/resumeIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  342. })
  343. } else {
  344. uni.navigateTo({
  345. url: `/pages/order/detail/index?id=${orderItem.id}&orderType=${orderItem.orderType}`
  346. })
  347. }
  348. }
  349. // 清空搜索
  350. const clearSearch = (): void => {
  351. keyword.value = ""
  352. page.value = 1
  353. loadData(true)
  354. }
  355. // 初始化
  356. onMounted(() => {
  357. loadStatusDictList()
  358. loadData(true as boolean | null)
  359. // 监听接单成功的事件,刷新列表
  360. uni.$on('refreshOrderList', () => {
  361. page.value = 1
  362. loadData(true)
  363. })
  364. })
  365. // 组件卸载前清理事件监听
  366. onBeforeUnmount(() => {
  367. refreshing.value = false
  368. loading.value = false
  369. // 移除事件监听
  370. uni.$off('refreshOrderList',{})
  371. })
  372. </script>
  373. <style lang="scss">
  374. .list-page {
  375. flex: 1;
  376. background-color: #e8f0f9;
  377. }
  378. .search-bar {
  379. padding: 20rpx 30rpx;
  380. background-color: #d7eafe;
  381. }
  382. .search-box {
  383. flex-direction: row;
  384. align-items: center;
  385. height: 72rpx;
  386. padding: 0 24rpx;
  387. background-color: #f5f5f5;
  388. border-radius: 36rpx;
  389. .search-icon {
  390. width: 32rpx;
  391. height: 32rpx;
  392. margin-right: 12rpx;
  393. }
  394. .search-input {
  395. flex: 1;
  396. font-size: 28rpx;
  397. color: #333333;
  398. }
  399. .clear-icon {
  400. margin-left: 12rpx;
  401. font-size: 28rpx;
  402. color: #999999;
  403. }
  404. }
  405. .list-item {
  406. margin: 24rpx 30rpx;
  407. background-color: #ffffff;
  408. border-radius: 16rpx;
  409. }
  410. .item-container {
  411. padding: 30rpx;
  412. }
  413. .item-header {
  414. flex-direction: row;
  415. align-items: center;
  416. margin-bottom: 16rpx;
  417. .item-title {
  418. flex: 1;
  419. font-size: 32rpx;
  420. color: #333333;
  421. font-weight: bold;
  422. }
  423. .detail-link {
  424. font-size: 28rpx;
  425. color: #999999;
  426. }
  427. }
  428. .item-header {
  429. flex-direction: row;
  430. align-items: flex-start;
  431. margin-bottom: 16rpx;
  432. .item-title {
  433. font-size: 30rpx;
  434. color: #333333;
  435. font-weight: bold;
  436. flex-wrap: wrap;
  437. flex: 0 1 80%;
  438. min-width: 0;
  439. }
  440. .info-value {
  441. font-size: 28rpx;
  442. color: #999999;
  443. margin-left: auto;
  444. flex: 0 0 auto;
  445. white-space: nowrap;
  446. }
  447. }
  448. .info-row {
  449. flex-direction: row;
  450. justify-content: space-between;
  451. align-items: center;
  452. .info-label {
  453. font-size: 26rpx;
  454. color: #666;
  455. }
  456. .info-value {
  457. font-size: 26rpx;
  458. }
  459. }
  460. .text-gray{
  461. font-size: 26rpx;
  462. color: #666;
  463. }
  464. .status-tag {
  465. padding: 8rpx 20rpx;
  466. border-radius: 20rpx;
  467. font-size: 24rpx;
  468. white-space: nowrap;
  469. margin-left: 20rpx;
  470. border: 1rpx solid;
  471. }
  472. /* 待接单 */
  473. .status-assigned {
  474. background-color: #ebf5ff;
  475. color: #409eff;
  476. border-color: #d8ebff;
  477. }
  478. /* 待结单 */
  479. .status-to_finish {
  480. background-color: #fff7e6;
  481. color: #fa8c16;
  482. border-color: #ffd591;
  483. }
  484. /* 待审批 */
  485. .status-to_approve {
  486. background-color: #fff7e6;
  487. color: #fa8c16;
  488. border-color: #ffd591;
  489. }
  490. /* 已挂起 */
  491. .status-suspended {
  492. background-color: #fff2f0;
  493. color: #ff4d4f;
  494. border-color: #ffccc7;
  495. }
  496. /* 已完成 */
  497. .status-completed {
  498. background-color: #f0f9eb;
  499. color: #5cb87a;
  500. border-color: #c2e7b0;
  501. }
  502. /* 待下发 */
  503. .status-to_issue {
  504. background-color: #f4f4f5;
  505. color: #909399;
  506. border-color: #e9e9eb;
  507. }
  508. /* 已归档 */
  509. .status-archived {
  510. background-color: #f0f9eb;
  511. color: #5cb87a;
  512. border-color: #c2e7b0;
  513. }
  514. /* 退回 */
  515. .status-return {
  516. background-color: #fff2f0;
  517. color: #ff4d4f;
  518. border-color: #ffccc7;
  519. }
  520. /* 退回 */
  521. .status-accept_return {
  522. background-color: #fff2f0;
  523. color: #ff4d4f;
  524. border-color: #ffccc7;
  525. }
  526. .btn-primary {
  527. z-index: 999;
  528. border-radius: 10rpx;
  529. font-size: 24rpx;
  530. white-space: nowrap;
  531. margin-left: 20rpx;
  532. background-color: #165DFF;
  533. line-height: 45rpx;
  534. color: #ffffff;
  535. }
  536. // /* 超时 */
  537. // .status-overdue {
  538. // background-color: #fff2f0;
  539. // color: #ff4d4f;
  540. // border-color: #ffccc7;
  541. // }
  542. </style>