approveOrder.uvue 20 KB

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