ToB企服应用市场:ToB评测及商务社交产业平台

标题: uniapp移动端优惠券! 附源码!!!! [打印本页]

作者: 涛声依旧在    时间: 2024-10-19 09:33
标题: uniapp移动端优惠券! 附源码!!!!
本文为常见的移动端uniapp优惠券,共有6种优惠券样式(参考了常见的优惠券),文本内容仅为示例,您可在此基础上调解为你想要的文本
  预览效果


   通过模拟数据,实现点击利用优惠券让其变为灰色的效果(模拟已利用效果)
  我用的是uniapp来写的

源码直接到uniapp项目中直接运行就可以

  1. <template>
  2.         <view class="content">
  3.                 <view class="yhq1" :class="item.isUse ? 'use' : ''" v-for="(item, index) in yhqList1" :key="index"
  4.                         @click="click(item)">
  5.                         <view class="left">
  6.                                 ¥{{ item.price }}
  7.                         </view>
  8.                         <view class="right">
  9.                                 <view class="tit">
  10.                                         {{ item.title }}
  11.                                 </view>
  12.                                 <view class="desc">
  13.                                         <view class="p">
  14.                                                 {{ item.time }}
  15.                                         </view>
  16.                                 </view>
  17.                         </view>
  18.                 </view>
  19.                 <view class="yhq2" :class="item.isUse ? 'use' : ''" v-for="(item, index) in yhqList2" :key="index"
  20.                         @click="click(item)">
  21.                         <view class="left">
  22.                                 ¥{{ item.price }}
  23.                         </view>
  24.                         <view class="right">
  25.                                 <view class="tit">
  26.                                         {{ item.title }}
  27.                                 </view>
  28.                                 <view class="desc">
  29.                                         <view class="p">
  30.                                                 {{ item.time }}
  31.                                         </view>
  32.                                 </view>
  33.                         </view>
  34.                 </view>
  35.                 <view class="yhq3" :class="item.isUse ? 'use' : ''" v-for="(item, index) in yhqList3" :key="index"
  36.                         @click="click(item)">
  37.                         <view class="left">
  38.                                 ¥{{ item.price }}
  39.                         </view>
  40.                         <view class="right">
  41.                                 <view class="tit">
  42.                                         {{ item.title }}
  43.                                 </view>
  44.                                 <view class="desc">
  45.                                         <view class="p">
  46.                                                 {{ item.time }}
  47.                                         </view>
  48.                                 </view>
  49.                         </view>
  50.                 </view>
  51.                 <view class="yhq4" :class="item.isUse ? 'use' : ''" v-for="(item, index) in yhqList4" :key="index"
  52.                         @click="click(item)">
  53.                         <view class="left">
  54.                                 ¥{{ item.price }}
  55.                         </view>
  56.                         <view class="right">
  57.                                 <view class="tit">
  58.                                         {{ item.title }}
  59.                                 </view>
  60.                                 <view class="desc">
  61.                                         <view class="p">
  62.                                                 {{ item.time }}
  63.                                         </view>
  64.                                 </view>
  65.                         </view>
  66.                 </view>
  67.                 <view class="yhq5" :class="item.isUse ? 'use' : ''" v-for="(item, index) in yhqList5" :key="index"
  68.                         @click="click(item)">
  69.                         <view class="left">
  70.                                 ¥{{ item.price }}
  71.                         </view>
  72.                         <view class="right">
  73.                                 <view class="tit">
  74.                                         {{ item.title }}
  75.                                 </view>
  76.                                 <view class="desc">
  77.                                         <view class="p">
  78.                                                 {{ item.time }}
  79.                                         </view>
  80.                                 </view>
  81.                         </view>
  82.                 </view>
  83.                 <view class="yhq6" :class="item.isUse ? 'use' : ''" v-for="(item, index) in yhqList6" :key="index"
  84.                         @click="click(item)">
  85.                         <view class="left">
  86.                                 ¥{{ item.price }}
  87.                         </view>
  88.                         <view class="right">
  89.                                 <view class="tit">
  90.                                         {{ item.title }}
  91.                                 </view>
  92.                                 <view class="desc">
  93.                                         <view class="p">
  94.                                                 {{ item.time }}
  95.                                         </view>
  96.                                 </view>
  97.                         </view>
  98.                 </view>
  99.         </view>
  100. </template>
  101. <script>
  102. export default {
  103.         data() {
  104.                 return {
  105.                         isUse: false, // 是否已使用
  106.                         yhqList1: [{
  107.                                 isUse: false,
  108.                                 title: '某某商品优惠券11',
  109.                                 price: '100',
  110.                                 time: '有效期至: 2025年10月1日'
  111.                         },
  112.                         {
  113.                                 isUse: false,
  114.                                 title: '某某商品优惠券12',
  115.                                 price: '100',
  116.                                 time: '有效期至: 2025年10月1日'
  117.                         },
  118.                         ],
  119.                         yhqList2: [{
  120.                                 isUse: false,
  121.                                 title: '某某商品优惠券21',
  122.                                 price: '100',
  123.                                 time: '有效期至: 2025年10月1日'
  124.                         },
  125.                         {
  126.                                 isUse: false,
  127.                                 title: '某某商品优惠券22',
  128.                                 price: '100',
  129.                                 time: '有效期至: 2025年10月1日'
  130.                         },
  131.                         ],
  132.                         yhqList3: [{
  133.                                 isUse: false,
  134.                                 title: '某某商品优惠券31',
  135.                                 price: '100',
  136.                                 time: '有效期至: 2025年10月1日'
  137.                         },
  138.                         {
  139.                                 isUse: false,
  140.                                 title: '某某商品优惠券32',
  141.                                 price: '100',
  142.                                 time: '有效期至: 2025年10月1日'
  143.                         },
  144.                         ],
  145.                         yhqList4: [{
  146.                                 isUse: false,
  147.                                 title: '某某商品优惠券41',
  148.                                 price: '100',
  149.                                 time: '有效期至: 2025年10月1日'
  150.                         },
  151.                         {
  152.                                 isUse: false,
  153.                                 title: '某某商品优惠券42',
  154.                                 price: '100',
  155.                                 time: '有效期至: 2025年10月1日'
  156.                         },
  157.                         ],
  158.                         yhqList5: [{
  159.                                 isUse: false,
  160.                                 title: '某某商品优惠券51',
  161.                                 price: '100',
  162.                                 time: '有效期至: 2025年10月1日'
  163.                         },
  164.                         {
  165.                                 isUse: false,
  166.                                 title: '某某商品优惠券52',
  167.                                 price: '100',
  168.                                 time: '有效期至: 2025年10月1日'
  169.                         },
  170.                         ],
  171.                         yhqList6: [{
  172.                                 isUse: false,
  173.                                 title: '某某商品优惠券61',
  174.                                 price: '100',
  175.                                 time: '有效期至: 2025年10月1日'
  176.                         },
  177.                         {
  178.                                 isUse: false,
  179.                                 title: '某某商品优惠券62',
  180.                                 price: '100',
  181.                                 time: '有效期至: 2025年10月1日'
  182.                         },
  183.                         ],
  184.                 }
  185.         },
  186.         methods: {
  187.                 click(item) {
  188.                         console.log(item);
  189.                         uni.showToast({
  190.                                 title: "使用优惠券",
  191.                                 icon: "none"
  192.                         })
  193.                         item.isUse = true
  194.                 }
  195.         }
  196. }
  197. </script>
  198. <style>
  199. .content {
  200.         padding: 20rpx;
  201. }
  202. .yhq1 {
  203.         width: 100%;
  204.         height: 100px;
  205.         margin-top: 15px;
  206.         background-image: linear-gradient(-225deg, #9EFBD3 0%, #57E9F2 48%, #45D4FB 100%);
  207.         -webkit-mask: radial-gradient(circle at 20px 20px, #ff0000 20px, blue 0);
  208.         -webkit-mask-position: -20px -20px;
  209.         display: flex;
  210.         justify-content: space-around;
  211.         align-items: center;
  212.         padding: 20rpx 30rpx 20rpx 50rpx;
  213.         box-sizing: border-box;
  214. }
  215. .use {
  216.         filter: grayscale(1);
  217.         /*  
  218. 是CSS3中的一个滤镜功能,用于将元素的内容(如图像、文本或背景)转换为灰度图像。grayscale() 函数接受一个介于0%到100%之间的参数,该参数定义了图像从原始彩色转换为灰度的程度。
  219. 当参数为0% 时,图像保持原有的彩色状态,不进行任何灰度转换。
  220. 当参数为100% 时,图像完全转换为灰度,所有颜色信息都被去除。
  221. 在中间值(如50%)时,图像会是部分彩色和部分灰度的混合。
  222. 这里的 1 相当于100%,表示最大的灰度转换程度。
  223. */
  224. }
  225. .left {
  226.         width: 20%;
  227.         font-size: 50rpx;
  228.         font-weight: 700;
  229.         color: #fff;
  230. }
  231. .right .tit {
  232.         font-size: 33rpx;
  233.         color: #fff;
  234.         font-weight: 600;
  235. }
  236. .right .desc .p {
  237.         font-size: 28rpx;
  238.         color: #d8d8d8;
  239.         margin-top: 10rpx;
  240. }
  241. .yhq2 {
  242.         width: 100%;
  243.         height: 100px;
  244.         margin-top: 15px;
  245.         background-image: linear-gradient(-225deg, #FFE29F 0%, #FFA99F 48%, #FF719A 100%);
  246.         -webkit-mask: radial-gradient(circle at 20px, #0000 16px, blue 0);
  247.         display: flex;
  248.         justify-content: space-around;
  249.         align-items: center;
  250.         padding: 20rpx 30rpx 20rpx 50rpx;
  251.         box-sizing: border-box;
  252. }
  253. .yhq3 {
  254.         width: 100%;
  255.         height: 100px;
  256.         margin-top: 15px;
  257.         background-image: linear-gradient(to right, #fddb92 0%, #d1fdff 100%);
  258.         -webkit-mask: radial-gradient(circle at 0, #0000 20px, blue 0),
  259.                 radial-gradient(circle at right, #0000 20px, blue 0);
  260.         -webkit-mask-size: 51%;
  261.         -webkit-mask-position: 0, 100%;
  262.         -webkit-mask-repeat: no-repeat;
  263.         display: flex;
  264.         justify-content: space-around;
  265.         align-items: center;
  266.         padding: 20rpx 30rpx 20rpx 50rpx;
  267.         box-sizing: border-box;
  268. }
  269. .yhq3 .left {
  270.         width: 35%;
  271.         height: 100%;
  272.         display: flex;
  273.         align-items: center;
  274.         border-right: 1px dashed #fff;
  275. }
  276. .yhq3 .right {
  277.         width: 55%;
  278.         text-align: center;
  279. }
  280. .yhq4 {
  281.         width: 100%;
  282.         height: 100px;
  283.         margin-top: 15px;
  284. background-image: linear-gradient(to right, #eea2a2 0%, #bbc1bf 19%, #57c6e1 42%, #b49fda 79%, #7ac5d8 100%);
  285.         -webkit-mask: radial-gradient(circle at 10px, #0000 10px, blue 0);
  286.         -webkit-mask-position: -10px;
  287.         -webkit-mask-size: 100% 30px;
  288.         display: flex;
  289.         justify-content: space-around;
  290.         align-items: center;
  291.         padding: 20rpx 30rpx 20rpx 50rpx;
  292.         box-sizing: border-box;
  293. }
  294. .yhq5 {
  295.         width: 100%;
  296.         height: 100px;
  297.         margin-top: 15px;
  298. background-image: linear-gradient(to top, #fbc2eb 0%, #a6c1ee 100%);
  299.         -webkit-mask: radial-gradient(circle at 20px 20px, #0000 20px, blue 0);
  300.         -webkit-mask-position: -20px -20px;
  301.         -webkit-mask-size: 50%;
  302.         display: flex;
  303.         justify-content: space-around;
  304.         align-items: center;
  305.         padding: 20rpx 30rpx 20rpx 50rpx;
  306.         box-sizing: border-box;
  307. }
  308. .yhq5 .left {
  309.         width: 35%;
  310.         height: 100%;
  311.         display: flex;
  312.         align-items: center;
  313.         border-right: 1px dashed #fff;
  314. }
  315. .yhq5 .right {
  316.         width: 55%;
  317.         text-align: center;
  318. }
  319. .yhq6 {
  320.         width: 100%;
  321.         height: 100px;
  322.         margin-top: 15px;
  323.      background-image: linear-gradient(to right, #ff9569 0%, #e92758 100%);
  324.         -webkit-mask: radial-gradient(circle at left center, transparent 20px, blue 20px);
  325.         display: flex;
  326.         justify-content: space-around;
  327.         align-items: center;
  328.         padding: 20rpx 30rpx 20rpx 50rpx;
  329.         box-sizing: border-box;
  330. }
  331. </style>
复制代码
欢迎进群讨论前端内容 谢谢大家


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4