index.vue 12 KB

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