index.vue 7.8 KB

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