projectForm.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <el-form :inline="true" class="searchBox">
  3. <el-form-item label="项目名称:" class="form project-name">
  4. <el-input v-model="queryParams.projectName" clearable />
  5. </el-form-item>
  6. <el-form-item label="人员:" class="form">
  7. <UserSelect
  8. ref="userSelectRef"
  9. construction="simple"
  10. :multiple="false"
  11. :onChange="onChangeUser"
  12. />
  13. </el-form-item>
  14. <el-form-item label="月份:" class="form">
  15. <el-date-picker
  16. v-model="queryParams.date"
  17. type="month"
  18. placeholder="请选择月份"
  19. :clearable="false"
  20. />
  21. </el-form-item>
  22. <el-form-item class="search-button">
  23. <el-button type="primary" :icon="Search" @click="onSearchHandle">查询</el-button>
  24. <ExportToExcel
  25. :data="exportData"
  26. :file-name="`${moment(queryParams.date).format('YYYY年M月')}项目工时统计.xlsx`"
  27. :colsWidth="colsWidth"
  28. :title="`${moment(queryParams.date).format('YYYY年M月')}-项目工时统计`"
  29. />
  30. </el-form-item>
  31. </el-form>
  32. </template>
  33. <script lang="ts" setup>
  34. /**
  35. * @description 查询表单
  36. */
  37. import { Search } from '@element-plus/icons-vue'
  38. import moment from 'moment'
  39. import request from '@/config/axios'
  40. import UserSelect from '@/components/UserSelect/index.vue'
  41. import ExportToExcel from '@/components/ExportToExcel/index.vue'
  42. import PubsubService from '@/utils/PubsubService'
  43. interface IQuery {
  44. projectName: string // 项目名称
  45. userId: string // 人员
  46. date: string // 日期
  47. }
  48. const queryParams = reactive<IQuery>({
  49. projectName: '',
  50. userId: '',
  51. date: moment().format('YYYY-MM')
  52. })
  53. // 查询
  54. const onSearchHandle: () => void = () => {
  55. queryParams.date = moment(queryParams.date).format('YYYY-MM')
  56. const params = {
  57. year: moment(queryParams.date).format('YYYY'),
  58. month: moment(queryParams.date).format('M'),
  59. userId: queryParams.userId ?? '',
  60. projectName: queryParams.projectName ?? ''
  61. }
  62. // 发布查询事件
  63. PubsubService.publish('xmgstj-form-onSearch', params)
  64. // onSearch?.(queryParams)
  65. // 重置查询
  66. getAllData()
  67. }
  68. // 切换人员
  69. const onChangeUser = (user) => {
  70. queryParams.userId = user
  71. }
  72. onMounted(() => {
  73. getAllData()
  74. })
  75. /* 导出 */
  76. // 导出头部
  77. const tableHead = [['人员', '项目名称', '项目编号', '项目工时(小时)']]
  78. // const newTableHead = [['公司', '月份', '部门', '人员', '项目编号', '合同编码', '工时']]
  79. // 列宽设置
  80. const colsWidth = ref([{ wch: 8 }, { wch: 100 }, { wch: 18 }, { wch: 15 }])
  81. const exportData = ref(tableHead)
  82. // 获取所有统计数据
  83. const getAllData = () => {
  84. // 发布获取所有统计数据事件
  85. PubsubService.publish('xmgstj-form-getAllData', {})
  86. request
  87. .get({
  88. url: '/adm/reportWorkloadStatistics/query-workload-statistics',
  89. params: {
  90. year: moment(queryParams.date).format('YYYY'),
  91. month: moment(queryParams.date).format('M'),
  92. userId: queryParams.userId ?? '',
  93. projectName: queryParams.projectName ?? '',
  94. isPage: false
  95. }
  96. })
  97. .then((res) => {
  98. getExportData(res)
  99. })
  100. .catch(() => {
  101. exportData.value = []
  102. })
  103. }
  104. // 整合导出表格数据
  105. const getExportData = (data) => {
  106. const tableBody = data.map((item) => [
  107. item.nickName ?? '',
  108. item.xmmc ?? '',
  109. item.xmbh ?? '',
  110. item.workTime ?? ''
  111. ])
  112. exportData.value = [...tableHead, ...tableBody]
  113. // console.log('exportData.value', exportData.value)
  114. }
  115. </script>
  116. <style scoped lang="scss">
  117. .project-name {
  118. width: 400px !important;
  119. }
  120. .search-button {
  121. display: flex;
  122. margin: 5px 0;
  123. align-items: center;
  124. flex-shrink: 0;
  125. }
  126. </style>