messageBox.js
6.72 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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// pages/mineDetail/messageBox/messageBox.js
import mineApi from '~/api/mineApi/index'
// import { handleCopy } from '~/utils/utils_wx'
import outputApi from '~/api/outputApi/index'
import { deleteSecond } from '~/utils/format'
// import drawQrcode from '~/utils/lib/weapp-qrcode.js'
Component({
options: {
addGlobalClass: true
},
/**
* 组件的属性列表
*/
properties: {},
/**
* 组件的初始数据
*/
data: {
navStyle: 'background-color: rgba(0,0,0,0);',
loginType: 0,
agree: true,
tabIndx: 0,
text: '',
tabList: ['战报', '通知'],
type: {
warReport: {
pageNum: 1,
pageSize: 10,
type: 0,
list: 'warReportList'
},
message: {
pageNum: 1,
pageSize: 10,
type: 1,
list: 'messageList'
}
},
// findKey: '',
warReportList: [],
messageList: [],
serviceMerchantId: ''
},
attached() {
// this.ewmChange()
// this.initTime()
let { userInfo } = wx.$storage.get()
let merchantId = userInfo.subLoginUser.merchantId
this.setData({
serviceMerchantId: userInfo.subLoginUser.merchantId
// serviceMerchantId: 12580
})
this.getMessageList('warReport')
this.getMessageList('message')
},
/**
* 组件的方法列表
*/
methods: {
// 实例化二维码canvas
// ewmChange(url) {
// let size = {}
// size.w = (wx.getSystemInfoSync().windowWidth / 750) * 600
// size.h = size.w
// var that = this
// drawQrcode({
// width: size.w,
// height: size.h,
// canvasId: 'myQrcode',
// text: url || that.data.text
// // v1.0.0+版本支持在二维码上绘制图片
// })
// },
preView(e) {
let { valueurl } = e.currentTarget.dataset
// console.log(e)
// console.log(valueUrl)
// let urls = []
// urls.push(valueUrl)
// // wx.$router.jumpH5(valueUrl)
// console.log(urls)
// console.log([valueUrl])
wx.$api.previewImage({
urls: [valueurl],
current: valueurl
})
},
showPoster(e) {
const { item } = e.currentTarget.dataset
let updatedTime = deleteSecond(item.createdTime)
this.setData({
// findKey: 'crowdFundActivityId',
posterItem: {
activityName: item.activityName,
posterUrl: item.valueUrl,
updatedTime,
// crowdFundActivityId: item.valueUrl,
type: 'warReport'
}
})
},
async copyLink(e) {
const { item } = e.currentTarget.dataset
// posterObj = this.selectComponent('#poster')
// this.setData({
// findKey: 'activityId'
// })
// try {
// let flag = await posterObj.check(item)
// posterObj.setData({
// poster: flag,
// show: true
// })
// } catch (error) {
wx.$api.showLoading('加载中...')
outputApi
.getPosterUrl({
id: item.crowdFundActivityId
})
.then(res => {
item.posterUrl = res
item.type = 'motherChainPoster'
console.log(item)
this.setData({
posterItem: item,
isShowTip: false
})
})
.catch(() => {
wx.$api.showToast('下载海报失败')
})
// }
},
share(e) {
// console.log(e)
let that = this
const dpr = wx.getSystemInfoSync().pixelRatio
wx.canvasToTempFilePath({
canvasId: 'myQrcode',
x: 0,
y: 0,
width: 600,
height: 600,
destWidth: 600 * dpr, // width*屏幕像素密度
destHeight: 600 * dpr, // height*屏幕像素密度
fileType: 'jpg',
quality: 1, //图片的质量,目前仅对 jpg 有效。取值范围为 (0, 1],不在范围内时当作 1.0 处理。
success: function (res) {
var tempFilePath = res.tempFilePath
wx.getImageInfo({
src: tempFilePath,
success(obj) {
wx.showShareImageMenu({
path: obj.path
})
},
fail() {}
})
},
fail: function (res) {
console.log(res)
}
})
},
navbarReady(e) {
let { height, statusBarHeight } = e.detail
console.log(e)
this.setData({
tabBarStyle: height / 2 + statusBarHeight
})
},
async refreshList(e) {
console.log(e)
let { type } = this.data
let { typename } = e.currentTarget.dataset
type[typename].pageNum = 1
let res = await this.getMessageList(typename)
let toastObj = {
success: {
title: '刷新成功',
icon: 'success'
},
fail: {
title: '刷新失败',
icon: 'error'
}
}
wx.$api.showToast({
...toastObj[res],
duration: 1000
})
},
scrollonReachBottom(e) {
console.log(e)
let { typename } = e.currentTarget.dataset
let { type } = this.data
// 判断当前页是否是末页
console.log(type[typename].pages == type[typename].currentPage)
if (type[typename].pages == type[typename].pageNum) return wx.$api.showToast('列表已到底')
type[typename].pageNum = type[typename].pageNum + 1
this.setData({
type
})
this.getMessageList(typename)
},
changeTabIndx(e) {
let { detail } = e
this.setData({
tabIndx: detail
})
},
MatchCeil(num) {
return Match.ceil(num)
},
getMessageList(typeName) {
let that = this
return new Promise((resolve, reject) => {
let { serviceMerchantId, type, warReportList, messageList } = this.data
let list = type[typeName]['list']
// console.log('list', this.data[list])
// return
let params = {
serviceMerchantId: serviceMerchantId,
...type[typeName]
}
// console.log(Math.ceil(2.8))
wx.$api.showLoading('加载中...')
mineApi
.messageBoxPage(params)
.then(result => {
console.log(result)
let { count, data, pageSize, pageNum, pages } = result
const listName = `${type[typeName]['list']}`
type[typeName]['pages'] = pages
type[typeName]['pageNum'] = pageNum
console.log(listName)
this.setData({
[listName]: type[typeName].pageNum == 1 ? data : [...this.data[list], ...data],
type,
triggered: false
})
resolve('success')
})
.catch(err => {
reject('fail')
})
.finally(() => {
wx.$api.hideLoading()
})
})
}
}
})