condition.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div class="condition">
  3. <div class="selct" style="display: inline-block" v-if="!typeShow">
  4. <!-- <span style="margin-right:15px"></span> -->
  5. <Select
  6. v-model:value="type"
  7. style="width: 100px; margin-right: 30px"
  8. placeholder="请选择类型"
  9. :options="typeOptions"
  10. @change="handleType"
  11. ></Select>
  12. </div>
  13. <div class="selct" style="display: inline-block; margin-right: 15px">
  14. <RangePicker v-model:value="selectTime" @calendarChange="calendarPriceRangeChange" valueFormat="YYYY-MM-DD" :disabled-date="disabledDate" format="YYYY-MM-DD" @change="handleTime"/>
  15. </div>
  16. <div class="selct" style="display: inline-block">
  17. <!-- <span style="margin-right:15px">颗粒度</span> -->
  18. <Select
  19. v-model:value="value"
  20. style="width: 100px; margin-right: 30px"
  21. placeholder="请选择颗粒度"
  22. :options="options"
  23. @change="handleData"
  24. ></Select>
  25. </div>
  26. <a-button type="primary" @click="but">导出</a-button>
  27. </div>
  28. </template>
  29. <script lang="ts" setup>
  30. import { ref, Ref, defineEmits } from 'vue';
  31. const emit = defineEmits(["alertSome"])
  32. import { Select, DatePicker } from 'ant-design-vue';
  33. const { RangePicker } = DatePicker;
  34. // import type { dataItemType } from './props';
  35. import type { Dayjs } from 'dayjs';
  36. import dayjs from 'dayjs';
  37. const props = defineProps({
  38. loading: Boolean,
  39. typeShow: Boolean,
  40. type: String,
  41. timeType: String,
  42. name:Object,
  43. });
  44. type RangeValue = [Dayjs, Dayjs];
  45. const picker = ref('date');
  46. const type = ref(props.timeType ||'0');
  47. const value = ref(props.type ||'0');
  48. const selectPriceDate = ref(dayjs().subtract(6,'month').format('YYYY-MM-DD'))
  49. const selectTime = ref<RangeValue>([dayjs().subtract(6,'month').format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]);
  50. const options = ref<SelectProps['options']>([
  51. {
  52. value: '0',
  53. label: '日',
  54. },
  55. {
  56. value: '1',
  57. label: '周',
  58. },
  59. {
  60. value: '2',
  61. label: '月',
  62. },
  63. ]);
  64. const disabledDate = (current: Dayjs) => {
  65. if(selectPriceDate.value){
  66. return current >dayjs(selectPriceDate.value).add(2,'year') || current < dayjs(selectPriceDate.value).subtract(2,'year')
  67. }else{
  68. return false
  69. }
  70. };
  71. const typeOptions = ref<SelectProps['options']>([
  72. {
  73. value: '0',
  74. label: props.name && props.name[0] || '新增',
  75. },
  76. {
  77. value: '1',
  78. label: props.name && props.name[1] || '累计',
  79. },
  80. ]);
  81. function calendarPriceRangeChange(date){
  82. selectPriceDate.value = date[0]
  83. }
  84. function handleData(val) {
  85. console.log('handleData',val)
  86. value.value = val
  87. output()
  88. }
  89. function handleType(val) {
  90. type.value = val
  91. output()
  92. }
  93. function handleTime(val) {
  94. console.log('selectTime',val)
  95. selectTime.value = val
  96. output()
  97. }
  98. function but(){
  99. if(!props.typeShow){
  100. emit('expor',type)
  101. }else{
  102. emit('expor')
  103. }
  104. }
  105. function output(){
  106. let data = {
  107. startTime:selectTime.value[0],
  108. endTime:selectTime.value[1],
  109. dataType:value.value,
  110. type:type.value,
  111. }
  112. emit('change',data)
  113. }
  114. </script>