coupon.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div class="bg-[#f5f5f5]">
  3. <div class="main-container">
  4. <div class="pt-[10px] flex justify-between mt-[25px]">
  5. <div class="w-[224px] flex flex-col">
  6. <info />
  7. <category />
  8. </div>
  9. <div class="flex-1 pb-[30px] px-[15px] pt-[15px] ml-[18px] bg-[#fff] rounded-[var(--rounded-big)]" v-loading="couponTable.loading">
  10. <div v-if="couponTable.data.length">
  11. <div class="flex-1 flex flex-wrap" >
  12. <template v-for="(item,index) in couponTable.data">
  13. <div class="w-[380px] h-[160px] mb-[20px] box-shadow flex mr-[30px]" >
  14. <div class="pl-[14px] flex-1 flex items-center justify-center">
  15. <div class="">
  16. <div class="text-[12px] flex items-baseline text-[#969696]">
  17. <p class="text-[16px] text-[var(--el-color-primary)]">
  18. <span class="price-font">¥</span>
  19. <span class="text-[28px] font-600 price-font">{{item.coupon_price}}</span>
  20. </p>
  21. <span v-if="item.min_condition_money === '0.00'">无门槛使用</span>
  22. <span v-else>满{{ item.coupon_min_price }}元可用</span>
  23. </div>
  24. <div class="mt-[12px] text-[14px] text-[#282828] leading-[22px] flex items-center">
  25. <span class="text-[var(--el-color-primary)] text-[12px] px-[7px] leading-[20px] text-center rounded-[10px] bg-color">{{item.type_name}}</span>
  26. <span class="ml-[5px] max-w-[120px] truncate">{{item.title}}</span>
  27. </div>
  28. <div class="mt-[12px] text-[14px] text-[#282828] leading-[22px] truncate max-w-[300px]">使用店铺:{{item.site_name}}</div>
  29. <div class="mt-[12px] text-[14px] text-[#282828] leading-[22px] flex items-center">
  30. <div v-if="item.valid_type == 1">领取之日起<span>{{ item.length || '' }}</span>天内有效</div>
  31. <div v-else> 有效期至<span>{{ item.valid_end_time ? item.valid_end_time.slice(0, 10) : '' }}</span></div>
  32. </div>
  33. </div>
  34. </div>
  35. <div v-if="item.btnType === 'collecting'" class="w-[52px] px-[18px] text-[16px] text-[#fff] cursor-pointer flex items-center leading-[24px] bg-[var(--el-color-primary)]" @click="getCouponFn(item.id,index)">
  36. 立即领取
  37. </div>
  38. <div v-if="item.btnType === 'using'" class="w-[52px] px-[18px] text-[16px] text-[#fff] cursor-pointer flex items-center leading-[24px] bg-[var(--el-color-primary)]" @click="toUse(item)" >
  39. 去使用
  40. </div>
  41. <div v-if="item.btnType === 'collected'" class="w-[52px] px-[18px] text-[16px] text-[#fff] cursor-pointer flex items-center leading-[24px] bg-[#999]" >
  42. 已领完
  43. </div>
  44. <div v-if="item.btnType === 'used'" class="w-[52px] px-[18px] text-[16px] text-[#fff] cursor-pointer flex items-center leading-[24px] bg-[#999]" >
  45. 已领完
  46. </div>
  47. </div>
  48. </template>
  49. </div>
  50. <div class="mt-[20px] flex justify-center">
  51. <el-pagination background small hide-on-single-page v-model:current-page="couponTable.page" v-model:page-size="couponTable.limit" layout="prev, pager, next" :total="couponTable.total" @size-change="loadCouponList()" @current-change="loadCouponList" />
  52. </div>
  53. </div>
  54. <div v-else>
  55. <el-empty description="暂无数据" :image-size="200" :image="img('static/resource/images/system/empty.png')" />
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </template>
  62. <script lang="ts" setup>
  63. import { ref,reactive,computed } from 'vue'
  64. import category from './components/category/index.vue'
  65. import info from './components/info/index.vue'
  66. import { getMallCouponList, getCoupon} from '@/addon/mall/api/coupon'
  67. import useMemberStore from '@/stores/member'
  68. import { useRouter, useRoute } from 'vue-router'
  69. const router = useRouter()
  70. const route = useRoute()
  71. const memberStore = useMemberStore()
  72. const userInfo = computed(() => memberStore.info)
  73. /**
  74. * 获取优惠券列表
  75. */
  76. const couponTable = reactive({
  77. page: 1,
  78. limit: 15,
  79. total: 0,
  80. loading: true,
  81. data: [],
  82. searchParam:{
  83. site_id:''
  84. }
  85. })
  86. couponTable.searchParam.site_id = route.query.site_id
  87. const loadCouponList = (page = 1) => {
  88. couponTable.page = page
  89. couponTable.loading = true
  90. getMallCouponList({
  91. page: couponTable.page,
  92. limit: couponTable.limit,
  93. ...couponTable.searchParam
  94. }).then(res =>{
  95. couponTable.loading = false
  96. couponTable.total = res.data.total
  97. couponTable.data = (res.data.data).map(el =>{
  98. if (!userInfo.value) {
  99. if (el.sum_count != -1 && el.receive_count === el.sum_count) {
  100. el.btnType = 'collected'//已领完
  101. } else {
  102. el.btnType = 'collecting'//领用
  103. }
  104. } else {
  105. if (el.is_receive) {
  106. if (el.member_receive_count < el.limit_count) {
  107. if (el.need_receive) {
  108. el.btnType = 'collecting'//领用
  109. } else {
  110. el.btnType = 'using'//去使用
  111. }
  112. } else {
  113. if (el.need_receive) {
  114. el.btnType = 'used'//已使用
  115. } else {
  116. el.btnType = 'using'//去使用
  117. }
  118. }
  119. } else {
  120. if (el.sum_count != -1 && el.receive_count === el.sum_count) {
  121. el.btnType = 'collected'//已领完
  122. } else {
  123. el.btnType = 'collecting'//领用
  124. }
  125. }
  126. }
  127. return el
  128. })
  129. })
  130. }
  131. loadCouponList()
  132. //领用
  133. const getCouponFn = (id,index) =>{
  134. if(!userInfo.value){
  135. memberStore.logOpen()
  136. return false
  137. }
  138. getCoupon({
  139. coupon_id:id,
  140. number:1,
  141. type:'receive'
  142. }).then(res =>{
  143. couponTable.data[index].is_receive = true
  144. couponTable.data[index].btnType = 'using'//去使用
  145. })
  146. }
  147. // 去使用
  148. const toUse = (data:any) =>{
  149. router.push({path:'/shop/detail',query:{site_id:data.site_id,coupon_id:data.id}})
  150. }
  151. </script>
  152. <style lang="scss" scoped>
  153. .box-shadow{
  154. box-shadow: 0 3px 20px rgba(0,0,0,.08)
  155. }
  156. .bg-color{
  157. background: rgba(233,51,35,.1)
  158. }
  159. </style>