index.uvue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. />
  14. <text v-if="searchKeyword.length > 0" class="clear-icon" @click="clearSearch">✕</text>
  15. </view>
  16. </view>
  17. <!-- 工单分类筛选 -->
  18. <view class="status-bar">
  19. <view class="status-box">
  20. <text
  21. class="status-txt"
  22. :class="{ 'stauts-sel': orderTypeFilter === '' }"
  23. @click="filterByOrderType('')"
  24. >
  25. 全部
  26. </text>
  27. <text
  28. class="status-txt"
  29. :class="{ 'stauts-sel': orderTypeFilter === '1' }"
  30. @click="filterByOrderType('1')"
  31. >
  32. 维修工单
  33. </text>
  34. <text
  35. class="status-txt"
  36. :class="{ 'stauts-sel': orderTypeFilter === '2' }"
  37. @click="filterByOrderType('2')"
  38. >
  39. 维保工单
  40. </text>
  41. </view>
  42. </view>
  43. <!-- 工时统计 -->
  44. <view class="stats-section">
  45. <view class="stats-header">
  46. <text class="stats-title">{{ timeRangeTitle }}工时统计</text>
  47. <view class="time-filters">
  48. <text
  49. class="time-filter"
  50. :class="{ 'time-filter-sel': timeRange === 'week' }"
  51. @click="changeTimeRange('week')"
  52. >
  53. 本周
  54. </text>
  55. <text
  56. class="time-filter"
  57. :class="{ 'time-filter-sel': timeRange === 'month' }"
  58. @click="changeTimeRange('month')"
  59. >
  60. 本月
  61. </text>
  62. <text
  63. class="time-filter"
  64. :class="{ 'time-filter-sel': timeRange === 'custom' }"
  65. @click="showCustomDatePicker"
  66. >
  67. 自定义
  68. </text>
  69. </view>
  70. </view>
  71. <!-- 统计数据 -->
  72. <view class="stats-content">
  73. <view class="total-hours">
  74. <text class="hours-value">{{ totalHours }}小时</text>
  75. <text class="hours-label">{{ timeRangeTitle }}总工时</text>
  76. </view>
  77. <view class="hours-breakdown">
  78. <view v-if="orderTypeFilter !== '1'" class="breakdown-item">
  79. <text class="breakdown-label">维保工时</text>
  80. <text class="breakdown-value">{{ maintenanceHours }}小时</text>
  81. </view>
  82. <view v-if="orderTypeFilter !== '2'" class="breakdown-item">
  83. <text class="breakdown-label">维修工时</text>
  84. <text class="breakdown-value">{{ repairHours }}小时</text>
  85. </view>
  86. <view v-if="rank !== null" class="breakdown-item">
  87. <text class="breakdown-label">排名</text>
  88. <text class="breakdown-value">第{{ rank }}名</text>
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. <!-- 工单列表 -->
  94. <common-list
  95. :dataList="orderList"
  96. :loading="loading"
  97. :refreshing="refreshing"
  98. :hasMore="hasMore"
  99. @refresh="handleRefresh"
  100. @loadMore="loadMore"
  101. @itemClick="viewOrderDetail"
  102. >
  103. <template #default="{ item }">
  104. <view class="list-item">
  105. <view class="item-container">
  106. <view class="item-header">
  107. <text class="item-title">{{ getPropertyValue(item, 'workOrderProjectNo') }}-风机编号{{ getPropertyValue(item, 'pcsDeviceName') }}的{{ getWorkOrderTypeText(getPropertyValue(item, 'orderType')) }}</text>
  108. <text class="info-value">{{ getOrderStatusText(getPropertyValue(item, 'workOrderStatus')) }}</text>
  109. </view>
  110. <view class="info-row">
  111. <view class="info-label">
  112. <text class="text-xs text-gray-500">下发时间: {{ formatDate(getPropertyValue(item, 'assignTime')) }}</text>
  113. </view>
  114. <view class="info-value">
  115. <text>处理时长: {{ formatNumber(parseFloat(getPropertyValue(item, 'handleHour'))) }}小时</text>
  116. </view>
  117. </view>
  118. </view>
  119. </view>
  120. </template>
  121. </common-list>
  122. <!-- 自定义时间选择弹窗 -->
  123. <l-popup v-model="showDatePickerPopup" position="bottom">
  124. <view class="date-picker-popup">
  125. <view class="popup-header">
  126. <text class="popup-title">选择时间范围</text>
  127. <view class="popup-actions">
  128. <text class="cancel-btn" @click="closeDatePicker">取消</text>
  129. <text class="confirm-btn" @click="confirmCustomDate">确定</text>
  130. </view>
  131. </view>
  132. <view class="date-picker-container">
  133. <view class="date-picker-item">
  134. <text class="date-label">开始时间</text>
  135. <input type="date" v-model="startDate" class="date-input" />
  136. </view>
  137. <view class="date-picker-item">
  138. <text class="date-label">结束时间</text>
  139. <input type="date" v-model="endDate" class="date-input" />
  140. </view>
  141. </view>
  142. </view>
  143. </l-popup>
  144. <!-- 底部 TabBar -->
  145. <custom-tabbar :current="2" />
  146. </view>
  147. </template>
  148. <script setup lang="uts">
  149. import { ref, computed, onMounted } from 'vue'
  150. import { listOrderHours, getOrderHourStatistics } from '@/api/worktime/index'
  151. // 数据状态
  152. const searchKeyword = ref<string>('')
  153. const orderTypeFilter = ref<string>('')
  154. const timeRange = ref<string>('month')
  155. const loading = ref<boolean>(false)
  156. const refreshing = ref<boolean>(false)
  157. const hasMore = ref<boolean>(true)
  158. const orderList = ref<any[]>([])
  159. const currentPage = ref<number>(1)
  160. const totalHours = ref<number>(0)
  161. const maintenanceHours = ref<number>(0)
  162. const repairHours = ref<number>(0)
  163. const rank = ref<number | null>(null)
  164. // 弹窗显示状态
  165. const showDatePickerPopup = ref<boolean>(false)
  166. // 自定义日期表单
  167. const startDate = ref<string>('')
  168. const endDate = ref<string>('')
  169. // 计算属性
  170. const timeRangeTitle = computed(() => {
  171. switch (timeRange.value) {
  172. case 'week':
  173. return '本周'
  174. case 'month':
  175. return '本月'
  176. case 'custom':
  177. return '自定义'
  178. default:
  179. return '本月'
  180. }
  181. })
  182. // Helper function to safely extract properties from item
  183. function getPropertyValue(item: any | null, propertyName: string): string {
  184. if (item == null) return ''
  185. const itemObj = item as UTSJSONObject
  186. const value = itemObj[propertyName]
  187. return value != null ? '' + value : ''
  188. }
  189. // 获取工单类型文本
  190. function getWorkOrderTypeText(orderType: string | null): string {
  191. if (orderType != null) {
  192. if (orderType == "1") {
  193. return "维修工单"
  194. } else if (orderType == "2") {
  195. return "维保工单"
  196. }
  197. }
  198. return ""
  199. }
  200. // 获取统计数据
  201. function getStatistics() {
  202. const params: UTSJSONObject = {
  203. keyword: searchKeyword.value,
  204. orderType: orderTypeFilter.value,
  205. timeRange: timeRange.value
  206. }
  207. if (timeRange.value === 'custom') {
  208. params.beginDate = startDate.value
  209. params.endDate = endDate.value
  210. }
  211. getOrderHourStatistics(params).then((response: any) => {
  212. const resultObj = response as UTSJSONObject
  213. const responseData = resultObj['data'] as UTSJSONObject
  214. if (responseData != null) {
  215. totalHours.value = (responseData['totalHours'] != null) ? parseFloat((responseData['totalHours'] as number).toFixed(1)) : 0
  216. maintenanceHours.value = (responseData['maintenanceHours'] != null) ? parseFloat((responseData['maintenanceHours'] as number).toFixed(1)) : 0
  217. repairHours.value = (responseData['repairHours'] != null) ? parseFloat((responseData['repairHours'] as number).toFixed(1)) : 0
  218. rank.value = (responseData['rank'] != null) ? responseData['rank'] as number : null
  219. } else {
  220. totalHours.value = 0
  221. maintenanceHours.value = 0
  222. repairHours.value = 0
  223. rank.value = null
  224. }
  225. })
  226. }
  227. // 方法
  228. function loadData(isRefresh: boolean) {
  229. const shouldRefresh = isRefresh
  230. if (loading.value && !shouldRefresh) {
  231. return
  232. }
  233. loading.value = true
  234. if (shouldRefresh) {
  235. currentPage.value = 1
  236. refreshing.value = true
  237. }
  238. const params: UTSJSONObject = {
  239. pageNum: currentPage.value,
  240. pageSize: 10,
  241. keyword: searchKeyword.value,
  242. orderType: orderTypeFilter.value,
  243. timeRange: timeRange.value
  244. }
  245. if (timeRange.value === 'custom') {
  246. params.beginDate = startDate.value
  247. params.endDate = endDate.value
  248. }
  249. listOrderHours(params).then((response: any) => {
  250. // 提取响应数据
  251. const resultObj = response as UTSJSONObject
  252. const responseData = resultObj['rows'] as any[]
  253. const responseTotal = resultObj['total'] as number
  254. if (shouldRefresh) {
  255. orderList.value = Array.isArray(responseData) ? responseData : []
  256. } else {
  257. const currentRows = Array.isArray(responseData) ? responseData : []
  258. orderList.value = [...orderList.value, ...currentRows]
  259. }
  260. hasMore.value = orderList.value.length < responseTotal
  261. loading.value = false
  262. refreshing.value = false
  263. }).catch(() => {
  264. loading.value = false
  265. refreshing.value = false
  266. })
  267. }
  268. function handleSearch() {
  269. loadData(true)
  270. getStatistics()
  271. }
  272. function clearSearch() {
  273. searchKeyword.value = ""
  274. loadData(true)
  275. getStatistics()
  276. }
  277. function filterByOrderType(type: string) {
  278. orderTypeFilter.value = type
  279. loadData(true)
  280. getStatistics()
  281. }
  282. function changeTimeRange(range: string) {
  283. timeRange.value = range
  284. loadData(true)
  285. getStatistics()
  286. }
  287. function loadMore() {
  288. if (!hasMore.value || loading.value) return
  289. currentPage.value++
  290. loadData(false)
  291. }
  292. function handleRefresh() {
  293. loadData(true)
  294. }
  295. function showCustomDatePicker() {
  296. showDatePickerPopup.value = true;
  297. }
  298. function closeDatePicker() {
  299. showDatePickerPopup.value = false;
  300. }
  301. function confirmCustomDate() {
  302. if (startDate.value == null || startDate.value == '' || endDate.value == null || endDate.value == '') {
  303. uni.showToast({ title: '请选择开始时间和结束时间', icon: 'none' })
  304. return
  305. }
  306. if (startDate.value != null && endDate.value != null && new Date(startDate.value as string) > new Date(endDate.value as string)) {
  307. uni.showToast({ title: '开始时间不能大于结束时间', icon: 'none' })
  308. return
  309. }
  310. closeDatePicker()
  311. timeRange.value = 'custom'
  312. loadData(true)
  313. getStatistics()
  314. }
  315. function viewOrderDetail(item: any) {
  316. // 跳转到工单详情页面
  317. if (item != null) {
  318. const itemObj = item as UTSJSONObject
  319. const id = itemObj['id']
  320. const orderType = itemObj['orderType']
  321. uni.navigateTo({
  322. url: `/pages/worktime/detail?id=${id}&orderType=${orderType}`
  323. })
  324. }
  325. }
  326. function getOrderStatusText(status: string): string {
  327. const statusMap: UTSJSONObject = {
  328. '1': '待接单',
  329. '2': '进行中',
  330. '3': '已完成',
  331. '4': '已关闭'
  332. }
  333. const result = statusMap[status]
  334. return result != null ? result as string : '未知状态'
  335. }
  336. function formatDate(dateString: string) {
  337. if (dateString == '' || dateString == null) return ''
  338. const date = new Date(dateString)
  339. const year = date.getFullYear()
  340. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  341. const day = date.getDate().toString().padStart(2, '0')
  342. const hours = date.getHours().toString().padStart(2, '0')
  343. const minutes = date.getMinutes().toString().padStart(2, '0')
  344. return `${year}-${month}-${day} ${hours}:${minutes}`
  345. }
  346. function formatNumber(value: number | null) {
  347. if (value === null) return '0.0'
  348. return value.toFixed(1)
  349. }
  350. // 生命周期
  351. onMounted(() => {
  352. loadData(false)
  353. getStatistics()
  354. })
  355. </script>
  356. <style lang="scss">
  357. .list-page {
  358. flex: 1;
  359. background-color: #e8f0f9;
  360. }
  361. /* 搜索栏样式 */
  362. .search-bar {
  363. padding: 20rpx 30rpx;
  364. background-color: #d7eafe;
  365. }
  366. .search-box {
  367. flex-direction: row;
  368. align-items: center;
  369. height: 72rpx;
  370. padding: 0 24rpx;
  371. background-color: #f5f5f5;
  372. border-radius: 36rpx;
  373. .search-icon {
  374. width: 32rpx;
  375. height: 32rpx;
  376. margin-right: 12rpx;
  377. }
  378. .search-input {
  379. flex: 1;
  380. font-size: 28rpx;
  381. color: #333333;
  382. }
  383. .clear-icon {
  384. margin-left: 12rpx;
  385. font-size: 28rpx;
  386. color: #999999;
  387. }
  388. }
  389. /* 工单分类筛选 */
  390. .status-bar {
  391. padding-bottom: 10px;
  392. padding-left: 30rpx;
  393. background-color: #d7eafe;
  394. }
  395. .status-box {
  396. flex-direction: row;
  397. align-items: center;
  398. height: 72rpx;
  399. flex: 1;
  400. .status-txt {
  401. padding: 8px 12px;
  402. text-align: center;
  403. margin-right: 12rpx;
  404. border-radius: 36rpx;
  405. background-color: #fff;
  406. font-size: 28rpx;
  407. }
  408. .stauts-sel {
  409. background-color: #007AFF;
  410. color: #fff;
  411. }
  412. }
  413. /* 工时统计 */
  414. .stats-section {
  415. margin: 15rpx 30rpx;
  416. background-color: #ffffff;
  417. border-radius: 16rpx;
  418. padding: 20rpx;
  419. }
  420. .stats-header {
  421. flex-direction: row;
  422. justify-content: space-between;
  423. align-items: center;
  424. margin-bottom: 20rpx;
  425. }
  426. .stats-title {
  427. font-size: 32rpx;
  428. font-weight: 500;
  429. flex: 1;
  430. }
  431. .time-filters {
  432. flex-direction: row;
  433. justify-content: flex-end;
  434. }
  435. .time-filter {
  436. padding: 6rpx 16rpx;
  437. margin-left: 12rpx;
  438. font-size: 24rpx;
  439. border-radius: 24rpx;
  440. background-color: #f2f3f5;
  441. color: #666;
  442. white-space: nowrap;
  443. }
  444. .time-filter-sel {
  445. background-color: #165dff;
  446. color: white;
  447. }
  448. .stats-content {
  449. margin-top: 20rpx;
  450. flex-direction: column;
  451. }
  452. .total-hours {
  453. margin-bottom: 30rpx;
  454. flex-direction: column;
  455. align-items: center;
  456. }
  457. .hours-label {
  458. font-size: 28rpx;
  459. color: #666;
  460. display: block;
  461. margin-bottom: 8rpx;
  462. }
  463. .hours-value {
  464. display: block;
  465. font-size: 48rpx;
  466. font-weight: bold;
  467. color: #165dff;
  468. line-height: 1.2;
  469. }
  470. .hours-breakdown {
  471. flex-direction: row;
  472. justify-content: space-between;
  473. }
  474. .breakdown-item {
  475. flex: 1;
  476. flex-direction: column;
  477. align-items: center;
  478. }
  479. .breakdown-label {
  480. display: block;
  481. font-size: 32rpx;
  482. font-weight: bold;
  483. color: #333;
  484. line-height: 1.4;
  485. }
  486. .breakdown-value {
  487. font-size: 28rpx;
  488. color: #666;
  489. display: block;
  490. margin-bottom: 8rpx;
  491. }
  492. /* 列表项样式 */
  493. .list-item {
  494. margin: 12rpx 30rpx;
  495. background-color: #ffffff;
  496. border-radius: 16rpx;
  497. }
  498. .item-container {
  499. padding: 30rpx;
  500. }
  501. .item-header {
  502. flex-direction: row;
  503. align-items: center;
  504. margin-bottom: 16rpx;
  505. .item-title {
  506. flex: 1;
  507. font-size: 32rpx;
  508. color: #333333;
  509. font-weight: bold;
  510. }
  511. .info-value {
  512. font-size: 28rpx;
  513. color: #999999;
  514. }
  515. }
  516. .info-row {
  517. flex-direction: row;
  518. justify-content: space-between;
  519. align-items: center;
  520. .info-label {
  521. font-size: 26rpx;
  522. color: #666666;
  523. }
  524. .info-value {
  525. font-size: 26rpx;
  526. color: #333333;
  527. }
  528. }
  529. /* 日期选择弹窗 */
  530. .date-picker-popup {
  531. background-color: white;
  532. border-top-left-radius: 30rpx;
  533. border-top-right-radius: 30rpx;
  534. padding: 40rpx;
  535. }
  536. .popup-header {
  537. display: flex;
  538. justify-content: space-between;
  539. align-items: center;
  540. margin-bottom: 40rpx;
  541. }
  542. .popup-title {
  543. font-size: 34rpx;
  544. font-weight: 500;
  545. }
  546. .cancel-btn {
  547. color: #999;
  548. padding: 10rpx 20rpx;
  549. }
  550. .confirm-btn {
  551. color: #165dff;
  552. padding: 10rpx 20rpx;
  553. font-weight: 500;
  554. }
  555. .date-picker-container {
  556. padding: 20rpx 0;
  557. }
  558. .date-picker-item {
  559. margin-bottom: 40rpx;
  560. }
  561. .date-label {
  562. display: block;
  563. margin-bottom: 20rpx;
  564. font-size: 30rpx;
  565. color: #333;
  566. }
  567. .date-input {
  568. width: 100%;
  569. padding: 20rpx;
  570. border: 2rpx solid #ddd;
  571. border-radius: 8rpx;
  572. font-size: 32rpx;
  573. }
  574. </style>