index.uvue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  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. const dictItem = inspectionTypeDictList.value.find(dict => dict.dictValue == inspectionType)
  727. return (dictItem != null ? dictItem.dictLabel : inspectionType) as string
  728. }
  729. }
  730. // 维修工单显示检修类型
  731. else if (orderType == "1") {
  732. const maintenanceType = getPropertyValue(item, 'maintenanceType')
  733. if (maintenanceType != null && maintenanceType != '') {
  734. // 如果字典尚未加载,返回原始值
  735. if (maintenanceTypeDictList.value.length == 0) {
  736. return maintenanceType
  737. }
  738. // 查找字典中对应的标签
  739. const dictItem = maintenanceTypeDictList.value.find(dict => dict.dictValue == maintenanceType)
  740. return (dictItem != null ? dictItem.dictLabel : maintenanceType) as string
  741. }
  742. }
  743. return ""
  744. }
  745. // 生命周期
  746. //onMounted(() => {
  747. onLoad((options: any) => {
  748. // 检查权限设置tabbar
  749. tabbar[2] = checkPermi(['gxt:app:worktime']) ? 1 : 0
  750. tabbar[3] = checkPermi(['gxt:app:score']) ? 1 : 0
  751. loadStatusDictList()
  752. loadInspectionTypeDictList()
  753. loadMaintenanceTypeDictList()
  754. loadData(false)
  755. getStatistics()
  756. dictLoaded.value = true
  757. })
  758. // 组件销毁时清除定时器
  759. onBeforeUnmount(() => {
  760. // 如果组件销毁前还有未完成的刷新操作,确保状态被重置
  761. loading.value = false;
  762. refreshing.value = false;
  763. isRefreshing.value = false;
  764. })
  765. </script>
  766. <style lang="scss">
  767. .list-page {
  768. flex: 1;
  769. background-color: #e8f0f9;
  770. padding-bottom: 150rpx; // 为底部 TabBar 留出空间
  771. }
  772. /* 搜索栏样式 */
  773. .search-bar {
  774. padding: 20rpx 30rpx;
  775. background-color: #d7eafe;
  776. }
  777. .search-box {
  778. flex-direction: row;
  779. align-items: center;
  780. height: 72rpx;
  781. padding: 0 24rpx;
  782. background-color: #f5f5f5;
  783. border-radius: 36rpx;
  784. .search-icon {
  785. width: 32rpx;
  786. height: 32rpx;
  787. margin-right: 12rpx;
  788. }
  789. .search-input {
  790. flex: 1;
  791. font-size: 28rpx;
  792. color: #333333;
  793. }
  794. .clear-icon {
  795. margin-left: 12rpx;
  796. font-size: 28rpx;
  797. color: #999999;
  798. }
  799. }
  800. /* 工单分类筛选 */
  801. .status-bar {
  802. padding-bottom: 10px;
  803. padding-left: 30rpx;
  804. background-color: #d7eafe;
  805. }
  806. .status-box {
  807. flex-direction: row;
  808. align-items: center;
  809. height: 72rpx;
  810. flex: 1;
  811. .status-txt {
  812. padding: 8px 14px;
  813. text-align: center;
  814. margin-right: 12rpx;
  815. border-radius: 36rpx;
  816. background-color: #fff;
  817. font-size: 28rpx;
  818. }
  819. .stauts-sel {
  820. background-color: #007AFF;
  821. color: #fff;
  822. }
  823. }
  824. /* 工时统计 */
  825. .stats-section {
  826. margin: 15rpx 30rpx;
  827. background-color: #ffffff;
  828. border-radius: 16rpx;
  829. padding: 20rpx;
  830. }
  831. .stats-header {
  832. flex-direction: row;
  833. justify-content: space-between;
  834. align-items: center;
  835. margin-bottom: 20rpx;
  836. }
  837. .stats-title {
  838. font-size: 32rpx;
  839. font-weight: bold;
  840. flex: 1;
  841. }
  842. .time-filters {
  843. flex-direction: row;
  844. justify-content: flex-end;
  845. }
  846. .time-tab {
  847. white-space: nowrap;
  848. margin: 0 8rpx;
  849. border-radius: 24rpx;
  850. background-color: #f2f3f5;
  851. }
  852. .time-filter {
  853. padding: 6rpx 12rpx;
  854. // margin-left: 12rpx;
  855. font-size: 24rpx;
  856. color: #666;
  857. }
  858. .time-filter-sel {
  859. background-color: #165dff;
  860. color: white;
  861. }
  862. .stats-content {
  863. margin-top: 20rpx;
  864. flex-direction: column;
  865. }
  866. .total-hours {
  867. margin-bottom: 30rpx;
  868. flex-direction: column;
  869. align-items: center;
  870. }
  871. .hours-label {
  872. font-size: 28rpx;
  873. color: #666;
  874. display: flex;
  875. margin-bottom: 8rpx;
  876. }
  877. .hours-value {
  878. display: flex;
  879. font-size: 48rpx;
  880. font-weight: bold;
  881. color: #165dff;
  882. line-height: 1.2;
  883. }
  884. .hours-breakdown {
  885. flex-direction: row;
  886. justify-content: space-between;
  887. }
  888. .breakdown-item {
  889. flex: 1;
  890. flex-direction: column;
  891. align-items: center;
  892. }
  893. .breakdown-label {
  894. display: flex;
  895. font-size: 32rpx;
  896. font-weight: bold;
  897. color: #333;
  898. line-height: 1.4;
  899. }
  900. .breakdown-value {
  901. font-size: 28rpx;
  902. color: #666;
  903. display: flex;
  904. margin-bottom: 8rpx;
  905. }
  906. /* 列表项样式 */
  907. .list-item {
  908. margin: 12rpx 30rpx;
  909. background-color: #ffffff;
  910. border-radius: 16rpx;
  911. }
  912. .item-container {
  913. padding: 30rpx;
  914. }
  915. .item-header {
  916. flex-direction: row;
  917. align-items: flex-start;
  918. margin-bottom: 16rpx;
  919. .item-title {
  920. font-size: 30rpx;
  921. color: #333333;
  922. font-weight: bold;
  923. flex-wrap: wrap;
  924. flex: 0 1 70%;
  925. min-width: 0;
  926. }
  927. .info-value {
  928. font-size: 28rpx;
  929. color: #999999;
  930. margin-left: auto;
  931. flex: 0 0 auto;
  932. white-space: nowrap;
  933. }
  934. }
  935. .info-row {
  936. flex-direction: row;
  937. justify-content: space-between;
  938. align-items: center;
  939. .info-label {
  940. font-size: 26rpx;
  941. color: #666;
  942. }
  943. .info-value {
  944. font-size: 26rpx;
  945. color: #666;
  946. }
  947. }
  948. .text-gray{
  949. font-size: 26rpx;
  950. color: #666;
  951. }
  952. /* 工单状态标签样式 */
  953. .status-tag {
  954. padding: 8rpx 20rpx;
  955. border-radius: 20rpx;
  956. font-size: 24rpx;
  957. white-space: nowrap;
  958. margin-left: 70rpx;
  959. border: 1rpx solid;
  960. }
  961. /* 待接单 */
  962. .status-assigned {
  963. background-color: #ebf5ff;
  964. color: #409eff;
  965. border-color: #d8ebff;
  966. }
  967. /* 待结单 */
  968. .status-to_finish {
  969. background-color: #fff7e6;
  970. color: #fa8c16;
  971. border-color: #ffd591;
  972. }
  973. /* 待审批 */
  974. .status-to_approve {
  975. background-color: #fff7e6;
  976. color: #fa8c16;
  977. border-color: #ffd591;
  978. }
  979. /* 已挂起 */
  980. .status-suspended {
  981. background-color: #fff2f0;
  982. color: #ff4d4f;
  983. border-color: #ffccc7;
  984. }
  985. /* 已完成 */
  986. .status-completed {
  987. background-color: #f0f9eb;
  988. color: #5cb87a;
  989. border-color: #c2e7b0;
  990. }
  991. /* 待下发 */
  992. .status-to_issue {
  993. background-color: #f4f4f5;
  994. color: #909399;
  995. border-color: #e9e9eb;
  996. }
  997. /* 已归档 */
  998. .status-archived {
  999. background-color: #f0f9eb;
  1000. color: #5cb87a;
  1001. border-color: #c2e7b0;
  1002. }
  1003. /* 日期选择弹窗 */
  1004. .date-picker-popup {
  1005. background-color: white;
  1006. border-top-left-radius: 30rpx;
  1007. border-top-right-radius: 30rpx;
  1008. padding: 40rpx;
  1009. padding-bottom: 40rpx;
  1010. margin-bottom: 150rpx;
  1011. }
  1012. .popup-header {
  1013. display: flex;
  1014. justify-content: space-between;
  1015. align-items: center;
  1016. margin-bottom: 40rpx;
  1017. }
  1018. .popup-title {
  1019. font-size: 34rpx;
  1020. font-weight: bold;
  1021. }
  1022. .popup-actions {
  1023. display: flex;
  1024. flex-direction: row;
  1025. // white-space: nowrap;
  1026. }
  1027. .popup-btn {
  1028. white-space: nowrap;
  1029. }
  1030. .cancel-btn {
  1031. color: #999;
  1032. padding: 10rpx 20rpx;
  1033. font-size: 30rpx;
  1034. font-weight: bold;
  1035. white-space: nowrap !important;
  1036. }
  1037. .confirm-btn {
  1038. color: #165dff;
  1039. padding: 10rpx 20rpx;
  1040. font-size: 30rpx;
  1041. font-weight: bold;
  1042. white-space: nowrap !important;
  1043. }
  1044. .date-picker-container {
  1045. padding: 20rpx 0;
  1046. padding-bottom: env(safe-area-inset-bottom); // 适配安全区域
  1047. }
  1048. .date-picker-item {
  1049. margin-bottom: 40rpx;
  1050. }
  1051. .date-label {
  1052. display: flex;
  1053. margin-bottom: 20rpx;
  1054. font-size: 30rpx;
  1055. color: #333;
  1056. }
  1057. .date-display {
  1058. width: 100%;
  1059. padding: 20rpx;
  1060. border: 2rpx solid #ddd;
  1061. border-radius: 8rpx;
  1062. font-size: 32rpx;
  1063. color: #333;
  1064. }
  1065. // 添加底部填充的类
  1066. .list-with-padding {
  1067. padding-bottom: 40rpx;
  1068. }
  1069. </style>