index.uvue 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  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,'')"
  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, 'finalize')"
  148. class="btn-primary info-value"
  149. @click.stop="handleItemClick(item, 'finalize')"
  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" && (orderItem.teamLeaderId == parseInt(userId.value) || roles.value.includes("管理员"))) {
  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 == "finalize" && orderItem.orderType == 1 && (orderItem.teamLeaderId == parseInt(userId.value) || roles.value.includes("管理员"))) {
  592. // 复启
  593. permit = orderItem.orderType == 2 ? ['gxt:maintenance:order:complete'] : ['gxt:repairOrder:finalize']
  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 == "finalize") {
  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. // 跳转到退回页面
  714. uni.navigateTo({
  715. url: `/pages/order/detail/returnIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  716. })
  717. } else if(orderItem.workOrderStatus == 'completed') {
  718. if(buttonType != '' && buttonType == "restart") {
  719. // 跳转到复运页面
  720. uni.navigateTo({
  721. url: `/pages/order/detail/restartIndex?id=${orderItem.id}&orderType=${orderItem.orderType}`
  722. })
  723. }
  724. } else {
  725. uni.navigateTo({
  726. url: `/pages/order/detail/index?id=${orderItem.id}&orderType=${orderItem.orderType}`
  727. })
  728. }
  729. }
  730. // 点击列表项
  731. const handleView = (item: any | null): void => {
  732. if (item == null) return
  733. const orderItem = item as acceptOrderInfoExtend
  734. uni.navigateTo({
  735. url: `/pages/order/detail/index?id=${orderItem.id}&orderType=${orderItem.orderType}`
  736. })
  737. }
  738. // 查看工单详情
  739. const showWorkOrderDetail = (item: any | null): void => {
  740. if (item == null) return
  741. const orderItem = item as acceptOrderInfoExtend
  742. uni.navigateTo({
  743. url: `/pages/workbench/detail/index?id=${orderItem.id}`
  744. })
  745. }
  746. // 清空搜索
  747. const clearSearch = (): void => {
  748. // 添加防重复调用检查(参考score/pending.uvue的实现)
  749. if (loading.value) {
  750. return;
  751. }
  752. // 添加防重复请求检查
  753. if (isSearching.value) {
  754. return
  755. }
  756. isSearching.value = true
  757. keyword.value = ""
  758. page.value = 1
  759. loadData(true, true) // 状态切换时禁用下拉刷新动画
  760. // 延迟重置标志位,确保请求发送后才允许下一次搜索
  761. setTimeout(() => {
  762. isSearching.value = false
  763. }, 100)
  764. }
  765. // 初始化
  766. // onMounted(() => {
  767. onLoad((options: any) => {
  768. // 检查权限设置tabbar
  769. tabbar[2] = checkPermi(['gxt:app:worktime']) ? 1 : 0
  770. tabbar[3] = checkPermi(['gxt:app:score']) ? 1 : 0
  771. const userInfo = getUserInfo()
  772. if (userInfo != null) {
  773. const userIdStr = userInfo['userId'].toString()
  774. userId.value = userIdStr
  775. roles.value = userInfo['roleNames'].toString()
  776. }
  777. const params = options as UTSJSONObject
  778. const isDeal = params['isDeal'] as string | null
  779. if(isDeal != null) {
  780. dealLoad.value = true;
  781. }
  782. loadStatusDictList()
  783. // 自动选中第一个可显示的状态
  784. // currentStatus.value = getFirstVisibleStatus()
  785. currentStatus.value = 'all'
  786. loadData(true, true) // 首次加载时禁用下拉刷新动画
  787. // 监听首页切换状态事件
  788. uni.$on('switchOrderStatus', (status: string) => {
  789. switchStatus(status)
  790. })
  791. // 监听接单成功的事件,刷新列表
  792. uni.$on('refreshOrderList', () => {
  793. page.value = 1
  794. loadData(true, false)
  795. })
  796. })
  797. // 组件卸载前清理事件监听
  798. onBeforeUnmount(() => {
  799. refreshing.value = false
  800. loading.value = false
  801. isRefreshing.value = false
  802. // 移除事件监听
  803. uni.$off('refreshOrderList',{})
  804. uni.$off('switchOrderStatus',{})
  805. })</script>
  806. <style lang="scss">
  807. .list-page {
  808. flex: 1;
  809. background-color: #e8f0f9;
  810. }
  811. .search-bar {
  812. padding: 20rpx 30rpx;
  813. background-color: #d7eafe;
  814. }
  815. .search-box {
  816. flex-direction: row;
  817. align-items: center;
  818. height: 72rpx;
  819. padding: 0 24rpx;
  820. background-color: #f5f5f5;
  821. border-radius: 36rpx;
  822. .search-icon {
  823. width: 32rpx;
  824. height: 32rpx;
  825. margin-right: 12rpx;
  826. }
  827. .search-input {
  828. flex: 1;
  829. font-size: 28rpx;
  830. color: #333333;
  831. }
  832. .clear-icon {
  833. margin-left: 12rpx;
  834. font-size: 28rpx;
  835. color: #999999;
  836. }
  837. }
  838. .status-bar{
  839. padding-bottom: 10px;
  840. padding-left:30rpx;
  841. background-color: #d7eafe;
  842. }
  843. .status-box {
  844. flex-direction: row;
  845. align-items: center;
  846. height: 72rpx;
  847. flex: 1;
  848. .status-txt{
  849. padding: 8px 12px;
  850. text-align: center;
  851. margin-right: 12rpx;
  852. border-radius: 36rpx;
  853. background-color: #fff;
  854. font-size: 28rpx;
  855. // cursor: pointer;
  856. }
  857. .stauts-sel{
  858. background-color: #007AFF;
  859. color: #fff;
  860. }
  861. }
  862. .list-item {
  863. margin: 24rpx 30rpx;
  864. background-color: #ffffff;
  865. border-radius: 16rpx;
  866. }
  867. .item-container {
  868. padding: 30rpx;
  869. }
  870. .item-address {
  871. font-size: 26rpx;
  872. color: #999999;
  873. margin-bottom: 20rpx;
  874. line-height: 40rpx;
  875. }
  876. .btn-primary {
  877. z-index: 999;
  878. border-radius: 10rpx;
  879. font-size: 24rpx;
  880. // white-space: nowrap;
  881. margin-left: 20rpx;
  882. background-color: #165DFF;
  883. line-height: 45rpx;
  884. color: #ffffff;
  885. .btn-text{
  886. color: #ffffff;
  887. font-size: 24rpx;
  888. padding: 5px 15px;
  889. }
  890. }
  891. .item-header {
  892. flex-direction: row;
  893. align-items: flex-start;
  894. margin-bottom: 16rpx;
  895. justify-content: space-between; /* 主轴两端对齐 */
  896. min-height: 55rpx;
  897. .item-title {
  898. font-size: 30rpx;
  899. color: #333333;
  900. font-weight: bold;
  901. flex-wrap: wrap;
  902. flex: 0 1 75%;
  903. min-width: 0;
  904. }
  905. .info-value {
  906. font-size: 28rpx;
  907. color: #999999;
  908. margin-left: auto;
  909. flex: 0 0 auto;
  910. white-space: nowrap;
  911. }
  912. }
  913. .info-row {
  914. flex-direction: row;
  915. justify-content: space-between;
  916. align-items: center;
  917. .info-label {
  918. font-size: 26rpx;
  919. color: #666;
  920. }
  921. .info-value {
  922. font-size: 26rpx;
  923. // color: #666;
  924. }
  925. }
  926. .text-gray{
  927. font-size: 26rpx;
  928. color: #666;
  929. }
  930. .status-view {
  931. border: 1rpx solid;
  932. border-radius: 20rpx;
  933. }
  934. .status-tag {
  935. padding: 8rpx 20rpx;
  936. border-radius: 20rpx;
  937. font-size: 24rpx;
  938. white-space: nowrap;
  939. // margin-left: 50rpx;
  940. // justify-content: flex-end;
  941. border: 1rpx solid;
  942. }
  943. /* 待接单 */
  944. .status-assigned {
  945. background-color: #ebf5ff;
  946. color: #409eff;
  947. border-color: #d8ebff;
  948. }
  949. /* 待结单 */
  950. .status-to_finish {
  951. background-color: #fff7e6;
  952. color: #fa8c16;
  953. border-color: #ffd591;
  954. }
  955. /* 待审批 */
  956. .status-to_approve {
  957. background-color: #fff7e6;
  958. color: #fa8c16;
  959. border-color: #ffd591;
  960. }
  961. /* 已挂起 */
  962. .status-suspended {
  963. background-color: #fff2f0;
  964. color: #ff4d4f;
  965. border-color: #ffccc7;
  966. }
  967. /* 自动挂起 */
  968. .status-auto_suspend {
  969. background-color: #fff2f0;
  970. color: #ff4d4f;
  971. border-color: #ffccc7;
  972. }
  973. /* 已完成 */
  974. .status-completed {
  975. background-color: #f0f9eb;
  976. color: #5cb87a;
  977. border-color: #c2e7b0;
  978. }
  979. /* 待下发 */
  980. .status-to_issue {
  981. background-color: #f4f4f5;
  982. color: #909399;
  983. border-color: #e9e9eb;
  984. }
  985. /* 已归档 */
  986. .status-archived {
  987. background-color: #f0f9eb;
  988. color: #5cb87a;
  989. border-color: #c2e7b0;
  990. }
  991. /* 退回 */
  992. .status-return {
  993. background-color: #fff2f0;
  994. color: #ff4d4f;
  995. border-color: #ffccc7;
  996. }
  997. /* 退回 */
  998. .status-accept_return {
  999. background-color: #fff2f0;
  1000. color: #ff4d4f;
  1001. border-color: #ffccc7;
  1002. }
  1003. /* 作废 */
  1004. .status-invalid {
  1005. background-color: #fff2f0;
  1006. color: #ff4d4f;
  1007. border-color: #ffccc7;
  1008. }
  1009. .scroll-view_H {
  1010. width: 100%;
  1011. flex-direction: row;
  1012. }
  1013. .scroll-view-item_H {
  1014. justify-content: center;
  1015. align-items: center;
  1016. .status-txt{
  1017. padding: 8px 12px;
  1018. text-align: center;
  1019. margin-right: 12rpx;
  1020. border-radius: 36rpx;
  1021. background-color: #fff;
  1022. font-size: 28rpx;
  1023. }
  1024. .stauts-sel{
  1025. background-color: #007AFF;
  1026. color: #fff;
  1027. }
  1028. }
  1029. .btn-group {
  1030. flex-direction: row;
  1031. align-items: center;
  1032. justify-content: flex-end;
  1033. margin-top: 20rpx;
  1034. }
  1035. </style>