index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <view :style="colorStyle">
  3. <view v-if="count > 1" class="acea-row row-around nav">
  4. <template v-for="item in navList">
  5. <view v-if="item.count" :key="item.type" :class="['acea-row', 'row-middle', type === item.type ? 'on' : '']" @click="setType(item.type)">{{ item.name }}</view>
  6. </template>
  7. </view>
  8. <view v-if="count > 1" style="height: 106rpx;"></view>
  9. <view class='coupon-list' v-if="couponsList.length">
  10. <view class='item acea-row row-center-wrapper' v-for="(item,index) in couponsList" :key="index" :class="{svip: item.receive_type === 4}">
  11. <view class="moneyCon acea-row row-center-wrapper">
  12. <view class='money' :class='item.is_use ? "moneyGray" : "" '>
  13. <view>{{$t(`¥`)}}<text class='num'>{{item.coupon_price}}</text></view>
  14. <view class="pic-num" v-if="item.use_min_price > 0">{{$t(`满`)}} {{item.use_min_price}} {{$t(`元可用`)}}</view>
  15. <view class="pic-num" v-else>{{$t(`无门槛券`)}}</view>
  16. </view>
  17. </view>
  18. <view class="text">
  19. <view class="condition">
  20. <view class="name line2">
  21. <view class="line-title" :class="item.is_use == true || item.is_use == 2 ? 'bg-color-huic' : ''" v-if="item.type === 0">{{$t(`通用劵`)}}</view>
  22. <view class="line-title" :class="item.is_use == true || item.is_use == 2 ? 'bg-color-huic' : ''" v-else-if="item.type === 1">{{$t(`品类券`)}}</view>
  23. <view class="line-title" :class="item.is_use == true || item.is_use == 2 ? 'bg-color-huic' : ''" v-else>{{$t(`商品券`)}}</view>
  24. <image v-if="item.receive_type === 4" class="pic" src="/static/images/fvip.png"></image>
  25. {{ $t(item.title) }}
  26. </view>
  27. </view>
  28. <view class="data acea-row row-between-wrapper">
  29. <view v-if="item.coupon_time">{{$t(`领取后`)}} {{item.coupon_time}} {{$t(`天内可用`)}}</view>
  30. <view v-else>{{ item.start_use_time ? item.start_use_time + '-' : '' }}{{ item.end_use_time }}</view>
  31. <view class="bnt gray" v-if="item.is_use == true">{{$t(`已领取`)}}</view>
  32. <view class="bnt gray" v-else-if="item.is_use == 2">{{$t(`已领完`)}}</view>
  33. <view class="bnt bg-color" v-else @click="getCoupon(item.id, index)">{{$t(`立即领取`)}}</view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class='loadingicon acea-row row-center-wrapper' v-if="couponsList.length">
  39. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  40. </view>
  41. <view class='noCommodity' v-else-if="!couponsList.length && page === 2">
  42. <view class='pictrue'>
  43. <!-- <image :src="imgHost + '/statics/images/noCoupon.png'"></image> -->
  44. </view>
  45. </view>
  46. <!-- #ifdef MP -->
  47. <authorize @onLoadFun="onLoadFun" @authColse="authColse"></authorize>
  48. <!-- #endif -->
  49. <!-- #ifndef MP -->
  50. <home></home>
  51. <!-- #endif -->
  52. </view>
  53. </template>
  54. <script>
  55. import {
  56. getCoupons,
  57. setCouponReceive
  58. } from '@/api/api.js';
  59. import {
  60. toLogin
  61. } from '@/libs/login.js';
  62. import {
  63. mapGetters
  64. } from "vuex";
  65. // #ifdef MP
  66. import authorize from '@/components/Authorize';
  67. // #endif
  68. import home from '@/components/home';
  69. import colors from '@/mixins/color.js';
  70. import {HTTP_REQUEST_URL} from '@/config/app';
  71. export default {
  72. components: {
  73. // #ifdef MP
  74. authorize,
  75. // #endif
  76. home
  77. },
  78. mixins:[colors],
  79. data() {
  80. return {
  81. imgHost:HTTP_REQUEST_URL,
  82. couponsList: [],
  83. loading: false,
  84. loadend: false,
  85. loadTitle: this.$t(`加载更多`), //提示语
  86. page: 1,
  87. limit: 20,
  88. isAuto: false, //没有授权的不会自动授权
  89. isShowAuth: false, //是否隐藏授权
  90. type: 0,
  91. navList: [{
  92. type: 0,
  93. name: this.$t(`通用券`),
  94. count: 0
  95. },
  96. {
  97. type: 1,
  98. name: this.$t(`品类券`),
  99. count: 0
  100. },
  101. {
  102. type: 2,
  103. name: this.$t(`商品券`),
  104. count: 0
  105. },
  106. ],
  107. count: 0
  108. };
  109. },
  110. computed: mapGetters(['isLogin']),
  111. watch: {
  112. isLogin: {
  113. handler: function(newV, oldV) {
  114. if (newV) {
  115. this.getUseCoupons();
  116. }
  117. },
  118. deep: true
  119. }
  120. },
  121. onLoad() {
  122. if (this.isLogin) {
  123. // #ifdef H5 || APP-PLUS
  124. this.getUseCoupons();
  125. // #endif
  126. } else {
  127. toLogin();
  128. }
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom: function() {
  134. this.getUseCoupons();
  135. },
  136. methods: {
  137. onLoadFun() {
  138. this.getUseCoupons();
  139. },
  140. // 授权关闭
  141. authColse: function(e) {
  142. this.isShowAuth = e;
  143. },
  144. getCoupon: function(id, index) {
  145. let that = this;
  146. let list = that.couponsList;
  147. //领取优惠券
  148. setCouponReceive(id).then(function(res) {
  149. list[index].is_use = true;
  150. that.$set(that, 'couponsList', list);
  151. that.$util.Tips({
  152. title: that.$t(`领取成功`)
  153. });
  154. }).catch(error => {
  155. return that.$util.Tips({
  156. title: error
  157. });
  158. })
  159. },
  160. /**
  161. * 获取领取优惠券列表
  162. */
  163. getUseCoupons: function() {
  164. let that = this
  165. if (this.loadend) return false;
  166. if (this.loading) return false;
  167. that.loading = true;
  168. that.loadTitle = that.$t(`加载更多`);
  169. getCoupons({
  170. type: that.type,
  171. page: that.page,
  172. limit: that.limit
  173. }).then(res => {
  174. let list = res.data.list,
  175. loadend = list.length < that.limit;
  176. let couponsList = that.$util.SplitArray(list, that.couponsList);
  177. res.data.count.forEach((value, index) => {
  178. that.navList[index].count = value;
  179. if (value) {
  180. that.count++;
  181. }
  182. });
  183. that.$set(that, 'couponsList', couponsList);
  184. that.loadend = loadend;
  185. that.loading = false;
  186. that.loadTitle = loadend ? that.$t(`我也是有底线的`) : that.$t(`加载更多`);
  187. that.page = that.page + 1;
  188. }).catch(err => {
  189. that.loading = false;
  190. that.loadTitle = that.$t(`加载更多`);
  191. });
  192. },
  193. setType: function(type) {
  194. if (this.type !== type) {
  195. this.type = type;
  196. this.couponsList = [];
  197. this.page = 1;
  198. this.loadend = false;
  199. this.getUseCoupons();
  200. }
  201. }
  202. }
  203. };
  204. </script>
  205. <style scoped>
  206. .nav {
  207. position: fixed;
  208. top: 0;
  209. left: 0;
  210. width: 100%;
  211. height: 106rpx;
  212. background-color: #FFFFFF;
  213. font-size: 30rpx;
  214. color: #999999;
  215. z-index: 9;
  216. }
  217. .nav .acea-row {
  218. border-top: 5rpx solid transparent;
  219. border-bottom: 5rpx solid transparent;
  220. cursor: pointer;
  221. }
  222. .nav .acea-row.on {
  223. border-bottom-color: var(--view-theme);
  224. color: #282828;
  225. }
  226. .coupon-list .pic-num {
  227. color: #FFFFFF;
  228. font-size: 24rpx;
  229. }
  230. .coupon-list .item .text .condition {
  231. display: flex;
  232. align-items: center;
  233. }
  234. .coupon-list .item .text .condition .name {
  235. font-size: 26rpx;
  236. font-weight: 500;
  237. display: flex;
  238. align-items: center;
  239. }
  240. .coupon-list .item .text .condition .pic {
  241. width: 30rpx;
  242. height: 30rpx;
  243. display: block;
  244. margin-right: 10rpx;
  245. display: inline-block;
  246. vertical-align: middle;
  247. }
  248. .condition .line-title {
  249. width: 70rpx;
  250. height: 32rpx !important;
  251. line-height: 30rpx;
  252. text-align: center;
  253. box-sizing: border-box;
  254. background: rgba(255, 247, 247, 1);
  255. border: 1px solid var(--view-theme);
  256. opacity: 1;
  257. border-radius: 20rpx;
  258. font-size: 18rpx !important;
  259. color: var(--view-theme);
  260. margin-right: 12rpx;
  261. text-align: center;
  262. display: inline-block;
  263. vertical-align: middle;
  264. }
  265. .condition .line-title.bg-color-huic {
  266. border-color: #BBB!important;
  267. color: #bbb!important;
  268. background-color: #F5F5F5!important;
  269. }
  270. </style>