index.uvue 39 KB

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