index.uvue 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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
  9. class="search-input"
  10. placeholder="搜索工单编码、风机编号"
  11. v-model="searchKeyword"
  12. @confirm="handleSearch"
  13. @blur="handleSearch"
  14. />
  15. <text v-if="searchKeyword.length > 0" class="clear-icon" @click="clearSearch">✕</text>
  16. </view>
  17. </view>
  18. <!-- 工单分类筛选 -->
  19. <view class="status-bar">
  20. <view class="status-box">
  21. <text
  22. class="status-txt"
  23. :class="{ 'stauts-sel': orderTypeFilter === '' }"
  24. @click="filterByOrderType('')"
  25. >
  26. 全部
  27. </text>
  28. <text
  29. class="status-txt"
  30. :class="{ 'stauts-sel': orderTypeFilter === '1' }"
  31. @click="filterByOrderType('1')"
  32. >
  33. 维修工单
  34. </text>
  35. <text
  36. class="status-txt"
  37. :class="{ 'stauts-sel': orderTypeFilter === '2' }"
  38. @click="filterByOrderType('2')"
  39. >
  40. 维保工单
  41. </text>
  42. </view>
  43. </view>
  44. <!-- 工时统计 -->
  45. <view class="stats-section">
  46. <view class="stats-header">
  47. <text class="stats-title">{{ timeRangeTitle }}工时统计</text>
  48. <view class="time-filters">
  49. <view class="time-tab">
  50. <text
  51. class="time-filter"
  52. :class="{ 'time-filter-sel': timeRange === 'week' }"
  53. @click="changeTimeRange('week')"
  54. >
  55. 本周
  56. </text>
  57. </view>
  58. <view class="time-tab">
  59. <text
  60. class="time-filter"
  61. :class="{ 'time-filter-sel': timeRange === 'month' }"
  62. @click="changeTimeRange('month')"
  63. >
  64. 本月
  65. </text>
  66. </view>
  67. <view class="time-tab">
  68. <text
  69. class="time-filter"
  70. :class="{ 'time-filter-sel': timeRange === 'custom' }"
  71. @click="showCustomDatePickerWithCheck"
  72. >
  73. 自定义
  74. </text>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 统计数据 -->
  79. <view class="stats-content">
  80. <view class="total-hours">
  81. <text class="hours-value">{{ totalHours }}小时</text>
  82. <text class="hours-label">{{ timeRangeTitle }}总工时</text>
  83. </view>
  84. <view class="hours-breakdown">
  85. <view v-if="orderTypeFilter !== '1'" class="breakdown-item">
  86. <text class="breakdown-label">维保工时</text>
  87. <text class="breakdown-value">{{ maintenanceHours }}小时</text>
  88. </view>
  89. <view v-if="orderTypeFilter !== '2'" class="breakdown-item">
  90. <text class="breakdown-label">维修工时</text>
  91. <text class="breakdown-value">{{ repairHours }}小时</text>
  92. </view>
  93. <view v-if="rank !== null && totalRankingUsers !== null" class="breakdown-item">
  94. <text class="breakdown-label">排名</text>
  95. <text class="breakdown-value">{{ rank }}/{{ totalRankingUsers }}</text>
  96. </view>
  97. </view>
  98. </view>
  99. </view>
  100. <!-- 工单列表 -->
  101. <common-list
  102. :dataList="orderList"
  103. :loading="loading"
  104. :refreshing="refreshing"
  105. :hasMore="hasMore"
  106. @refresh="handleRefresh"
  107. @loadMore="loadMore"
  108. @itemClick="handleItemClick"
  109. class="list-with-padding"
  110. >
  111. <template #default="{ item, index }">
  112. <view class="list-item">
  113. <view class="item-container">
  114. <view class="item-header">
  115. <text class="item-title">{{ getPropertyValue(item, 'workOrderProjectNo') }}-风机编号{{ getPropertyValue(item, 'pcsDeviceName') }}的{{ getWorkOrderTypeText(getPropertyValue(item, 'orderType')) }}</text>
  116. <text class="status-tag" :class="getStatusClass(item)">{{ getWorkOrderStatus(item) }}</text>
  117. </view>
  118. <view class="info-row">
  119. <view class="info-label">
  120. <text class="text-gray">{{ getWorkOrderTypeInfo(item) }}</text>
  121. </view>
  122. </view>
  123. <view class="info-row">
  124. <view class="info-label">
  125. <text class="text-gray">下发时间: {{ getPropertyValue(item, 'assignTime') }}</text>
  126. </view>
  127. <view class="info-value">
  128. <text class="text-gray">处理时长: {{ formatNumber(parseFloat(getPropertyValue(item, 'handleHour'))) }}小时</text>
  129. </view>
  130. </view>
  131. </view>
  132. </view>
  133. </template>
  134. </common-list>
  135. <!-- 自定义时间选择弹窗 -->
  136. <l-popup v-model="showDatePickerPopup" position="bottom">
  137. <view class="date-picker-popup">
  138. <view class="popup-header">
  139. <text class="popup-title">选择时间范围</text>
  140. <view class="popup-actions">
  141. <text class="confirm-btn" @click="confirmCustomDate">确定</text>
  142. <text class="cancel-btn" @click="closeDatePicker">取消</text>
  143. </view>
  144. </view>
  145. <view class="date-picker-container">
  146. <view class="date-picker-item">
  147. <text class="date-label">开始时间</text>
  148. <view class="date-display" @click="openStartDatePicker">
  149. {{ startDate != null && startDate != '' ? startDate : '请选择开始时间' }}
  150. </view>
  151. </view>
  152. <view class="date-picker-item">
  153. <text class="date-label">结束时间</text>
  154. <view class="date-display" @click="openEndDatePicker">
  155. {{ endDate != null && endDate != '' ? endDate : '请选择结束时间' }}
  156. </view>
  157. </view>
  158. </view>
  159. </view>
  160. </l-popup>
  161. <!-- Start Date Picker -->
  162. <l-popup v-model="showStartDatePicker" position="bottom">
  163. <l-date-time-picker
  164. :mode="7"
  165. format="YYYY-MM-DD"
  166. :modelValue="startDate"
  167. confirm-btn="确定"
  168. cancel-btn="取消"
  169. @confirm="onStartDateConfirm"
  170. @cancel="showStartDatePicker = false">
  171. </l-date-time-picker>
  172. </l-popup>
  173. <!-- End Date Picker -->
  174. <l-popup v-model="showEndDatePicker" position="bottom">
  175. <l-date-time-picker
  176. :mode="7"
  177. format="YYYY-MM-DD"
  178. :modelValue="endDate"
  179. confirm-btn="确定"
  180. cancel-btn="取消"
  181. @confirm="onEndDateConfirm"
  182. @cancel="showEndDatePicker = false">
  183. </l-date-time-picker>
  184. </l-popup>
  185. <!-- 底部 TabBar -->
  186. <custom-tabbar :current="2" :hide0="tabbar[0]" :hide1="tabbar[1]" :hide2="tabbar[2]" :hide3="tabbar[3]"/>
  187. </view>
  188. </template>
  189. <script setup lang="uts">
  190. import { ref, computed, onLoad, onBeforeUnmount } from 'vue'
  191. import { listOrderHours, getOrderHourStatistics } from '@/api/worktime/index'
  192. import { getDictDataByType } from '@/api/dict/index'
  193. import type { SysDictData } from '@/types/dict'
  194. // 数据状态
  195. const searchKeyword = ref<string>('')
  196. const orderTypeFilter = ref<string>('')
  197. const timeRange = ref<string>('month')
  198. const loading = ref<boolean>(false)
  199. const refreshing = ref<boolean>(false)
  200. const hasMore = ref<boolean>(true)
  201. const orderList = ref<any[]>([])
  202. const currentPage = ref<number>(1)
  203. const totalHours = ref<number>(0)
  204. const maintenanceHours = ref<number>(0)
  205. const repairHours = ref<number>(0)
  206. const rank = ref<number | null>(null)
  207. const totalRankingUsers = ref<number | null>(null)
  208. // 添加防重复刷新的标志
  209. const isRefreshing = ref<boolean>(false)
  210. // 添加刷新时间戳,用于防抖
  211. const lastRefreshTime = ref<number>(0)
  212. // 弹窗显示状态
  213. const showDatePickerPopup = ref<boolean>(false)
  214. const showStartDatePicker = ref<boolean>(false)
  215. const showEndDatePicker = ref<boolean>(false)
  216. // 自定义日期表单
  217. const startDate = ref<string>('')
  218. const endDate = ref<string>('')
  219. const tabbar = [1,1,1,1]
  220. // 工单状态字典列表
  221. const statusDictList = ref<SysDictData[]>([])
  222. // 维保类型字典列表
  223. const inspectionTypeDictList = ref<SysDictData[]>([])
  224. // 检修类型字典列表
  225. const maintenanceTypeDictList = ref<SysDictData[]>([])
  226. const dictLoaded = ref<boolean>(false)
  227. // 计算属性
  228. const timeRangeTitle = computed(() => {
  229. switch (timeRange.value) {
  230. case 'week':
  231. return '本周'
  232. case 'month':
  233. return '本月'
  234. case 'custom':
  235. return '自定义'
  236. default:
  237. return '本月'
  238. }
  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 != null && 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. // 获取维保类型字典列表
  278. const loadInspectionTypeDictList = async (): Promise<void> => {
  279. try {
  280. const result = await getDictDataByType('gxt_inspection_type')
  281. const resultObj = result as UTSJSONObject
  282. if (resultObj['code'] == 200) {
  283. const data = resultObj['data'] as any[]
  284. const dictData: SysDictData[] = []
  285. if (data != null && data.length > 0) {
  286. for (let i = 0; i < data.length; i++) {
  287. const item = data[i] as UTSJSONObject
  288. // 只提取需要的字段
  289. const dictItem: SysDictData = {
  290. dictValue: item['dictValue'] as string | null,
  291. dictLabel: item['dictLabel'] as string | null,
  292. dictCode: null,
  293. dictSort: null,
  294. dictType: null,
  295. cssClass: null,
  296. listClass: null,
  297. isDefault: null,
  298. status: null,
  299. default: null,
  300. createTime: null,
  301. remark: null
  302. }
  303. dictData.push(dictItem)
  304. }
  305. }
  306. inspectionTypeDictList.value = dictData
  307. }
  308. } catch (e: any) {
  309. console.error('获取维保类型字典失败:', e.message)
  310. }
  311. }
  312. // 获取检修类型字典列表
  313. const loadMaintenanceTypeDictList = async (): Promise<void> => {
  314. try {
  315. const result = await getDictDataByType('gxt_maintenance_type')
  316. const resultObj = result as UTSJSONObject
  317. if (resultObj['code'] == 200) {
  318. const data = resultObj['data'] as any[]
  319. const dictData: SysDictData[] = []
  320. if (data != null && data.length > 0) {
  321. for (let i = 0; i < data.length; i++) {
  322. const item = data[i] as UTSJSONObject
  323. // 只提取需要的字段
  324. const dictItem: SysDictData = {
  325. dictValue: item['dictValue'] as string | null,
  326. dictLabel: item['dictLabel'] as string | null,
  327. dictCode: null,
  328. dictSort: null,
  329. dictType: null,
  330. cssClass: null,
  331. listClass: null,
  332. isDefault: null,
  333. status: null,
  334. default: null,
  335. createTime: null,
  336. remark: null
  337. }
  338. dictData.push(dictItem)
  339. }
  340. }
  341. maintenanceTypeDictList.value = dictData
  342. }
  343. } catch (e: any) {
  344. console.error('获取检修类型字典失败:', e.message)
  345. }
  346. }
  347. // Helper function to safely extract properties from item
  348. function getPropertyValue(item: any | null, propertyName: string): string {
  349. if (item == null) return ''
  350. const itemObj = item as UTSJSONObject
  351. const value = itemObj[propertyName]
  352. return value != null ? '' + value : ''
  353. }
  354. // 获取工单类型文本
  355. function getWorkOrderTypeText(orderType: string | null): string {
  356. if (orderType != null) {
  357. if (orderType == "1") {
  358. return "维修工单"
  359. } else if (orderType == "2") {
  360. return "维保工单"
  361. }
  362. }
  363. return ""
  364. }
  365. // 获取工单状态文本
  366. function getWorkOrderStatus(item: any | null): string | null {
  367. if (item == null) return ''
  368. const rawStatus = getPropertyValue(item, 'workOrderStatus')
  369. if (rawStatus == null || rawStatus == '') return ''
  370. // 如果字典尚未加载,返回原始值
  371. if (!dictLoaded.value) {
  372. return rawStatus
  373. }
  374. // 查找字典中对应的标签
  375. const dictItem = statusDictList.value.find(dict => dict.dictValue == rawStatus)
  376. return dictItem != null ? dictItem.dictLabel : rawStatus
  377. }
  378. // 获取工单状态样式类
  379. function getStatusClass(item: any | null): string {
  380. if (item == null) return ''
  381. const rawStatus = getPropertyValue(item, 'workOrderStatus')
  382. if (rawStatus == null || rawStatus == '') return ''
  383. return `status-${rawStatus}`
  384. }
  385. // 获取统计数据
  386. function getStatistics() {
  387. const params: UTSJSONObject = {
  388. //keyword: searchKeyword.value,
  389. orderType: orderTypeFilter.value,
  390. timeRange: timeRange.value
  391. }
  392. if (timeRange.value === 'custom') {
  393. params.beginDate = startDate.value
  394. params.endDate = endDate.value
  395. }
  396. // 添加 finally 块确保状态始终会被重置
  397. getOrderHourStatistics(params).then((response: any) => {
  398. const resultObj = response as UTSJSONObject
  399. const responseData = resultObj['data'] as UTSJSONObject
  400. if (responseData != null) {
  401. totalHours.value = (responseData['totalHours'] != null) ? parseFloat((responseData['totalHours'] as number).toFixed(1)) : 0
  402. maintenanceHours.value = (responseData['maintenanceHours'] != null) ? parseFloat((responseData['maintenanceHours'] as number).toFixed(1)) : 0
  403. repairHours.value = (responseData['repairHours'] != null) ? parseFloat((responseData['repairHours'] as number).toFixed(1)) : 0
  404. rank.value = (responseData['rank'] != null) ? responseData['rank'] as number : null
  405. totalRankingUsers.value = (responseData['totalRankingUsers'] != null) ? responseData['totalRankingUsers'] as number : null
  406. } else {
  407. totalHours.value = 0
  408. maintenanceHours.value = 0
  409. repairHours.value = 0
  410. rank.value = null
  411. totalRankingUsers.value = null
  412. }
  413. }).catch((error) => {
  414. console.error('获取工时统计数据失败:', error);
  415. // 发生错误时也要重置数据
  416. totalHours.value = 0
  417. maintenanceHours.value = 0
  418. repairHours.value = 0
  419. rank.value = null
  420. totalRankingUsers.value = null;
  421. }).finally(() => {
  422. // 统计数据获取完成,无特定加载状态需要重置
  423. })
  424. }
  425. // 方法
  426. function loadData(isRefresh: boolean, disablePullDown = false) {
  427. // 防止重复请求的核心机制 - 参考工单页面的简单有效方式
  428. if (loading.value) {
  429. // 确保刷新状态最终被重置,防止卡死
  430. if (!isRefresh) {
  431. refreshing.value = false;
  432. }
  433. return
  434. }
  435. const shouldRefresh = isRefresh !== false
  436. loading.value = true
  437. if (shouldRefresh && !disablePullDown) {
  438. currentPage.value = 1
  439. refreshing.value = true
  440. } else if (shouldRefresh && disablePullDown) {
  441. // 筛选条件变化时,重置页码但不触发下拉刷新
  442. currentPage.value = 1
  443. // 即使禁用下拉刷新,也要确保刷新状态最终被重置
  444. refreshing.value = false
  445. } else {
  446. // 对于加载更多操作,不需要显示下拉刷新状态
  447. refreshing.value = false;
  448. }
  449. const params: UTSJSONObject = {
  450. pageNum: currentPage.value,
  451. pageSize: 5,
  452. keyword: searchKeyword.value,
  453. orderType: orderTypeFilter.value,
  454. timeRange: timeRange.value
  455. }
  456. if (timeRange.value === 'custom') {
  457. params.beginDate = startDate.value
  458. params.endDate = endDate.value
  459. }
  460. // 添加 finally 块确保状态始终会被重置
  461. listOrderHours(params).then((response: any) => {
  462. // 提取响应数据
  463. const resultObj = response as UTSJSONObject
  464. console.log('API响应数据:', resultObj)
  465. const responseData = resultObj['rows'] as any[]
  466. const responseTotal = resultObj['total'] as number
  467. if (shouldRefresh) {
  468. orderList.value = Array.isArray(responseData) ? responseData : []
  469. } else {
  470. const currentRows = Array.isArray(responseData) ? responseData : []
  471. orderList.value = [...orderList.value, ...currentRows]
  472. }
  473. hasMore.value = orderList.value.length < responseTotal
  474. }).catch((error) => {
  475. console.error('获取工单列表失败:', error);
  476. // 出错时也需要重置刷新状态
  477. if (shouldRefresh) {
  478. refreshing.value = false;
  479. isRefreshing.value = false;
  480. }
  481. }).finally(() => {
  482. // 无论成功还是失败,都重置所有加载状态
  483. loading.value = false;
  484. // 确保刷新状态最终被重置
  485. if (shouldRefresh) {
  486. refreshing.value = false;
  487. // 使用setTimeout确保状态彻底重置
  488. setTimeout(() => {
  489. isRefreshing.value = false;
  490. }, 50);
  491. }
  492. })
  493. }
  494. function clearSearch() {
  495. console.log("clearSearch被触发")
  496. // 添加防重复调用检查
  497. if (loading.value) {
  498. return;
  499. }
  500. searchKeyword.value = "";
  501. currentPage.value = 1;
  502. loadData(true, true); // 添加true参数表示这是筛选条件变化触发的加载,应禁用下拉刷新
  503. getStatistics();
  504. }
  505. function handleSearch() {
  506. console.log("handleSearch被触发")
  507. // 添加防重复调用检查
  508. if (loading.value) {
  509. return;
  510. }
  511. loadData(true, true); // 添加true参数表示这是筛选条件变化触发的加载,应禁用下拉刷新
  512. getStatistics()
  513. }
  514. // 防止iOS中input事件多次触发
  515. const handleSearchWithPrevent = (() => {
  516. let lastCall = 0;
  517. return () => {
  518. const now = new Date().getTime();
  519. if (now - lastCall < 300) { // 300ms内最多执行一次
  520. return;
  521. }
  522. lastCall = now;
  523. handleSearch();
  524. };
  525. })();
  526. function filterByOrderType(type: string) {
  527. console.log("filterByOrderType被触发")
  528. // 添加防重复调用检查
  529. if (loading.value) {
  530. return;
  531. }
  532. orderTypeFilter.value = type;
  533. loadData(true, true); // 添加true参数表示这是筛选条件变化触发的加载,应禁用下拉刷新
  534. getStatistics();
  535. }
  536. function changeTimeRange(range: string) {
  537. console.log("changeTimeRange被触发")
  538. // 添加防重复调用检查
  539. if (loading.value) {
  540. return;
  541. }
  542. timeRange.value = range;
  543. loadData(true, true); // 添加true参数表示这是筛选条件变化触发的加载,应禁用下拉刷新
  544. getStatistics();
  545. }
  546. function filterByOrderTypeWithCheck(type: string) {
  547. // 防止重复点击触发多次请求
  548. if (orderTypeFilter.value === type) {
  549. return;
  550. }
  551. filterByOrderType(type);
  552. }
  553. function changeTimeRangeWithCheck(range: string) {
  554. // 防止重复点击触发多次请求
  555. if (timeRange.value === range) {
  556. return;
  557. }
  558. changeTimeRange(range);
  559. }
  560. function loadMore() {
  561. console.log("loadMore被触发")
  562. if (!hasMore.value || loading.value) return
  563. currentPage.value++
  564. loadData(false)
  565. }
  566. function handleRefresh() {
  567. console.log("handleRefresh被触发")
  568. console.log("loading.value===",loading.value)
  569. console.log("isRefreshing.value===",isRefreshing.value)
  570. // 防抖处理,避免频繁触发
  571. const now = Date.now();
  572. if (now - lastRefreshTime.value < 1000) {
  573. console.log("刷新操作过于频繁,忽略本次触发");
  574. refreshing.value = false;
  575. return;
  576. }
  577. lastRefreshTime.value = now;
  578. // 添加防重复调用检查
  579. if (loading.value || isRefreshing.value) {
  580. // 如果已经在加载或正在刷新,直接重置刷新状态
  581. refreshing.value = false;
  582. return;
  583. }
  584. console.log("loading.value1===",loading.value)
  585. console.log("isRefreshing.value1===",isRefreshing.value)
  586. // 设置刷新标志
  587. isRefreshing.value = true;
  588. loadData(true); // 使用默认的下拉刷新行为
  589. // 确保在一定时间后重置刷新标志,防止意外情况
  590. setTimeout(() => {
  591. isRefreshing.value = false
  592. }, 100) // 延迟重置,确保状态完全更新
  593. }
  594. function showCustomDatePicker() {
  595. // 初始化日期值
  596. if (startDate.value == '' || endDate.value == '') {
  597. const now = new Date()
  598. const year = now.getFullYear()
  599. const month = (now.getMonth() + 1).toString().padStart(2, '0')
  600. const day = now.getDate().toString().padStart(2, '0')
  601. endDate.value = `${year}-${month}-${day}`
  602. // 默认开始日期为7天前
  603. const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000)
  604. const weekAgoYear = weekAgo.getFullYear()
  605. const weekAgoMonth = (weekAgo.getMonth() + 1).toString().padStart(2, '0')
  606. const weekAgoDay = weekAgo.getDate().toString().padStart(2, '0')
  607. startDate.value = `${weekAgoYear}-${weekAgoMonth}-${weekAgoDay}`
  608. }
  609. showDatePickerPopup.value = true
  610. }
  611. function closeDatePicker() {
  612. showStartDatePicker.value = false
  613. showEndDatePicker.value = false
  614. showDatePickerPopup.value = false
  615. }
  616. function confirmCustomDate() {
  617. if (startDate.value == null || startDate.value == '' || endDate.value == null || endDate.value == '') {
  618. uni.showToast({ title: '请选择开始时间和结束时间', icon: 'none' })
  619. return
  620. }
  621. if (startDate.value != null && endDate.value != null && new Date(startDate.value as string) > new Date(endDate.value as string)) {
  622. uni.showToast({ title: '开始时间不能大于结束时间', icon: 'none' })
  623. return
  624. }
  625. closeDatePicker()
  626. timeRange.value = 'custom'
  627. // 添加防重复调用检查
  628. if (loading.value) {
  629. return;
  630. }
  631. loadData(true, true); // 添加true参数表示这是筛选条件变化触发的加载,应禁用下拉刷新
  632. getStatistics()
  633. }
  634. function showCustomDatePickerWithCheck() {
  635. // 防止重复点击触发多次请求
  636. if (timeRange.value === 'custom') {
  637. // 重新选择日期
  638. showCustomDatePicker();
  639. return;
  640. }
  641. showCustomDatePicker();
  642. }
  643. // 打开开始日期选择器
  644. function openStartDatePicker() {
  645. showStartDatePicker.value = true
  646. }
  647. // 打开结束日期选择器
  648. function openEndDatePicker() {
  649. showEndDatePicker.value = true
  650. }
  651. function onStartDateConfirm(value: string) {
  652. // 检查结束时间是否小于新的开始时间
  653. if (endDate.value != null && endDate.value != '' && new Date(value) > new Date(endDate.value as string)) {
  654. uni.showToast({ title: '开始时间不能大于结束时间', icon: 'none' })
  655. return
  656. }
  657. startDate.value = value
  658. showStartDatePicker.value = false
  659. }
  660. function onEndDateConfirm(value: string) {
  661. // 检查新的结束时间是否小于开始时间
  662. if (startDate.value != null && startDate.value != '' && new Date(startDate.value as string) > new Date(value)) {
  663. uni.showToast({ title: '结束时间不能小于开始时间', icon: 'none' })
  664. return
  665. }
  666. endDate.value = value
  667. showEndDatePicker.value = false
  668. }
  669. // 点击列表项
  670. function handleItemClick(item: any | null, index: number): void {
  671. if (item == null) return
  672. const itemObj = item as UTSJSONObject
  673. const id = itemObj.get('id')
  674. const orderType = itemObj.get('orderType')
  675. if (id != null && orderType != null) {
  676. // 转换为字符串
  677. const idStr = '' + id
  678. const orderTypeStr = '' + orderType
  679. uni.navigateTo({
  680. url: `/pages/worktime/detail/index?id=${idStr}&orderType=${orderTypeStr}`
  681. })
  682. }
  683. }
  684. function getOrderStatusText(status: string): string {
  685. const statusMap: UTSJSONObject = {
  686. '1': '待接单',
  687. '2': '进行中',
  688. '3': '已完成',
  689. '4': '已关闭'
  690. }
  691. const result = statusMap[status]
  692. return result != null ? result as string : '未知状态'
  693. }
  694. function formatDate(dateString: string) {
  695. if (dateString == '' || dateString == null) return ''
  696. const date = new Date(dateString)
  697. const year = date.getFullYear()
  698. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  699. const day = date.getDate().toString().padStart(2, '0')
  700. const hours = date.getHours().toString().padStart(2, '0')
  701. const minutes = date.getMinutes().toString().padStart(2, '0')
  702. return `${year}-${month}-${day} ${hours}:${minutes}`
  703. }
  704. function formatNumber(value: number | null) {
  705. if (value === null) return '0.0'
  706. return value.toFixed(1)
  707. }
  708. // 获取工单类型相关信息(维保类型或检修类型)
  709. function getWorkOrderTypeInfo(item: any | null): string {
  710. if (item == null) return ''
  711. const orderType = getPropertyValue(item, 'orderType')
  712. // 维保工单显示维保类型
  713. if (orderType == "2") {
  714. const inspectionType = getPropertyValue(item, 'inspectionType')
  715. if (inspectionType != null && inspectionType != '') {
  716. // 如果字典尚未加载,返回原始值
  717. if (inspectionTypeDictList.value.length == 0) {
  718. return inspectionType
  719. }
  720. // 查找字典中对应的标签
  721. const dictItem = inspectionTypeDictList.value.find(dict => dict.dictValue == inspectionType)
  722. return (dictItem != null ? dictItem.dictLabel : inspectionType) as string
  723. }
  724. }
  725. // 维修工单显示检修类型
  726. else if (orderType == "1") {
  727. const maintenanceType = getPropertyValue(item, 'maintenanceType')
  728. if (maintenanceType != null && maintenanceType != '') {
  729. // 如果字典尚未加载,返回原始值
  730. if (maintenanceTypeDictList.value.length == 0) {
  731. return maintenanceType
  732. }
  733. // 查找字典中对应的标签
  734. const dictItem = maintenanceTypeDictList.value.find(dict => dict.dictValue == maintenanceType)
  735. return (dictItem != null ? dictItem.dictLabel : maintenanceType) as string
  736. }
  737. }
  738. return ""
  739. }
  740. // 生命周期
  741. onLoad((options) => {
  742. loadStatusDictList()
  743. loadInspectionTypeDictList()
  744. loadMaintenanceTypeDictList()
  745. loadData(false)
  746. getStatistics()
  747. dictLoaded.value = true
  748. })
  749. // 组件销毁时清除定时器
  750. onBeforeUnmount(() => {
  751. // 如果组件销毁前还有未完成的刷新操作,确保状态被重置
  752. loading.value = false;
  753. refreshing.value = false;
  754. isRefreshing.value = false;
  755. })
  756. </script>
  757. <style lang="scss">
  758. .list-page {
  759. flex: 1;
  760. background-color: #e8f0f9;
  761. padding-bottom: 150rpx; // 为底部 TabBar 留出空间
  762. }
  763. /* 搜索栏样式 */
  764. .search-bar {
  765. padding: 20rpx 30rpx;
  766. background-color: #d7eafe;
  767. }
  768. .search-box {
  769. flex-direction: row;
  770. align-items: center;
  771. height: 72rpx;
  772. padding: 0 24rpx;
  773. background-color: #f5f5f5;
  774. border-radius: 36rpx;
  775. .search-icon {
  776. width: 32rpx;
  777. height: 32rpx;
  778. margin-right: 12rpx;
  779. }
  780. .search-input {
  781. flex: 1;
  782. font-size: 28rpx;
  783. color: #333333;
  784. }
  785. .clear-icon {
  786. margin-left: 12rpx;
  787. font-size: 28rpx;
  788. color: #999999;
  789. }
  790. }
  791. /* 工单分类筛选 */
  792. .status-bar {
  793. padding-bottom: 10px;
  794. padding-left: 30rpx;
  795. background-color: #d7eafe;
  796. }
  797. .status-box {
  798. flex-direction: row;
  799. align-items: center;
  800. height: 72rpx;
  801. flex: 1;
  802. .status-txt {
  803. padding: 8px 14px;
  804. text-align: center;
  805. margin-right: 12rpx;
  806. border-radius: 36rpx;
  807. background-color: #fff;
  808. font-size: 28rpx;
  809. }
  810. .stauts-sel {
  811. background-color: #007AFF;
  812. color: #fff;
  813. }
  814. }
  815. /* 工时统计 */
  816. .stats-section {
  817. margin: 15rpx 30rpx;
  818. background-color: #ffffff;
  819. border-radius: 16rpx;
  820. padding: 20rpx;
  821. }
  822. .stats-header {
  823. flex-direction: row;
  824. justify-content: space-between;
  825. align-items: center;
  826. margin-bottom: 20rpx;
  827. }
  828. .stats-title {
  829. font-size: 32rpx;
  830. font-weight: bold;
  831. flex: 1;
  832. }
  833. .time-filters {
  834. flex-direction: row;
  835. justify-content: flex-end;
  836. }
  837. .time-tab {
  838. white-space: nowrap;
  839. margin: 0 8rpx;
  840. border-radius: 24rpx;
  841. background-color: #f2f3f5;
  842. }
  843. .time-filter {
  844. padding: 6rpx 12rpx;
  845. // margin-left: 12rpx;
  846. font-size: 24rpx;
  847. color: #666;
  848. }
  849. .time-filter-sel {
  850. background-color: #165dff;
  851. color: white;
  852. }
  853. .stats-content {
  854. margin-top: 20rpx;
  855. flex-direction: column;
  856. }
  857. .total-hours {
  858. margin-bottom: 30rpx;
  859. flex-direction: column;
  860. align-items: center;
  861. }
  862. .hours-label {
  863. font-size: 28rpx;
  864. color: #666;
  865. display: flex;
  866. margin-bottom: 8rpx;
  867. }
  868. .hours-value {
  869. display: flex;
  870. font-size: 48rpx;
  871. font-weight: bold;
  872. color: #165dff;
  873. line-height: 1.2;
  874. }
  875. .hours-breakdown {
  876. flex-direction: row;
  877. justify-content: space-between;
  878. }
  879. .breakdown-item {
  880. flex: 1;
  881. flex-direction: column;
  882. align-items: center;
  883. }
  884. .breakdown-label {
  885. display: flex;
  886. font-size: 32rpx;
  887. font-weight: bold;
  888. color: #333;
  889. line-height: 1.4;
  890. }
  891. .breakdown-value {
  892. font-size: 28rpx;
  893. color: #666;
  894. display: flex;
  895. margin-bottom: 8rpx;
  896. }
  897. /* 列表项样式 */
  898. .list-item {
  899. margin: 12rpx 30rpx;
  900. background-color: #ffffff;
  901. border-radius: 16rpx;
  902. }
  903. .item-container {
  904. padding: 30rpx;
  905. }
  906. .item-header {
  907. flex-direction: row;
  908. align-items: flex-start;
  909. margin-bottom: 16rpx;
  910. .item-title {
  911. font-size: 30rpx;
  912. color: #333333;
  913. font-weight: bold;
  914. flex-wrap: wrap;
  915. flex: 0 1 70%;
  916. min-width: 0;
  917. }
  918. .info-value {
  919. font-size: 28rpx;
  920. color: #999999;
  921. margin-left: auto;
  922. flex: 0 0 auto;
  923. white-space: nowrap;
  924. }
  925. }
  926. .info-row {
  927. flex-direction: row;
  928. justify-content: space-between;
  929. align-items: center;
  930. .info-label {
  931. font-size: 26rpx;
  932. color: #666;
  933. }
  934. .info-value {
  935. font-size: 26rpx;
  936. color: #666;
  937. }
  938. }
  939. .text-gray{
  940. font-size: 26rpx;
  941. color: #666;
  942. }
  943. /* 工单状态标签样式 */
  944. .status-tag {
  945. padding: 8rpx 20rpx;
  946. border-radius: 20rpx;
  947. font-size: 24rpx;
  948. white-space: nowrap;
  949. margin-left: 70rpx;
  950. border: 1rpx solid;
  951. }
  952. /* 待接单 */
  953. .status-assigned {
  954. background-color: #ebf5ff;
  955. color: #409eff;
  956. border-color: #d8ebff;
  957. }
  958. /* 待结单 */
  959. .status-to_finish {
  960. background-color: #fff7e6;
  961. color: #fa8c16;
  962. border-color: #ffd591;
  963. }
  964. /* 待审批 */
  965. .status-to_approve {
  966. background-color: #fff7e6;
  967. color: #fa8c16;
  968. border-color: #ffd591;
  969. }
  970. /* 已挂起 */
  971. .status-suspended {
  972. background-color: #fff2f0;
  973. color: #ff4d4f;
  974. border-color: #ffccc7;
  975. }
  976. /* 已完成 */
  977. .status-completed {
  978. background-color: #f0f9eb;
  979. color: #5cb87a;
  980. border-color: #c2e7b0;
  981. }
  982. /* 待下发 */
  983. .status-to_issue {
  984. background-color: #f4f4f5;
  985. color: #909399;
  986. border-color: #e9e9eb;
  987. }
  988. /* 已归档 */
  989. .status-archived {
  990. background-color: #f0f9eb;
  991. color: #5cb87a;
  992. border-color: #c2e7b0;
  993. }
  994. /* 日期选择弹窗 */
  995. .date-picker-popup {
  996. background-color: white;
  997. border-top-left-radius: 30rpx;
  998. border-top-right-radius: 30rpx;
  999. padding: 40rpx;
  1000. padding-bottom: 40rpx;
  1001. margin-bottom: 150rpx;
  1002. }
  1003. .popup-header {
  1004. display: flex;
  1005. justify-content: space-between;
  1006. align-items: center;
  1007. margin-bottom: 40rpx;
  1008. }
  1009. .popup-title {
  1010. font-size: 34rpx;
  1011. font-weight: bold;
  1012. }
  1013. .popup-actions {
  1014. display: flex;
  1015. flex-direction: row;
  1016. }
  1017. .cancel-btn {
  1018. color: #999;
  1019. padding: 10rpx 20rpx;
  1020. }
  1021. .confirm-btn {
  1022. color: #165dff;
  1023. padding: 10rpx 20rpx;
  1024. font-weight: bold;
  1025. }
  1026. .date-picker-container {
  1027. padding: 20rpx 0;
  1028. padding-bottom: env(safe-area-inset-bottom); // 适配安全区域
  1029. }
  1030. .date-picker-item {
  1031. margin-bottom: 40rpx;
  1032. }
  1033. .date-label {
  1034. display: flex;
  1035. margin-bottom: 20rpx;
  1036. font-size: 30rpx;
  1037. color: #333;
  1038. }
  1039. .date-display {
  1040. width: 100%;
  1041. padding: 20rpx;
  1042. border: 2rpx solid #ddd;
  1043. border-radius: 8rpx;
  1044. font-size: 32rpx;
  1045. color: #333;
  1046. }
  1047. // 添加底部填充的类
  1048. .list-with-padding {
  1049. padding-bottom: 40rpx;
  1050. }
  1051. </style>