OnlineDurationDialog.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <confirm-dialog
  3. ref="dialog"
  4. size="lg fixed"
  5. title="在线时长报表"
  6. @confirm="onConfirm"
  7. >
  8. <template #default>
  9. <div class="l-flex__fill l-flex">
  10. <department-tree
  11. class="c-sibling-item c-sidebar u-width--xl"
  12. @change="onGroupChanged"
  13. />
  14. <div class="c-sibling-item far">
  15. <div class="c-sibling-item--v u-required">日期范围</div>
  16. <el-date-picker
  17. v-model="dateRange"
  18. class="c-sibling-item--v"
  19. type="daterange"
  20. range-separator="至"
  21. value-format="yyyy-MM-dd"
  22. :picker-options="pickerOptions"
  23. :editable="false"
  24. />
  25. </div>
  26. </div>
  27. </template>
  28. </confirm-dialog>
  29. </template>
  30. <script>
  31. import { mapGetters } from 'vuex'
  32. import { parseTime } from '@/utils'
  33. import {
  34. getOnlineDurationExcel,
  35. getRangeOnlineDurationExcel,
  36. getDepartmentOnlineDurationExcel,
  37. getDepartmentRangeOnlineDurationExcel
  38. } from '../api'
  39. export default {
  40. name: 'OnlineDurationDialog',
  41. data () {
  42. return {
  43. dateRange: []
  44. }
  45. },
  46. computed: {
  47. ...mapGetters(['tenant']),
  48. pickerOptions () {
  49. return {
  50. disabledDate: this.isDisableDate
  51. }
  52. }
  53. },
  54. methods: {
  55. show () {
  56. this.dateRange = [parseTime(new Date() - 3600000 * 24 * 6, '{y}-{m}-{d}'), parseTime(new Date(), '{y}-{m}-{d}')]
  57. this.$refs.dialog.show()
  58. },
  59. onGroupChanged (group) {
  60. this.$group = group
  61. },
  62. isDisableDate (date) {
  63. return date > Date.now()
  64. },
  65. onConfirm (done) {
  66. const groupPath = this.$group.path
  67. if (this.dateRange) {
  68. const time = this.dateRange[0] === this.dateRange[1] ? this.dateRange[0] : `${this.dateRange[0]}~${this.dateRange[1]}`
  69. if (this.tenant === groupPath) {
  70. getRangeOnlineDurationExcel({
  71. sumDateFrom: this.dateRange[0],
  72. sumDateTo: this.dateRange[1]
  73. }, time).then(done)
  74. } else {
  75. getDepartmentRangeOnlineDurationExcel({
  76. department: this.$group.path,
  77. sumDateFrom: this.dateRange[0],
  78. sumDateTo: this.dateRange[1]
  79. }, `${this.$group.name}_${time}`).then(done)
  80. }
  81. } else if (this.tenant === groupPath) {
  82. getOnlineDurationExcel().then(done)
  83. } else {
  84. getDepartmentOnlineDurationExcel(this.$group.path, this.$group.name).then(done)
  85. }
  86. }
  87. }
  88. }
  89. </script>