pendingOrder.uvue 31 KB

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