金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

278 lines
6.2 KiB

  1. <template>
  2. <view>
  3. <lf-nav :showIcon="true" :spreadOut="false" bgColor="transparent"></lf-nav>
  4. <view class="head">
  5. <image class="img" mode="aspectFill" src="https://picsum.photos/seed/picsum/200/300"></image>
  6. <view class="suspension" hover-class="lf-opacity" @click="$url('/pages/coupon/index/index')">我的优惠券</view>
  7. </view>
  8. <view class="coupon-wrap">
  9. <view class="coupon-box" v-for="(item,index) of coupon_list" :key="index">
  10. <view class="coupon-card lf-m-b-30" :class="item.ifpast?'lf-bg-999':''">
  11. <view class="coupon-circle-top">
  12. <view class="coupon-circle1"></view>
  13. </view>
  14. <view class="coupon-circle-bottom">
  15. <view class="coupon-circle1"></view>
  16. </view>
  17. <view class="coupon-radius">
  18. <view class="coupon-left">
  19. <view class="lf-color-white" v-if="item.action_type.type == 'cash'">
  20. <text class="lf-font-24"></text>
  21. <text class="lf-font-70 lf-color-white lf-font-bold">{{item.action_type.value}}</text>
  22. </view>
  23. </view>
  24. <view class="coupon-right">
  25. <view class="lf-font-32 lf-font-bold lf-color-white">{{item.title}}</view>
  26. <view class="lf-font-24 lf-color-white">有效期{{item.starts_at}}~{{item.ends_at}}</view>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="coupon-receive" :class="item.ifpast?'lf-bg-999':''" @click="receive(item.code)">立即领取</view>
  31. <block v-if="item.ifpast">
  32. <view class="coupon-opacity"></view>
  33. <view class="coupon-end" :class="item.ifpast?'lf-bg-999':''">
  34. <view>抢光了</view>
  35. </view>
  36. </block>
  37. </view>
  38. </view>
  39. <u-back-top :scrollTop="pageScrollTop"></u-back-top>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. data(){
  45. return {
  46. coupon_list: []
  47. }
  48. },
  49. onLoad(){
  50. this.getCouponsList();
  51. },
  52. onPullDownRefresh() {
  53. this.getCouponsList();
  54. },
  55. methods: {
  56. receive(code){
  57. this.$http.post({
  58. api: 'api/coupon/convert',
  59. data: {
  60. coupon_code: code
  61. },
  62. header: {
  63. Authorization: this.$cookieStorage.get('user_token')
  64. }
  65. }).then(res => {
  66. if(res.data.code == 200) {
  67. this.$msg('领取成功');
  68. this.getCouponsList();
  69. }else {
  70. this.$msg(JSON.stringify(res.data.message));
  71. }
  72. }).catch(err => {
  73. console.log("====", err);
  74. })
  75. },
  76. compareDate(val) {
  77. var nowTime = new Date(new Date().toLocaleDateString()).getTime();
  78. let oldTime = new Date(new Date(val).toLocaleDateString()).getTime();
  79. if(nowTime>oldTime) {
  80. return true;
  81. }else {
  82. return false;
  83. }
  84. },
  85. //获取优惠券列表
  86. getCouponsList() {
  87. this.$http.get({
  88. api: 'api/coupons/list',
  89. header: {
  90. Authorization: this.$cookieStorage.get('user_token')
  91. }
  92. }).then(res => {
  93. this.coupon_list = res.data.data;
  94. this.coupon_list.forEach((item,index) => {
  95. if(this.compareDate(item.ends_at)) {
  96. this.$set(item,'ifpast',true);
  97. }else {
  98. this.$set(item,'ifpast',false);
  99. }
  100. })
  101. uni.stopPullDownRefresh();
  102. }).catch(err => {
  103. console.log("====", err);
  104. })
  105. }
  106. }
  107. }
  108. </script>
  109. <style lang="scss" scoped="scoped">
  110. .lf-bg-999 {
  111. background-color: #999!important;
  112. }
  113. .head{
  114. height: 376rpx;
  115. width: 750rpx;
  116. position: relative;
  117. .img{
  118. width: 100%;
  119. height: 100%;
  120. }
  121. .suspension{
  122. position: absolute;
  123. bottom: 30rpx;
  124. right: 0;
  125. width: 165rpx;
  126. height: 54rpx;
  127. background: #15716E;
  128. border-radius: 100rpx 0rpx 0rpx 100rpx;
  129. border: 2rpx solid #FFFFFF;
  130. font-size: 24rpx;
  131. color: #FFFFFF;
  132. display: flex;
  133. justify-content: center;
  134. align-items: center;
  135. }
  136. }
  137. .coupon-wrap {
  138. display: flex;
  139. justify-content: center;
  140. margin-top: 30rpx;
  141. flex-direction: column;
  142. align-content: center;
  143. align-items: center;
  144. }
  145. .coupon-box{
  146. display: flex;
  147. align-items: center;
  148. position: relative;
  149. }
  150. .coupon-card {
  151. overflow: hidden;
  152. position: relative;
  153. display: flex;
  154. align-items: center;
  155. justify-content: center;
  156. width: 637rpx;
  157. // display: flex;
  158. height: 171rpx;
  159. // opacity: 0.59;
  160. // border: 1rpx solid #FFFFFF;
  161. background: #15716E;
  162. border-radius: 20rpx;
  163. z-index: 3;
  164. }
  165. .coupon-radius {
  166. width: 627rpx;
  167. display: flex;
  168. height: 161rpx;
  169. border: 1rpx dashed #ccc;
  170. // background: #15716E;
  171. border-radius: 20rpx;
  172. }
  173. .coupon-circle1 {
  174. width: 40rpx;
  175. height: 40rpx;
  176. background-color: white;
  177. border-radius: 50%;
  178. }
  179. .coupon-circle-top {
  180. width: 50rpx;
  181. height: 50rpx;
  182. border-radius: 50%;
  183. // background-color: red;
  184. position: absolute;
  185. border: 1px dashed #ccc;
  186. left: 190rpx;
  187. top: -20rpx;
  188. display: flex;
  189. align-items: center;
  190. text-align: center;
  191. justify-content: center;
  192. }
  193. .coupon-circle-bottom {
  194. width: 50rpx;
  195. height: 50rpx;
  196. border-radius: 50%;
  197. // background-color: red;
  198. position: absolute;
  199. border: 1px dashed #ccc;
  200. left: 190rpx;
  201. bottom: -20rpx;
  202. display: flex;
  203. align-items: center;
  204. text-align: center;
  205. justify-content: center;
  206. }
  207. .coupon-right {
  208. text-align: left;
  209. justify-content: center;
  210. align-items: flex-start;
  211. display: flex;
  212. flex-direction: column;
  213. margin-left: 84rpx;
  214. }
  215. .coupon-left {
  216. margin-left: 40rpx;
  217. display: flex;
  218. flex-direction: column;
  219. justify-content: center;
  220. align-items: center;
  221. }
  222. .coupon-receive{
  223. width: 45rpx;
  224. height: 126rpx;
  225. font-size: 24rpx;
  226. background: #22A19F;
  227. border-radius: 6rpx;
  228. line-height: 1.2;
  229. color: #FFFFFF;
  230. text-align: center;
  231. display: flex;
  232. justify-content: center;
  233. align-items: center;
  234. transform: translate(-16rpx, -9rpx) rotate(10deg);
  235. transform-origin: bottom;
  236. position: relative;
  237. z-index: 1;
  238. }
  239. .coupon-opacity{
  240. width: 102%;
  241. height: 100%;
  242. position: absolute;
  243. left: 0;
  244. right: 0;
  245. top: 0;
  246. bottom: 0;
  247. background-color: rgba(255,255,255,0.5);
  248. z-index: 5;
  249. }
  250. .coupon-end{
  251. position: absolute;
  252. z-index: 7;
  253. width: 136rpx;
  254. height: 136rpx;
  255. background-color: #15716E;
  256. border-radius: 50%;
  257. top: calc(50% - 81rpx);
  258. left: calc(50% - 68rpx);
  259. display: flex;
  260. justify-content: center;
  261. align-items: center;
  262. &>view{
  263. width: 126rpx;
  264. height: 126rpx;
  265. border: 2rpx dashed #FFFFFF;
  266. border-radius: 50%;
  267. font-size: 32rpx;
  268. color: #FFFFFF;
  269. display: flex;
  270. justify-content: center;
  271. align-items: center;
  272. transform: rotate(-38deg);
  273. }
  274. }
  275. </style>