give.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <app-layout>
  3. <view v-if="type === 'give'">
  4. <app-card-give :card="card" @receive="receive"></app-card-give>
  5. </view>
  6. <view v-if="type === 'detail'">
  7. <app-card-detail @share="hShareAppMessage" :list="card"></app-card-detail>
  8. </view>
  9. </app-layout>
  10. </template>
  11. <script>
  12. import {mapState} from "vuex";
  13. import appCardGive from '../components/app-card-give.vue';
  14. import appCardDetail from '../components/app-card-detail.vue';
  15. export default {
  16. name: "give",
  17. components: {
  18. appCardGive,
  19. appCardDetail
  20. },
  21. data() {
  22. return {
  23. card: null,
  24. type: null,
  25. };
  26. },
  27. computed: {
  28. ...mapState({
  29. cardImg: state => state.mallConfig.__wxapp_img.card,
  30. })
  31. },
  32. onLoad(options) { this.$commonLoad.onload(options);
  33. this.loadData(options);
  34. },
  35. // #ifdef MP
  36. onShareAppMessage() {
  37. return this.hShareAppMessage();
  38. },
  39. // #endif
  40. methods: {
  41. hShareAppMessage() {
  42. return this.$shareAppMessage({
  43. title: this.card.app_share_title ? this.card.app_share_title : '送你一张卡券,赶快来领取吧',
  44. imageUrl: this.card.app_share_pic ? this.card.app_share_pic : this.cardImg.img_card_2,
  45. path: '/pages/card/give/give',
  46. params: {
  47. card_id: this.card.id
  48. }
  49. });
  50. },
  51. loadData(options) {
  52. this.$showLoading();
  53. this.$request({
  54. url: this.$api.card.give,
  55. method: 'get',
  56. data: {
  57. cardId: options.card_id
  58. }
  59. }).then(response => {
  60. this.$hideLoading();
  61. if (response.code === 0) {
  62. let data = response.data;
  63. this.type = data.type;
  64. this.card = response.data;
  65. let title = '';
  66. if (data.type === 'give') {
  67. title = '领取卡券'
  68. } else {
  69. title = '卡券详情'
  70. }
  71. uni.setNavigationBarTitle({
  72. title: title,
  73. });
  74. }
  75. })
  76. },
  77. receive() {
  78. this.loadData({card_id: this.card.id})
  79. }
  80. },
  81. }
  82. </script>
  83. <style scoped lang="scss">
  84. </style>