merchant.js
4.49 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
// pages/tab/outputValue/components/merchant/merchant.js
import { IMG_URL } from '~/utils/constantData'
import outputValueApi from '~/api/outputValueApi/index'
Component({
/**
* 组件的属性列表
*/
properties: {
searchForm: {
type: Object,
value: () => {
return {
// 服务商商户号
partnerMerchantId: '',
// 4S店商户号
merchantId: '',
// 年月(yyyy-MM)
yearMonth: '',
// 场景(1精品升级,3众筹,0会员权益)
sceneType: ''
}
}
},
tabBarStyle: {
type: Number,
observer: function (n) {
if (n) this.setData({ emptyDataStyle: `height: calc(100vh - ${n}px - 88rpx - 24rpx)` })
}
}
},
/**
* 组件的初始数据
*/
data: {
IMG_URL,
bgUrl: `${IMG_URL}/personal/empty_tran.png`,
formData: {},
serviceName: '',
totalObj: {},
pageCof: {
startYearMonth: '',
endYearMonth: ''
},
isEnd: false,
loading: true,
scrollTop: 0,
isAsk: false,
// 1精品升级(太阳膜),3众筹,0会员权益)
merchantList: [],
},
/**
* 组件的方法列表
*/
methods: {
merchantRefresh(isReset = false) {
if (isReset) {
this.setData({
['pageCof.startYearMonth']: '',
['pageCof.endYearMonth']: '',
isEnd: false,
loading: true,
scrollTop: 0,
isAsk: false
})
}
this.getTotal()
this.getMerchantList(isReset)
},
getTotal() {
let { userInfo } = wx.$storage.get()
let params = {
merchantId: userInfo.subLoginUser.isSuper ? '' : userInfo.subLoginUser.merchantId
}
outputValueApi.getMerchantTotal(params).then(res => {
this.setData({
totalObj: res || {}
})
})
},
getMore() {
this.getMerchantList()
},
// month作为分页参数
dealMonth(isReset = false, monthInterval = 1) {
let { startTime, endTime } = this.data.searchForm
let { startYearMonth, endYearMonth } = this.data.pageCof
// 获取当前日期
let _currentDate = new Date()
// 获取前n个月的日期
let _endMonthDate = new Date()
let searchStart = startTime ? new Date(startTime.replace(/-/g, '/')) : ''
// 翻页
if (startYearMonth && endYearMonth) {
_currentDate = new Date(startYearMonth)
_endMonthDate = new Date(startYearMonth)
} else if (startTime && endTime) {
_currentDate = new Date(endTime.replace(/-/g, '/'))
_endMonthDate = new Date(endTime.replace(/-/g, '/'))
}
_endMonthDate.setMonth(_currentDate.getMonth() - monthInterval)
let _startMonthDate = new Date(isReset ? _currentDate : _endMonthDate)
_startMonthDate.setMonth(_startMonthDate.getMonth() - monthInterval)
endYearMonth = isReset ? _currentDate.format('yyyy-MM') : _endMonthDate.format('yyyy-MM')
startYearMonth = searchStart > _startMonthDate ? new Date(searchStart).format('yyyy-MM') : _startMonthDate.format('yyyy-MM')
this.setData({
['pageCof.startYearMonth']: startYearMonth,
['pageCof.endYearMonth']: endYearMonth,
isEnd: new Date(new Date(startTime.replace(/-/g, '/'))).format('yyyy-MM') == startYearMonth
})
},
getMerchantList(isReset = false) {
let { userInfo } = wx.$storage.get()
let { searchForm, merchantList, isAsk, isEnd } = this.data
if (isAsk || isEnd) {
return true
}
this.setData({
serviceName: userInfo.subLoginUser.merchantName,
loading: true,
isAsk: true
})
this.dealMonth(isReset)
let params = {
partnerMerchantId: userInfo.subLoginUser.isSuper ? '' : userInfo.subLoginUser.merchantId,
merchantId: searchForm.shopMerchantIds.length ? searchForm.shopMerchantIds[0] : '',
sceneType: searchForm.sceneType,
...this.data.pageCof
}
wx.$api.showLoading('加载中...')
const paiName = searchForm.sceneType ? 'getQuerySceneList' : 'getAllSceneList'
outputValueApi[paiName](params).then(res => {
this.setData({
merchantList: isReset ? (res || []) : merchantList.concat(res || [])
})
if (isReset) {
this.setData({
scrollTop: 0
})
}
}).finally(() => {
wx.hideLoading()
this.setData({
triggered: false,
loading: false,
isAsk: false
})
})
}
}
})