almostOverdue.uvue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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 { almostOverdueList } 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 almostOverdueList(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. updateTime: item['updateTime'] as string | null, // 新增字段
  148. workEndTime: item['workEndTime'] as string | null // 新增字段
  149. }
  150. newData.push(orderItem)
  151. }
  152. if (shouldRefresh) {
  153. dataList.value = newData
  154. } else {
  155. dataList.value = [...dataList.value, ...newData]
  156. }
  157. total.value = responseTotal
  158. hasMore.value = dataList.value.length < responseTotal
  159. } else {
  160. const msg = resultObj['msg'] as string | null
  161. uni.showToast({
  162. title: msg ?? '加载失败',
  163. icon: 'none'
  164. })
  165. }
  166. } catch (e: any) {
  167. uni.showToast({
  168. title: e.message ?? '加载失败',
  169. icon: 'none'
  170. })
  171. } finally {
  172. loading.value = false
  173. // #ifdef WEB
  174. // Web 平台立即重置
  175. refreshing.value = false
  176. // #endif
  177. // #ifndef WEB
  178. // App 平台延迟重置刷新状态,确保 UI 更新
  179. setTimeout(() => {
  180. refreshing.value = false
  181. }, 100)
  182. // #endif
  183. }
  184. // #ifdef WEB
  185. // Web 平台额外确保重置
  186. refreshing.value = false
  187. // #endif
  188. }
  189. // 辅助函数:从 any 类型提取属性
  190. const getOrderType = (item: any | null): string => {
  191. if (item == null) return ''
  192. const orderInfoItem = item as acceptOrderInfo
  193. return orderInfoItem.orderType == 1?"维修工单":"维保工单";
  194. }
  195. const getWorkOrderProjectNo = (item: any | null): string | null => {
  196. if (item == null) return ''
  197. const orderInfoItem = item as acceptOrderInfo
  198. return orderInfoItem.workOrderProjectNo
  199. }
  200. const getPcsDeviceName = (item: any | null): string | null=> {
  201. if (item == null) return ''
  202. const orderInfoItem = item as acceptOrderInfo
  203. return orderInfoItem.pcsDeviceName
  204. }
  205. const getCreateTime = (item: any | null): string|null => {
  206. if (item == null) return null
  207. const orderInfoItem = item as acceptOrderInfo
  208. return orderInfoItem.createTime
  209. }
  210. const getWorkOrderStatus = (item: any | null): string | null => {
  211. if (item == null) return ''
  212. const orderInfoItem = item as acceptOrderInfo
  213. const rawStatus = orderInfoItem.workOrderStatus
  214. if (rawStatus==null) return ''
  215. // 如果字典尚未加载,返回原始值
  216. if (!dictLoaded.value) {
  217. return rawStatus
  218. }
  219. // 查找字典中对应的标签
  220. const dictItem = statusDictList.value.find(dict => dict.dictValue == rawStatus)
  221. return dictItem!=null ? dictItem.dictLabel : rawStatus
  222. }
  223. const getStatusClass = (item: any | null): string => {
  224. if (item == null) return ''
  225. const orderInfoItem = item as acceptOrderInfo
  226. const rawStatus = orderInfoItem.workOrderStatus
  227. if (rawStatus==null) return ''
  228. // const status = rawStatus
  229. // 返回对应的状态类名
  230. return `status-${rawStatus}`
  231. }
  232. // 下拉刷新
  233. const handleRefresh = async (): Promise<void> => {
  234. refreshing.value = true
  235. await loadData(true as boolean | null)
  236. }
  237. // 加载更多
  238. const loadMore = (): void => {
  239. if (!hasMore.value || loading.value) {
  240. return
  241. }
  242. page.value++
  243. loadData(false as boolean | null)
  244. }
  245. // 搜索
  246. const handleSearch = (): void => {
  247. page.value = 1
  248. console.log("======搜索=====" + keyword.value)
  249. loadData(true as boolean | null)
  250. }
  251. // 点击列表项
  252. const handleItemClick = (item: any | null, index: number): void => {
  253. if (item == null) return
  254. const orderItem = item as acceptOrderInfo
  255. // 跳转到工单详情页
  256. uni.navigateTo({
  257. url: `/pages/order/detail/index?id=${orderItem.id}&orderType=${orderItem.orderType}`
  258. })
  259. }
  260. // 清空搜索
  261. const clearSearch = (): void => {
  262. keyword.value = ""
  263. page.value = 1
  264. loadData(true)
  265. }
  266. // 初始化
  267. onMounted(() => {
  268. loadStatusDictList()
  269. loadData(true as boolean | null)
  270. })
  271. // 组件卸载前清理事件监听
  272. onBeforeUnmount(() => {
  273. refreshing.value = false
  274. loading.value = false
  275. })
  276. </script>
  277. <style lang="scss">
  278. .list-page {
  279. flex: 1;
  280. background-color: #e8f0f9;
  281. }
  282. .search-bar {
  283. padding: 20rpx 30rpx;
  284. background-color: #d7eafe;
  285. }
  286. .search-box {
  287. flex-direction: row;
  288. align-items: center;
  289. height: 72rpx;
  290. padding: 0 24rpx;
  291. background-color: #f5f5f5;
  292. border-radius: 36rpx;
  293. .search-icon {
  294. width: 32rpx;
  295. height: 32rpx;
  296. margin-right: 12rpx;
  297. }
  298. .search-input {
  299. flex: 1;
  300. font-size: 28rpx;
  301. color: #333333;
  302. }
  303. .clear-icon {
  304. margin-left: 12rpx;
  305. font-size: 28rpx;
  306. color: #999999;
  307. }
  308. }
  309. .list-item {
  310. margin: 24rpx 30rpx;
  311. background-color: #ffffff;
  312. border-radius: 16rpx;
  313. }
  314. .item-container {
  315. padding: 30rpx;
  316. }
  317. .item-header {
  318. flex-direction: row;
  319. align-items: center;
  320. margin-bottom: 16rpx;
  321. .item-title {
  322. flex: 1;
  323. font-size: 32rpx;
  324. color: #333333;
  325. font-weight: bold;
  326. }
  327. .detail-link {
  328. font-size: 28rpx;
  329. color: #999999;
  330. }
  331. }
  332. .item-header {
  333. flex-direction: row;
  334. align-items: flex-start;
  335. margin-bottom: 16rpx;
  336. .item-title {
  337. font-size: 30rpx;
  338. color: #333333;
  339. font-weight: bold;
  340. flex-wrap: wrap;
  341. flex: 0 1 80%;
  342. min-width: 0;
  343. }
  344. .info-value {
  345. font-size: 28rpx;
  346. color: #999999;
  347. margin-left: auto;
  348. flex: 0 0 auto;
  349. white-space: nowrap;
  350. }
  351. }
  352. .info-row {
  353. flex-direction: row;
  354. justify-content: space-between;
  355. align-items: center;
  356. .info-label {
  357. font-size: 26rpx;
  358. color: #666;
  359. }
  360. .info-value {
  361. font-size: 26rpx;
  362. }
  363. }
  364. .text-gray{
  365. font-size: 26rpx;
  366. color: #666;
  367. }
  368. .status-tag {
  369. padding: 8rpx 20rpx;
  370. border-radius: 20rpx;
  371. font-size: 24rpx;
  372. white-space: nowrap;
  373. margin-left: 20rpx;
  374. border: 1rpx solid;
  375. }
  376. /* 待接单 */
  377. .status-assigned {
  378. background-color: #ebf5ff;
  379. color: #409eff;
  380. border-color: #d8ebff;
  381. }
  382. /* 待结单 */
  383. .status-to_finish {
  384. background-color: #fff7e6;
  385. color: #fa8c16;
  386. border-color: #ffd591;
  387. }
  388. /* 待审批 */
  389. .status-to_approve {
  390. background-color: #fff7e6;
  391. color: #fa8c16;
  392. border-color: #ffd591;
  393. }
  394. /* 已挂起 */
  395. .status-suspended {
  396. background-color: #fff2f0;
  397. color: #ff4d4f;
  398. border-color: #ffccc7;
  399. }
  400. /* 已完成 */
  401. .status-completed {
  402. background-color: #f0f9eb;
  403. color: #5cb87a;
  404. border-color: #c2e7b0;
  405. }
  406. /* 待下发 */
  407. .status-to_issue {
  408. background-color: #f4f4f5;
  409. color: #909399;
  410. border-color: #e9e9eb;
  411. }
  412. /* 已归档 */
  413. .status-archived {
  414. background-color: #f0f9eb;
  415. color: #5cb87a;
  416. border-color: #c2e7b0;
  417. }
  418. </style>