小程序端工程代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.0 KiB

  1. <template>
  2. <view v-if="couponList.length > 0">
  3. <view class="coupon-window" :class="value ? 'on' : ''">
  4. <view class="couponWinList">
  5. <view class="item acea-row row-between-wrapper" v-for="(item, couponwindiwIndex) in couponList" :key="couponwindiwIndex">
  6. <view class="money font-color-red">
  7. <text class="num">{{ item.coupon_price }}</text>
  8. </view>
  9. <view class="text">
  10. <view class="name">
  11. 购物买{{ item.use_min_price }}{{ item.coupon_price }}
  12. </view>
  13. <view v-if="item.end_time">
  14. {{ item.start_time }}-{{ item.end_time }}
  15. </view>
  16. </view>
  17. </view>
  18. <view style="height:120rpx"></view>
  19. </view>
  20. <view class="lid">
  21. <view class="bnt font-color-red" @click="checked">立即领取</view>
  22. <view class="iconfont icon-guanbi3" @click="close"></view>
  23. </view>
  24. </view>
  25. <view class="mask" @touchmove.prevent :hidden="!value"></view>
  26. </view>
  27. </template>
  28. <script>
  29. import {
  30. mapGetters
  31. } from "vuex";
  32. import {handleLoginFailure} from "@/utils";
  33. import {
  34. couponReceiveBatch
  35. } from "@/api/user";
  36. export default {
  37. name: "CouponWindow",
  38. props: {
  39. couponList: {
  40. type: Array,
  41. default: () => []
  42. }
  43. },
  44. computed: mapGetters(["isLogin"]),
  45. data: function() {
  46. return {
  47. value: true
  48. };
  49. },
  50. mounted: function() {},
  51. methods: {
  52. checked() {
  53. const isLogin = this.isLogin;
  54. if (!isLogin) return handleLoginFailure();
  55. const ids = this.couponList.reduce((initial, coupon) => {
  56. initial.push(coupon.id);
  57. return initial;
  58. }, []);
  59. couponReceiveBatch(ids)
  60. .then(() => {
  61. this.$emit("success");
  62. uni.showToast({
  63. title: '领取成功',
  64. icon: 'success',
  65. duration: 2000
  66. });
  67. })
  68. .catch(() => {
  69. uni.showToast({
  70. title: '已领取',
  71. icon: 'none',
  72. duration: 2000
  73. });
  74. });
  75. if (isLogin) {
  76. this.value = false;
  77. this.$emit("checked");
  78. }
  79. },
  80. close: function() {
  81. this.value = false;
  82. this.$emit("close");
  83. }
  84. }
  85. };
  86. </script>