index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <!-- 领优惠卷模块 -->
  3. <view class="getCoupons" :style="colorStyle">
  4. <view v-if="count > 1" class="header acea-row row-around">
  5. <view class="item" :class="type==index?'on':''" v-if="item.count" v-for="(item,index) in navList" :key="index" @click="setType(index)">{{ item.name }}</view>
  6. </view>
  7. <view v-if="couponsList.length" class="list" :class="count<=1?'on':''">
  8. <view class="item acea-row row-between-wrapper" v-for="(item,index) in couponsList" :key="index" :class="{svip: item.receive_type === 4}">
  9. <view class="left" v-if="item.products.length>1 || item.products.length == 0">
  10. <view class="name line1" :class='item.is_use ? "moneyGray" : ""'>
  11. <text class="label" :class="item.is_use ? 'bg-color-huic' : ''" v-if="item.type === 0">通用券</text>
  12. <text class="label" :class="item.is_use ? 'bg-color-huic' : ''" v-else-if="item.type === 1">品类券</text>
  13. <text class="label" :class="item.is_use ? 'bg-color-huic' : ''" v-else>商品券</text>
  14. {{ item.title }}
  15. </view>
  16. <view class="pictrueList acea-row" v-if="item.products.length>1">
  17. <view class="itemn" v-for="(j,indexn) in item.products" :key="indexn" v-if="indexn<3" @click="goDetails(j)">
  18. <view class="pictrue">
  19. <!-- <image :src="j.image"></image> -->
  20. <lazyLoad :src="j.image" width="100%" height="100%"></lazyLoad>
  21. </view>
  22. <view class="money">¥{{j.price}}</view>
  23. </view>
  24. </view>
  25. <view v-else class="time" :class='item.is_use ? "moneyGray" : ""'>
  26. <view v-if="item.coupon_time">领取后{{item.coupon_time}}天内可用</view>
  27. <view v-else>{{ item.start_time ? item.start_time + '-' : '' }}{{ item.end_time }}</view>
  28. </view>
  29. </view>
  30. <view class="left acea-row row-middle" v-else @click="goDetails(item.products[0])">
  31. <view class="pictrues">
  32. <image :src="item.products[0].image"></image>
  33. </view>
  34. <view class="text">
  35. <view class="top">
  36. <view class="title">{{ item.title }}</view>
  37. <view class="acea-row">
  38. <view class="label" :class="item.is_use ? 'bg-color-huic' : ''" v-if="item.type === 0">通用券</view>
  39. <view class="label" :class="item.is_use ? 'bg-color-huic' : ''" v-else-if="item.type === 1">品类券</view>
  40. <view class="label" :class="item.is_use ? 'bg-color-huic' : ''" v-else>商品券</view>
  41. </view>
  42. </view>
  43. <view class="money">¥{{item.products[0].price}}</view>
  44. </view>
  45. </view>
  46. <view class="right" :class='item.is_use ? "moneyGray" : ""'>
  47. <view class="iconfont icon-yilingqu" v-if="item.is_use == true"></view>
  48. <view><text class="label" v-if="item.coupon_type==1">¥</text><text class="num">{{item.coupon_type==1?item.coupon_price:parseFloat(item.coupon_price)/10}}</text><text class="label" v-if="item.coupon_type!=1">折</text></view>
  49. <view v-if="item.use_min_price > 0">满{{item.use_min_price}}可用</view>
  50. <view v-else>无门槛券</view>
  51. <view class="bnt acea-row row-center-wrapper bg-color-huic" v-if="item.is_use == true">已领取</view>
  52. <view class="bnt acea-row row-center-wrapper bg-color-huic" v-else-if="item.is_use == 2">已领完</view>
  53. <view class="bnt acea-row row-center-wrapper" v-else @click="getCoupon(item.id, index)">立即领取</view>
  54. <view class="labelVip" v-if="item.receive_type === 4 && !item.is_use">
  55. <image src="../static/vipLable.png"></image>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <view class='loadingicon acea-row row-center-wrapper' v-if="couponsList.length">
  61. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  62. </view>
  63. <view class='noCommodity' v-else-if="!couponsList.length && page === 2">
  64. <view class='pictrue'>
  65. <image :src="imgHost + '/statics/images/noCoupon.png'"></image>
  66. </view>
  67. </view>
  68. <home v-if="navigation"></home>
  69. </view>
  70. </template>
  71. <script>
  72. import {
  73. getCoupons,
  74. setCouponReceive
  75. } from '@/api/api.js';
  76. import {
  77. toLogin
  78. } from '@/libs/login.js';
  79. import {
  80. mapGetters
  81. } from "vuex";
  82. import home from '@/components/home';
  83. import lazyLoad from '@/components/muqian-lazyLoad/muqian-lazyLoad.vue'
  84. import colors from '@/mixins/color.js';
  85. import {HTTP_REQUEST_URL} from '@/config/app';
  86. export default {
  87. components: {
  88. home,
  89. lazyLoad
  90. },
  91. mixins:[colors],
  92. data() {
  93. return {
  94. couponsList: [],
  95. loading: false,
  96. loadend: false,
  97. loadTitle: '加载更多', //提示语
  98. page: 1,
  99. limit: 20,
  100. isAuto: false, //没有授权的不会自动授权
  101. isShowAuth: false, //是否隐藏授权
  102. type: 0,
  103. navList: [{
  104. name: '通用券',
  105. count: 0
  106. },
  107. {
  108. name: '品类券',
  109. count: 0
  110. },
  111. {
  112. name: '商品券',
  113. count: 0
  114. },
  115. ],
  116. count: 0,
  117. imgHost:HTTP_REQUEST_URL
  118. };
  119. },
  120. computed: mapGetters(['isLogin']),
  121. watch: {
  122. isLogin: {
  123. handler: function(newV, oldV) {
  124. if (newV) {
  125. this.getUseCoupons();
  126. }
  127. },
  128. deep: true
  129. }
  130. },
  131. onLoad() {
  132. if (this.isLogin) {
  133. this.getUseCoupons();
  134. } else {
  135. toLogin();
  136. }
  137. },
  138. onShow() {
  139. uni.removeStorageSync('form_type_cart');
  140. },
  141. /**
  142. * 页面上拉触底事件的处理函数
  143. */
  144. onReachBottom: function() {
  145. this.getUseCoupons();
  146. },
  147. methods: {
  148. goDetails(item){
  149. uni.navigateTo({
  150. url: '/pages/goods_details/index?id=' + item.id
  151. })
  152. },
  153. // 授权关闭
  154. authColse: function(e) {
  155. this.isShowAuth = e;
  156. },
  157. getCoupon: function(id, index) {
  158. let that = this;
  159. let list = that.couponsList;
  160. //领取优惠券
  161. setCouponReceive(id).then(function(res) {
  162. list[index].is_use = true;
  163. that.$set(that, 'couponsList', list);
  164. that.$util.Tips({
  165. title: '领取成功'
  166. });
  167. }).catch(error => {
  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 = '加载更多';
  182. getCoupons({
  183. type: that.type,
  184. page: that.page,
  185. limit: that.limit
  186. }).then(res => {
  187. let list = res.data.list,
  188. loadend = list.length < that.limit;
  189. let couponsList = that.$util.SplitArray(list, that.couponsList);
  190. res.data.count.forEach((value, index) => {
  191. that.navList[index].count = value;
  192. if (value) {
  193. that.count++;
  194. }
  195. });
  196. that.$set(that, 'couponsList', couponsList);
  197. that.loadend = loadend;
  198. that.loading = false;
  199. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  200. that.page = that.page + 1;
  201. }).catch(err => {
  202. that.loading = false;
  203. that.loadTitle = '加载更多';
  204. });
  205. },
  206. setType: function(type) {
  207. if (this.type !== type) {
  208. this.type = type;
  209. this.couponsList = [];
  210. this.page = 1;
  211. this.loadend = false;
  212. this.getUseCoupons();
  213. }
  214. }
  215. }
  216. };
  217. </script>
  218. <style scoped lang="scss">
  219. .getCoupons{
  220. .bg-color-huic{
  221. color: #ccc!important;
  222. background: #F1F1F1!important;
  223. }
  224. .header{
  225. background-color: var(--view-theme);
  226. height: 200rpx;
  227. border-radius: 0 0 70rpx 70rpx;
  228. .item{
  229. width: 138rpx;
  230. height: 54rpx;
  231. border-radius: 28rpx;
  232. text-align: center;
  233. line-height: 54rpx;
  234. color: #fff;
  235. margin-top: 38rpx;
  236. &.on{
  237. background-color: #fff;
  238. color: var(--view-theme);
  239. }
  240. }
  241. }
  242. .list{
  243. margin-top: -70rpx;
  244. &.on{
  245. margin-top: 24rpx;
  246. .item{
  247. &::after{
  248. background-color: #F2F2F2!important;
  249. }
  250. }
  251. }
  252. .item{
  253. width: 690rpx;
  254. height: 240rpx;
  255. border-radius: 18rpx;
  256. background-color: #fff;
  257. margin: 0 auto 24rpx auto;
  258. padding: 22rpx 0 18rpx 28rpx;
  259. overflow: hidden;
  260. position: relative;
  261. &::after{
  262. content: ' ';
  263. width: 30rpx;
  264. height: 30rpx;
  265. border-radius: 50%;
  266. position: absolute;
  267. left:65.5%;
  268. top:-14rpx;
  269. background-color: #F2F2F2;
  270. }
  271. &::before{
  272. content: ' ';
  273. width: 30rpx;
  274. height: 30rpx;
  275. border-radius: 50%;
  276. position: absolute;
  277. left:65.5%;
  278. bottom:-14rpx;
  279. background-color: #F2F2F2;
  280. }
  281. &:first-child{
  282. &::after{
  283. background-color: var(--view-theme);
  284. }
  285. }
  286. .left{
  287. width: 440rpx;
  288. border-right: 1px dashed #eee;
  289. .time{
  290. color: #666666;
  291. font-size: 22rpx;
  292. margin-top: 90rpx;
  293. &.moneyGray{
  294. color: #ccc;
  295. }
  296. }
  297. .pictrues{
  298. width: 172rpx;
  299. height: 172rpx;
  300. border-radius: 12rpx;
  301. margin-right: 20rpx;
  302. image{
  303. width: 100%;
  304. height: 100%;
  305. border-radius: 12rpx;
  306. }
  307. }
  308. .text{
  309. width: 234rpx;
  310. .money{
  311. color: #999999;
  312. font-size: 20rpx;
  313. margin-top: 8rpx;
  314. }
  315. .top{
  316. height: 130rpx;
  317. .title{
  318. font-size: 26rpx;
  319. color: #333;
  320. }
  321. .label{
  322. background-color: var(--view-minorColorT);
  323. padding: 4rpx 12rpx;
  324. border-radius: 20rpx;
  325. color: var(--view-theme);
  326. font-size: 18rpx;
  327. margin-top: 8rpx;
  328. }
  329. }
  330. }
  331. .pictrueList{
  332. margin-top: 20rpx;
  333. .itemn{
  334. width: 120rpx;
  335. margin-right: 24rpx;
  336. .money{
  337. text-align: center;
  338. color: #999;
  339. font-size: 20rpx;
  340. margin-top: 8rpx;
  341. }
  342. .pictrue{
  343. width: 100%;
  344. height: 120rpx;
  345. border-radius: 8rpx;
  346. image{
  347. width: 100%;
  348. height: 100%;
  349. border-radius: 8rpx;
  350. }
  351. }
  352. }
  353. }
  354. .name{
  355. font-size: 24rpx;
  356. &.moneyGray{
  357. color: #ccc;
  358. }
  359. .label{
  360. background-color: var(--view-minorColorT);
  361. padding: 4rpx 12rpx;
  362. border-radius: 20rpx;
  363. color: var(--view-theme);
  364. font-size: 18rpx;
  365. margin-right: 8rpx;
  366. }
  367. }
  368. }
  369. .right{
  370. width: 212rpx;
  371. text-align: center;
  372. font-size: 24rpx;
  373. color: var(--view-theme);
  374. position: relative;
  375. .icon-yilingqu{
  376. position: absolute;
  377. right: -14rpx;
  378. top:-74rpx;
  379. font-size: 100rpx;
  380. z-index:0;
  381. }
  382. .labelVip{
  383. width: 128rpx;
  384. height: 82rpx;
  385. position: absolute;
  386. right: 10rpx;
  387. bottom: -40rpx;
  388. image{
  389. width: 100%;
  390. height: 100%;
  391. }
  392. }
  393. .label{
  394. font-size: 26rpx;
  395. font-weight: 600;
  396. }
  397. .num{
  398. font-size: 50rpx;
  399. font-weight: 600;
  400. }
  401. .bnt{
  402. width: 138rpx;
  403. height: 44rpx;
  404. background: linear-gradient(135deg, var(--view-minorColor) 0%, var(--view-theme) 100%);
  405. border-radius: 24rpx;
  406. color: #fff;
  407. font-size: 24rpx;
  408. margin: 16rpx auto 0 auto;
  409. position: relative;
  410. z-index:1;
  411. }
  412. &.moneyGray{
  413. color: #CCCCCC;
  414. }
  415. }
  416. &.svip{
  417. .right{
  418. color: #D98C2B;
  419. .bnt{
  420. background: linear-gradient(90deg, #F1BE52 0%, #E9A655 100%);
  421. }
  422. &.moneyGray{
  423. color: #CCCCCC;
  424. }
  425. }
  426. .name{
  427. .label{
  428. background-color: #FFEFCD;
  429. color: #D18E00;
  430. }
  431. }
  432. }
  433. }
  434. }
  435. }
  436. </style>