coupon.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. <template>
  2. <!-- 优惠券 -->
  3. <view :style="[couponWrapStyle]" v-show="!isSortType">
  4. <view class="coupon-wrap" :style="[couponWrapBgColor]" v-if="couponList.length">
  5. <view v-if="dataConfig.styleConfig.tabVal == 0" class="coupon1 p-24">
  6. <scroll-view scroll-x="true">
  7. <view class="list acea-row">
  8. <view v-for="item in couponList" :key="item.id" class="item" :style="[couponItemFirstStyle]">
  9. <view class="text">
  10. <view class="money" :style="[couponMoneyColor]">
  11. <template>
  12. {{ $t(`¥`) }}<text class="number">{{ item.coupon_price }}</text>
  13. </template>
  14. </view>
  15. <view class="info">
  16. <text v-if="item.use_min_price">{{ $t(`满`) }}{{ item.use_min_price }}{{ $t(`可用`) }}</text>
  17. <text v-else>{{ $t(`无门槛券`) }}</text>
  18. </view>
  19. </view>
  20. <view v-if="item.is_use >= item.receive_limit" class="button" :style="[bntBgColor]">{{ $t(`已领取`) }}</view>
  21. <view v-else class="button" :style="[bntBgColor]" @click="receiveCoupon(item)">{{ $t(`去领取`) }}</view>
  22. </view>
  23. </view>
  24. </scroll-view>
  25. </view>
  26. <view v-else-if="dataConfig.styleConfig.tabVal == 1" class="coupon2 p-24">
  27. <scroll-view scroll-x="true">
  28. <view class="list acea-row">
  29. <view v-for="item in couponList" :key="item.id" class="item">
  30. <view class="name">{{ item.type | typeFilter}}</view>
  31. <view class="text" :style="[couponMoneyColor]">
  32. <view class="money">
  33. <template>
  34. {{ $t(`¥`) }}<text class="number">{{ item.coupon_price }}</text>
  35. </template>
  36. </view>
  37. <view class="info">
  38. <text v-if="item.use_min_price">{{ $t(`满`) }}{{ item.use_min_price }}{{ $t(`可用`) }}</text>
  39. <text v-else>{{ $t(`无门槛券`) }}</text>
  40. </view>
  41. </view>
  42. <view v-if="item.is_use >= item.receive_limit" class="button" :style="[bntBgColor]">{{ $t(`已领取`) }}</view>
  43. <view v-else class="button" :style="[bntBgColor]" @click="receiveCoupon(item)">{{ $t(`去领取`) }}</view>
  44. </view>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. <view v-else-if="dataConfig.styleConfig.tabVal == 2" class="coupon3 p-24 rd-16rpx" :style="[coupon3Color]">
  49. <scroll-view scroll-x="true">
  50. <view class="list acea-row">
  51. <view v-for="item in couponList" :key="item.id" class="item">
  52. <view class="inner acea-row">
  53. <view class="text acea-row row-column row-middle row-center">
  54. <view class="money">
  55. <template>
  56. {{ $t(`¥`) }}<text class="number">{{ item.coupon_price }}</text>
  57. </template>
  58. </view>
  59. <view class="info">
  60. <text v-if="item.use_min_price">{{ $t(`满`) }}{{ item.use_min_price }}{{ $t(`可用`) }}</text>
  61. <text v-else>{{ $t(`无门槛券`) }}</text>
  62. </view>
  63. </view>
  64. <view v-if="item.is_use >= item.receive_limit" class="button acea-row row-middle">{{ $t(`已领取`) }}</view>
  65. <view v-else class="button acea-row row-middle" @click="receiveCoupon(item)">{{ $t(`立即领取`) }}</view>
  66. </view>
  67. </view>
  68. </view>
  69. </scroll-view>
  70. </view>
  71. <view v-else-if="dataConfig.styleConfig.tabVal == 3" class="coupon4" :style="[coupon4Color]">
  72. <view class="content">
  73. <scroll-view scroll-x="true">
  74. <view class="list acea-row">
  75. <view v-for="item in couponList" :key="item.id" :style="[couponItemStyle]" class="item">
  76. <view class="name" :style="typeStyle">
  77. <view class="inner">{{ item.type | typeFilter }}</view>
  78. </view>
  79. <view class="text">
  80. <view class="money" :style="[couponMoneyColor]">
  81. <template>
  82. {{ $t(`¥`) }}<text class="number">{{ item.coupon_price }}</text>
  83. </template>
  84. </view>
  85. <view class="info">
  86. <text v-if="item.use_min_price">{{ $t(`满`) }}{{ item.use_min_price }}{{ $t(`可用`) }}</text>
  87. <text v-else>{{ $t(`无门槛券`) }}</text>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </scroll-view>
  93. <view class="station acea-row row-column row-middle row-center" :style="[bntBgColor]">
  94. <view class="station-name">{{ $t(`先领券 再购物`) }}</view>
  95. <view class="station-info">{{ $t(`领券下单·享购物优惠`) }}</view>
  96. <view class="button" @click="goCoupon">{{ $t(`立即领取`) }}</view>
  97. </view>
  98. </view>
  99. </view>
  100. <view v-else-if="dataConfig.styleConfig.tabVal == 4" class="coupon5 pt-24 pb-24 pr-20 pl-20 rd-16rpx">
  101. <scroll-view scroll-x="true">
  102. <view class="list acea-row">
  103. <view v-for="item in couponList" :key="item.id" class="item acea-row" :style="[bntBgColor]">
  104. <view class="text acea-row row-column row-middle row-center">
  105. <view class="money" :style="[couponMoneyColor]">
  106. <template>
  107. {{ $t(`¥`) }}<text class="number">{{ item.coupon_price }}</text>
  108. </template>
  109. </view>
  110. <view class="info" :style="[couponMoneyColor]">
  111. <text v-if="item.use_min_price">{{ $t(`满`) }}{{ item.use_min_price }}{{ $t(`可用`) }}</text>
  112. <text v-else>{{ $t(`无门槛券`) }}</text>
  113. </view>
  114. </view>
  115. <view v-if="item.is_use >= item.receive_limit" class="button acea-row row-middle">{{ $t(`已领取`) }}</view>
  116. <view v-else class="button acea-row row-middle" @click="receiveCoupon(item)">{{ $t(`领取`) }}</view>
  117. </view>
  118. </view>
  119. </scroll-view>
  120. </view>
  121. </view>
  122. </view>
  123. </template>
  124. <script>
  125. import {
  126. getCoupons,
  127. setCouponReceive
  128. } from '@/api/api.js';
  129. import {
  130. mapGetters
  131. } from "vuex";
  132. export default {
  133. props: {
  134. dataConfig: {
  135. type: Object,
  136. default: () => {}
  137. },
  138. isSortType: {
  139. type: String | Number,
  140. default: 0
  141. }
  142. },
  143. watch: {
  144. isLogin: {
  145. handler: function(newV, oldV) {
  146. if (newV) {
  147. this.getCoupon();
  148. }
  149. },
  150. deep: true
  151. }
  152. },
  153. filters:{
  154. typeFilter(val){
  155. let obj = {
  156. 0: '通用券',
  157. 1: '品类券',
  158. 2: '商品券',
  159. 3: '品牌券',
  160. };
  161. return obj[val]
  162. }
  163. },
  164. data() {
  165. return {
  166. isAuto: false, //没有授权的不会自动授权
  167. isShowAuth: false, //是否隐藏授权
  168. couponList: [],
  169. };
  170. },
  171. computed: {
  172. ...mapGetters(['isLogin']),
  173. couponMoneyColor() {
  174. let styleObject = {};
  175. if (this.dataConfig.toneConfig.tabVal) {
  176. styleObject['color'] = this.dataConfig.couponMoneyColor.color[0].item;
  177. }
  178. return styleObject;
  179. },
  180. couponItemFirstStyle(){
  181. if (this.dataConfig.toneConfig.tabVal) {
  182. return {
  183. background: this.dataConfig.couponBgColor.color[0].item
  184. }
  185. }else{
  186. return {
  187. background: 'var(--view-theme)'
  188. }
  189. }
  190. },
  191. couponItemStyle() {
  192. return {
  193. 'margin-right': `${this.dataConfig.spacingConfig.val * 2}rpx`,
  194. }
  195. },
  196. typeStyle(){
  197. if (!this.dataConfig.toneConfig.tabVal) {
  198. return {
  199. background: 'var(--view-theme)',
  200. color: 'var(--view-theme)'
  201. }
  202. }else{
  203. return {
  204. background: this.dataConfig.couponMoneyColor.color[0].item,
  205. color: this.dataConfig.couponMoneyColor.color[0].item
  206. }
  207. }
  208. },
  209. bntBgColor() {
  210. let styleObject = {};
  211. if (this.dataConfig.toneConfig.tabVal) {
  212. styleObject['background'] = `linear-gradient(180deg, ${this.dataConfig.bntBgColor.color[0].item} 0%, ${this.dataConfig.bntBgColor.color[1].item} 100%)`;
  213. }
  214. return styleObject;
  215. },
  216. coupon3Color() {
  217. let styleObject = {
  218. '--coupon3-color': 'var(--view-theme)',
  219. };
  220. if (this.dataConfig.toneConfig.tabVal) {
  221. styleObject['--coupon3-color'] = this.dataConfig.couponMoneyColor.color[0].item;
  222. }
  223. return styleObject;
  224. },
  225. coupon4Color() {
  226. let styleObject = {
  227. '--coupon4-color': 'var(--view-theme)',
  228. };
  229. if (this.dataConfig.toneConfig.tabVal) {
  230. styleObject['--coupon4-color'] = this.dataConfig.couponBgColor.color[0].item;
  231. }
  232. return styleObject;
  233. },
  234. couponWrapBgColor() {
  235. let styleObject = {
  236. '--module-color': this.dataConfig.moduleColor2.color[0].item,
  237. };
  238. if (this.dataConfig.styleConfig.tabVal == 1) {
  239. styleObject['--module-color'] = `linear-gradient(90deg,${this.dataConfig.moduleColor.color[0].item} 0%,${this.dataConfig.moduleColor.color[1].item} 100%)`;
  240. }
  241. // if (this.dataConfig.styleConfig.tabVal == 3) {
  242. let borderRadius = `${this.dataConfig.fillet.val * 2}rpx`;
  243. if (this.dataConfig.fillet.type) {
  244. borderRadius =
  245. `${this.dataConfig.fillet.valList[0].val * 2}rpx ${this.dataConfig.fillet.valList[1].val * 2}rpx ${this.dataConfig.fillet.valList[3].val * 2}rpx ${this.dataConfig.fillet.valList[2].val * 2}rpx`;
  246. }
  247. styleObject['border-radius'] = borderRadius;
  248. // }
  249. return styleObject;
  250. },
  251. couponWrapStyle() {
  252. return {
  253. 'padding': `${this.dataConfig.topConfig.val * 2}rpx ${this.dataConfig.prConfig.val * 2}rpx ${this.dataConfig.bottomConfig.val * 2}rpx`,
  254. 'margin-top': `${this.dataConfig.mbConfig.val * 2}rpx`,
  255. 'background': this.dataConfig.bottomBgColor.color[0].item,
  256. };
  257. },
  258. },
  259. mounted() {
  260. this.getCoupon();
  261. },
  262. methods: {
  263. getCoupon: function() {
  264. let that = this;
  265. let limit = that.$config.LIMIT;
  266. getCoupons({
  267. page: 1,
  268. limit: this.dataConfig.numberConfig.val >= limit ? limit : this.dataConfig.numberConfig.val,
  269. type: -1,
  270. }).then(res => {
  271. that.$set(that, 'couponList', res.data.list);
  272. }).catch(err => {
  273. return that.$util.Tips({
  274. title: err
  275. });
  276. });
  277. },
  278. receiveCoupon: function(item) {
  279. let that = this;
  280. if (!that.isLogin) {
  281. this.$emit('changeLogin');
  282. } else {
  283. setCouponReceive(item.id)
  284. .then(function() {
  285. item.is_use = true;
  286. that.$set(that, 'couponList', that.couponList);
  287. that.$util.Tips({
  288. title: "领取成功"
  289. });
  290. })
  291. .catch(function(err) {
  292. that.$util.Tips({
  293. title: err
  294. });
  295. });
  296. }
  297. },
  298. goCoupon() {
  299. uni.navigateTo({
  300. url: '/pages/users/user_get_coupon/index'
  301. })
  302. },
  303. }
  304. }
  305. </script>
  306. <style lang="scss">
  307. .coupon-wrap {
  308. background: var(--module-color);
  309. }
  310. .coupon1 {
  311. .list {
  312. flex-wrap: nowrap;
  313. }
  314. .item {
  315. flex-shrink: 0;
  316. position: relative;
  317. width: 156rpx;
  318. height: 156rpx;
  319. border-radius: 32rpx;
  320. margin-top: 20rpx;
  321. margin-right: 12rpx;
  322. background: var(--view-theme);
  323. .text {
  324. width: 144rpx;
  325. height: 156rpx;
  326. padding-top: 22rpx;
  327. border: 2rpx solid #FCEAE9;
  328. border-radius: 16rpx;
  329. margin: -20rpx auto 0;
  330. background: #FFFFFF;
  331. }
  332. .money {
  333. height: 40rpx;
  334. text-align: center;
  335. font-weight: 500;
  336. font-size: 28rpx;
  337. color: var(--view-theme);
  338. }
  339. .number {
  340. font-family: SemiBold;
  341. font-size: 40rpx;
  342. line-height: 40rpx;
  343. }
  344. .info {
  345. margin-top: 10rpx;
  346. text-align: center;
  347. font-size: 18rpx;
  348. line-height: 26rpx;
  349. color: #999999;
  350. }
  351. .button {
  352. position: absolute;
  353. right: 0;
  354. bottom: 0;
  355. left: 0;
  356. height: 76rpx;
  357. padding-top: 28rpx;
  358. border-radius: 0 0 32rpx 32rpx;
  359. background: linear-gradient(90deg, var(--view-theme) 0%, var(--view-gradient) 100%);
  360. text-align: center;
  361. font-weight: 500;
  362. font-size: 24rpx;
  363. color: #FFFFFF;
  364. &::before {
  365. content: "";
  366. position: absolute;
  367. top: 0;
  368. left: 0;
  369. width: 156rpx;
  370. height: 20rpx;
  371. border: 8rpx solid #FCEAE9;
  372. border-top-color: #FFFFFF;
  373. border-bottom-right-radius: 78rpx 20rpx;
  374. border-bottom-left-radius: 78rpx 20rpx;
  375. box-sizing: border-box;
  376. background: #FFFFFF;
  377. }
  378. }
  379. }
  380. }
  381. .coupon2 {
  382. .list {
  383. flex-wrap: nowrap;
  384. }
  385. .item {
  386. flex-shrink: 0;
  387. width: 204rpx;
  388. height: 232rpx;
  389. padding-top: 28rpx;
  390. border-radius: 16rpx;
  391. margin-top: 0;
  392. margin-right: 12rpx;
  393. background: #FFFFFF;
  394. }
  395. .name {
  396. text-align: center;
  397. font-weight: 500;
  398. font-size: 24rpx;
  399. line-height: 34rpx;
  400. color: #333333;
  401. }
  402. .text {
  403. margin-top: 8rpx;
  404. text-align: center;
  405. color: var(--view-theme);
  406. }
  407. .money {
  408. height: 48rpx;
  409. font-weight: 500;
  410. font-size: 28rpx;
  411. }
  412. .number {
  413. font-family: SemiBold;
  414. font-size: 44rpx;
  415. }
  416. .info {
  417. font-size: 18rpx;
  418. line-height: 26rpx;
  419. }
  420. .button {
  421. width: 136rpx;
  422. height: 48rpx;
  423. border-radius: 24rpx;
  424. margin: 12rpx auto 0;
  425. background: linear-gradient(90deg, var(--view-theme) 0%, var(--view-gradient) 100%);
  426. text-align: center;
  427. font-weight: 500;
  428. font-size: 24rpx;
  429. line-height: 48rpx;
  430. color: #FFFFFF;
  431. }
  432. }
  433. .coupon3 {
  434. .list {
  435. flex-wrap: nowrap;
  436. }
  437. .item {
  438. flex-shrink: 0;
  439. width: 274rpx;
  440. height: 150rpx;
  441. border: 1rpx solid var(--coupon3-color);
  442. border-radius: 16rpx;
  443. margin-top: 0;
  444. margin-right: 12rpx;
  445. background: var(--coupon3-color);
  446. }
  447. .inner {
  448. height: 100%;
  449. border-radius: 15rpx;
  450. background: rgba(255, 255, 255, 0.9);
  451. }
  452. .text {
  453. flex: 1;
  454. position: relative;
  455. &::before {
  456. content: "";
  457. position: absolute;
  458. top: 0;
  459. right: 0;
  460. z-index: 2;
  461. width: 16rpx;
  462. height: 16rpx;
  463. border: 1rpx solid var(--coupon3-color);
  464. border-radius: 50%;
  465. background: var(--module-color);
  466. transform: translate(50%, -50%);
  467. }
  468. &::after {
  469. content: "";
  470. position: absolute;
  471. bottom: 0;
  472. right: 0;
  473. z-index: 2;
  474. width: 16rpx;
  475. height: 16rpx;
  476. border: 1rpx solid var(--coupon3-color);
  477. border-radius: 50%;
  478. background: var(--module-color);
  479. transform: translate(50%, 50%);
  480. }
  481. }
  482. .money {
  483. height: 48rpx;
  484. text-align: center;
  485. font-weight: 500;
  486. font-size: 28rpx;
  487. color: var(--coupon3-color);
  488. }
  489. .number {
  490. font-family: SemiBold;
  491. font-size: 44rpx;
  492. }
  493. .info {
  494. margin-top: 8rpx;
  495. text-align: center;
  496. font-size: 24rpx;
  497. line-height: 34rpx;
  498. color: var(--coupon3-color);
  499. }
  500. .button {
  501. position: relative;
  502. width: 74rpx;
  503. padding: 0 24rpx;
  504. font-size: 26rpx;
  505. line-height: 28rpx;
  506. color: var(--coupon3-color);
  507. &::before {
  508. content: "";
  509. position: absolute;
  510. top: 12rpx;
  511. bottom: 12rpx;
  512. left: 0;
  513. border-left: 1rpx dashed var(--coupon3-color);
  514. }
  515. }
  516. }
  517. .coupon5 {
  518. .list {
  519. flex-wrap: nowrap;
  520. }
  521. .item {
  522. flex-shrink: 0;
  523. width: 228rpx;
  524. height: 108rpx;
  525. border-radius: 12rpx;
  526. margin-right: 12rpx;
  527. background: linear-gradient(0deg, var(--view-theme) 0%, var(--view-gradient) 100%);
  528. }
  529. .text {
  530. flex: 1;
  531. border-radius: 12rpx;
  532. background: radial-gradient(circle at left 54rpx, var(--module-color) 11rpx, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.8) 100%) top;
  533. }
  534. .money {
  535. height: 48rpx;
  536. font-weight: 500;
  537. font-size: 28rpx;
  538. color: var(--view-theme);
  539. }
  540. .number {
  541. font-family: SemiBold;
  542. font-size: 44rpx;
  543. }
  544. .info {
  545. font-size: 22rpx;
  546. line-height: 30rpx;
  547. color: var(--view-theme);
  548. }
  549. .button {
  550. width: 56rpx;
  551. padding: 0 16rpx;
  552. font-size: 24rpx;
  553. line-height: 28rpx;
  554. color: #FFFFFF;
  555. }
  556. }
  557. .coupon4 {
  558. padding: 24rpx 20rpx;
  559. border-radius: 16rpx;
  560. .content {
  561. position: relative;
  562. padding: 20rpx 296rpx 20rpx 20rpx;
  563. border-radius: 24rpx;
  564. background: var(--coupon4-color);
  565. }
  566. .list {
  567. flex-wrap: nowrap;
  568. }
  569. .item {
  570. flex-shrink: 0;
  571. width: 140rpx;
  572. height: 132rpx;
  573. border-radius: 12rpx;
  574. margin-right: 12rpx;
  575. background: #FFFFFF;
  576. }
  577. .name {
  578. width: 108rpx;
  579. height: 38rpx;
  580. line-height: 38rpx;
  581. border-radius: 0 0 19rpx 19rpx;
  582. margin: 0 auto;
  583. background: var(--coupon4-color);
  584. text-align: center;
  585. font-size: 22rpx;
  586. color: var(--coupon4-color);
  587. }
  588. .inner {
  589. width: 100%;
  590. height: 100%;
  591. border-radius: 0 0 19rpx 19rpx;
  592. background: rgba(255, 255, 255, 0.9);
  593. }
  594. .money {
  595. height: 46rpx;
  596. margin-top: 10rpx;
  597. text-align: center;
  598. font-weight: 500;
  599. font-size: 28rpx;
  600. color: var(--coupon4-color);
  601. }
  602. .number {
  603. font-family: SemiBold;
  604. font-size: 40rpx;
  605. }
  606. .info {
  607. margin-top: 4rpx;
  608. text-align: center;
  609. font-size: 18rpx;
  610. line-height: 26rpx;
  611. color: #333333;
  612. }
  613. .station {
  614. position: absolute;
  615. top: 0;
  616. right: 0;
  617. bottom: 0;
  618. width: 296rpx;
  619. // padding-left: 12rpx;
  620. border-radius: 0 24rpx 24rpx 0;
  621. // background: radial-gradient(circle at -180rpx 86rpx, transparent 200rpx, var(--coupon4-color) 0%, var(--coupon4-color) 100%);
  622. background: linear-gradient(0deg, var(--view-theme) 0%, var(--view-gradient) 100%);
  623. // filter: drop-shadow(-16rpx 0rpx 10rpx rgba(0, 0, 0, 0.10));
  624. }
  625. .station-name {
  626. font-weight: 500;
  627. font-size: 32rpx;
  628. line-height: 44rpx;
  629. color: #FFFFFF;
  630. }
  631. .station-info {
  632. margin-top: 4rpx;
  633. font-size: 20rpx;
  634. line-height: 28rpx;
  635. color: #F5F5F5;
  636. }
  637. .button {
  638. width: 160rpx;
  639. height: 48rpx;
  640. border-radius: 24rpx;
  641. margin-top: 8rpx;
  642. background: rgba(255, 255, 255, 0.9);
  643. text-align: center;
  644. font-weight: 500;
  645. font-size: 24rpx;
  646. line-height: 48rpx;
  647. color: var(--coupon4-color);
  648. }
  649. }
  650. </style>