TimeSearch.vue
5.83 KB
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
<template>
<div>
<div class="top flex">
<div :class="[reportType==0?'report-name':'report-month-name' ,'text-hide']">
{{ userInfo.merchantName || 'XXXX商户名称-10月小结' }}-
<span>{{ text }}小结</span>
</div>
<template v-if="outputData.reportTimeStart && reportType == 0">
<div class="time small-text" @click="showDateSelect = true">
{{ new Date(outputData.reportTimeStart).format('yyyy.MM.dd') }}- {{ new Date(outputData.reportTimeEnd).format('yyyy.MM.dd') }}
<van-icon name="arrow-down" />
</div>
</template>
<template v-if="outputData.reportTimeStart && reportType == 1">
<div class="time small-text" @click="showDateSelect = true">
{{ outputData.reportTimeStart.slice(0, outputData.reportTimeStart.length - 3) }}
<van-icon name="arrow-down" />
</div>
</template>
</div>
<van-popup v-model="showDateSelect" v-if="showDateSelect" position="bottom">
<van-picker show-toolbar :title="reportType == 0 ? '选择日期' : '选择月份'" :columns="dateColumns" :default-index="defaultIndex" @confirm="confirmDate" @cancel="showDateSelect = false" />
</van-popup>
</div>
</template>
<script>
import { mapState, mapActions, mapMutations } from 'vuex'
export default {
name: 'TimeSearch',
data() {
return {
showDateSelect: false,
dateColumns: [],
text: '',
defaultIndex: 0
}
},
computed: {
...mapState({
tabIndex: state => state.report.tabIndex,
reportData: state => state.report.reportData,
reportType: state => state.report.reportType,
outputData: state => state.report.outputData,
userInfo: state => state.report.userInfo
})
},
mounted() {
this.initDate()
},
methods: {
...mapActions({
getReport: 'report/getReport',
getCumerchantReport: 'report/getCumerchantReport',
getCugroupReport: 'report/getCugroupReport'
}),
...mapMutations({
SET_START_TIME: 'report/SET_START_TIME',
INIT_DATA: 'report/INIT_DATA',
SET_TABTYPE_INDEX: 'report/SET_TABTYPE_INDEX'
}),
initDate() {
let { reportType } = this
let now = new Date()
let dateColumns = []
if (reportType == 0) {
let dateTime = now.getTime()
let day = now.getDay() || 7
let oneDayTime = 24 * 60 * 60 * 1000
for (let i = 24; i > 0; i--) {
let monday = new Date(dateTime - (day - 1 + i * 7) * oneDayTime).format('yyyy-MM-dd') // 获取周一
let sunday = new Date(dateTime + (7 - day - i * 7) * oneDayTime).format('yyyy-MM-dd') // 获取周日
dateColumns.push(`${monday}~${sunday}`)
}
this.dateColumns = dateColumns
let time = this.dateColumns[this.dateColumns.length - 1].split('~')
this.SET_START_TIME({
reportTimeStart: time[0],
reportTimeEnd: time[1]
})
} else {
let nowMonth = now.getMonth()
for (let i = nowMonth - 12; i <= nowMonth - 1; i++) {
dateColumns.push(new Date(new Date().setMonth(i)).format('yyyy-MM'))
}
this.dateColumns = dateColumns
this.SET_START_TIME({
reportTimeStart: this.dateColumns[this.dateColumns.length - 1] + '-01'
})
}
this.defaultIndex = this.dateColumns.length //初始选中项的索引
this.initTextData()
},
initTextData() {
let { reportType, outputData } = this
if (reportType == 0) {
this.text = '周'
} else {
let time = outputData.reportTimeStart.split('-')
if (parseInt(time[1]) > 9) {
this.text = time[1] + '月'
} else {
this.text = time[1] && time[1].split('')[1] + '月'
}
}
},
confirmDate(e) {
let {
reportType,
tabIndex,
userInfo: { accountLevel }
} = this
let time = ''
this.showLoading('加载中...')
if (reportType == 1) {
time = `${e}-01`
this.SET_START_TIME({
reportTimeStart: time
})
} else {
time = e.split('~')[0]
this.SET_START_TIME({
reportTimeStart: e.split('~')[0],
reportTimeEnd: e.split('~')[1]
})
}
this.INIT_DATA()
if (tabIndex == 0) {
//客户
if (accountLevel == 4) {
//门店
this.getCumerchantReport({
reportType: this.reportType,
startDate: time,
success: res => {
this.hideLoading()
// this.INIT_DATA()
}
})
} else {
//集团
this.getCugroupReport({
reportType: this.reportType,
startDate: time,
success: res => {
this.hideLoading()
// this.INIT_DATA()
}
})
}
} else if (tabIndex == 1) {
//产值
this.getReport({
reportType: this.reportType,
reportTimeStart: time,
success: res => {
this.hideLoading()
// this.INIT_DATA()
}
})
}
this.defaultIndex = this.dateColumns.indexOf(e)
this.initTextData()
this.SET_TABTYPE_INDEX({ index: 0 })
this.showDateSelect = false
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang='scss'>
.top {
border-radius: 4px;
width: 345px;
height: 40px;
box-sizing: border-box;
background: #6191d1;
z-index: 9;
margin-top: 15px;
padding: 0 10px;
.report-name {
width: 50%;
height: 15px;
font-size: 14px;
font-weight: 500;
color: #ffffff;
line-height: 15px;
}
.report-month-name{
width: 70%;
height: 15px;
font-size: 14px;
font-weight: 500;
color: #ffffff;
line-height: 15px;
}
.time {
margin-left: auto;
}
}
</style>