dcc
2024-08-03 1613da5e0d5b13b20fc384da3595766efe8ffb24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!-- 日期搜索组件 -->
<template>
  <div class="search-header">
    <div
      class="changdate"
      :class="{ active: isActive == index }"
      v-for="(item, index) in datedata"
      :key="index"
      @click="changeDate(item, index)"
    >
      {{ item.txt }}
    </div>
    <div class="datepicker">
      <div class="time-text">{{ $t("message.home.shijian") }}</div>
      <el-date-picker
        v-model="dateValue"
        type="daterange"
        :range-separator="$t('message.home.to')"
        :start-placeholder="$t('message.user.xuanzekaishishijian')"
        :end-placeholder="$t('message.user.xuanzejiehsushijian')"
        @change="dataPickerChange"
      >
      </el-date-picker>
    </div>
    <span class="btn" @click="handleSearch">{{
      $t("message.home.chaxun")
    }}</span>
    <span class="btn" @click="handleReset">{{
      $t("message.home.chongzhi")
    }}</span>
  </div>
</template>
 
<script>
import dayjs from "dayjs";
export default {
  name: "dateSearch",
  data() {
    return {
      datedata: [
        { txt: this.$t("message.home.oneDay"), value: 1 },
        { txt: this.$t("message.home.aWeek"), value: 7 },
        { txt: this.$t("message.home.aMonth"), value: 30 },
        { txt: this.$t("message.home.threeMonths"), value: 90 },
      ],
      isActive: -1,
      dateValue: "",
      endTime: "",
      startTime: "",
    };
  },
 
  methods: {
    handleSearch() {
      this.$parent.getList(this.startTime, this.endTime, true);
    },
    handleReset() {
      this.dateValue = [];
      this.startTime = undefined;
      this.endTime = undefined;
      this.isActive = -1;
      this.handleSearch();
    },
    dataPickerChange(val) {
      if (val.length > 1) {
        this.startTime = dayjs(val[0]).format("YYYY-MM-DD");
        this.endTime = dayjs(val[1]).format("YYYY-MM-DD");
      }
    },
    changeDate(item, index) {
      this.isActive = index;
      const time = dayjs().format("YYYY-MM-DD");
      this.endTime = time;
 
      switch (item.value) {
        case 1:
          this.startTime = time;
          break;
        case 7:
          this.startTime = dayjs().subtract(7, "day").format("YYYY-MM-DD");
          break;
        case 30:
          this.startTime = dayjs().subtract(1, "month").format("YYYY-MM-DD");
          break;
        case 90:
          this.startTime = dayjs().subtract(3, "month").format("YYYY-MM-DD");
          break;
        default:
          break;
      }
      this.handleSearch();
    },
  },
};
</script>
<style scoped>
.search-header {
  line-height: 40px;
  background: #000;
}
.search-header div {
  display: inline-block;
}
.changdate {
  width: 90px;
  text-align: center;
  cursor: pointer;
}
 
.changdate:hover {
  background: #24282d;
}
.active {
  background: #24282d;
  color: #1c73c7;
}
.time-text {
  margin-top: -4px;
  margin-right: 10px;
}
.datepicker {
  margin-left: 10px;
  /* margin-top: 4px; */
}
 
.search-header .btn {
  display: inline-block;
  margin-left: 20px;
  line-height: 25px;
  text-align: center;
  background: #24282d;
  border-radius: 4px;
  cursor: pointer;
  padding: 2px 8px;
}
.search-header .btn:hover {
  color: #1c73c7;
}
</style>