index.uvue 31 KB

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