subscribe.js
2.66 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
// component/menu/addDelete.js
import util from '../../utils/util';
import App from '../../utils/api';
const subscribe=[
'ZwAkHfP8xUvBZKJn4VXsjRxUDTuCMjWqd8lTsdCPdks',//包厢预订通知 状态、预订门店、包厢名称、备注
'Pf1iEkCA8TnfeqEMkf-_338U78d4Js36pk6sbB0yem0',//消费金额反馈提醒 消费总额、包间名称、餐厅名称、预订日期
]
Component({
/**
* 组件的属性列表
*/
properties: {
ids:{
type:Array,
value:subscribe.keys()
}
},
/**
* 组件的初始数据
*/
data: {
},
attached(){
},
ready () {
},
detached(){
},
observers: {
ids:function(){
console.log('this.data.ids',this.data.ids)
this.subscribeIds=[];
this.data.ids.forEach(i=>{
this.subscribeIds.push(subscribe[i])
})
},
},
/**
* 组件的方法列表
*/
methods: {
subscribe(){
console.log('subscribe',this.subscribeIds)
wx.requestSubscribeMessage({
tmplIds:this.subscribeIds,
success:res=>{
console.log('wx.requestSubscribeMessage.success',res)
if(res.errMsg!='requestSubscribeMessage:ok'){
wx.showModal({
title: '授权提示',
content: '请点击确定打开订阅授权',
confirmColor: '#199095',
cancelColor: '#999',
success: function (res) {
if (res.confirm) {
util.setting();
}
}
})
return;
}
let accept=[]
this.subscribeIds.forEach(id=>{
if(res[id]=='accept'){
accept.push(id)
}
})
if(accept.length>0){
util.toast('订阅成功','none')
setTimeout(()=>{
App.Wechat.Subscribe({
tplid:accept.toString()
})
},800)
this.triggerEvent('event',{type:'success'})
}else{
util.toast('订阅失败,请在设置中打开','none')
this.triggerEvent('event',{type:'fail'})
}
},
fail:(efail)=>{
this.triggerEvent('event',{type:'fail'})
console.log('wx.requestSubscribeMessage.fail',efail)
if(efail.errMsg.indexOf('not ended')) return;
wx.showModal({
title: '授权提示',
content: '您拒绝了订阅消息,请点击确定打开授权',
confirmColor: '#199095',
cancelColor: '#999',
success: function (res) {
if (res.confirm) {
util.setting();
}
}
})
},
})
},
}
})