coupon.vue 5.6 KB

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