index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. this.getUseCoupons(1);
  132. }
  133. },
  134. deep: true
  135. }
  136. },
  137. onLoad() {
  138. if (this.isLogin) {
  139. this.getUseCoupons(1);
  140. } else {
  141. toLogin()
  142. }
  143. },
  144. onShow() {
  145. uni.removeStorageSync('form_type_cart');
  146. },
  147. /**
  148. * 页面上拉触底事件的处理函数
  149. */
  150. onReachBottom: function() {
  151. this.getUseCoupons();
  152. },
  153. methods: {
  154. goDetails(item){
  155. uni.navigateTo({
  156. url: '/pages/goods_details/index?id=' + item.id
  157. })
  158. },
  159. onLoadFun(){
  160. this.getUseCoupons();
  161. this.isShowAuth = false;
  162. },
  163. // 授权关闭
  164. authColse: function(e) {
  165. this.isShowAuth = e;
  166. },
  167. getCoupon: function(id, index) {
  168. let that = this;
  169. let list = that.couponsList;
  170. //领取优惠券
  171. setCouponReceive(id).then(function(res) {
  172. list[index].is_use = true;
  173. that.$set(that, 'couponsList', list);
  174. that.$util.Tips({
  175. title: '领取成功'
  176. });
  177. }).catch(error => {
  178. return that.$util.Tips({
  179. title: error
  180. });
  181. })
  182. },
  183. /**
  184. * 获取领取优惠券列表
  185. */
  186. getUseCoupons: function(num) {
  187. let that = this
  188. if (this.loadend) return false;
  189. if (this.loading) return false;
  190. that.loading = true;
  191. that.loadTitle = '加载更多';
  192. getCoupons({
  193. type: that.type,
  194. page: that.page,
  195. limit: that.limit
  196. }).then(res => {
  197. let list = res.data.list,
  198. loadend = list.length < that.limit,
  199. countIndex = [];
  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. countIndex.push(index);
  206. }
  207. });
  208. if(num){
  209. that.type = countIndex[0];
  210. }
  211. that.$set(that, 'couponsList', couponsList);
  212. that.loadend = loadend;
  213. that.loading = false;
  214. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  215. that.page = that.page + 1;
  216. }).catch(err => {
  217. that.loading = false;
  218. that.loadTitle = '加载更多';
  219. });
  220. },
  221. setType: function(type) {
  222. if (this.type !== type) {
  223. this.type = type;
  224. this.couponsList = [];
  225. this.page = 1;
  226. this.loadend = false;
  227. this.getUseCoupons();
  228. }
  229. }
  230. }
  231. };
  232. </script>
  233. <style scoped lang="scss">
  234. .getCoupons{
  235. .bg-color-huic{
  236. color: #ccc!important;
  237. background: #F1F1F1!important;
  238. }
  239. .header{
  240. background-color: var(--view-theme);
  241. height: 200rpx;
  242. border-radius: 0 0 70rpx 70rpx;
  243. .item{
  244. width: 138rpx;
  245. height: 54rpx;
  246. border-radius: 28rpx;
  247. text-align: center;
  248. line-height: 54rpx;
  249. color: #fff;
  250. margin-top: 38rpx;
  251. &.on{
  252. background-color: #fff;
  253. color: var(--view-theme);
  254. }
  255. }
  256. }
  257. .list{
  258. margin-top: -70rpx;
  259. &.on{
  260. margin-top: 24rpx;
  261. .item{
  262. &::after{
  263. background-color: #F2F2F2!important;
  264. }
  265. }
  266. }
  267. .item{
  268. width: 690rpx;
  269. height: 240rpx;
  270. border-radius: 18rpx;
  271. background-color: #fff;
  272. margin: 0 auto 24rpx auto;
  273. padding: 22rpx 0 18rpx 28rpx;
  274. overflow: hidden;
  275. position: relative;
  276. &::after{
  277. content: ' ';
  278. width: 30rpx;
  279. height: 30rpx;
  280. border-radius: 50%;
  281. position: absolute;
  282. left:65.5%;
  283. top:-14rpx;
  284. background-color: #F2F2F2;
  285. }
  286. &::before{
  287. content: ' ';
  288. width: 30rpx;
  289. height: 30rpx;
  290. border-radius: 50%;
  291. position: absolute;
  292. left:65.5%;
  293. bottom:-14rpx;
  294. background-color: #F2F2F2;
  295. }
  296. &:first-child{
  297. &::after{
  298. background-color: var(--view-theme);
  299. }
  300. }
  301. .left{
  302. width: 440rpx;
  303. border-right: 1px dashed #eee;
  304. .time{
  305. color: #666666;
  306. font-size: 22rpx;
  307. margin-top: 90rpx;
  308. &.moneyGray{
  309. color: #ccc;
  310. }
  311. }
  312. .pictrues{
  313. width: 172rpx;
  314. height: 172rpx;
  315. border-radius: 12rpx;
  316. margin-right: 20rpx;
  317. image{
  318. width: 100%;
  319. height: 100%;
  320. border-radius: 12rpx;
  321. }
  322. }
  323. .text{
  324. width: 234rpx;
  325. .money{
  326. color: #999999;
  327. font-size: 20rpx;
  328. margin-top: 8rpx;
  329. }
  330. .top{
  331. height: 130rpx;
  332. .title{
  333. font-size: 26rpx;
  334. color: #333;
  335. }
  336. .label{
  337. background-color: var(--view-minorColorT);
  338. padding: 4rpx 12rpx;
  339. border-radius: 20rpx;
  340. color: var(--view-theme);
  341. font-size: 18rpx;
  342. margin-top: 8rpx;
  343. }
  344. }
  345. }
  346. .pictrueList{
  347. margin-top: 20rpx;
  348. .itemn{
  349. width: 120rpx;
  350. margin-right: 24rpx;
  351. .money{
  352. text-align: center;
  353. color: #999;
  354. font-size: 20rpx;
  355. margin-top: 8rpx;
  356. }
  357. .pictrue{
  358. width: 100%;
  359. height: 120rpx;
  360. border-radius: 8rpx;
  361. image{
  362. width: 100%;
  363. height: 100%;
  364. border-radius: 8rpx;
  365. }
  366. }
  367. }
  368. }
  369. .name{
  370. font-size: 24rpx;
  371. &.moneyGray{
  372. color: #ccc;
  373. }
  374. .label{
  375. background-color: var(--view-minorColorT);
  376. padding: 4rpx 12rpx;
  377. border-radius: 20rpx;
  378. color: var(--view-theme);
  379. font-size: 18rpx;
  380. margin-right: 8rpx;
  381. }
  382. }
  383. }
  384. .right{
  385. width: 212rpx;
  386. text-align: center;
  387. font-size: 24rpx;
  388. color: var(--view-theme);
  389. position: relative;
  390. .icon-yilingqu{
  391. position: absolute;
  392. right: -14rpx;
  393. top:-74rpx;
  394. font-size: 100rpx;
  395. z-index:0;
  396. }
  397. .labelVip{
  398. width: 128rpx;
  399. height: 82rpx;
  400. position: absolute;
  401. right: 10rpx;
  402. bottom: -40rpx;
  403. image{
  404. width: 100%;
  405. height: 100%;
  406. }
  407. }
  408. .label{
  409. font-size: 26rpx;
  410. font-weight: 600;
  411. }
  412. .num{
  413. font-size: 50rpx;
  414. font-weight: 600;
  415. }
  416. .bnt{
  417. width: 138rpx;
  418. height: 44rpx;
  419. background: linear-gradient(135deg, var(--view-minorColor) 0%, var(--view-theme) 100%);
  420. border-radius: 24rpx;
  421. color: #fff;
  422. font-size: 24rpx;
  423. margin: 16rpx auto 0 auto;
  424. position: relative;
  425. z-index:1;
  426. }
  427. &.moneyGray{
  428. color: #CCCCCC;
  429. }
  430. }
  431. &.svip{
  432. .right{
  433. color: #D98C2B;
  434. .bnt{
  435. background: linear-gradient(90deg, #F1BE52 0%, #E9A655 100%);
  436. }
  437. &.moneyGray{
  438. color: #CCCCCC;
  439. }
  440. }
  441. .name{
  442. .label{
  443. background-color: #FFEFCD;
  444. color: #D18E00;
  445. }
  446. }
  447. }
  448. }
  449. }
  450. }
  451. </style>