index.vue 7.8 KB

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