index.uvue 19 KB

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