template-msg.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <app-layout>
  3. <view>
  4. <view class="title">温馨提示:测试前请先点击"订阅",授权后点击"发送"</view>
  5. <view class="list" v-if="list.length > 0">
  6. <view class="item dir-left-nowrap cross-center" v-for="(item, index) in list" :key="index">
  7. <view class="box-grow-1">{{item.name}}</view>
  8. <view class="box-grow-0 btn btn-subscribe" @click="subscribe(index)">
  9. <app-jump-button>订阅</app-jump-button>
  10. </view>
  11. <view class="box-grow-0 btn btn-send" @click="send(index)">发送</view>
  12. </view>
  13. </view>
  14. </view>
  15. </app-layout>
  16. </template>
  17. <script>
  18. export default {
  19. name: "template-msg",
  20. data() {
  21. return {
  22. list: [],
  23. };
  24. },
  25. onLoad(options) {
  26. this.loadData();
  27. },
  28. methods: {
  29. loadData() {
  30. this.$showLoading();
  31. this.$request({
  32. url: this.$api.template.template,
  33. }).then(response => {
  34. this.$hideLoading();
  35. if (response.code == 0) {
  36. this.list = response.data.list;
  37. } else {
  38. uni.showToast({
  39. title: response.msg,
  40. icon: 'none',
  41. duration: 1000
  42. })
  43. }
  44. }).catch(response => {
  45. this.$hideLoading();
  46. });
  47. },
  48. subscribe(index) {
  49. let template = this.list[index];
  50. this.$subscribe([template.tpl_id]).then(res => {
  51. // #ifdef MP_WEIXIN
  52. if (res[template.tpl_id] == 'accept') {
  53. uni.showModal({
  54. title: '提示',
  55. content: '订阅成功',
  56. showCancel: false,
  57. })
  58. } else {
  59. uni.showModal({
  60. title: '提示',
  61. content: '取消订阅',
  62. showCancel: false,
  63. })
  64. }
  65. // #endif
  66. // #ifndef MP-WEIXIN
  67. uni.showModal({
  68. title: '提示',
  69. content: '订阅成功',
  70. showCancel: false,
  71. })
  72. // #endif
  73. });
  74. },
  75. send(index) {
  76. this.$showLoading({
  77. text: '发送中'
  78. });
  79. this.$request({
  80. url: this.$api.template.template,
  81. method: 'post',
  82. data: {
  83. templateTpl: this.list[index].tpl_name
  84. }
  85. }).then(response => {
  86. this.$hideLoading();
  87. if (response.code == 0) {
  88. uni.showModal({
  89. title: '提示',
  90. content: response.data.msg,
  91. showCancel: false,
  92. })
  93. } else {
  94. this.$hideLoading();
  95. uni.showToast({
  96. title: response.msg,
  97. icon: 'none',
  98. duration: 1000
  99. })
  100. }
  101. })
  102. }
  103. }
  104. }
  105. </script>
  106. <style scoped lang="scss">
  107. .title {
  108. font-size: $uni-font-size-general-one;
  109. color: #ff8a00;
  110. height: #{88rpx};
  111. line-height: #{88rpx};
  112. padding: #{0 24rpx};
  113. background-color: #fff0d9;
  114. }
  115. .list {
  116. padding: #{24rpx};
  117. .item {
  118. margin-bottom: #{24rpx};
  119. background-color: #ffffff;
  120. height: #{120rpx};
  121. padding: #{0 40rpx};
  122. border-radius: #{16rpx};
  123. .btn {
  124. font-size: $uni-font-size-general-two;
  125. padding: #{20rpx 30rpx};
  126. border-radius: #{64rpx};
  127. margin-left: #{20rpx};
  128. &.btn-subscribe {
  129. border: #{1rpx solid #409eff};
  130. background-color: #ffffff;
  131. color: #409eff;
  132. }
  133. &.btn-send {
  134. background-color: #409eff;
  135. color: #ffffff;
  136. }
  137. }
  138. }
  139. }
  140. </style>