index.uvue 20 KB

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