index.uvue 32 KB

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