index.uvue 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  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="scroll-view_H" direction="horizontal" :show-scrollbar="false">
  14. <view class="scroll-view-item_H uni-bg-red">
  15. <text class="status-txt" :class="{'stauts-sel': currentStatus === 'all'}" @click="switchStatus('all')">全部</text>
  16. </view>
  17. <!-- <view class="scroll-view-item_H uni-bg-green" v-if="checkPermi(['gxt:maintenance:order:edit','gxt:repairOrder:edit']) && !dealLoad">
  18. <text class="status-txt" :class="{'stauts-sel': currentStatus === 'to_issue,accept_return'}" @click="switchStatus('to_issue,accept_return')">待下发</text>
  19. </view> -->
  20. <view class="scroll-view-item_H uni-bg-green" v-if="checkPermi(['gxt:maintenance:order:accept','gxt:repairOrder:accept']) && !dealLoad">
  21. <text class="status-txt" :class="{'stauts-sel': currentStatus === 'assigned'}" @click="switchStatus('assigned')">待接单</text>
  22. </view>
  23. <view class="scroll-view-item_H" v-if="checkPermi(['gxt:maintenance:order:suspend','gxt:repairOrder:suspend']) && !dealLoad">
  24. <text class="status-txt" :class="{'stauts-sel': currentStatus === 'to_finish'}" @click="switchStatus('to_finish')">待结单</text>
  25. </view>
  26. <view class="scroll-view-item_H" v-if="checkPermi(['gxt:maintenance:order:approve','gxt:repairOrder:approve']) && !dealLoad">
  27. <text class="status-txt" :class="{'stauts-sel': currentStatus === 'to_approve'}" @click="switchStatus('to_approve')">待审批</text>
  28. </view>
  29. <view class="scroll-view-item_H" v-if="checkPermi(['gxt:maintenance:order:resume','gxt:repairOrder:resume']) && !dealLoad">
  30. <text class="status-txt" :class="{'stauts-sel': currentStatus === 'suspended'}" @click="switchStatus('suspended')">已挂起</text>
  31. </view>
  32. <view class="scroll-view-item_H" v-if="checkPermi(['gxt:maintenance:order:autoResume','gxt:repairOrder:autoResume']) && !dealLoad">
  33. <text class="status-txt" :class="{'stauts-sel': currentStatus === 'auto_suspend'}" @click="switchStatus('auto_suspend')">自动挂起</text>
  34. </view>
  35. <view class="scroll-view-item_H" v-if="checkPermi(['gxt:maintenance:order:restart','gxt:repairOrder:restart']) && !dealLoad">
  36. <text class="status-txt" :class="{'stauts-sel': currentStatus === 'completed'}" @click="switchStatus('completed')">已完成</text>
  37. </view>
  38. <view class="scroll-view-item_H" v-if="dealLoad">
  39. <text class="status-txt" :class="{'stauts-sel': currentStatus === 'pending'}" @click="switchStatus('pending')">待处理</text>
  40. </view>
  41. </scroll-view>
  42. </view>
  43. <!-- 列表内容 -->
  44. <common-list
  45. :dataList="dataList"
  46. :loading="loading"
  47. :refreshing="refreshing"
  48. :hasMore="hasMore"
  49. @refresh="handleRefresh"
  50. @loadMore="loadMore"
  51. @itemClick="handleView"
  52. >
  53. <template #default="{ item, index }">
  54. <view class="list-item">
  55. <view class="item-container">
  56. <view class="item-header">
  57. <text class="item-title">{{ getWorkOrderProjectNo(item) }}-{{ getPcsStationName(item) }}{{ getPcsDeviceName(item) }}{{ getOrderType(item) }}</text>
  58. <text class="status-tag" :class="getStatusClass(item)" >{{ getWorkOrderStatus(item) }}</text>
  59. <!-- <view class="status-view" :class="getStatusClass(item)"><text class="status-tag" :class="getStatusClass(item)" >{{ getWorkOrderStatus(item) }}</text></view> -->
  60. </view>
  61. <view class="info-row">
  62. <view class="info-label">
  63. <text class="text-gray">{{ getDisplayTime(item) }}</text>
  64. </view>
  65. </view>
  66. <view class="btn-group">
  67. <view
  68. v-if="(getOrderStatus(item) == 'assigned' || getOrderStatus(item) == 'return') && canHandleOrder(item,'accept')"
  69. class="btn-primary info-value"
  70. @click.stop="handleItemClick(item,'accept')"
  71. >
  72. <text class="btn-text">接单</text>
  73. </view>
  74. <view
  75. v-if="(getOrderStatus(item) == 'assigned' || getOrderStatus(item) == 'to_finish')
  76. && canHandleOrder(item,'shutdown') && (item as acceptOrderInfoExtend).pauseTime == null"
  77. class="btn-primary info-value"
  78. @click.stop="handleItemClick(item,'shutdown')"
  79. >
  80. <text class="btn-text">停机</text>
  81. </view>
  82. <view
  83. v-if="(getOrderStatus(item) == 'assigned' || getOrderStatus(item) == 'to_finish' || getOrderStatus(item) == 'completed')
  84. && canHandleOrder(item,'restart') && (item as acceptOrderInfoExtend).restartTime == null"
  85. class="btn-primary info-value"
  86. @click.stop="handleItemClick(item,'restart')"
  87. >
  88. <text class="btn-text">复运</text>
  89. </view>
  90. <view
  91. v-if="getOrderStatus(item) == 'to_approve' && canHandleOrder(item,'')"
  92. class="btn-primary info-value"
  93. @click.stop="handleItemClick(item,'')"
  94. >
  95. <text class="btn-text">审批</text>
  96. </view>
  97. <view
  98. v-if="getOrderStatus(item) == 'suspended' && canHandleOrder(item,'')"
  99. class="btn-primary info-value"
  100. @click.stop="handleItemClick(item,'')"
  101. >
  102. <text class="btn-text">恢复</text>
  103. </view>
  104. <view
  105. v-if="getOrderStatus(item) == 'auto_suspend' && canHandleOrder(item,'')"
  106. class="btn-primary info-value"
  107. @click.stop="handleItemClick(item,'')"
  108. >
  109. <text class="btn-text">恢复</text>
  110. </view>
  111. <view
  112. v-if="getOrderStatus(item) == 'return' && canHandleOrder(item,'acceptReturn')"
  113. class="btn-primary info-value"
  114. @click.stop="handleItemClick(item,'acceptReturn')"
  115. >
  116. <text class="btn-text">退回</text>
  117. </view>
  118. <view
  119. v-if="getOrderStatus(item) == 'assigned' && canHandleOrder(item,'acceptReturn')"
  120. class="btn-primary info-value"
  121. @click.stop="handleItemClick(item,'acceptReturn')"
  122. >
  123. <text class="btn-text">退回</text>
  124. </view>
  125. <view
  126. v-if="getOrderStatus(item) == 'to_finish' && canHandleOrder(item, 'return')"
  127. class="btn-primary info-value"
  128. @click.stop="handleItemClick(item, 'return')"
  129. >
  130. <text class="btn-text">退回</text>
  131. </view>
  132. <view
  133. v-if="getOrderStatus(item) == 'to_finish' && canHandleOrder(item, 'complete')"
  134. class="btn-primary info-value"
  135. @click.stop="handleItemClick(item, 'complete')"
  136. >
  137. <text class="btn-text">结单</text>
  138. </view>
  139. <view
  140. v-if="getOrderStatus(item) == 'to_finish' && canHandleOrder(item, 'suspend')"
  141. class="btn-primary info-value"
  142. @click.stop="handleItemClick(item, 'suspend')"
  143. >
  144. <text class="btn-text">挂起</text>
  145. </view>
  146. <view
  147. v-if="getOrderStatus(item) == 'to_finish' && canHandleOrder(item, 'resetStart')"
  148. class="btn-primary info-value"
  149. @click.stop="handleItemClick(item, 'resetStart')"
  150. >
  151. <text class="btn-text">复启</text>
  152. </view>
  153. </view>
  154. </view>
  155. </view>
  156. </template>
  157. </common-list>
  158. <custom-tabbar :current="1" :hide0="tabbar[0]" :hide1="tabbar[1]" :hide2="tabbar[2]" :hide3="tabbar[3]"/>
  159. </view>
  160. </template>
  161. <script setup lang="uts">
  162. import { ref, onBeforeUnmount, onMounted, reactive } from 'vue'
  163. // import type { acceptOrderInfo } from '../../types/order'
  164. import type { SysDictData, DictDataResponse } from '../../types/dict'
  165. import { getOrderList } from '../../api/order/list'
  166. import { getDictDataByType } from '../../api/dict/index'
  167. import {checkPermi, getUserInfo} from '../../utils/storage'
  168. type acceptOrderInfoExtend = {
  169. orderType: Number
  170. id: Number
  171. teamLeaderId: Number
  172. acceptUserId: Number
  173. teamLeaderName: string | null
  174. acceptUserName: string | null
  175. acceptTime: string | null
  176. assignTime: string | null
  177. assignUserName: string | null
  178. status: Number
  179. workOrderProjectNo: string | null
  180. workOrderStatus: string | null
  181. gxtCenterId: Number
  182. gxtCenter: string | null
  183. pcsStationId: Number
  184. pcsStationName: string | null
  185. pcsDeviceId: Number
  186. pcsDeviceName: string | null
  187. brand: string | null
  188. model: string | null
  189. createTime: string | null
  190. suspendReason: string | null
  191. rejectionReason: string | null
  192. updateTime: string | null
  193. workEndTime: string | null
  194. orderEntryType: string | null
  195. pauseTime: string | null
  196. restartTime: string | null
  197. }
  198. const userId = ref<string>("")
  199. const roles = ref<string>('')
  200. // 列表数据
  201. const dataList = ref<acceptOrderInfoExtend[]>([])
  202. let keyword = ref<string>("")
  203. const page = ref<number>(1)
  204. const pageSize: number = 10
  205. const hasMore = ref<boolean>(true)
  206. const loading = ref<boolean>(false)
  207. const refreshing = ref<boolean>(false)
  208. const total = ref<number>(0)
  209. let currentStatus = ref<string>('') // 添加状态管理
  210. const statusDictList = ref<SysDictData[]>([]) // 工单状态字典列表
  211. const tabbar = reactive([1,1,1,1])
  212. // 添加防重复请求的标志位(参考score/pending.uvue的实现)
  213. const isSearching = ref<boolean>(false)
  214. // 添加防重复刷新的标志
  215. const isRefreshing = ref<boolean>(false)
  216. // 添加刷新时间戳,用于防抖
  217. const lastRefreshTime = ref<number>(0)
  218. // 添加字典加载状态
  219. const dictLoaded = ref<boolean>(false)
  220. // 待处理工单加载
  221. const dealLoad = ref<boolean>(false)
  222. type StatusItem = {
  223. key: string,
  224. permis: string[],
  225. condition: () => boolean
  226. }
  227. const statusConfig: StatusItem[] = [
  228. { key: 'all', permis: ['gxt:order:all'], condition: () => !dealLoad.value },
  229. { key: 'assigned', permis: ['gxt:maintenance:order:accept','gxt:repairOrder:accept'], condition: () => !dealLoad.value },
  230. { key: 'to_finish', permis: ['gxt:maintenance:order:suspend','gxt:repairOrder:suspend'], condition: () => !dealLoad.value },
  231. { key: 'to_approve', permis: ['gxt:maintenance:order:approve','gxt:repairOrder:approve'], condition: () => !dealLoad.value },
  232. { key: 'suspended', permis: ['gxt:maintenance:order:resume','gxt:repairOrder:resume'], condition: () => !dealLoad.value },
  233. { key: 'completed', permis: ['gxt:maintenance:order:restart','gxt:repairOrder:restart'], condition: () => !dealLoad.value }
  234. ]
  235. const getOrderStatus = (item: any | null): string => {
  236. if (item == null) return ''
  237. const orderItem = item as acceptOrderInfoExtend
  238. return orderItem.workOrderStatus ?? ''
  239. }
  240. // 获取工单状态字典列表
  241. const loadStatusDictList = async (): Promise<void> => {
  242. try {
  243. const result = await getDictDataByType('gxt_work_order_status')
  244. const resultObj = result as UTSJSONObject
  245. if (resultObj['code'] == 200) {
  246. const data = resultObj['data'] as any[]
  247. const dictData: SysDictData[] = []
  248. if (data.length > 0) {
  249. for (let i = 0; i < data.length; i++) {
  250. const item = data[i] as UTSJSONObject
  251. // 只提取需要的字段
  252. const dictItem: SysDictData = {
  253. dictValue: item['dictValue'] as string | null,
  254. dictLabel: item['dictLabel'] as string | null,
  255. dictCode: null,
  256. dictSort: null,
  257. dictType: null,
  258. cssClass: null,
  259. listClass: null,
  260. isDefault: null,
  261. status: null,
  262. default: null,
  263. createTime: null,
  264. remark: null
  265. }
  266. dictData.push(dictItem)
  267. }
  268. }
  269. statusDictList.value = dictData
  270. dictLoaded.value = true
  271. }
  272. } catch (e: any) {
  273. console.error('获取工单状态字典失败:', e.message)
  274. dictLoaded.value = true
  275. }
  276. }
  277. const getFirstVisibleStatus = (): string => {
  278. for (const item of statusConfig) {
  279. const hasPerm = item.permis.length === 0 || checkPermi(item.permis)
  280. const meetsCondition = item.condition()
  281. if (hasPerm && meetsCondition) {
  282. // if (hasPerm) {
  283. return item.key as string
  284. }
  285. }
  286. return 'all' // fallback,理论上不会走到这里
  287. }
  288. let loadCount = 0
  289. // 加载列表数据
  290. const loadData = async (isRefresh: boolean | null, disablePullDown: boolean | null): Promise<void> => {
  291. const id = ++loadCount
  292. console.log(`【loadData #${id}】开始, isRefresh=${isRefresh}, disablePullDown=${disablePullDown}`)
  293. // 防止重复请求的核心机制(参考score/pending.uvue的实现)
  294. if (loading.value) {
  295. // 确保刷新状态最终被重置,防止卡死
  296. if (isRefresh != true) {
  297. refreshing.value = false;
  298. }
  299. return
  300. }
  301. const shouldRefresh = isRefresh != null ? isRefresh : false
  302. const shouldDisablePullDown = disablePullDown != null ? disablePullDown : false
  303. loading.value = true
  304. if (shouldRefresh && !shouldDisablePullDown) {
  305. page.value = 1
  306. refreshing.value = true
  307. } else if (shouldRefresh && shouldDisablePullDown) {
  308. // 状态切换时,重置页码但不触发动画
  309. page.value = 1
  310. // 即使禁用下拉刷新,也要确保刷新状态最终被重置
  311. refreshing.value = false
  312. } else {
  313. // 对于加载更多操作,不需要显示下拉刷新状态
  314. refreshing.value = false;
  315. }
  316. try {
  317. // 处理默认值
  318. const searchKeyword = keyword.value.length > 0 ? keyword.value : null
  319. const result = await getOrderList(page.value, pageSize, searchKeyword, currentStatus.value)
  320. // 提取响应数据
  321. const resultObj = result as UTSJSONObject
  322. const code = resultObj['code'] as number
  323. const responseData = resultObj['rows'] as any[]
  324. const responseTotal = resultObj['total'] as number
  325. if (code == 200) {
  326. // 将 any[] 转换为 acceptOrderInfoExtend[]
  327. // const newData: acceptOrderInfoExtend[] = []
  328. const newData: acceptOrderInfoExtend[] = []
  329. for (let i = 0; i < responseData.length; i++) {
  330. const item = responseData[i] as UTSJSONObject
  331. const orderItem: acceptOrderInfoExtend = {
  332. orderType: item['orderType'] as Number,
  333. id: item['id'] as Number,
  334. teamLeaderId: item['teamLeaderId'] != null ? (item['teamLeaderId'] as Number) : 0,
  335. acceptUserId: item['acceptUserId'] != null ? (item['acceptUserId'] as Number) : 0,
  336. teamLeaderName: item['teamLeaderName'] as string | null,
  337. acceptUserName: item['acceptUserName'] as string | null,
  338. acceptTime: item['acceptTime'] as string | null,
  339. assignTime: item['assignTime'] as string | null,
  340. assignUserName: item['assignUserName'] as string | null,
  341. status: (item['status']==null)?0:item['status'] as Number,
  342. workOrderProjectNo: item['workOrderProjectNo'] as string | null,
  343. workOrderStatus: item['workOrderStatus'] as string | null,
  344. gxtCenterId: item['gxtCenterId'] as Number | 0,
  345. gxtCenter: item['gxtCenter'] as string | null,
  346. pcsStationId: item['pcsStationId'] as Number | 0,
  347. pcsStationName: item['pcsStationName'] as string | null,
  348. pcsDeviceId: item['pcsDeviceId'] as Number | 0,
  349. pcsDeviceName: item['pcsDeviceName'] as string | null,
  350. brand: item['brand'] as string | null,
  351. model: item['model'] as string | null,
  352. createTime: item['createTime'] as string | null,
  353. suspendReason: item['suspendReason'] as string | null,
  354. rejectionReason: item['rejectionReason'] as string | null,
  355. updateTime: item['updateTime'] as string | null, // 新增字段
  356. workEndTime: item['workEndTime'] as string | null,// 新增字段
  357. orderEntryType: item['orderEntryType'] as string | null,
  358. pauseTime: item['pauseTime'] as string | null,
  359. restartTime: item['restartTime'] as string | null
  360. }
  361. newData.push(orderItem)
  362. }
  363. // 不再在前端过滤,直接使用API返回的数据
  364. if (shouldRefresh) {
  365. dataList.value = newData
  366. } else {
  367. dataList.value = [...dataList.value, ...newData]
  368. }
  369. total.value = responseTotal
  370. hasMore.value = dataList.value.length < responseTotal
  371. // 通知首页更新待接单数量
  372. if (currentStatus.value === 'assigned') {
  373. uni.$emit('refreshAssignedCount')
  374. }
  375. } else {
  376. const msg = resultObj['msg'] as string | null
  377. uni.showToast({
  378. title: msg ?? '加载失败',
  379. icon: 'none'
  380. })
  381. }
  382. } catch (e: any) {
  383. uni.showToast({
  384. title: e.message ?? '加载失败',
  385. icon: 'none'
  386. })
  387. } finally {
  388. loading.value = false
  389. // 确保刷新状态能结束(参考score/pending.uvue的实现)
  390. if (shouldRefresh) {
  391. refreshing.value = false;
  392. // 使用setTimeout确保状态彻底重置
  393. setTimeout(() => {
  394. isRefreshing.value = false;
  395. }, 50);
  396. }
  397. }
  398. }
  399. // 辅助函数:从 any 类型提取属性
  400. const getOrderType = (item: any | null): string => {
  401. if (item == null) return ''
  402. const orderInfoItem = item as acceptOrderInfoExtend
  403. return orderInfoItem.orderType == 1?"维修工单":"维保工单";
  404. }
  405. const getWorkOrderProjectNo = (item: any | null): string | null => {
  406. if (item == null) return ''
  407. const orderInfoItem = item as acceptOrderInfoExtend
  408. return orderInfoItem.workOrderProjectNo
  409. }
  410. const getPcsStationName = (item: any | null): string | null=> {
  411. if (item == null) return ''
  412. const orderInfoItem = item as acceptOrderInfoExtend
  413. return orderInfoItem.pcsStationName
  414. }
  415. const getPcsDeviceName = (item: any | null): string | null=> {
  416. if (item == null) return ''
  417. const orderInfoItem = item as acceptOrderInfoExtend
  418. return orderInfoItem.pcsDeviceName
  419. }
  420. const getAssignTime = (item: any | null): string|null => {
  421. if (item == null) return null
  422. const orderInfoItem = item as acceptOrderInfoExtend
  423. return orderInfoItem.assignTime
  424. }
  425. const getAcceptTime = (item: any | null): string|null => {
  426. if (item == null) return null
  427. const orderInfoItem = item as acceptOrderInfoExtend
  428. return orderInfoItem.acceptTime
  429. }
  430. const getCreateTime = (item: any | null): string|null => {
  431. if (item == null) return null
  432. const orderInfoItem = item as acceptOrderInfoExtend
  433. return orderInfoItem.createTime
  434. }
  435. // 根据状态显示不同的时间
  436. const getDisplayTime = (item: any | null): string|null => {
  437. if (item == null) return null
  438. const orderInfoItem = item as acceptOrderInfoExtend
  439. // 如果是"待接单"状态,显示派单时间
  440. if (orderInfoItem.workOrderStatus == 'assigned' || orderInfoItem.workOrderStatus == 'auto_suspend') {
  441. return '下发时间:' + orderInfoItem.assignTime
  442. } else if(orderInfoItem.workOrderStatus == 'to_finish') {
  443. if(orderInfoItem.workEndTime != null) {
  444. return '结束时间:' + orderInfoItem.workEndTime
  445. }
  446. return '接单时间:' + orderInfoItem.acceptTime
  447. } else if(orderInfoItem.workOrderStatus == 'to_approve') {
  448. return '申请挂起时间:' + orderInfoItem.updateTime
  449. } else if(orderInfoItem.workOrderStatus == 'suspended') {
  450. return '审批通过时间:' + orderInfoItem.updateTime
  451. } else if(orderInfoItem.workOrderStatus == 'return' || orderInfoItem.workOrderStatus == 'accept_return') {
  452. return '退回时间:' + orderInfoItem.updateTime
  453. } else if(orderInfoItem.workOrderStatus == 'completed') {
  454. return '结单时间:' + orderInfoItem.updateTime
  455. } else if(orderInfoItem.workOrderStatus == 'archived') {
  456. return '归档时间:' + orderInfoItem.updateTime
  457. }
  458. // 默认显示创建时间
  459. return '创建时间:' + orderInfoItem.createTime
  460. }
  461. const getWorkOrderStatus = (item: any | null): string | null => {
  462. if (item == null) return ''
  463. const orderInfoItem = item as acceptOrderInfoExtend
  464. const rawStatus = orderInfoItem.workOrderStatus
  465. if (rawStatus==null) return ''
  466. // 如果字典尚未加载,返回原始值
  467. if (!dictLoaded.value) {
  468. return rawStatus
  469. }
  470. // 查找字典中对应的标签
  471. const dictItem = statusDictList.value.find(dict => dict.dictValue == rawStatus)
  472. return dictItem!=null ? dictItem.dictLabel : rawStatus
  473. }
  474. const getStatusClass = (item: any | null): string => {
  475. if (item == null) return ''
  476. const orderInfoItem = item as acceptOrderInfoExtend
  477. const rawStatus = orderInfoItem.workOrderStatus
  478. if (rawStatus==null) return ''
  479. // const status = rawStatus
  480. // 返回对应的状态类名
  481. return `status-${rawStatus}`
  482. }
  483. // 切换状态
  484. const switchStatus = (status: string): void => {
  485. // 添加防重复调用检查(参考score/pending.uvue的实现)
  486. if (loading.value) {
  487. return;
  488. }
  489. // 添加防重复请求检查
  490. if (isSearching.value) {
  491. return
  492. }
  493. isSearching.value = true
  494. currentStatus.value = status
  495. page.value = 1
  496. loadData(true, true) // 第二个参数为true表示禁用下拉刷新动画
  497. // 延迟重置标志位,确保请求发送后才允许下一次搜索
  498. setTimeout(() => {
  499. isSearching.value = false
  500. }, 100)
  501. }
  502. // 下拉刷新
  503. const handleRefresh = async (): Promise<void> => {
  504. console.log("handleRefresh被触发")
  505. console.log("loading.value===",loading.value)
  506. console.log("isRefreshing.value===",isRefreshing.value)
  507. // 防抖处理,避免频繁触发(参考score/pending.uvue的实现)
  508. const now = Date.now();
  509. if (now - lastRefreshTime.value < 1000) {
  510. refreshing.value = false;
  511. return;
  512. }
  513. lastRefreshTime.value = now;
  514. // 添加防重复调用检查
  515. if (loading.value || isRefreshing.value) {
  516. // 如果已经在加载或正在刷新,直接重置刷新状态
  517. refreshing.value = false;
  518. return;
  519. }
  520. console.log("loading.value1===",loading.value)
  521. console.log("isRefreshing.value1===",isRefreshing.value)
  522. // 设置刷新标志
  523. isRefreshing.value = true;
  524. try {
  525. await loadData(true, false); // 使用默认的下拉刷新行为
  526. } catch (error) {
  527. console.error('刷新失败:', error);
  528. refreshing.value = false;
  529. isRefreshing.value = false;
  530. }
  531. // 确保在一定时间后重置刷新标志,防止意外情况
  532. setTimeout(() => {
  533. isRefreshing.value = false
  534. }, 100) // 延迟重置,确保状态完全更新
  535. }
  536. // 加载更多
  537. const loadMore = (): void => {
  538. if (!hasMore.value || loading.value) {
  539. return
  540. }
  541. page.value++
  542. loadData(false, false)
  543. }
  544. // 搜索
  545. const handleSearch = (): void => {
  546. // 添加防重复调用检查(参考score/pending.uvue的实现)
  547. if (loading.value) {
  548. return;
  549. }
  550. // 添加防重复请求检查
  551. if (isSearching.value) {
  552. return
  553. }
  554. isSearching.value = true
  555. page.value = 1
  556. loadData(true, true) // 状态切换时禁用下拉刷新动画
  557. // 延迟重置标志位,确保请求发送后才允许下一次搜索
  558. setTimeout(() => {
  559. isSearching.value = false
  560. }, 100)
  561. }
  562. const handleSearchOnBlur = (): void => {
  563. handleSearch()
  564. }
  565. // 方法:判断当前工单是否显示操作按钮
  566. const canHandleOrder = (item: any | null, buttonType: string | ''): boolean => {
  567. if (item == null) return false
  568. let permit: string[] = []
  569. const orderItem = item as acceptOrderInfoExtend
  570. if(orderItem.workOrderStatus == 'assigned') {
  571. if(buttonType != '' && buttonType == "acceptReturn" && orderItem.orderType == 1) {
  572. // 接单退回
  573. permit = ['gxt:repairOrder:acceptReturn']
  574. } else if(buttonType != '' && buttonType == "accept") {
  575. // 接单
  576. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:accept'] : ['gxt:repairOrder:accept']
  577. } else if(buttonType != '' && buttonType == "shutdown" && orderItem.orderType == 2) {
  578. //停机
  579. permit = ['gxt:maintenance:order:shutdown']
  580. } else if(buttonType != '' && buttonType == "restart") {
  581. // 复运
  582. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:restart'] : ['gxt:repairOrder:restart']
  583. }
  584. } else if(orderItem.workOrderStatus == 'to_finish') {
  585. if(buttonType != '' && buttonType == "suspend" ) {
  586. // 挂起
  587. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:suspend'] : ['gxt:repairOrder:suspend']
  588. } else if(buttonType != '' && buttonType == "return" && orderItem.orderType == 1 && (orderItem.teamLeaderId == parseInt(userId.value) || roles.value.includes("管理员"))) {
  589. // 退回
  590. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:return'] : ['gxt:repairOrder:return']
  591. } else if(buttonType != '' && buttonType == "resetStart" && orderItem.orderType == 1) {
  592. // 复启
  593. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:resetStart'] : ['gxt:repairOrder:resetStart']
  594. // } else if(buttonType != '' && buttonType == "complete" && (orderItem.teamLeaderId == parseInt(userId.value) || roles.value.includes("管理员"))) {
  595. } else if(buttonType != '' && buttonType == "complete") {
  596. // 结单
  597. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:complete'] : ['gxt:repairOrder:finalize']
  598. } else if(buttonType != '' && buttonType == "shutdown" && orderItem.orderType == 2) {
  599. // 停机
  600. permit = ['gxt:maintenance:order:shutdown']
  601. } else if(buttonType != '' && buttonType == "restart") {
  602. // 复运
  603. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:restart'] : ['gxt:repairOrder:restart']
  604. }
  605. } else if(orderItem.workOrderStatus == 'to_approve') {
  606. // 审批
  607. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:approve'] : ['gxt:repairOrder:approve']
  608. } else if(orderItem.workOrderStatus == 'suspended' && (orderItem.teamLeaderId == parseInt(userId.value) || roles.value.includes("管理员"))) {
  609. // 恢复
  610. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:resume'] : ['gxt:repairOrder:resume']
  611. } else if(orderItem.workOrderStatus == 'return') {
  612. // 接单退回
  613. permit = ['gxt:repairOrder:acceptReturn']
  614. } else if(orderItem.workOrderStatus == 'auto_suspend') {
  615. // 自动挂起恢复
  616. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:autoResume'] : ['gxt:repairOrder:autoResume']
  617. } else if(orderItem.workOrderStatus == 'shutdown' && orderItem.orderType == 2) {
  618. // 停机
  619. permit = ['gxt:maintenance:order:shutdown']
  620. } else if(orderItem.workOrderStatus == 'completed') {
  621. // 复运
  622. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:restart'] : ['gxt:repairOrder:restart']
  623. } else {
  624. return false
  625. }
  626. return checkPermi(permit)
  627. }
  628. // 点击列表项
  629. const handleItemClick = (item: any | null, buttonType: string | ''): void => {
  630. if (item == null) return
  631. const orderItem = item as acceptOrderInfoExtend
  632. // if(currentStatus.value === '' || currentStatus.value === 'completed' || currentStatus.value === 'all') {
  633. // // 传递orderType参数以便详情页决定调用哪个API
  634. // uni.navigateTo({
  635. // url: `/pages/order/detail/index?id=${orderItem.id}&orderType=${orderItem.orderType}`
  636. // })
  637. // } else
  638. if(orderItem.workOrderStatus == 'assigned') {
  639. if(buttonType != '' && buttonType == "acceptReturn") {
  640. // 跳转到退回页面
  641. uni.navigateTo({
  642. url: `/pages/order/detail/returnIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  643. })
  644. } else if(buttonType != '' && buttonType == "shutdown") {
  645. // 跳转到停机页面
  646. uni.navigateTo({
  647. url: `/pages/order/detail/shutdownIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  648. })
  649. } else if(buttonType != '' && buttonType == "restart") {
  650. // 跳转到复运页面
  651. uni.navigateTo({
  652. url: `/pages/order/detail/restartIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  653. })
  654. } else {
  655. // 跳转到接单页面
  656. uni.navigateTo({
  657. url: `/pages/order/detail/acceptIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  658. })
  659. }
  660. } else if(orderItem.workOrderStatus == 'to_finish') {
  661. if(buttonType != '' && buttonType == "suspend") {
  662. // 跳转到待挂起页面
  663. uni.navigateTo({
  664. url: `/pages/order/detail/suspendIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  665. })
  666. } else if(buttonType != '' && buttonType == "return") {
  667. // 跳转到退回页面
  668. uni.navigateTo({
  669. url: `/pages/order/detail/returnIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  670. })
  671. } else if(buttonType != '' && buttonType == "resetStart" && orderItem.orderType == 1) {
  672. // 跳转到复启页面
  673. uni.navigateTo({
  674. url: `/pages/order/detail/resetIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  675. })
  676. } else if(buttonType != '' && buttonType == "complete" && orderItem.orderType == 2 && orderItem.orderEntryType == '1') {
  677. // 跳转到结单页面
  678. uni.navigateTo({
  679. url: `/pages/order/detail/wbFinalize?id=${orderItem.id}&orderType=${orderItem.orderType}`
  680. })
  681. } else if(buttonType != '' && buttonType == "complete" && orderItem.orderType == 1) {
  682. // 跳转到结单页面
  683. uni.navigateTo({
  684. url: `/pages/order/detail/wxFinalize?id=${orderItem.id}&orderType=${orderItem.orderType}`
  685. })
  686. } else if(buttonType != '' && buttonType == "complete" && orderItem.orderType == 2 && orderItem.orderEntryType == '2') {
  687. // 跳转到补录结单页面
  688. uni.navigateTo({
  689. url: `/pages/order/detail/wbBackfillFinalize?id=${orderItem.id}&orderType=${orderItem.orderType}`
  690. })
  691. } else if(buttonType != '' && buttonType == "shutdown") {
  692. // 跳转到停机页面
  693. uni.navigateTo({
  694. url: `/pages/order/detail/shutdownIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  695. })
  696. } else if(buttonType != '' && buttonType == "restart") {
  697. // 跳转到复运页面
  698. uni.navigateTo({
  699. url: `/pages/order/detail/restartIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  700. })
  701. }
  702. } else if(orderItem.workOrderStatus == 'to_approve') {
  703. // 跳转到待审批页面
  704. uni.navigateTo({
  705. url: `/pages/order/detail/approveIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  706. })
  707. } else if(orderItem.workOrderStatus == 'suspended' || orderItem.workOrderStatus == 'auto_suspend') {
  708. // 跳转到恢复页面
  709. uni.navigateTo({
  710. url: `/pages/order/detail/resumeIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  711. })
  712. } else if(orderItem.workOrderStatus == 'return') {
  713. if(buttonType != '' && buttonType == "accept") {
  714. // 跳转到接单页面
  715. uni.navigateTo({
  716. url: `/pages/order/detail/acceptIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  717. })
  718. } else if(buttonType != '' && buttonType == "acceptReturn") {
  719. // 跳转到退回页面
  720. uni.navigateTo({
  721. url: `/pages/order/detail/returnIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  722. })
  723. }
  724. } else if(orderItem.workOrderStatus == 'completed') {
  725. if(buttonType != '' && buttonType == "restart") {
  726. // 跳转到复运页面
  727. uni.navigateTo({
  728. url: `/pages/order/detail/restartIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  729. })
  730. }
  731. } else {
  732. uni.navigateTo({
  733. url: `/pages/order/detail/index?id=${orderItem.id}&orderType=${orderItem.orderType}`
  734. })
  735. }
  736. }
  737. // 点击列表项
  738. const handleView = (item: any | null): void => {
  739. if (item == null) return
  740. const orderItem = item as acceptOrderInfoExtend
  741. uni.navigateTo({
  742. url: `/pages/order/detail/index?id=${orderItem.id}&orderType=${orderItem.orderType}`
  743. })
  744. }
  745. // 查看工单详情
  746. const showWorkOrderDetail = (item: any | null): void => {
  747. if (item == null) return
  748. const orderItem = item as acceptOrderInfoExtend
  749. uni.navigateTo({
  750. url: `/pages/workbench/detail/index?id=${orderItem.id}`
  751. })
  752. }
  753. // 清空搜索
  754. const clearSearch = (): void => {
  755. // 添加防重复调用检查(参考score/pending.uvue的实现)
  756. if (loading.value) {
  757. return;
  758. }
  759. // 添加防重复请求检查
  760. if (isSearching.value) {
  761. return
  762. }
  763. isSearching.value = true
  764. keyword.value = ""
  765. page.value = 1
  766. loadData(true, true) // 状态切换时禁用下拉刷新动画
  767. // 延迟重置标志位,确保请求发送后才允许下一次搜索
  768. setTimeout(() => {
  769. isSearching.value = false
  770. }, 100)
  771. }
  772. // 初始化
  773. // onMounted(() => {
  774. onLoad((options: any) => {
  775. // 检查权限设置tabbar
  776. tabbar[2] = checkPermi(['gxt:app:worktime']) ? 1 : 0
  777. tabbar[3] = checkPermi(['gxt:app:score']) ? 1 : 0
  778. const userInfo = getUserInfo()
  779. if (userInfo != null) {
  780. const userIdStr = userInfo['userId'].toString()
  781. userId.value = userIdStr
  782. roles.value = userInfo['roleNames'].toString()
  783. }
  784. const params = options as UTSJSONObject
  785. const isDeal = params['isDeal'] as string | null
  786. if(isDeal != null) {
  787. dealLoad.value = true;
  788. }
  789. loadStatusDictList()
  790. // 自动选中第一个可显示的状态
  791. // currentStatus.value = getFirstVisibleStatus()
  792. currentStatus.value = 'all'
  793. loadData(true, true) // 首次加载时禁用下拉刷新动画
  794. // 监听首页切换状态事件
  795. uni.$on('switchOrderStatus', (status: string) => {
  796. switchStatus(status)
  797. })
  798. // 监听接单成功的事件,刷新列表
  799. uni.$on('refreshOrderList', () => {
  800. page.value = 1
  801. loadData(true, false)
  802. })
  803. })
  804. // 组件卸载前清理事件监听
  805. onBeforeUnmount(() => {
  806. refreshing.value = false
  807. loading.value = false
  808. isRefreshing.value = false
  809. // 移除事件监听
  810. uni.$off('refreshOrderList',{})
  811. uni.$off('switchOrderStatus',{})
  812. })</script>
  813. <style lang="scss">
  814. .list-page {
  815. flex: 1;
  816. background-color: #e8f0f9;
  817. }
  818. .search-bar {
  819. padding: 20rpx 30rpx;
  820. background-color: #d7eafe;
  821. }
  822. .search-box {
  823. flex-direction: row;
  824. align-items: center;
  825. height: 72rpx;
  826. padding: 0 24rpx;
  827. background-color: #f5f5f5;
  828. border-radius: 36rpx;
  829. .search-icon {
  830. width: 32rpx;
  831. height: 32rpx;
  832. margin-right: 12rpx;
  833. }
  834. .search-input {
  835. flex: 1;
  836. font-size: 28rpx;
  837. color: #333333;
  838. }
  839. .clear-icon {
  840. margin-left: 12rpx;
  841. font-size: 28rpx;
  842. color: #999999;
  843. }
  844. }
  845. .status-bar{
  846. padding-bottom: 10px;
  847. padding-left:30rpx;
  848. background-color: #d7eafe;
  849. }
  850. .status-box {
  851. flex-direction: row;
  852. align-items: center;
  853. height: 72rpx;
  854. flex: 1;
  855. .status-txt{
  856. padding: 8px 12px;
  857. text-align: center;
  858. margin-right: 12rpx;
  859. border-radius: 36rpx;
  860. background-color: #fff;
  861. font-size: 28rpx;
  862. // cursor: pointer;
  863. }
  864. .stauts-sel{
  865. background-color: #007AFF;
  866. color: #fff;
  867. }
  868. }
  869. .list-item {
  870. margin: 24rpx 30rpx;
  871. background-color: #ffffff;
  872. border-radius: 16rpx;
  873. }
  874. .item-container {
  875. padding: 30rpx;
  876. }
  877. .item-address {
  878. font-size: 26rpx;
  879. color: #999999;
  880. margin-bottom: 20rpx;
  881. line-height: 40rpx;
  882. }
  883. .btn-primary {
  884. z-index: 999;
  885. border-radius: 10rpx;
  886. font-size: 24rpx;
  887. // white-space: nowrap;
  888. margin-left: 20rpx;
  889. background-color: #165DFF;
  890. line-height: 45rpx;
  891. color: #ffffff;
  892. .btn-text{
  893. color: #ffffff;
  894. font-size: 24rpx;
  895. padding: 5px 15px;
  896. }
  897. }
  898. .item-header {
  899. flex-direction: row;
  900. align-items: flex-start;
  901. margin-bottom: 16rpx;
  902. justify-content: space-between; /* 主轴两端对齐 */
  903. min-height: 55rpx;
  904. .item-title {
  905. font-size: 30rpx;
  906. color: #333333;
  907. font-weight: bold;
  908. flex-wrap: wrap;
  909. flex: 0 1 75%;
  910. min-width: 0;
  911. }
  912. .info-value {
  913. font-size: 28rpx;
  914. color: #999999;
  915. margin-left: auto;
  916. flex: 0 0 auto;
  917. white-space: nowrap;
  918. }
  919. }
  920. .info-row {
  921. flex-direction: row;
  922. justify-content: space-between;
  923. align-items: center;
  924. .info-label {
  925. font-size: 26rpx;
  926. color: #666;
  927. }
  928. .info-value {
  929. font-size: 26rpx;
  930. // color: #666;
  931. }
  932. }
  933. .text-gray{
  934. font-size: 26rpx;
  935. color: #666;
  936. }
  937. .status-view {
  938. border: 1rpx solid;
  939. border-radius: 20rpx;
  940. }
  941. .status-tag {
  942. padding: 8rpx 20rpx;
  943. border-radius: 20rpx;
  944. font-size: 24rpx;
  945. white-space: nowrap;
  946. // margin-left: 50rpx;
  947. // justify-content: flex-end;
  948. border: 1rpx solid;
  949. }
  950. /* 待接单 */
  951. .status-assigned {
  952. background-color: #ebf5ff;
  953. color: #409eff;
  954. border-color: #d8ebff;
  955. }
  956. /* 待结单 */
  957. .status-to_finish {
  958. background-color: #fff7e6;
  959. color: #fa8c16;
  960. border-color: #ffd591;
  961. }
  962. /* 待审批 */
  963. .status-to_approve {
  964. background-color: #fff7e6;
  965. color: #fa8c16;
  966. border-color: #ffd591;
  967. }
  968. /* 已挂起 */
  969. .status-suspended {
  970. background-color: #fff2f0;
  971. color: #ff4d4f;
  972. border-color: #ffccc7;
  973. }
  974. /* 自动挂起 */
  975. .status-auto_suspend {
  976. background-color: #fff2f0;
  977. color: #ff4d4f;
  978. border-color: #ffccc7;
  979. }
  980. /* 已完成 */
  981. .status-completed {
  982. background-color: #f0f9eb;
  983. color: #5cb87a;
  984. border-color: #c2e7b0;
  985. }
  986. /* 待下发 */
  987. .status-to_issue {
  988. background-color: #f4f4f5;
  989. color: #909399;
  990. border-color: #e9e9eb;
  991. }
  992. /* 已归档 */
  993. .status-archived {
  994. background-color: #f0f9eb;
  995. color: #5cb87a;
  996. border-color: #c2e7b0;
  997. }
  998. /* 退回 */
  999. .status-return {
  1000. background-color: #fff2f0;
  1001. color: #ff4d4f;
  1002. border-color: #ffccc7;
  1003. }
  1004. /* 退回 */
  1005. .status-accept_return {
  1006. background-color: #fff2f0;
  1007. color: #ff4d4f;
  1008. border-color: #ffccc7;
  1009. }
  1010. /* 作废 */
  1011. .status-invalid {
  1012. background-color: #fff2f0;
  1013. color: #ff4d4f;
  1014. border-color: #ffccc7;
  1015. }
  1016. .scroll-view_H {
  1017. width: 100%;
  1018. flex-direction: row;
  1019. }
  1020. .scroll-view-item_H {
  1021. justify-content: center;
  1022. align-items: center;
  1023. .status-txt{
  1024. padding: 8px 12px;
  1025. text-align: center;
  1026. margin-right: 12rpx;
  1027. border-radius: 36rpx;
  1028. background-color: #fff;
  1029. font-size: 28rpx;
  1030. }
  1031. .stauts-sel{
  1032. background-color: #007AFF;
  1033. color: #fff;
  1034. }
  1035. }
  1036. .btn-group {
  1037. flex-direction: row;
  1038. align-items: center;
  1039. justify-content: flex-end;
  1040. margin-top: 20rpx;
  1041. }
  1042. </style>