index.uvue 31 KB

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