index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <template>
  2. <!-- 我的有优惠券模块 -->
  3. <view :style="colorStyle">
  4. <view class="header">
  5. <view class="navbar acea-row">
  6. <view class="item acea-row row-center-wrapper" :class="{ on: navOn === 0 }" @click="onNav(0)">
  7. <view>待使用({{ not_used }}张)</view>
  8. </view>
  9. <view class="item acea-row row-center-wrapper" :class="{ on: navOn === 1 }" @click="onNav(1)">
  10. <view>已使用({{ used }}张)</view>
  11. </view>
  12. <view class="item acea-row row-center-wrapper" :class="{ on: navOn === 2 }" @click="onNav(2)">
  13. <view>已失效({{ expired }}张)</view>
  14. </view>
  15. </view>
  16. <view class="subnavbar acea-row">
  17. <view class="shade">
  18. <image v-if="shadeLeft" src="../static/shade.png" class="img1"></image>
  19. </view>
  20. <scroll-view scroll-x="true" class="scroll-view acea-row row-middle" @scrolltolower="scrolltolower" @scrolltoupper="scrolltoupper" @scroll="scroll">
  21. <view class="acea-row row-middle" style="flex-wrap: nowrap;">
  22. <view class="item" :class="{ on: type === '' }" @click="onSubNav('')">
  23. <view class="inner">全部</view>
  24. </view>
  25. <view v-if="navOn == 0" class="item" :class="{ on: type == -1 }" @click="onSubNav(-1)">
  26. <view class="inner">快过期</view>
  27. </view>
  28. <view class="item" :class="{ on: type === 0 }" @click="onSubNav(0)">
  29. <view class="inner">通用券</view>
  30. </view>
  31. <view class="item" :class="{ on: type == 1 }" @click="onSubNav(1)">
  32. <view class="inner">品类券</view>
  33. </view>
  34. <view class="item" :class="{ on: type == 2 }" @click="onSubNav(2)">
  35. <view class="inner">商品券</view>
  36. </view>
  37. <view class="item" :class="{ on: type == 3 }" @click="onSubNav(3)">
  38. <view class="inner">品牌券</view>
  39. </view>
  40. </view>
  41. </scroll-view>
  42. <view class="shade">
  43. <image v-if="shadeRight" src="../static/shade.png" class="img"></image>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="header-shadow"></view>
  48. <view class='coupon-list'>
  49. <view class="item" :class="{ gray: navOn }" v-for='(item,index) in couponsList' :key="index">
  50. <view class="item-box acea-row" :class="{svip: item.receive_type === 4}">
  51. <view class="moneyCon acea-row row-center-wrapper">
  52. <view class='money'>
  53. <BaseMoney v-if="item.coupon_type==1" :money="item.coupon_price" symbolSize="28" integerSize="52" isCoupon
  54. :color="item.is_use ? '#cccccc' : item.receive_type === 4 ? '#FACC7D' : '#ffffff'"></BaseMoney>
  55. <view v-else-if="item.coupon_type==2" class="SemiBold">{{ parseFloat(item.coupon_price)/10 }}<text class="fs-28 pingfang pl-4">折</text></view>
  56. <view class="pic-num" v-if="item.use_min_price > 0">满{{item.use_min_price}}可用</view>
  57. <view class="pic-num" v-else>无门槛券</view>
  58. </view>
  59. </view>
  60. <view class="text acea-row row-column row-center">
  61. <view class='condition'>
  62. <view class="name line1">
  63. {{ item.coupon_title }}
  64. </view>
  65. </view>
  66. <view class='data acea-row row-between-wrapper'>
  67. <view>{{item.add_time}}-{{item.end_time}}</view>
  68. </view>
  69. <view class="text-bottom acea-row row-middle">
  70. <view v-if="item.applicable_type === 0">通用优惠券</view>
  71. <view v-else-if="item.applicable_type === 1">品类优惠券</view>
  72. <view v-else-if="item.applicable_type === 3">品牌优惠券</view>
  73. <view v-else>商品优惠券</view>
  74. <view v-show="item.rule">丨</view>
  75. <view class="" v-show="item.rule" @click="openRule(index)">查看用券规则<text class="iconfont icon-ic_downarrow"></text></view>
  76. </view>
  77. </view>
  78. <view class="btn-box acea-row row-middle">
  79. <view class="btn disabled" v-if="navOn == 1">已使用</view>
  80. <view class="btn disabled" v-else-if="navOn == 2">已失效</view>
  81. <view class="btn" v-else @click="useCoupon(item)">去使用</view>
  82. </view>
  83. </view>
  84. <view class="rule-desc" v-if="item.ruleShow">
  85. <view v-for="(ruleItem, idx) in item.rules" :key="idx">{{ ruleItem }}</view>
  86. </view>
  87. </view>
  88. </view>
  89. <view class='px-20' v-if="!couponsList.length && !loading">
  90. <emptyPage title="暂无优惠券,去看点别的吧~" src="/statics/images/noCoupon.gif"></emptyPage>
  91. </view>
  92. </view>
  93. </template>
  94. <script>
  95. import {
  96. getCouponsNum,
  97. getUserCoupons
  98. } from '@/api/api.js';
  99. import {
  100. toLogin
  101. } from '@/libs/login.js';
  102. import {
  103. mapGetters
  104. } from "vuex";
  105. import colors from '@/mixins/color.js';
  106. import emptyPage from '@/components/emptyPage.vue';
  107. import {
  108. HTTP_REQUEST_URL
  109. } from '@/config/app';
  110. export default {
  111. components: {
  112. emptyPage
  113. },
  114. mixins: [colors],
  115. data() {
  116. return {
  117. couponsList: [],
  118. loading: false,
  119. isAuto: false, //没有授权的不会自动授权
  120. isShowAuth: false, //是否隐藏授权
  121. navOn: 0,
  122. type: '',
  123. page: 1,
  124. limit: 15,
  125. finished: false,
  126. imgHost: HTTP_REQUEST_URL,
  127. expired: 0,
  128. not_used: 0,
  129. used: 0,
  130. shadeRight: true,
  131. shadeLeft: true
  132. };
  133. },
  134. computed: mapGetters(['isLogin']),
  135. watch: {
  136. isLogin: {
  137. handler: function(newV, oldV) {
  138. if (newV) {
  139. // #ifdef H5 || APP-PLUS
  140. this.getUseCoupons();
  141. // #endif
  142. }
  143. },
  144. deep: true
  145. }
  146. },
  147. onLoad() {
  148. if (this.isLogin) {
  149. this.getCouponsNum();
  150. this.getUseCoupons();
  151. } else {
  152. toLogin()
  153. }
  154. },
  155. onShow() {
  156. uni.removeStorageSync('form_type_cart');
  157. },
  158. onReachBottom() {
  159. this.getUseCoupons();
  160. },
  161. methods: {
  162. getCouponsNum() {
  163. getCouponsNum().then(res => {
  164. this.used = res.data.used;
  165. this.not_used = res.data.not_used;
  166. this.expired = res.data.expired;
  167. });
  168. },
  169. onNav: function(type) {
  170. this.navOn = type;
  171. this.onSubNav('')
  172. },
  173. onSubNav(type) {
  174. this.type = type;
  175. this.couponsList = [];
  176. this.page = 1;
  177. this.finished = false;
  178. this.getUseCoupons();
  179. },
  180. useCoupon(item) {
  181. let url = '';
  182. // 通用券
  183. if (item.category_id == 0 && item.product_id == '' && item.brand_id == 0) {
  184. url = '/pages/goods/goods_list/index?title=默认'
  185. }
  186. // 品类券
  187. if (item.category_id != 0) {
  188. if (item.category_type == 1) {
  189. url = '/pages/goods/goods_list/index?cid=' + item.category_id + '&title=' + item.category_name
  190. } else {
  191. url = '/pages/goods/goods_list/index?sid=' + item.category_id + '&title=' + item.category_name
  192. }
  193. }
  194. //商品券
  195. if (item.product_id != '') {
  196. let arr = item.product_id.split(',');
  197. let num = arr.length;
  198. if (num == 1) {
  199. url = '/pages/goods_details/index?id=' + item.product_id
  200. } else {
  201. url = '/pages/goods/goods_list/index?productId=' + item.product_id + '&title=默认'
  202. }
  203. }
  204. //品牌券
  205. if (item.brand_id != 0) {
  206. url = '/pages/goods/goods_list/index?brandId=' + item.brand_id + '&title=默认'
  207. }
  208. uni.navigateTo({
  209. url: url
  210. });
  211. },
  212. /**
  213. * 授权回调
  214. */
  215. onLoadFun: function() {
  216. this.getUseCoupons();
  217. this.isShowAuth = false;
  218. },
  219. // 授权关闭
  220. authColse: function(e) {
  221. this.isShowAuth = e
  222. },
  223. /**
  224. * 获取领取优惠券列表
  225. */
  226. getUseCoupons: function() {
  227. let that = this;
  228. if (that.loading || that.finished) {
  229. return;
  230. }
  231. that.loading = true;
  232. uni.showLoading({
  233. title: '正在加载…'
  234. });
  235. getUserCoupons(this.navOn, {
  236. type: this.type,
  237. page: this.page,
  238. limit: this.limit
  239. }).then(res => {
  240. that.loading = false;
  241. uni.hideLoading();
  242. res.data.forEach(item => {
  243. item.ruleShow = false;
  244. item.rules = item.rule ? item.rule.split('\n') : [];
  245. });
  246. that.couponsList = that.couponsList.concat(res.data);
  247. that.finished = res.data.length < that.limit;
  248. that.page += 1;
  249. }).catch(err => {
  250. that.loading = false;
  251. uni.showToast({
  252. title: err,
  253. icon: 'none'
  254. });
  255. });
  256. },
  257. openRule(index) {
  258. this.couponsList[index].ruleShow = !this.couponsList[index].ruleShow
  259. },
  260. scrolltolower() {
  261. this.$nextTick(() => {
  262. this.shadeRight = false
  263. })
  264. },
  265. scrolltoupper() {
  266. this.$nextTick(() => {
  267. this.shadeLeft = false
  268. })
  269. },
  270. scroll(event) {
  271. this.$nextTick(() => {
  272. this.shadeRight = true
  273. this.shadeLeft = true
  274. })
  275. }
  276. }
  277. }
  278. </script>
  279. <style lang="scss" scoped>
  280. .money {
  281. display: flex;
  282. flex-direction: column;
  283. justify-content: center;
  284. }
  285. .pic-num {
  286. color: #ffffff;
  287. font-size: 24rpx;
  288. }
  289. .coupon-list .item .text .condition {
  290. display: flex;
  291. align-items: center;
  292. }
  293. .coupon-list .item .text .condition .name {
  294. font-size: 28rpx;
  295. line-height: 40rpx;
  296. font-weight: 500;
  297. width: 310rpx;
  298. }
  299. .coupon-list .item .text .condition .pic {
  300. width: 30rpx;
  301. height: 30rpx;
  302. display: block;
  303. margin-right: 10rpx;
  304. display: inline-block;
  305. vertical-align: sub;
  306. }
  307. .condition .line-title {
  308. /* width: 70rpx; */
  309. padding: 0 12rpx;
  310. height: 32rpx !important;
  311. /* #ifndef APP */
  312. line-height: 28rpx;
  313. /* #endif */
  314. /* #ifdef APP */
  315. line-height: 30rpx;
  316. /* #endif */
  317. text-align: center;
  318. box-sizing: border-box;
  319. background: var(--view-minorColorT);
  320. border: 1px solid var(--view-theme);
  321. opacity: 1;
  322. border-radius: 20rpx;
  323. font-size: 18rpx !important;
  324. color: var(--view-theme);
  325. margin-right: 12rpx;
  326. text-align: center;
  327. display: inline-block;
  328. vertical-align: middle;
  329. }
  330. .condition .title {
  331. vertical-align: middle;
  332. }
  333. .condition .line-title.bg-color-huic {
  334. border-color: #BBB !important;
  335. color: #bbb !important;
  336. background-color: #F5F5F5 !important;
  337. }
  338. .header-shadow {
  339. height: 194rpx;
  340. }
  341. .header {
  342. position: fixed;
  343. top: 0;
  344. left: 0;
  345. width: 100%;
  346. background-color: #FFFFFF;
  347. z-index: 9;
  348. }
  349. .subnavbar {
  350. height: 92rpx;
  351. .scroll-view {
  352. flex: 1;
  353. min-width: 0;
  354. white-space: nowrap;
  355. }
  356. .shade {
  357. position: relative;
  358. width: 40rpx;
  359. .img {
  360. position: absolute;
  361. top: 0;
  362. left: 0;
  363. width: 18rpx;
  364. height: 100%;
  365. transform: translateX(-50%);
  366. }
  367. .img1 {
  368. position: absolute;
  369. top: 0;
  370. right: 0;
  371. width: 18rpx;
  372. height: 100%;
  373. transform: translateX(50%);
  374. }
  375. }
  376. .item {
  377. flex-shrink: 0;
  378. width: 120rpx;
  379. height: 52rpx;
  380. border-radius: 26rpx;
  381. margin-left: 22rpx;
  382. background: #F5F5F5;
  383. text-align: center;
  384. font-size: 22rpx;
  385. line-height: 52rpx;
  386. color: #666666;
  387. &:first-child {
  388. margin-left: 0;
  389. }
  390. .inner {
  391. height: 52rpx;
  392. border: 1rpx solid transparent;
  393. border-radius: 26rpx;
  394. background: rgba(255, 255, 255, 0);
  395. background-clip: content-box;
  396. transform: rotateZ(360deg);
  397. }
  398. &.on {
  399. background: var(--view-theme);
  400. color: var(--view-theme);
  401. .inner {
  402. background-color: rgba(255, 255, 255, 0.9);
  403. }
  404. }
  405. }
  406. }
  407. .navbar {
  408. height: 82rpx;
  409. .item {
  410. flex: 1;
  411. position: relative;
  412. font-size: 26rpx;
  413. color: #666666;
  414. .number {
  415. height: 34rpx;
  416. padding: 0 16rpx;
  417. border-radius: 17rpx;
  418. margin-top: 8rpx;
  419. background-color: transparent;
  420. font-size: 24rpx;
  421. line-height: 34rpx;
  422. color: #666666;
  423. }
  424. &.on {
  425. font-weight: 500;
  426. font-size: 28rpx;
  427. color: var(--view-theme);
  428. .number {
  429. background-color: var(--view-theme);
  430. color: #FFFFFF;
  431. }
  432. }
  433. }
  434. }
  435. .coupon-list {
  436. padding: 0 20rpx;
  437. margin-top: 0;
  438. .item {
  439. height: auto;
  440. background: none;
  441. }
  442. .item-box {
  443. height: 170rpx;
  444. border-radius: 24rpx;
  445. background: #FFFFFF;
  446. }
  447. .moneyCon {
  448. border-radius: 24rpx 0 0 24rpx;
  449. background: linear-gradient(270deg, var(--view-gradient) 0%, var(--view-theme) 100%);
  450. color: #FFFFFF;
  451. }
  452. .money {
  453. position: relative;
  454. background-image: radial-gradient(circle at left, #F5F5F5 16rpx, transparent 0);
  455. color: #FFFFFF;
  456. font-size: 52rpx;
  457. font-family: Regular;
  458. &::after {
  459. content: "";
  460. position: absolute;
  461. top: 0;
  462. bottom: 0;
  463. right: 0;
  464. width: 6rpx;
  465. background-image: radial-gradient(circle at 6rpx, #FFFFFF 6rpx, transparent 6rpx);
  466. background-size: 6rpx 18rpx;
  467. }
  468. }
  469. .pic-num {
  470. margin-top: 8rpx;
  471. font-weight: 400;
  472. font-size: 22rpx;
  473. line-height: 28rpx;
  474. }
  475. .text-bottom {
  476. margin-top: 20rpx;
  477. font-size: 20rpx;
  478. line-height: 28rpx;
  479. color: #999999;
  480. .iconfont {
  481. margin-left: 6rpx;
  482. font-size: 20rpx;
  483. }
  484. }
  485. .btn-box {
  486. padding: 0 20rpx;
  487. }
  488. .btn {
  489. height: 52rpx;
  490. padding: 0 24rpx;
  491. border-radius: 26rpx;
  492. background-color: var(--view-minorColorT);
  493. font-weight: 500;
  494. font-size: 22rpx;
  495. line-height: 52rpx;
  496. color: var(--view-theme);
  497. }
  498. .disabled {
  499. background-color: #ccc;
  500. color: #fff;
  501. }
  502. .rule-desc {
  503. padding: 42rpx 24rpx 24rpx;
  504. border-radius: 0 0 24rpx 24rpx;
  505. background: linear-gradient(180deg, #F7F7F7 0%, #FFFFFF 100%);
  506. font-size: 20rpx;
  507. line-height: 28rpx;
  508. color: #999999;
  509. }
  510. .gray {
  511. .moneyCon {
  512. background: #CCCCCC;
  513. }
  514. .item-right {
  515. background-color: #CCCCCC;
  516. color: #FFFFFF;
  517. }
  518. }
  519. }
  520. .svip .btn {
  521. background: linear-gradient(90deg, #584834 0%, #32302D 100%);
  522. color: #FACC7D;
  523. }
  524. .svip .moneyCon {
  525. background: linear-gradient(90deg, #584834 0%, #32302D 100%);
  526. color: #FACC7D;
  527. }
  528. .svip .pic-num {
  529. color: #FACC7D;
  530. }
  531. </style>