FormEcharts.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div class="form-container">
  3. <el-form :inline="true" :model="form" label-width="0">
  4. <el-form-item label="">
  5. <el-select style="width: 106px !important; min-width: 106px !important;" v-model="form.timeCompare"
  6. placeholder="时段对比">
  7. <el-option label="时段对比" value="time1" />
  8. </el-select>
  9. </el-form-item>
  10. <el-form-item label="">
  11. <el-button type="primary" style="background-color: rgba(22, 122, 240, 1); border-color: rgba(22, 122, 240, 1);"
  12. @click="openDatePicker">
  13. <Svg name="date"></Svg>对比时间
  14. <el-date-picker v-if="type === 'date'" class="date-picker" v-model="tempSelectedDates" type="dates" placeholder=""
  15. format="YYYY-MM-DD" value-format="YYYY-MM-DD" style="width: 100%; margin-bottom: 16px;"
  16. :close-on-click-modal="false" :close-on-press-escape="false" :teleported="false"
  17. :popper-class="'date-picker-no-close'" @change="handleDateChange">
  18. </el-date-picker>
  19. </el-button>
  20. <div class="clear-btn" style="display: none;" @click="clearAllDates">清空</div>
  21. </el-form-item>
  22. </el-form>
  23. <div class="average-time">
  24. {{ averageValue.time }}:&nbsp;
  25. <span>{{ averageValue.value }}</span>
  26. </div>
  27. </div>
  28. </template>
  29. <script setup lang="ts">
  30. import { formatDate } from '/@/utils/formatTime';
  31. import { ref, reactive, defineEmits, defineProps } from 'vue'
  32. import Svg from '/@/components/Svg.vue';
  33. const emit = defineEmits(['dateChange']);
  34. const props = defineProps({
  35. averageValue: {
  36. type: Object,
  37. default: () => ({
  38. time: '',
  39. value: ''
  40. })
  41. },
  42. type: {
  43. type: String,
  44. default: 'date'
  45. },
  46. form: {
  47. type: Object,
  48. default: () => ({})
  49. }
  50. })
  51. // const form = reactive(props.form);
  52. // 临时存储选中的日期,用于弹窗内编辑
  53. const tempSelectedDates = ref<string[]>([]);
  54. // 打开弹窗时初始化临时数据
  55. const openDatePicker = () => { };
  56. // 清空选中的日期
  57. const clearAllDates = () => {
  58. tempSelectedDates.value = [];
  59. }
  60. // 日期更新事件
  61. const handleDateChange = (val: string[]) => {
  62. // 触发父组件的日期更新事件
  63. emit('dateChange', val);
  64. }
  65. watch(props.form, (newVal) => {
  66. console.log(newVal);
  67. const date = formatDate(new Date(newVal.date), 'YYYY-mm-dd');
  68. tempSelectedDates.value = [date];
  69. handleDateChange([date]);
  70. }, { deep: true, immediate: true })
  71. </script>
  72. <style scoped lang="scss">
  73. @import '/@/views/count/styles/common.scss';
  74. .form-container {
  75. position: relative;
  76. margin: 53px auto 0px;
  77. width: 100%;
  78. max-width: 1360px;
  79. display: flex;
  80. justify-content: space-between;
  81. .average-time {
  82. font-family: Source Han Sans SC;
  83. font-weight: 400;
  84. font-style: Regular;
  85. font-size: 16px;
  86. color: rgba(18, 18, 18, 1);
  87. span {
  88. color: rgba(22, 122, 240, 1);
  89. }
  90. }
  91. :deep(.el-form-item__content .el-date-editor) {
  92. position: absolute;
  93. top: 0;
  94. left: 0;
  95. width: 106px !important;
  96. min-width: 106px !important;
  97. height: 100%;
  98. opacity: 0;
  99. }
  100. :deep(.el-input__inner),
  101. :deep(.el-date-editor--dates .el-input__wrapper) {
  102. cursor: pointer;
  103. }
  104. }
  105. </style>