coupon.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. import {
  45. toLogin
  46. } from '@/libs/login.js';
  47. export default {
  48. name: 'coupon',
  49. props: {
  50. dataConfig: {
  51. type: Object,
  52. default: () => {}
  53. },
  54. isSortType:{
  55. type: String | Number,
  56. default:0
  57. }
  58. },
  59. computed: mapGetters(['isLogin']),
  60. components: {},
  61. watch:{
  62. isLogin:{
  63. handler:function(newV,oldV){
  64. if(newV){
  65. this.getCoupon();
  66. }
  67. },
  68. deep:true
  69. }
  70. },
  71. data() {
  72. return {
  73. isAuto: false, //没有授权的不会自动授权
  74. isShowAuth: false, //是否隐藏授权
  75. couponList: [],
  76. bgColor: this.dataConfig.bgColor.color[0].item,
  77. themeColor: this.dataConfig.themeColor.color[0].item,
  78. mbConfig: this.dataConfig.mbConfig.val,
  79. bgStyle: this.dataConfig.bgStyle.type,
  80. prConfig: this.dataConfig.prConfig.val
  81. };
  82. },
  83. created() {},
  84. mounted() {
  85. this.getCoupon();
  86. },
  87. methods: {
  88. getCoupon: function() {
  89. let that = this;
  90. let limit = that.$config.LIMIT;
  91. getCoupons({
  92. page: 1,
  93. limit: limit,
  94. type: -1
  95. }).then(res => {
  96. that.$set(that, 'couponList', res.data.list);
  97. }).catch(err => {
  98. return that.$util.Tips({
  99. title: err
  100. });
  101. });
  102. },
  103. receiveCoupon: function(item) {
  104. let that = this;
  105. if (!that.isLogin) {
  106. toLogin();
  107. } else {
  108. setCouponReceive(item.id)
  109. .then(function() {
  110. item.is_use = true;
  111. that.$set(that, 'couponList', that.couponList);
  112. that.$util.Tips({
  113. title: "领取成功"
  114. });
  115. })
  116. .catch(function(err) {
  117. that.$util.Tips({
  118. title: err
  119. });
  120. });
  121. }
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="scss">
  127. .coupon-scroll {
  128. white-space: nowrap;
  129. vertical-align: middle;
  130. }
  131. .coupon {
  132. background-color: #fff;
  133. padding: 20rpx;
  134. .item {
  135. display: flex;
  136. width: 304rpx;
  137. height: 122rpx;
  138. background-color: #DDDDDD;
  139. border-radius: 8rpx;
  140. color: #fff;
  141. position: relative;
  142. display: inline-block;
  143. flex-shrink: 0;
  144. .roll{
  145. position: absolute;
  146. width: 20rpx;
  147. height: 20rpx;
  148. border-radius: 50%;
  149. background: #fff;
  150. &.up-roll{
  151. right: 52rpx;
  152. top: -10rpx;
  153. }
  154. &.down-roll{
  155. right: 52rpx;
  156. bottom: -10rpx;
  157. }
  158. }
  159. // &::before {
  160. // position: absolute;
  161. // content: ' ';
  162. // width: 20rpx;
  163. // height: 20rpx;
  164. // border-radius: 50%;
  165. // background-color: #fff;
  166. // right: 52rpx;
  167. // top: -10rpx;
  168. // }
  169. // &::after {
  170. // position: absolute;
  171. // content: ' ';
  172. // width: 20rpx;
  173. // height: 20rpx;
  174. // border-radius: 50%;
  175. // background-color: #fff;
  176. // right: 52rpx;
  177. // bottom: -10rpx;
  178. // }
  179. .itemCon {
  180. height: 100%;
  181. width: 100%;
  182. .text {
  183. width: 240rpx;
  184. .money {
  185. font-size: 48rpx;
  186. text-align: center;
  187. text {
  188. font-size: 24rpx;
  189. }
  190. }
  191. .info {
  192. font-size: 24rpx;
  193. text-align: center;
  194. }
  195. }
  196. .bnt {
  197. position: relative;
  198. height: 100%;
  199. font-size: 20rpx;
  200. display: block;
  201. writing-mode: vertical-lr;
  202. line-height: 1.2;
  203. width: 64rpx;
  204. border-left: 1px dashed #fff;
  205. text{
  206. position: absolute;
  207. left: 56%;
  208. top: 50%;
  209. transform: translate(-50%,-50%);
  210. }
  211. }
  212. }
  213. }
  214. .wrapper {
  215. display: flex;
  216. }
  217. .more-box {
  218. display: flex;
  219. flex-direction: column;
  220. align-items: center;
  221. justify-content: center;
  222. background-color: #fff;
  223. border-radius: 16rpx;
  224. padding: 0 10px;
  225. height: 122rpx;
  226. image {
  227. width: 20rpx;
  228. height: 20rpx;
  229. margin-top: 10rpx;
  230. margin: 10rpx 0 0 5rpx;
  231. }
  232. .txt {
  233. display: block;
  234. writing-mode: vertical-lr;
  235. font-size: 20rpx;
  236. line-height: 1.2;
  237. }
  238. }
  239. }
  240. </style>