| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528 |
- <template>
- <uni-navbar-lite :showLeft=true title="超时工单"></uni-navbar-lite>
- <view class="list-page">
- <!-- 搜索栏 -->
- <view class="search-bar">
- <view class="search-box">
- <image class="search-icon" src="/static/images/workbench/list/1.png" mode="aspectFit"></image>
- <input class="search-input" type="text" placeholder="搜索工单编码、风机编号" v-model="keyword" @confirm="handleSearch" @blur="handleSearch" />
- <text v-if="keyword.length > 0" class="clear-icon" @click="clearSearch">✕</text>
- </view>
- </view>
- <!-- 列表内容 -->
- <common-list
- :dataList="dataList"
- :loading="loading"
- :refreshing="refreshing"
- :hasMore="hasMore"
- @refresh="handleRefresh"
- @loadMore="loadMore"
- @itemClick="handleItemClick"
- >
- <template #default="{ item, index }">
- <view class="list-item">
- <view class="item-container">
- <view class="item-header">
- <text class="item-title">{{ getWorkOrderProjectNo(item) }}-{{ getPcsDeviceName(item) }}{{ getOrderType(item) }}</text>
- <text class="status-tag" :class="getStatusClass(item)">{{ getWorkOrderStatus(item) }}</text>
- </view>
- <view class="info-row">
- <view class="info-label">
- <text class="text-gray">{{ getCreateTime(item) }}</text>
- </view>
- <view class="info-value">
- <view
- v-if="canHandleOrder(item)"
- class="btn-primary info-value"
- @click.stop="handleItemClick(item)"
- >
- <text class="btn-text">接单</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- </common-list>
- </view>
- </template>
- <script setup lang="uts">
- import { ref, onBeforeUnmount, onMounted } from 'vue'
- import type { acceptOrderInfo } from '../../types/order'
- import type { SysDictData } from '../../types/dict'
- import { overdueList } from '../../api/order/list'
- import { getDictDataByType } from '../../api/dict/index'
- import {checkPermi} from '../../utils/storage'
- // 列表数据
- const dataList = ref<acceptOrderInfo[]>([])
- let keyword = ref<string>("")
- const page = ref<number>(1)
- const pageSize: number = 10
- const hasMore = ref<boolean>(true)
- const loading = ref<boolean>(false)
- const refreshing = ref<boolean>(false)
- const total = ref<number>(0)
- const statusDictList = ref<SysDictData[]>([]) // 工单状态字典列表
- // 添加字典加载状态
- const dictLoaded = ref<boolean>(false)
-
- // 方法:判断当前工单是否显示操作按钮(基于 orderType)
- const canHandleOrder = (item: any | null): boolean => {
- if (item == null) return false
- let permit: string[] = []
- const orderItem = item as acceptOrderInfo
- // 接单
- permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:accept'] : ['gxt:repairOrder:accept']
- return checkPermi(permit)
- }
- // 获取工单状态字典列表
- const loadStatusDictList = async (): Promise<void> => {
- try {
- const result = await getDictDataByType('gxt_work_order_status')
- const resultObj = result as UTSJSONObject
- if (resultObj['code'] == 200) {
- const data = resultObj['data'] as any[]
- const dictData: SysDictData[] = []
- if (data.length > 0) {
- for (let i = 0; i < data.length; i++) {
- const item = data[i] as UTSJSONObject
- // 只提取需要的字段
- const dictItem: SysDictData = {
- dictValue: item['dictValue'] as string | null,
- dictLabel: item['dictLabel'] as string | null,
- dictCode: null,
- dictSort: null,
- dictType: null,
- cssClass: null,
- listClass: null,
- isDefault: null,
- status: null,
- default: null,
- createTime: null,
- remark: null
- }
- dictData.push(dictItem)
- }
- }
- statusDictList.value = dictData
- dictLoaded.value = true
- }
- } catch (e: any) {
- console.error('获取工单状态字典失败:', e.message)
- dictLoaded.value = true
- }
- }
- // 加载列表数据
- const loadData = async (isRefresh: boolean | null): Promise<void> => {
- if (loading.value) {
- // 如果正在加载,直接重置刷新状态
- refreshing.value = false
- return
- }
- try {
- loading.value = true
- // 处理默认值
- const shouldRefresh = isRefresh != null ? isRefresh : false
- if (shouldRefresh) {
- page.value = 1
- }
- console.log("searchKeyword===" + keyword.value)
- // 调用 API,传递关键字参数
- const searchKeyword = keyword.value.length > 0 ? keyword.value : null
- const result = await overdueList(page.value, pageSize, searchKeyword)
- // 提取响应数据
- const resultObj = result as UTSJSONObject
- const code = resultObj['code'] as number
- const responseData = resultObj['rows'] as any[]
- const responseTotal = resultObj['total'] as number
- if (code == 200) {
- // 将 any[] 转换为 acceptOrderInfo[]
- const newData: acceptOrderInfo[] = []
- for (let i = 0; i < responseData.length; i++) {
- const item = responseData[i] as UTSJSONObject
- const orderItem: acceptOrderInfo = {
- orderType: item['orderType'] as Number,
- id: item['id'] as Number,
- teamLeaderId: item['teamLeaderId'] != null ? (item['teamLeaderId'] as Number) : 0,
- acceptUserId: item['acceptUserId'] != null ? (item['acceptUserId'] as Number) : 0,
- teamLeaderName: item['teamLeaderName'] as string | null,
- acceptUserName: item['acceptUserName'] as string | null,
- acceptTime: item['acceptTime'] as string | null,
- assignTime: item['assignTime'] as string | null,
- assignUserName: item['assignUserName'] as string | null,
- status: (item['status']==null)?0:item['status'] as Number,
- workOrderProjectNo: item['workOrderProjectNo'] as string | null,
- workOrderStatus: item['workOrderStatus'] as string | null,
- gxtCenterId: item['gxtCenterId'] as Number | 0,
- gxtCenter: item['gxtCenter'] as string | null,
- pcsStationId: item['pcsStationId'] as Number | 0,
- pcsStationName: item['pcsStationName'] as string | null,
- pcsDeviceId: item['pcsDeviceId'] as Number | 0,
- pcsDeviceName: item['pcsDeviceName'] as string | null,
- brand: item['brand'] as string | null,
- model: item['model'] as string | null,
- createTime: item['createTime'] as string | null,
- suspendReason: item['suspendReason'] as string | null,
- rejectionReason: item['rejectionReason'] as string | null,
- updateTime: item['updateTime'] as string | null, // 新增字段
- workEndTime: item['workEndTime'] as string | null // 新增字段
- }
- newData.push(orderItem)
- }
- if (shouldRefresh) {
- dataList.value = newData
- } else {
- dataList.value = [...dataList.value, ...newData]
- }
- total.value = responseTotal
- hasMore.value = dataList.value.length < responseTotal
- } else {
- const msg = resultObj['msg'] as string | null
- uni.showToast({
- title: msg ?? '加载失败',
- icon: 'none'
- })
- }
- } catch (e: any) {
- uni.showToast({
- title: e.message ?? '加载失败',
- icon: 'none'
- })
- } finally {
- loading.value = false
- // #ifdef WEB
- // Web 平台立即重置
- refreshing.value = false
- // #endif
- // #ifndef WEB
- // App 平台延迟重置刷新状态,确保 UI 更新
- setTimeout(() => {
- refreshing.value = false
- }, 100)
- // #endif
- }
- // #ifdef WEB
- // Web 平台额外确保重置
- refreshing.value = false
- // #endif
- }
- // 辅助函数:从 any 类型提取属性
- const getOrderType = (item: any | null): string => {
- if (item == null) return ''
- const orderInfoItem = item as acceptOrderInfo
- return orderInfoItem.orderType == 1?"维修工单":"维保工单";
- }
- const getWorkOrderProjectNo = (item: any | null): string | null => {
- if (item == null) return ''
- const orderInfoItem = item as acceptOrderInfo
- return orderInfoItem.workOrderProjectNo
- }
- const getPcsDeviceName = (item: any | null): string | null=> {
- if (item == null) return ''
- const orderInfoItem = item as acceptOrderInfo
- return orderInfoItem.pcsDeviceName
- }
- const getCreateTime = (item: any | null): string|null => {
- if (item == null) return null
- const orderInfoItem = item as acceptOrderInfo
- return "下发时间:" + orderInfoItem.assignTime
- }
- const getWorkOrderStatus = (item: any | null): string | null => {
- if (item == null) return ''
- const orderInfoItem = item as acceptOrderInfo
- const rawStatus = orderInfoItem.workOrderStatus
- if (rawStatus==null) return ''
- // 如果字典尚未加载,返回原始值
- if (!dictLoaded.value) {
- return rawStatus
- }
- // 查找字典中对应的标签
- const dictItem = statusDictList.value.find(dict => dict.dictValue == rawStatus)
- return dictItem!=null ? dictItem.dictLabel : rawStatus
- }
- const getStatusClass = (item: any | null): string => {
- if (item == null) return ''
- const orderInfoItem = item as acceptOrderInfo
- const rawStatus = orderInfoItem.workOrderStatus
- if (rawStatus==null) return ''
- // const status = rawStatus
- // 返回对应的状态类名
- return `status-${rawStatus}`
- }
- // 下拉刷新
- const handleRefresh = async (): Promise<void> => {
- refreshing.value = true
- await loadData(true as boolean | null)
- }
- // 加载更多
- const loadMore = (): void => {
- if (!hasMore.value || loading.value) {
- return
- }
- page.value++
- loadData(false as boolean | null)
- }
- // 搜索
- const handleSearch = (): void => {
- page.value = 1
- console.log("======搜索=====" + keyword.value)
- loadData(true as boolean | null)
- }
- // 点击列表项
- const handleItemClick = (item: any | null): void => {
- if (item == null) return
- const orderItem = item as acceptOrderInfo
- // 跳转到工单详情页
- uni.navigateTo({
- url: `/pages/order/detail/acceptIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
- })
- }
- // 清空搜索
- const clearSearch = (): void => {
- keyword.value = ""
- page.value = 1
- loadData(true)
- }
- // 初始化
- onMounted(() => {
- loadStatusDictList()
- loadData(true as boolean | null)
- // 监听接单成功的事件,刷新列表
- uni.$on('refreshOrderList', () => {
- page.value = 1
- loadData(true)
- })
- })
- // 组件卸载前清理事件监听
- onBeforeUnmount(() => {
- refreshing.value = false
- loading.value = false
- // 移除事件监听
- uni.$off('refreshOrderList',{})
- })
- </script>
- <style lang="scss">
- .list-page {
- flex: 1;
- background-color: #e8f0f9;
- }
- .search-bar {
- padding: 20rpx 30rpx;
- background-color: #d7eafe;
- }
- .search-box {
- flex-direction: row;
- align-items: center;
- height: 72rpx;
- padding: 0 24rpx;
- background-color: #f5f5f5;
- border-radius: 36rpx;
- .search-icon {
- width: 32rpx;
- height: 32rpx;
- margin-right: 12rpx;
- }
- .search-input {
- flex: 1;
- font-size: 28rpx;
- color: #333333;
- }
- .clear-icon {
- margin-left: 12rpx;
- font-size: 28rpx;
- color: #999999;
- }
- }
- .list-item {
- margin: 24rpx 30rpx;
- background-color: #ffffff;
- border-radius: 16rpx;
- }
- .item-container {
- padding: 30rpx;
- }
- .item-header {
- flex-direction: row;
- align-items: center;
- margin-bottom: 16rpx;
- .item-title {
- flex: 1;
- font-size: 32rpx;
- color: #333333;
- font-weight: bold;
- }
- .detail-link {
- font-size: 28rpx;
- color: #999999;
- }
- }
- .item-header {
- flex-direction: row;
- align-items: flex-start;
- margin-bottom: 16rpx;
- .item-title {
- font-size: 30rpx;
- color: #333333;
- font-weight: bold;
- flex-wrap: wrap;
- flex: 0 1 80%;
- min-width: 0;
- }
- .info-value {
- font-size: 28rpx;
- color: #999999;
- margin-left: auto;
- flex: 0 0 auto;
- white-space: nowrap;
- }
- }
- .info-row {
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- .info-label {
- font-size: 26rpx;
- color: #666;
- }
- .info-value {
- font-size: 26rpx;
- }
- }
- .text-gray{
- font-size: 26rpx;
- color: #666;
- }
- .status-tag {
- padding: 8rpx 20rpx;
- border-radius: 20rpx;
- font-size: 24rpx;
- white-space: nowrap;
- margin-left: 20rpx;
- border: 1rpx solid;
- }
- /* 待接单 */
- .status-assigned {
- background-color: #ebf5ff;
- color: #409eff;
- border-color: #d8ebff;
- }
- /* 待结单 */
- .status-to_finish {
- background-color: #fff7e6;
- color: #fa8c16;
- border-color: #ffd591;
- }
- /* 待审批 */
- .status-to_approve {
- background-color: #fff7e6;
- color: #fa8c16;
- border-color: #ffd591;
- }
- /* 已挂起 */
- .status-suspended {
- background-color: #fff2f0;
- color: #ff4d4f;
- border-color: #ffccc7;
- }
- /* 已完成 */
- .status-completed {
- background-color: #f0f9eb;
- color: #5cb87a;
- border-color: #c2e7b0;
- }
- /* 待下发 */
- .status-to_issue {
- background-color: #f4f4f5;
- color: #909399;
- border-color: #e9e9eb;
- }
- /* 已归档 */
- .status-archived {
- background-color: #f0f9eb;
- color: #5cb87a;
- border-color: #c2e7b0;
- }
- .btn-primary {
- z-index: 999;
- border-radius: 10rpx;
- font-size: 24rpx;
- // white-space: nowrap;
- margin-left: 20rpx;
- background-color: #165DFF;
- line-height: 45rpx;
- color: #ffffff;
- .btn-text{
- color: #ffffff;
- font-size: 24rpx;
- padding: 5px 15px;
- }
- }
- // /* 超时 */
- // .status-overdue {
- // background-color: #fff2f0;
- // color: #ff4d4f;
- // border-color: #ffccc7;
- // }
- </style>
|