index.uvue 30 KB

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