overdue.uvue 20 KB

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