coupon.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <!-- 优惠券 -->
  3. <view v-show="!isSortType" :style="{padding:'0 '+prConfig*2+'rpx'}">
  4. <view class="coupon" :class="bgStyle===0?'':'borderRadius15'" :style="'background-color:'+bgColor+';margin-top:' + mbConfig*2 +'rpx;'" v-if="couponList.length">
  5. <scroll-view scroll-x="true" class="coupon-scroll" show-scrollbar="false">
  6. <view class="wrapper">
  7. <view class="item" :style="item.is_use?'':'background-color:'+ themeColor +';'" style="margin-right: 20rpx;" v-for="(item,index) in couponList"
  8. :key="index" hover-class="none">
  9. <view class="itemCon acea-row row-between-wrapper">
  10. <view class="text">
  11. <view class="money"><text v-if="item.coupon_type==1">¥</text>{{item.coupon_type==1?item.coupon_price:parseFloat(item.coupon_price)/10}}<text v-if="item.coupon_type==2">折</text></view>
  12. <view class="info">满{{item.use_min_price}}元可用</view>
  13. <!-- #ifdef H5 || APP-PLUS -->
  14. <slot name="bottom" :item="item"></slot>
  15. <!-- #endif -->
  16. <!-- #ifdef MP -->
  17. <slot name="bottom{{index}}"></slot>
  18. <!-- #endif -->
  19. </view>
  20. <view class="bnt" v-if="item.is_use===true"><text>已 领 取</text></view>
  21. <view class="bnt" v-else-if="item.is_use===false" @click="receiveCoupon(item)"><text>立 即 领 取</text></view>
  22. <view class="bnt" v-else-if="item.is_use===2"><text>已 过 期</text></view>
  23. </view>
  24. <view class="roll up-roll" :style="{background:bgColor}"></view>
  25. <view class="roll down-roll" :style="{background:bgColor}"></view>
  26. </view>
  27. <navigator url="/pages/users/user_get_coupon/index" class="more-box" hover-class="none">
  28. <view class="txt">更多</view>
  29. <image src="/static/images/mores.png"></image>
  30. </navigator>
  31. </view>
  32. </scroll-view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import {
  38. getCoupons,
  39. setCouponReceive
  40. } from '@/api/api.js';
  41. import {
  42. mapGetters
  43. } from "vuex";
  44. export default {
  45. name: 'coupon',
  46. props: {
  47. dataConfig: {
  48. type: Object,
  49. default: () => {}
  50. },
  51. isSortType:{
  52. type: String | Number,
  53. default:0
  54. }
  55. },
  56. computed: mapGetters(['isLogin']),
  57. components: {},
  58. watch:{
  59. isLogin:{
  60. handler:function(newV,oldV){
  61. if(newV){
  62. this.getCoupon();
  63. }
  64. },
  65. deep:true
  66. }
  67. },
  68. data() {
  69. return {
  70. isAuto: false, //没有授权的不会自动授权
  71. isShowAuth: false, //是否隐藏授权
  72. couponList: [],
  73. bgColor: this.dataConfig.bgColor.color[0].item,
  74. themeColor: this.dataConfig.themeColor.color[0].item,
  75. mbConfig: this.dataConfig.mbConfig.val,
  76. bgStyle: this.dataConfig.bgStyle.type,
  77. prConfig: this.dataConfig.prConfig.val
  78. };
  79. },
  80. created() {},
  81. mounted() {
  82. this.getCoupon();
  83. },
  84. methods: {
  85. getCoupon: function() {
  86. let that = this;
  87. let limit = that.$config.LIMIT;
  88. getCoupons({
  89. page: 1,
  90. limit: limit,
  91. type: -1
  92. }).then(res => {
  93. that.$set(that, 'couponList', res.data.list);
  94. }).catch(err => {
  95. return that.$util.Tips({
  96. title: err
  97. });
  98. });
  99. },
  100. receiveCoupon: function(item) {
  101. let that = this;
  102. if (!that.isLogin) {
  103. this.$emit('changeLogin');
  104. } else {
  105. setCouponReceive(item.id)
  106. .then(function() {
  107. item.is_use = true;
  108. that.$set(that, 'couponList', that.couponList);
  109. that.$util.Tips({
  110. title: "领取成功"
  111. });
  112. })
  113. .catch(function(err) {
  114. that.$util.Tips({
  115. title: err
  116. });
  117. });
  118. }
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss">
  124. .coupon-scroll {
  125. white-space: nowrap;
  126. vertical-align: middle;
  127. }
  128. .coupon {
  129. background-color: #fff;
  130. padding: 20rpx;
  131. .item {
  132. display: flex;
  133. width: 304rpx;
  134. height: 122rpx;
  135. background-color: #DDDDDD;
  136. border-radius: 8rpx;
  137. color: #fff;
  138. position: relative;
  139. display: inline-block;
  140. flex-shrink: 0;
  141. .roll{
  142. position: absolute;
  143. width: 20rpx;
  144. height: 20rpx;
  145. border-radius: 50%;
  146. background: #fff;
  147. &.up-roll{
  148. right: 52rpx;
  149. top: -10rpx;
  150. }
  151. &.down-roll{
  152. right: 52rpx;
  153. bottom: -10rpx;
  154. }
  155. }
  156. // &::before {
  157. // position: absolute;
  158. // content: ' ';
  159. // width: 20rpx;
  160. // height: 20rpx;
  161. // border-radius: 50%;
  162. // background-color: #fff;
  163. // right: 52rpx;
  164. // top: -10rpx;
  165. // }
  166. // &::after {
  167. // position: absolute;
  168. // content: ' ';
  169. // width: 20rpx;
  170. // height: 20rpx;
  171. // border-radius: 50%;
  172. // background-color: #fff;
  173. // right: 52rpx;
  174. // bottom: -10rpx;
  175. // }
  176. .itemCon {
  177. height: 100%;
  178. width: 100%;
  179. .text {
  180. width: 240rpx;
  181. .money {
  182. font-size: 48rpx;
  183. text-align: center;
  184. text {
  185. font-size: 24rpx;
  186. }
  187. }
  188. .info {
  189. font-size: 24rpx;
  190. text-align: center;
  191. }
  192. }
  193. .bnt {
  194. position: relative;
  195. height: 100%;
  196. font-size: 20rpx;
  197. display: block;
  198. writing-mode: vertical-lr;
  199. line-height: 1.2;
  200. width: 64rpx;
  201. border-left: 1px dashed #fff;
  202. text{
  203. position: absolute;
  204. left: 56%;
  205. top: 50%;
  206. transform: translate(-50%,-50%);
  207. }
  208. }
  209. }
  210. }
  211. .wrapper {
  212. display: flex;
  213. }
  214. .more-box {
  215. display: flex;
  216. flex-direction: column;
  217. align-items: center;
  218. justify-content: center;
  219. background-color: #fff;
  220. border-radius: 16rpx;
  221. padding: 0 10px;
  222. height: 122rpx;
  223. image {
  224. width: 20rpx;
  225. height: 20rpx;
  226. margin-top: 10rpx;
  227. margin: 10rpx 0 0 5rpx;
  228. }
  229. .txt {
  230. display: block;
  231. writing-mode: vertical-lr;
  232. font-size: 20rpx;
  233. line-height: 1.2;
  234. }
  235. }
  236. }
  237. </style>