messageBox.js
5.22 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
// pages/mineDetail/messageBox/messageBox.js
import mineApi from '~/api/mineApi/index'
// import { handleCopy } from '~/utils/utils_wx'
let drawQrcode = require('~/utils/lib/weapp-qrcode.js')
Component({
/**
* 组件的属性列表
*/
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'
}
},
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
})
},
downLoad(e) {
const { item } = e.currentTarget.dataset
this.setData({
posterItem: {
activityName: item.activityName,
posterUrl: item.valueUrl
}
})
},
copyLink(e) {
console.log(e)
let that = this
let { url } = e.currentTarget.dataset
this.ewmChange(url)
setTimeout(() => {
this.share()
}, 100)
},
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
})
},
refreshList(e) {
// console.log(e)
let { type } = this.data
let { typename } = e.currentTarget.dataset
type[typename].pageNum = 1
this.getMessageList(typename)
},
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
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
})
})
.catch(err => {})
.finally(() => {
wx.$api.hideLoading()
})
}
}
})