RepairWorkHour.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <div class="page-header-index-wide">
  3. <a-card :bordered="false">
  4. <a-tabs v-model="activeTab" @change="handleTabChange">
  5. <a-tab-pane tab="按维修人统计" key="user"></a-tab-pane>
  6. <a-tab-pane tab="按设备统计" key="sb"></a-tab-pane>
  7. </a-tabs>
  8. <div class="table-page-search-wrapper" @keyup.enter="handleSearch">
  9. <a-form layout="inline">
  10. <a-row :gutter="48">
  11. <a-col :md="8" :sm="24" v-if="activeTab === 'user'">
  12. <a-form-item label="维修人">
  13. <a-input v-model="queryParam.repairUserName" placeholder="请输入维修人姓名" allow-clear/>
  14. </a-form-item>
  15. </a-col>
  16. <a-col :md="8" :sm="24" v-else>
  17. <a-form-item label="设备">
  18. <a-input v-model="queryParam.keyword" placeholder="请输入设备名称/编号" allow-clear/>
  19. </a-form-item>
  20. </a-col>
  21. <a-col :md="10" :sm="24">
  22. <a-form-item label="维修开始时间">
  23. <a-range-picker
  24. v-model="dateRange"
  25. format="YYYY-MM-DD"
  26. style="width: 100%"
  27. :placeholder="['开始日期', '结束日期']"/>
  28. </a-form-item>
  29. </a-col>
  30. <a-col :md="6" :sm="24">
  31. <span class="table-page-search-submitButtons">
  32. <a-button type="primary" @click="handleSearch">查询</a-button>
  33. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  34. </span>
  35. </a-col>
  36. </a-row>
  37. </a-form>
  38. </div>
  39. <div class="table-operator">
  40. <a-button type="primary" icon="download" @click="doExport">导出</a-button>
  41. </div>
  42. <s-table
  43. ref="table"
  44. size="default"
  45. :rowKey="rowKey"
  46. :columns="columns"
  47. :data="loadData"
  48. showPagination="auto"
  49. >
  50. <span slot="action" slot-scope="record">
  51. <template>
  52. <a @click="handleDetail(record)">查看明细</a>
  53. <a-divider type="vertical"/>
  54. <a @click="doExportDetail(record)">导出明细</a>
  55. </template>
  56. </span>
  57. </s-table>
  58. </a-card>
  59. <detail-modal ref="detailModal"/>
  60. </div>
  61. </template>
  62. <script>
  63. import { STable } from '@/components'
  64. import DetailModal from './modules/DetailModal'
  65. import {
  66. getWorkHourByUser,
  67. getWorkHourBySb,
  68. exportWorkHourUser,
  69. exportWorkHourSb,
  70. exportWorkHourDetail
  71. } from '@/api/report/application-form'
  72. export default {
  73. name: 'RepairWorkHourReport',
  74. components: {
  75. STable,
  76. DetailModal
  77. },
  78. data () {
  79. return {
  80. // 当前统计维度:user-按维修人,sb-按设备
  81. activeTab: 'user',
  82. // 查询参数
  83. queryParam: {
  84. repairUserName: null,
  85. keyword: null
  86. },
  87. // 维修开始时间范围
  88. dateRange: [],
  89. // 加载数据方法 必须为 Promise 对象
  90. loadData: parameter => {
  91. const query = this.buildQuery()
  92. parameter = {
  93. ...parameter,
  94. ...query
  95. }
  96. const fetchFn = this.activeTab === 'user' ? getWorkHourByUser : getWorkHourBySb
  97. return fetchFn(parameter)
  98. .then(res => {
  99. return res.data
  100. })
  101. }
  102. }
  103. },
  104. computed: {
  105. rowKey () {
  106. return this.activeTab === 'user' ? 'repairUserId' : 'sbId'
  107. },
  108. columns () {
  109. const indexColumn = {
  110. title: '序号',
  111. checked: true,
  112. dataIndex: 'index',
  113. width: '70px',
  114. customRender: (text, record, index) => {
  115. const pagination = this.$refs.table && this.$refs.table.localPagination
  116. if (pagination) {
  117. return `${(pagination.current - 1) * pagination.pageSize + index + 1}`
  118. }
  119. return `${index + 1}`
  120. }
  121. }
  122. const hourRender = (text) => {
  123. return this.BaseTool.Object.isBlank(text) ? '0.00' : Number(text).toFixed(2)
  124. }
  125. const commonColumns = [
  126. {
  127. title: '维修次数',
  128. checked: true,
  129. dataIndex: 'num'
  130. },
  131. {
  132. title: '总维修工时(小时)',
  133. checked: true,
  134. dataIndex: 'totalRepairHours',
  135. customRender: hourRender
  136. },
  137. {
  138. title: '平均工时(小时)',
  139. checked: true,
  140. dataIndex: 'avgRepairHours',
  141. customRender: hourRender
  142. },
  143. {
  144. title: '总停机修复时长(小时)',
  145. checked: true,
  146. dataIndex: 'totalDealHours',
  147. customRender: hourRender
  148. },
  149. {
  150. title: '操作',
  151. checked: true,
  152. key: 'action',
  153. width: '180px',
  154. align: 'center',
  155. scopedSlots: { customRender: 'action' }
  156. }
  157. ]
  158. if (this.activeTab === 'user') {
  159. return [
  160. indexColumn,
  161. {
  162. title: '维修人',
  163. checked: true,
  164. dataIndex: 'repairUserName'
  165. },
  166. ...commonColumns
  167. ]
  168. }
  169. return [
  170. indexColumn,
  171. {
  172. title: '设备编号',
  173. checked: true,
  174. dataIndex: 'sbNo'
  175. },
  176. {
  177. title: '设备名称',
  178. checked: true,
  179. dataIndex: 'sbName'
  180. },
  181. ...commonColumns
  182. ]
  183. }
  184. },
  185. methods: {
  186. buildQuery () {
  187. const query = {}
  188. if (this.activeTab === 'user') {
  189. if (this.BaseTool.String.isNotBlank(this.queryParam.repairUserName)) {
  190. query.repairUserName = this.queryParam.repairUserName
  191. }
  192. } else {
  193. if (this.BaseTool.String.isNotBlank(this.queryParam.keyword)) {
  194. query.keyword = this.queryParam.keyword
  195. }
  196. }
  197. if (this.dateRange && this.dateRange.length === 2) {
  198. query.searchRepairStartTime = this.dateRange[0].format('YYYY-MM-DD') + ' 00:00:00'
  199. query.searchRepairEndTime = this.dateRange[1].format('YYYY-MM-DD') + ' 23:59:59'
  200. }
  201. return query
  202. },
  203. handleTabChange () {
  204. this.$nextTick(() => {
  205. this.$refs.table.refresh(true)
  206. })
  207. },
  208. handleSearch () {
  209. this.$refs.table.refresh(true)
  210. },
  211. resetSearchForm () {
  212. this.queryParam = {
  213. repairUserName: null,
  214. keyword: null
  215. }
  216. this.dateRange = []
  217. this.$refs.table.refresh(true)
  218. },
  219. doExport () {
  220. const parameter = this.buildQuery()
  221. const exportFn = this.activeTab === 'user' ? exportWorkHourUser : exportWorkHourSb
  222. exportFn(parameter).then(file => {
  223. this.BaseTool.UPLOAD.downLoadExportExcel(file)
  224. })
  225. },
  226. handleDetail (record) {
  227. const modal = this.$refs.detailModal
  228. modal.base({
  229. type: this.activeTab,
  230. record: record,
  231. searchRepairStartTime: this.buildQuery().searchRepairStartTime,
  232. searchRepairEndTime: this.buildQuery().searchRepairEndTime
  233. })
  234. },
  235. doExportDetail (record) {
  236. const parameter = this.buildDetailQuery(record)
  237. exportWorkHourDetail(parameter).then(file => {
  238. this.BaseTool.UPLOAD.downLoadExportExcel(file)
  239. })
  240. },
  241. buildDetailQuery (record) {
  242. const parameter = {}
  243. if (this.activeTab === 'user') {
  244. parameter.repairUserId = record.repairUserId
  245. } else {
  246. parameter.sbId = record.sbId
  247. }
  248. const timeQuery = this.buildQuery()
  249. if (timeQuery.searchRepairStartTime) {
  250. parameter.searchRepairStartTime = timeQuery.searchRepairStartTime
  251. }
  252. if (timeQuery.searchRepairEndTime) {
  253. parameter.searchRepairEndTime = timeQuery.searchRepairEndTime
  254. }
  255. return parameter
  256. }
  257. }
  258. }
  259. </script>
  260. <style lang="less" scoped>
  261. </style>