index.uvue 32 KB

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