coupon.vue 17 KB

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