index.uvue 17 KB

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