pendingOrder.uvue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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 { getOrderList } 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 getOrderList(page.value, pageSize, searchKeyword, "pending")
  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. if(orderItem.workOrderStatus == 'assigned') {
  254. uni.navigateTo({
  255. url: `/pages/order/detail/acceptIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  256. })
  257. } else if(orderItem.workOrderStatus == 'to_approve') {
  258. // 跳转到待审批页面
  259. uni.navigateTo({
  260. url: `/pages/order/detail/approveIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  261. })
  262. } else if(orderItem.workOrderStatus == 'suspended') {
  263. // 跳转到恢复页面
  264. uni.navigateTo({
  265. url: `/pages/order/detail/resumeIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  266. })
  267. } else {
  268. uni.navigateTo({
  269. url: `/pages/order/detail/index?id=${orderItem.id}&orderType=${orderItem.orderType}`
  270. })
  271. }
  272. }
  273. // 清空搜索
  274. const clearSearch = (): void => {
  275. keyword.value = ""
  276. page.value = 1
  277. loadData(true)
  278. }
  279. // 初始化
  280. onMounted(() => {
  281. loadStatusDictList()
  282. loadData(true as boolean | null)
  283. // 监听接单成功的事件,刷新列表
  284. uni.$on('refreshOrderList', () => {
  285. page.value = 1
  286. loadData(true)
  287. })
  288. })
  289. // 组件卸载前清理事件监听
  290. onBeforeUnmount(() => {
  291. refreshing.value = false
  292. loading.value = false
  293. // 移除事件监听
  294. uni.$off('refreshOrderList',{})
  295. })
  296. </script>
  297. <style lang="scss">
  298. .list-page {
  299. flex: 1;
  300. background-color: #e8f0f9;
  301. }
  302. .search-bar {
  303. padding: 20rpx 30rpx;
  304. background-color: #d7eafe;
  305. }
  306. .search-box {
  307. flex-direction: row;
  308. align-items: center;
  309. height: 72rpx;
  310. padding: 0 24rpx;
  311. background-color: #f5f5f5;
  312. border-radius: 36rpx;
  313. .search-icon {
  314. width: 32rpx;
  315. height: 32rpx;
  316. margin-right: 12rpx;
  317. }
  318. .search-input {
  319. flex: 1;
  320. font-size: 28rpx;
  321. color: #333333;
  322. }
  323. .clear-icon {
  324. margin-left: 12rpx;
  325. font-size: 28rpx;
  326. color: #999999;
  327. }
  328. }
  329. .list-item {
  330. margin: 24rpx 30rpx;
  331. background-color: #ffffff;
  332. border-radius: 16rpx;
  333. }
  334. .item-container {
  335. padding: 30rpx;
  336. }
  337. .item-header {
  338. flex-direction: row;
  339. align-items: center;
  340. margin-bottom: 16rpx;
  341. .item-title {
  342. flex: 1;
  343. font-size: 32rpx;
  344. color: #333333;
  345. font-weight: bold;
  346. }
  347. .detail-link {
  348. font-size: 28rpx;
  349. color: #999999;
  350. }
  351. }
  352. .item-header {
  353. flex-direction: row;
  354. align-items: flex-start;
  355. margin-bottom: 16rpx;
  356. .item-title {
  357. font-size: 30rpx;
  358. color: #333333;
  359. font-weight: bold;
  360. flex-wrap: wrap;
  361. flex: 0 1 80%;
  362. min-width: 0;
  363. }
  364. .info-value {
  365. font-size: 28rpx;
  366. color: #999999;
  367. margin-left: auto;
  368. flex: 0 0 auto;
  369. white-space: nowrap;
  370. }
  371. }
  372. .info-row {
  373. flex-direction: row;
  374. justify-content: space-between;
  375. align-items: center;
  376. .info-label {
  377. font-size: 26rpx;
  378. color: #666;
  379. }
  380. .info-value {
  381. font-size: 26rpx;
  382. }
  383. }
  384. .text-gray{
  385. font-size: 26rpx;
  386. color: #666;
  387. }
  388. .status-tag {
  389. padding: 8rpx 20rpx;
  390. border-radius: 20rpx;
  391. font-size: 24rpx;
  392. white-space: nowrap;
  393. margin-left: 20rpx;
  394. border: 1rpx solid;
  395. }
  396. /* 待接单 */
  397. .status-assigned {
  398. background-color: #ebf5ff;
  399. color: #409eff;
  400. border-color: #d8ebff;
  401. }
  402. /* 待结单 */
  403. .status-to_finish {
  404. background-color: #fff7e6;
  405. color: #fa8c16;
  406. border-color: #ffd591;
  407. }
  408. /* 待审批 */
  409. .status-to_approve {
  410. background-color: #fff7e6;
  411. color: #fa8c16;
  412. border-color: #ffd591;
  413. }
  414. /* 已挂起 */
  415. .status-suspended {
  416. background-color: #fff2f0;
  417. color: #ff4d4f;
  418. border-color: #ffccc7;
  419. }
  420. /* 已完成 */
  421. .status-completed {
  422. background-color: #f0f9eb;
  423. color: #5cb87a;
  424. border-color: #c2e7b0;
  425. }
  426. /* 待下发 */
  427. .status-to_issue {
  428. background-color: #f4f4f5;
  429. color: #909399;
  430. border-color: #e9e9eb;
  431. }
  432. /* 已归档 */
  433. .status-archived {
  434. background-color: #f0f9eb;
  435. color: #5cb87a;
  436. border-color: #c2e7b0;
  437. }
  438. // /* 超时 */
  439. // .status-overdue {
  440. // background-color: #fff2f0;
  441. // color: #ff4d4f;
  442. // border-color: #ffccc7;
  443. // }
  444. </style>