index.uvue 31 KB

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