overdue.uvue 14 KB

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