index.uvue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. </view>
  10. </view>
  11. <view class="status-bar">
  12. <view class="status-box">
  13. <text class="status-txt" :class="{'stauts-sel':ix == 0}">全部</text>
  14. <text class="status-txt" :class="{'stauts-sel':ix == 1}">待接单</text>
  15. </view>
  16. </view>
  17. <!-- 列表内容 -->
  18. <common-list
  19. :dataList="dataList"
  20. :loading="loading"
  21. :refreshing="refreshing"
  22. :hasMore="hasMore"
  23. @refresh="handleRefresh"
  24. @loadMore="loadMore"
  25. @itemClick="handleItemClick"
  26. >
  27. <template #default="{ item, index }">
  28. <view class="list-item">
  29. <view class="item-container">
  30. <view class="item-header">
  31. <image class="location-icon" src="/static/images/workbench/list/2.png" mode="aspectFit"></image>
  32. <text class="item-title">{{ getOrderType(item) }}</text>
  33. <text class="detail-link">类型 ›</text>
  34. </view>
  35. <text class="item-address">{{ getWorkOrderProjectNo(item) }}</text>
  36. <view class="item-info">
  37. <view class="info-row">
  38. <view class="info-item">
  39. <text class="info-label">工单状态</text>
  40. <text class="info-value">{{ getWorkOrderStatus(item) }}</text>
  41. </view>
  42. <view class="info-item">
  43. <text class="info-label">场站</text>
  44. <text class="info-value">{{ getPcsStationName(item) }}</text>
  45. </view>
  46. </view>
  47. <view class="info-row">
  48. <view class="info-item">
  49. <text class="info-label">设备名</text>
  50. <text class="info-value">{{ getPcsDeviceName(item) }}</text>
  51. </view>
  52. <view class="info-item">
  53. <text class="info-label">派单时间</text>
  54. <text class="info-value">{{ getAssignTime(item) }}</text>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. </common-list>
  62. <custom-tabbar :current="1" />
  63. </view>
  64. </template>
  65. <script setup lang="uts">
  66. import { ref, computed, onBeforeUnmount } from 'vue'
  67. import type { orderInfo, orderListResponse } from '../../types/order'
  68. import { getOrderList } from '../../api/order/list'
  69. // 列表数据
  70. const dataList = ref<orderInfo[]>([])
  71. const keyword = ref<string>("")
  72. const page = ref<number>(1)
  73. const pageSize: number = 10
  74. const hasMore = ref<boolean>(true)
  75. const loading = ref<boolean>(false)
  76. const refreshing = ref<boolean>(false)
  77. const total = ref<number>(0)
  78. const ix = ref<number>(1)
  79. // 辅助函数:从 any 类型提取属性
  80. const getOrderType = (item: any | null): string => {
  81. if (item == null) return ''
  82. const orderInfoItem = item as orderInfo
  83. return orderInfoItem.orderType == 1?"维修工单":"维保工单";
  84. }
  85. const getWorkOrderProjectNo = (item: any | null): string | null => {
  86. if (item == null) return ''
  87. const orderInfoItem = item as orderInfo
  88. return orderInfoItem.workOrderProjectNo
  89. }
  90. const getWorkOrderStatus = (item: any | null): string | null => {
  91. if (item == null) return ''
  92. const orderInfoItem = item as orderInfo
  93. return orderInfoItem.workOrderStatus
  94. }
  95. const getPcsStationName = (item: any | null): string | null=> {
  96. if (item == null) return ''
  97. const orderInfoItem = item as orderInfo
  98. return orderInfoItem.pcsStationName
  99. }
  100. const getPcsDeviceName = (item: any | null): string | null=> {
  101. if (item == null) return ''
  102. const orderInfoItem = item as orderInfo
  103. return orderInfoItem.pcsDeviceName
  104. }
  105. const getAssignTime = (item: any | null): string|null => {
  106. if (item == null) return null
  107. const orderInfoItem = item as orderInfo
  108. return orderInfoItem.assignTime
  109. }
  110. // 加载列表数据
  111. const loadData = async (isRefresh: boolean | null): Promise<void> => {
  112. if (loading.value) {
  113. // 如果正在加载,直接重置刷新状态
  114. refreshing.value = false
  115. return
  116. }
  117. try {
  118. loading.value = true
  119. // 处理默认值
  120. const shouldRefresh = isRefresh != null ? isRefresh : false
  121. if (shouldRefresh) {
  122. page.value = 1
  123. }
  124. // 调用 API
  125. const searchKeyword = keyword.value.length > 0 ? keyword.value : null
  126. const result = await getOrderList(page.value, pageSize, searchKeyword)
  127. // 提取响应数据
  128. const resultObj = result as UTSJSONObject
  129. const code = resultObj['code'] as number
  130. const responseData = resultObj['rows'] as any[]
  131. const responseTotal = resultObj['total'] as number
  132. if (code == 200) {
  133. // 将 any[] 转换为 orderInfo[]
  134. const newData: orderInfo[] = []
  135. for (let i = 0; i < responseData.length; i++) {
  136. const item = responseData[i] as UTSJSONObject
  137. const orderItem: orderInfo = {
  138. orderType: item['orderType'] as Number,
  139. id: item['id'] as Number,
  140. teamLeaderName: item['teamLeaderName'] as string | '',
  141. acceptUserName: item['acceptUserName'] as string | '',
  142. acceptTime: item['acceptTime'] as string | null,
  143. assignTime: item['assignTime'] as string | null,
  144. assignUserName: item['assignUserName'] as string | null,
  145. status: (item['status']==null)?0:item['status'] as Number,
  146. workOrderProjectNo: item['workOrderProjectNo'] as string | null,
  147. workOrderStatus: item['workOrderStatus'] as string | null,
  148. gxtCenterId: item['gxtCenterId'] as Number | 0,
  149. gxtCenter: item['gxtCenter'] as string | null,
  150. pcsStationId: item['pcsStationId'] as Number | 0,
  151. pcsStationName: item['pcsStationName'] as string | null,
  152. pcsDeviceId: item['pcsDeviceId'] as Number | 0,
  153. pcsDeviceName: item['pcsDeviceName'] as string | null,
  154. brand: item['brand'] as string | null,
  155. model: item['model'] as string | null
  156. }
  157. newData.push(orderItem)
  158. }
  159. if (shouldRefresh) {
  160. dataList.value = newData
  161. } else {
  162. dataList.value = [...dataList.value, ...newData]
  163. }
  164. total.value = responseTotal
  165. hasMore.value = dataList.value.length < responseTotal
  166. } else {
  167. const msg = resultObj['msg'] as string | null
  168. uni.showToast({
  169. title: msg ?? '加载失败',
  170. icon: 'none'
  171. })
  172. }
  173. } catch (e: any) {
  174. uni.showToast({
  175. title: e.message ?? '加载失败',
  176. icon: 'none'
  177. })
  178. } finally {
  179. loading.value = false
  180. // #ifdef WEB
  181. // Web 平台立即重置
  182. refreshing.value = false
  183. // #endif
  184. // #ifndef WEB
  185. // App 平台延迟重置刷新状态,确保 UI 更新
  186. setTimeout(() => {
  187. refreshing.value = false
  188. }, 100)
  189. // #endif
  190. }
  191. // #ifdef WEB
  192. // Web 平台额外确保重置
  193. refreshing.value = false
  194. // #endif
  195. }
  196. // 下拉刷新
  197. const handleRefresh = async (): Promise<void> => {
  198. refreshing.value = true
  199. await loadData(true as boolean | null)
  200. }
  201. // 加载更多
  202. const loadMore = (): void => {
  203. if (!hasMore.value || loading.value) {
  204. return
  205. }
  206. page.value++
  207. loadData(false as boolean | null)
  208. }
  209. // 搜索
  210. const handleSearch = (): void => {
  211. page.value = 1
  212. loadData(true as boolean | null)
  213. }
  214. // 点击列表项
  215. const handleItemClick = (item: any | null, index: number): void => {
  216. if (item == null) return
  217. const contractorItem = item as ContractorInfo
  218. uni.navigateTo({
  219. url: `/pages/workbench/detail/index?id=${contractorItem.id}`
  220. })
  221. }
  222. // 组件卸载前清理
  223. onBeforeUnmount(() => {
  224. refreshing.value = false
  225. loading.value = false
  226. })
  227. // 初始化
  228. loadData(true as boolean | null)
  229. </script>
  230. <style lang="scss">
  231. .list-page {
  232. flex: 1;
  233. background-color: #e8f0f9;
  234. }
  235. .search-bar {
  236. padding: 20rpx 30rpx;
  237. background-color: #d7eafe;
  238. }
  239. .search-box {
  240. flex-direction: row;
  241. align-items: center;
  242. height: 72rpx;
  243. padding: 0 24rpx;
  244. background-color: #f5f5f5;
  245. border-radius: 36rpx;
  246. .search-icon {
  247. width: 32rpx;
  248. height: 32rpx;
  249. margin-right: 12rpx;
  250. }
  251. .search-input {
  252. flex: 1;
  253. font-size: 28rpx;
  254. color: #333333;
  255. }
  256. }
  257. .status-bar{
  258. padding-bottom: 10px;
  259. padding-left:30rpx;
  260. background-color: #d7eafe;
  261. }
  262. .status-box {
  263. flex-direction: row;
  264. align-items: center;
  265. height: 72rpx;
  266. flex: 1;
  267. .status-txt{
  268. padding: 8px;
  269. width: 70px;
  270. text-align: center;
  271. margin-right: 12rpx;
  272. border-radius: 36rpx;
  273. background-color: #fff;
  274. font-size: 28rpx;
  275. }
  276. .stauts-sel{
  277. background-color: blue;
  278. color: #fff;
  279. }
  280. }
  281. .list-item {
  282. margin: 24rpx 30rpx;
  283. background-color: #ffffff;
  284. border-radius: 16rpx;
  285. }
  286. .item-container {
  287. padding: 30rpx;
  288. }
  289. .item-header {
  290. flex-direction: row;
  291. align-items: center;
  292. margin-bottom: 16rpx;
  293. .location-icon {
  294. width: 32rpx;
  295. height: 32rpx;
  296. margin-right: 8rpx;
  297. }
  298. .item-title {
  299. flex: 1;
  300. font-size: 32rpx;
  301. color: #333333;
  302. font-weight: bold;
  303. }
  304. .detail-link {
  305. font-size: 28rpx;
  306. color: #999999;
  307. }
  308. }
  309. .item-address {
  310. font-size: 26rpx;
  311. color: #999999;
  312. margin-bottom: 20rpx;
  313. line-height: 40rpx;
  314. }
  315. .item-info {
  316. padding: 20rpx;
  317. background-color: #f8f9fa;
  318. border-radius: 8rpx;
  319. .info-row {
  320. flex-direction: row;
  321. margin-bottom: 16rpx;
  322. &:last-child {
  323. margin-bottom: 0;
  324. }
  325. .info-item {
  326. flex: 1;
  327. flex-direction: row;
  328. align-items: center;
  329. .info-label {
  330. font-size: 26rpx;
  331. color: #666666;
  332. margin-right: 8rpx;
  333. white-space: nowrap;
  334. }
  335. .info-value {
  336. flex: 1;
  337. font-size: 26rpx;
  338. color: #333333;
  339. }
  340. }
  341. }
  342. }
  343. </style>