overdue.uvue 15 KB

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