coupon.vue 5.6 KB

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