couponModel.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <Popup ref="popRef" mode="center" closeOnClickOverlay>
  3. <template #content>
  4. <view class="content">
  5. <image
  6. :src="coupon.picture"
  7. class="img"
  8. mode="widthFix"
  9. v-if="coupon.picture"
  10. @click="drawCoupon"
  11. >
  12. </image>
  13. </view>
  14. </template>
  15. <template #footer>
  16. <view class="close" @click="close">
  17. <image
  18. class="icon-font"
  19. mode="widthFix"
  20. src="/static/home/close.png"
  21. ></image>
  22. </view>
  23. </template>
  24. </Popup>
  25. </template>
  26. <script setup>
  27. import { ref, watch, computed, nextTick } from "vue";
  28. import Popup from "@/components/popup.vue";
  29. import { t } from "@/locale";
  30. import { useSystemStore } from "@/store";
  31. import { SHOP_GET_COUPON } from "@/api";
  32. import { Toast, TimeOut } from "@/utils";
  33. const useSystem = useSystemStore();
  34. const coupon = computed(() => useSystem.getCoupon);
  35. const props = defineProps({
  36. coponData: {
  37. type: Object,
  38. },
  39. });
  40. const popRef = ref(null);
  41. const emit = defineEmits(["open", "close"]);
  42. const open = () => {
  43. popRef.value && popRef.value.open();
  44. };
  45. const close = () => {
  46. popRef.value && popRef.value.close();
  47. emit("close");
  48. };
  49. const drawCoupon = async () => {
  50. if (!coupon.value.id) return;
  51. try {
  52. const res = await SHOP_GET_COUPON(coupon.value.id);
  53. Toast(res.msg).then(() => {
  54. TimeOut(() => {
  55. close();
  56. useSystem.setCoupon();
  57. uni.navigateTo({ url: "/pages/user/coupon" });
  58. });
  59. });
  60. } catch (error) {
  61. Toast(error.msg);
  62. }
  63. };
  64. watch(
  65. () => coupon.value?.show,
  66. (val) => {
  67. if (val) {
  68. nextTick(() => {
  69. open();
  70. });
  71. } else {
  72. close();
  73. }
  74. },
  75. {
  76. immediate: true,
  77. }
  78. );
  79. defineExpose({ open, close });
  80. </script>
  81. <style lang="less" scoped>
  82. @import url("@/style.less");
  83. :deep(.conts) {
  84. width: 600rpx;
  85. padding: 0 !important;
  86. }
  87. :deep(.u-popup__content) {
  88. background-color: transparent !important;
  89. }
  90. :deep(.footer) {
  91. padding: 0 !important;
  92. }
  93. .content {
  94. width: 100%;
  95. .img {
  96. width: 100%;
  97. height: auto;
  98. display: block;
  99. }
  100. }
  101. .close {
  102. .flex_center();
  103. height: 76rpx;
  104. width: 100%;
  105. background-color: transparent;
  106. .icon-font {
  107. width: 46rpx;
  108. height: 46rpx;
  109. }
  110. }
  111. </style>