index.uvue 29 KB

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