index.uvue 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177
  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' || getOrderStatus(item) == 'completed')
  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' || getOrderStatus(item) == 'assigned') && 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. } else if(buttonType != '' && buttonType == "resetStart" && orderItem.orderType == 1) {
  584. // 复启
  585. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:resetStart'] : ['gxt:repairOrder:resetStart']
  586. }
  587. } else if(orderItem.workOrderStatus == 'to_finish') {
  588. if(buttonType != '' && buttonType == "suspend" ) {
  589. // 挂起
  590. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:suspend'] : ['gxt:repairOrder:suspend']
  591. } else if(buttonType != '' && buttonType == "return" && orderItem.orderType == 1 && (orderItem.teamLeaderId == parseInt(userId.value) || roles.value.includes("管理员"))) {
  592. // 退回
  593. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:return'] : ['gxt:repairOrder:return']
  594. } else if(buttonType != '' && buttonType == "resetStart" && orderItem.orderType == 1) {
  595. // 复启
  596. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:resetStart'] : ['gxt:repairOrder:resetStart']
  597. // } else if(buttonType != '' && buttonType == "complete" && (orderItem.teamLeaderId == parseInt(userId.value) || roles.value.includes("管理员"))) {
  598. } else if(buttonType != '' && buttonType == "complete") {
  599. // 结单
  600. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:complete'] : ['gxt:repairOrder:finalize']
  601. } else if(buttonType != '' && buttonType == "shutdown" && orderItem.orderType == 2) {
  602. // 停机
  603. permit = ['gxt:maintenance:order:shutdown']
  604. } else if(buttonType != '' && buttonType == "restart") {
  605. // 复运
  606. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:restart'] : ['gxt:repairOrder:restart']
  607. }
  608. } else if(orderItem.workOrderStatus == 'to_approve') {
  609. // 审批
  610. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:approve'] : ['gxt:repairOrder:approve']
  611. } else if(orderItem.workOrderStatus == 'suspended' && (orderItem.teamLeaderId == parseInt(userId.value) || roles.value.includes("管理员"))) {
  612. // 恢复
  613. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:resume'] : ['gxt:repairOrder:resume']
  614. } else if(orderItem.workOrderStatus == 'return') {
  615. // 接单退回
  616. permit = ['gxt:repairOrder:acceptReturn']
  617. } else if(orderItem.workOrderStatus == 'auto_suspend') {
  618. // 自动挂起恢复
  619. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:autoResume'] : ['gxt:repairOrder:autoResume']
  620. } else if(orderItem.workOrderStatus == 'shutdown' && orderItem.orderType == 2) {
  621. // 停机
  622. permit = ['gxt:maintenance:order:shutdown']
  623. } else if(orderItem.workOrderStatus == 'completed') {
  624. if(buttonType != '' && buttonType == "restart") {
  625. // 复运
  626. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:restart'] : ['gxt:repairOrder:restart']
  627. } else if(buttonType != '' && buttonType == "shutdown" && orderItem.orderType == 2) {
  628. //停机
  629. permit = ['gxt:maintenance:order:shutdown']
  630. }
  631. } else {
  632. return false
  633. }
  634. return checkPermi(permit)
  635. }
  636. // 点击列表项
  637. const handleItemClick = (item: any | null, buttonType: string | ''): void => {
  638. if (item == null) return
  639. const orderItem = item as acceptOrderInfoExtend
  640. // if(currentStatus.value === '' || currentStatus.value === 'completed' || currentStatus.value === 'all') {
  641. // // 传递orderType参数以便详情页决定调用哪个API
  642. // uni.navigateTo({
  643. // url: `/pages/order/detail/index?id=${orderItem.id}&orderType=${orderItem.orderType}`
  644. // })
  645. // } else
  646. if(orderItem.workOrderStatus == 'assigned') {
  647. if(buttonType != '' && buttonType == "acceptReturn") {
  648. // 跳转到退回页面
  649. uni.navigateTo({
  650. url: `/pages/order/detail/returnIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  651. })
  652. } else if(buttonType != '' && buttonType == "shutdown") {
  653. // 跳转到停机页面
  654. uni.navigateTo({
  655. url: `/pages/order/detail/shutdownIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  656. })
  657. } else if(buttonType != '' && buttonType == "restart") {
  658. // 跳转到复运页面
  659. uni.navigateTo({
  660. url: `/pages/order/detail/restartIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  661. })
  662. } else if(buttonType != '' && buttonType == "resetStart" && orderItem.orderType == 1) {
  663. // 跳转到复启页面
  664. uni.navigateTo({
  665. url: `/pages/order/detail/resetIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  666. })
  667. } else {
  668. // 跳转到接单页面
  669. uni.navigateTo({
  670. url: `/pages/order/detail/acceptIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  671. })
  672. }
  673. } else if(orderItem.workOrderStatus == 'to_finish') {
  674. if(buttonType != '' && buttonType == "suspend") {
  675. // 跳转到待挂起页面
  676. uni.navigateTo({
  677. url: `/pages/order/detail/suspendIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  678. })
  679. } else if(buttonType != '' && buttonType == "return") {
  680. // 跳转到退回页面
  681. uni.navigateTo({
  682. url: `/pages/order/detail/returnIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  683. })
  684. } else if(buttonType != '' && buttonType == "resetStart" && orderItem.orderType == 1) {
  685. // 跳转到复启页面
  686. uni.navigateTo({
  687. url: `/pages/order/detail/resetIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  688. })
  689. } else if(buttonType != '' && buttonType == "complete" && orderItem.orderType == 2 && orderItem.orderEntryType == '1') {
  690. // 跳转到结单页面
  691. uni.navigateTo({
  692. url: `/pages/order/detail/wbFinalize?id=${orderItem.id}&orderType=${orderItem.orderType}`
  693. })
  694. } else if(buttonType != '' && buttonType == "complete" && orderItem.orderType == 1) {
  695. // 跳转到结单页面
  696. uni.navigateTo({
  697. url: `/pages/order/detail/wxFinalize?id=${orderItem.id}&orderType=${orderItem.orderType}`
  698. })
  699. } else if(buttonType != '' && buttonType == "complete" && orderItem.orderType == 2 && orderItem.orderEntryType == '2') {
  700. // 跳转到补录结单页面
  701. uni.navigateTo({
  702. url: `/pages/order/detail/wbBackfillFinalize?id=${orderItem.id}&orderType=${orderItem.orderType}`
  703. })
  704. } else if(buttonType != '' && buttonType == "shutdown") {
  705. // 跳转到停机页面
  706. uni.navigateTo({
  707. url: `/pages/order/detail/shutdownIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  708. })
  709. } else if(buttonType != '' && buttonType == "restart") {
  710. // 跳转到复运页面
  711. uni.navigateTo({
  712. url: `/pages/order/detail/restartIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  713. })
  714. }
  715. } else if(orderItem.workOrderStatus == 'to_approve') {
  716. // 跳转到待审批页面
  717. uni.navigateTo({
  718. url: `/pages/order/detail/approveIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  719. })
  720. } else if(orderItem.workOrderStatus == 'suspended' || orderItem.workOrderStatus == 'auto_suspend') {
  721. // 跳转到恢复页面
  722. uni.navigateTo({
  723. url: `/pages/order/detail/resumeIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  724. })
  725. } else if(orderItem.workOrderStatus == 'return') {
  726. if(buttonType != '' && buttonType == "accept") {
  727. // 跳转到接单页面
  728. uni.navigateTo({
  729. url: `/pages/order/detail/acceptIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  730. })
  731. } else if(buttonType != '' && buttonType == "acceptReturn") {
  732. // 跳转到退回页面
  733. uni.navigateTo({
  734. url: `/pages/order/detail/returnIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  735. })
  736. }
  737. } else if(orderItem.workOrderStatus == 'completed') {
  738. if(buttonType != '' && buttonType == "restart") {
  739. // 跳转到复运页面
  740. uni.navigateTo({
  741. url: `/pages/order/detail/restartIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  742. })
  743. } else if(buttonType != '' && buttonType == "shutdown") {
  744. // 跳转到停机页面
  745. uni.navigateTo({
  746. url: `/pages/order/detail/shutdownIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  747. })
  748. }
  749. } else {
  750. uni.navigateTo({
  751. url: `/pages/order/detail/index?id=${orderItem.id}&orderType=${orderItem.orderType}`
  752. })
  753. }
  754. }
  755. // 点击列表项
  756. const handleView = (item: any | null): void => {
  757. if (item == null) return
  758. const orderItem = item as acceptOrderInfoExtend
  759. uni.navigateTo({
  760. url: `/pages/order/detail/index?id=${orderItem.id}&orderType=${orderItem.orderType}`
  761. })
  762. }
  763. // 查看工单详情
  764. const showWorkOrderDetail = (item: any | null): void => {
  765. if (item == null) return
  766. const orderItem = item as acceptOrderInfoExtend
  767. uni.navigateTo({
  768. url: `/pages/workbench/detail/index?id=${orderItem.id}`
  769. })
  770. }
  771. // 清空搜索
  772. const clearSearch = (): void => {
  773. // 添加防重复调用检查(参考score/pending.uvue的实现)
  774. if (loading.value) {
  775. return;
  776. }
  777. // 添加防重复请求检查
  778. if (isSearching.value) {
  779. return
  780. }
  781. isSearching.value = true
  782. keyword.value = ""
  783. page.value = 1
  784. loadData(true, true) // 状态切换时禁用下拉刷新动画
  785. // 延迟重置标志位,确保请求发送后才允许下一次搜索
  786. setTimeout(() => {
  787. isSearching.value = false
  788. }, 100)
  789. }
  790. // 初始化
  791. // onMounted(() => {
  792. onLoad((options: any) => {
  793. // 检查权限设置tabbar
  794. tabbar[2] = checkPermi(['gxt:app:worktime']) ? 1 : 0
  795. tabbar[3] = checkPermi(['gxt:app:score']) ? 1 : 0
  796. const userInfo = getUserInfo()
  797. if (userInfo != null) {
  798. const userIdStr = userInfo['userId'].toString()
  799. userId.value = userIdStr
  800. roles.value = userInfo['roleNames'].toString()
  801. }
  802. const params = options as UTSJSONObject
  803. const isDeal = params['isDeal'] as string | null
  804. if(isDeal != null) {
  805. dealLoad.value = true;
  806. }
  807. loadStatusDictList()
  808. // 自动选中第一个可显示的状态
  809. // currentStatus.value = getFirstVisibleStatus()
  810. currentStatus.value = 'all'
  811. loadData(true, true) // 首次加载时禁用下拉刷新动画
  812. // 监听首页切换状态事件
  813. uni.$on('switchOrderStatus', (status: string) => {
  814. switchStatus(status)
  815. })
  816. // 监听接单成功的事件,刷新列表
  817. uni.$on('refreshOrderList', () => {
  818. page.value = 1
  819. loadData(true, false)
  820. })
  821. })
  822. // 组件卸载前清理事件监听
  823. onBeforeUnmount(() => {
  824. refreshing.value = false
  825. loading.value = false
  826. isRefreshing.value = false
  827. // 移除事件监听
  828. uni.$off('refreshOrderList',{})
  829. uni.$off('switchOrderStatus',{})
  830. })</script>
  831. <style lang="scss">
  832. .list-page {
  833. flex: 1;
  834. background-color: #e8f0f9;
  835. }
  836. .search-bar {
  837. padding: 20rpx 30rpx;
  838. background-color: #d7eafe;
  839. }
  840. .search-box {
  841. flex-direction: row;
  842. align-items: center;
  843. height: 72rpx;
  844. padding: 0 24rpx;
  845. background-color: #f5f5f5;
  846. border-radius: 36rpx;
  847. .search-icon {
  848. width: 32rpx;
  849. height: 32rpx;
  850. margin-right: 12rpx;
  851. }
  852. .search-input {
  853. flex: 1;
  854. font-size: 28rpx;
  855. color: #333333;
  856. }
  857. .clear-icon {
  858. margin-left: 12rpx;
  859. font-size: 28rpx;
  860. color: #999999;
  861. }
  862. }
  863. .status-bar{
  864. padding-bottom: 10px;
  865. padding-left:30rpx;
  866. background-color: #d7eafe;
  867. }
  868. .status-box {
  869. flex-direction: row;
  870. align-items: center;
  871. height: 72rpx;
  872. flex: 1;
  873. .status-txt{
  874. padding: 8px 12px;
  875. text-align: center;
  876. margin-right: 12rpx;
  877. border-radius: 36rpx;
  878. background-color: #fff;
  879. font-size: 28rpx;
  880. // cursor: pointer;
  881. }
  882. .stauts-sel{
  883. background-color: #007AFF;
  884. color: #fff;
  885. }
  886. }
  887. .list-item {
  888. margin: 24rpx 30rpx;
  889. background-color: #ffffff;
  890. border-radius: 16rpx;
  891. }
  892. .item-container {
  893. padding: 30rpx;
  894. }
  895. .item-address {
  896. font-size: 26rpx;
  897. color: #999999;
  898. margin-bottom: 20rpx;
  899. line-height: 40rpx;
  900. }
  901. .btn-primary {
  902. z-index: 999;
  903. border-radius: 10rpx;
  904. font-size: 24rpx;
  905. // white-space: nowrap;
  906. margin-left: 20rpx;
  907. background-color: #165DFF;
  908. line-height: 45rpx;
  909. color: #ffffff;
  910. .btn-text{
  911. color: #ffffff;
  912. font-size: 24rpx;
  913. padding: 5px 15px;
  914. }
  915. }
  916. .item-header {
  917. flex-direction: row;
  918. align-items: flex-start;
  919. margin-bottom: 16rpx;
  920. justify-content: space-between; /* 主轴两端对齐 */
  921. min-height: 55rpx;
  922. .item-title {
  923. font-size: 30rpx;
  924. color: #333333;
  925. font-weight: bold;
  926. flex-wrap: wrap;
  927. flex: 0 1 75%;
  928. min-width: 0;
  929. }
  930. .info-value {
  931. font-size: 28rpx;
  932. color: #999999;
  933. margin-left: auto;
  934. flex: 0 0 auto;
  935. white-space: nowrap;
  936. }
  937. }
  938. .info-row {
  939. flex-direction: row;
  940. justify-content: space-between;
  941. align-items: center;
  942. .info-label {
  943. font-size: 26rpx;
  944. color: #666;
  945. }
  946. .info-value {
  947. font-size: 26rpx;
  948. // color: #666;
  949. }
  950. }
  951. .text-gray{
  952. font-size: 26rpx;
  953. color: #666;
  954. }
  955. .status-view {
  956. border: 1rpx solid;
  957. border-radius: 20rpx;
  958. }
  959. .status-tag {
  960. padding: 8rpx 20rpx;
  961. border-radius: 20rpx;
  962. font-size: 24rpx;
  963. white-space: nowrap;
  964. // margin-left: 50rpx;
  965. // justify-content: flex-end;
  966. border: 1rpx solid;
  967. }
  968. /* 待接单 */
  969. .status-assigned {
  970. background-color: #ebf5ff;
  971. color: #409eff;
  972. border-color: #d8ebff;
  973. }
  974. /* 待结单 */
  975. .status-to_finish {
  976. background-color: #fff7e6;
  977. color: #fa8c16;
  978. border-color: #ffd591;
  979. }
  980. /* 待审批 */
  981. .status-to_approve {
  982. background-color: #fff7e6;
  983. color: #fa8c16;
  984. border-color: #ffd591;
  985. }
  986. /* 已挂起 */
  987. .status-suspended {
  988. background-color: #fff2f0;
  989. color: #ff4d4f;
  990. border-color: #ffccc7;
  991. }
  992. /* 自动挂起 */
  993. .status-auto_suspend {
  994. background-color: #fff2f0;
  995. color: #ff4d4f;
  996. border-color: #ffccc7;
  997. }
  998. /* 已完成 */
  999. .status-completed {
  1000. background-color: #f0f9eb;
  1001. color: #5cb87a;
  1002. border-color: #c2e7b0;
  1003. }
  1004. /* 待下发 */
  1005. .status-to_issue {
  1006. background-color: #f4f4f5;
  1007. color: #909399;
  1008. border-color: #e9e9eb;
  1009. }
  1010. /* 已归档 */
  1011. .status-archived {
  1012. background-color: #f0f9eb;
  1013. color: #5cb87a;
  1014. border-color: #c2e7b0;
  1015. }
  1016. /* 退回 */
  1017. .status-return {
  1018. background-color: #fff2f0;
  1019. color: #ff4d4f;
  1020. border-color: #ffccc7;
  1021. }
  1022. /* 退回 */
  1023. .status-accept_return {
  1024. background-color: #fff2f0;
  1025. color: #ff4d4f;
  1026. border-color: #ffccc7;
  1027. }
  1028. /* 作废 */
  1029. .status-invalid {
  1030. background-color: #fff2f0;
  1031. color: #ff4d4f;
  1032. border-color: #ffccc7;
  1033. }
  1034. .scroll-view_H {
  1035. width: 100%;
  1036. flex-direction: row;
  1037. }
  1038. .scroll-view-item_H {
  1039. justify-content: center;
  1040. align-items: center;
  1041. .status-txt{
  1042. padding: 8px 12px;
  1043. text-align: center;
  1044. margin-right: 12rpx;
  1045. border-radius: 36rpx;
  1046. background-color: #fff;
  1047. font-size: 28rpx;
  1048. }
  1049. .stauts-sel{
  1050. background-color: #007AFF;
  1051. color: #fff;
  1052. }
  1053. }
  1054. .btn-group {
  1055. flex-direction: row;
  1056. align-items: center;
  1057. justify-content: flex-end;
  1058. margin-top: 20rpx;
  1059. }
  1060. </style>