storeWarning.js
4.99 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
// pages/components/storeWarning/storeWarning.js
import IndexApi from '~/api/index/index'
// 预计算安全的月份时间戳,避免初始 0 值
const __NOW__ = new Date()
const __CUR_YM_TS__ = new Date(
__NOW__.getFullYear(),
__NOW__.getMonth(),
1
).getTime()
const __MIN_YM_TS__ = new Date(
__NOW__.getFullYear(),
__NOW__.getMonth() - 11,
1
).getTime()
Component({
/**
* 组件的属性列表
*/
properties: {
staffUuid: {
type: String,
value: ''
},
regionId: {
type: String,
value: ''
}
},
// 组件生命周期
lifetimes: {
attached() {
this.getMonthList()
this.getWarningStores()
}
},
/**
* 组件的初始数据
*/
data: {
// 月份选择器
monthPickerShow: false,
minMonthDate: __MIN_YM_TS__,
maxMonthDate: __CUR_YM_TS__,
monthPickerValue: __CUR_YM_TS__,
pendingMonthValue: 0,
warningStores: {
backstopWarningCount: 0,
lossWarningCount: 0,
lostShopWarningCount: 0
}
},
/**
* 组件的方法列表
*/
methods: {
// 打开/关闭月份选择器
changeMonth() {
console.log('changeMonth')
this.setData({
monthPickerShow: true,
pendingMonthValue: this.data.monthPickerValue
})
},
closeMonthPicker() {
this.setData({ monthPickerShow: false })
}, // 弹窗事件:确认后写入月份值与文案
popupConfirm() {
const val = this.data.pendingMonthValue || this.data.monthPickerValue
if (val) {
const d = new Date(val)
console.log(val, d)
this.setData(
{
monthPickerValue: val,
boardMonthText: `${d.getMonth() + 1}月`,
boardMonthActive: true,
boardScopeActive: false,
// yyyy-MM(月份补零)
// value: `${y}-${String(m).padStart(2, '0')}`,
// M(回显用,不补零)
// name: `${m}月`
month: `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(
2,
'0'
)}`,
showMonth: `${d.getMonth() + 1}月`
},
() => {
this.getWarningStores()
}
)
}
this.closeMonthPicker()
},
cancel() {
this.closeMonthPicker()
},
onMonthChange(e) {
const values = e.detail.getValues()
const year = Number(
String(values?.[0] || '').replace(/[年月日时分]/g, '')
)
const month = Number(
String(values?.[1] || '').replace(/[年月日时分]/g, '')
)
if (!year || !month) return
const ts = new Date(year, month - 1, 1).getTime()
this.setData({ pendingMonthValue: ts })
},
navigateToStoreDetail: function (e) {
let { index } = e.currentTarget.dataset
console.log(e, 'e')
wx.$router.go('packageIndex.warningStoreList', {
month: this.data.month,
index: index
// storeUuid: e.currentTarget.dataset.storeuuid
})
// wx.navigateTo({
// url: `/pages/storeDetail/storeDetail?storeUuid=${e.currentTarget.dataset.storeuuid}`
// })
},
// 选择月份
// changeMonth() {
// let { monthList, month } = this.data
// console.log(month, 'monthList')
// this.setData({
// showSelectPopup: true,
// selectOptions: monthList,
// selectTitle: '日期选择',
// selectMultiple: false,
// // selectType: 'coopMode',
// selectValue: [month]
// })
// },
hideSelectPopup() {
this.setData({
showSelectPopup: false
})
},
getWarningStores() {
let { month, staffUuid, regionId } = this.data
let params = { month }
if (staffUuid) {
params.staffUuid = staffUuid
}
if (regionId) {
params.regionId = regionId
}
IndexApi.getWarningStores(params).then(res => {
console.log(res, 'res')
this.setData({
warningStores: res.data
})
})
},
//实现一个方法,或者当前到往前12月份的数组 是一个对象,有moth yyyy-MM,和回显用的月份showMonth M
getMonthList() {
const monthList = []
const now = new Date()
// 逐月递减生成最近12个月,考虑跨年
for (let i = 0; i < 12; i++) {
const d = new Date(now.getFullYear(), now.getMonth() - i, 1)
const y = d.getFullYear()
const m = d.getMonth() + 1
monthList.push({
// yyyy-MM(月份补零)
value: `${y}-${String(m).padStart(2, '0')}`,
// M(回显用,不补零)
name: `${m}月`
})
}
// 默认选中当前月份
this.setData({
monthList,
month: monthList[0].value,
showMonth: monthList[0].name
})
console.log(monthList, 'monthList')
}
}
})