pendingOrder.uvue 18 KB

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