zhanghua
11 小时以前 4049531e168e3abd88c1c7809c4350424622cd8e
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<template>
  <div>
    <div class="breadcrumb">
      <span @click="clickBreadcrumb(item, index)" :class="{ 'active': item.selected }" v-for="(item, index) in dateList"
        :key="index"> {{ item.title }}</span>
      <div class="date-picker">
        <Select @on-change="changeSelect($event, selectedWay)" :value="month" placeholder="年月查询" clearable
          style="width:200px;margin-left:10px;">
          <Option v-for="(item, i) in dates" :value="item.year + '-' + item.month" :key="i" clearable>
            {{ item.year + '年' + item.month + '月' }}</Option>
        </Select>
      </div>
      <div class="shop-list" v-if="!closeShop">
        <Select clearable @on-change="changeshop(selectedWay)" v-model="storeId" placeholder="店铺查询"
          style="width:200px;margin-left:10px;">
          <Scroll :on-reach-bottom="handleReachBottom">
            <Option v-for="(item, index) in shopsData" :value="item.id" :key="index">{{ item.storeName }}</Option>
          </Scroll>
        </Select>
      </div>
    </div>
  </div>
</template>
<script>
import { getShopListData } from "@/api/shops.js";
export default {
  props: ["closeShop"],
  data() {
    return {
      month: "", // 月份
 
      selectedWay: {
        // 可选时间项
        title: "过去7天",
        selected: true,
        searchType: "LAST_SEVEN",
      },
      storeId: "", // 店铺id
      dates: [], // 日期列表
      params: {
        // 请求参数
        pageNumber: 1,
        pageSize: 10,
        storeName: "",
      },
      dateList: [
        // 筛选条件
        {
          title: "今天",
          selected: false,
          searchType: "TODAY",
        },
        {
          title: "昨天",
          selected: false,
          searchType: "YESTERDAY",
        },
        {
          title: "过去7天",
          selected: true,
          searchType: "LAST_SEVEN",
        },
        {
          title: "过去30天",
          selected: false,
          searchType: "LAST_THIRTY",
        },
      ],
      originDateList: [
        // 筛选条件
        {
          title: "今天",
          selected: false,
          searchType: "TODAY",
        },
        {
          title: "昨天",
          selected: false,
          searchType: "YESTERDAY",
        },
        {
          title: "过去7天",
          selected: true,
          searchType: "LAST_SEVEN",
        },
        {
          title: "过去30天",
          selected: false,
          searchType: "LAST_THIRTY",
        },
      ],
 
      shopTotal: "", // 店铺总数
      shopsData: [], // 店铺数据
    };
  },
  mounted() {
    this.getFiveYears();
    this.getShopList();
  },
  methods: {
    // 页面触底
    handleReachBottom() {
      setTimeout(() => {
        if (this.params.pageNumber * this.params.pageSize <= this.shopTotal) {
          this.params.pageNumber++;
          this.getShopList();
        }
      }, 1500);
    },
    // 查询店铺列表
    getShopList() {
      getShopListData(this.params).then((res) => {
        if (res.success) {
          /**
           * 解决数据请求中,滚动栏会一直上下跳动
           */
          this.shopTotal = res.result.total;
 
          this.shopsData.push(...res.result.records);
        }
      });
    },
    // 变更店铺
    changeshop(val) {
      this.selectedWay.storeId = this.storeId;
      this.$emit("selected", this.selectedWay);
    },
 
    // 获取近5年 年月
    getFiveYears() {
      let getYear = new Date().getFullYear();
 
      let lastFiveYear = getYear - 5;
      let maxMonth = new Date().getMonth() + 1;
      let dates = [];
      // 循环出过去5年
      for (let year = lastFiveYear; year <= getYear; year++) {
        for (let month = 1; month <= 12; month++) {
          if (year == getYear && month > maxMonth) {
          } else {
            dates.push({
              year: year,
              month: month,
            });
          }
        }
      }
      this.dates = dates.reverse();
    },
    // 改变已选店铺
    changeSelect(e) {
      this.month = e
      if (this.month) {
        this.dateList.forEach((res) => {
          res.selected = false;
        });
        this.selectedWay.year = this.month.split("-")[0];
        this.selectedWay.month = this.month.split("-")[1];
        this.selectedWay.searchType = "";
 
        this.$emit("selected", this.selectedWay);
      } else {
 
        const current = this.dateList.find(item => { return item.selected })
        this.selectedWay = current
        this.clickBreadcrumb(current)
        this.$emit("selected", this.selectedWay);
 
 
      }
    },
    // 变更时间
    clickBreadcrumb(item) {
 
      let currentIndex;
      this.dateList.forEach((res,index) => {
        res.selected = false;
        if(res.title === item.title){
          currentIndex = index
        }
      });
      item.selected = true;
      item.storeId = this.storeId;
      this.month = "";
      if (item.searchType == "") {
       let currentDate = this.originDateList[currentIndex].searchType
        if (currentDate) {
          item.searchType = currentDate
        } else {
          item.searchType = "LAST_SEVEN";
        }
      }
      this.selectedWay = item;
      this.selectedWay.year = new Date().getFullYear();
      this.selectedWay.month = "";
 
      this.$emit("selected", this.selectedWay);
    },
  },
};
</script>
<style lang="scss" scoped>
.breadcrumb {
  display: flex;
  align-items: center;
  >span {
    margin-right: 15px;
    cursor: pointer;
  }
}
 
.active {
  color: $theme_color;
  position: relative;
}
 
.date-picker {}
 
.active:before {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 0;
  width: 100%;
  height: 3px;
  background: $theme_color;
}
</style>