index.uvue 37 KB

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