condition.vue 3.8 KB

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