index.vue 11 KB

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