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
| <template>
| <view>
| <u-toast ref="uToast" /><u-no-network></u-no-network>
| <u-navbar title="消息订阅" safeAreaInsetTop fixed placeholder>
| <view class="coreshop-navbar-left-slot" slot="left">
| <u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
| <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
| <u-icon name="home" size="22" @click="goHome"></u-icon>
| </view>
| <view slot="right">
| </view>
| </u-navbar>
| <view class="content">
| <view class="coreshop-tabbar-height">
| <view class='coreshop-cell-group right-img'>
| <view class='coreshop-cell-item' v-for="(item, i) in msgList" :key="i" v-if="item.status">
| <view class='coreshop-cell-item-hd'>
| <view class='coreshop-cell-hd-title'>{{item.name}}</view>
| <view class='cell-hd-desc'>{{item.desc}}</view>
| </view>
| <view class='coreshop-cell-item-ft'>
| <view v-if="!item.is" class='subscription-btn' @click="subscription(item.func, item.tmpl)">添加通知</view>
| <view v-if="item.is" class='subscription-btn isTrue' @click="subscription(item.func, item.tmpl)">已加通知</view>
| </view>
| </view>
| </view>
| </view>
| </view>
| </view>
|
| </template>
|
| <script>
| export default {
| data() {
| return {
| msgList: [
| {
| name: '下单通知',
| desc: '商城下单成功后通知我',
| func: 'order',
| tmpl: '',
| status: false,
| is: false
| },
| {
| name: '支付通知',
| desc: '订单支付后通知我',
| func: 'pay',
| tmpl: '',
| status: false,
| is: false
| },
| {
| name: '待付通知',
| desc: '未支付订单取消前通知我',
| func: 'cancel',
| tmpl: '',
| status: false,
| is: false
| },
| {
| name: '发货通知',
| desc: '订单发货后通知我',
| func: 'ship',
| tmpl: '',
| status: false,
| is: false
| },
| {
| name: '售后通知',
| desc: '订单售后结果通知我',
| func: 'aftersale',
| tmpl: '',
| status: false,
| is: false
| },
| {
| name: '退款通知',
| desc: '售后退款结果通知我',
| func: 'refund',
| tmpl: '',
| status: false,
| is: false
| },
| ]
| }
| },
| onShow() {
| this.getSubscriptionTmplIds();
| },
| methods: {
| //获取模板
| getSubscriptionTmplIds: function () {
| this.$u.api.getSubscriptionTmplIds(null).then(res => {
| if (res.status) {
| for (let i = 0; i < this.msgList.length; i++) {
| for (var j = 0; j < res.data.length; j++) {
| if (this.msgList[i].func == res.data[j].templateTitle) {
| this.msgList[i].tmpl = res.data[j].templateId;
| this.msgList[i].is = res.data[j].is;
| }
| }
| if (this.msgList[i].tmpl != '') {
| this.msgList[i].status = true;
| }
| }
| } else {
| this.$u.toast('消息订阅配置信息获取失败');
| }
| });
| },
| //发起订阅
| subscription: function (func, tmpl) {
| console.log('进入订阅发起');
| let _this = this;
| uni.requestSubscribeMessage({
| tmplIds: [tmpl],
| success(res) {
| if (res.errMsg == "requestSubscribeMessage:ok") {
| let data = {
| 'templateId': tmpl,
| 'status': res[tmpl]
| }
| _this.$u.api.setSubscriptionStatus(data).then(res => {
| _this.getSubscriptionTmplIds();
| });
| } else {
| _this.$refs.uToast.show({
| message: '操作失败,请稍候重试!', type: 'error', complete: function () {
| _this.getSubscriptionTmplIds();
| }
| });
| }
| }, fail(res) {
| _this.$u.toast(res.errMsg);
| }
| });
| }
| }
| }
| </script>
| <style lang="scss" scoped>
| @import "subscription.scss";
| </style>
|
|