金诚优选前端代码
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.

284 lines
6.5 KiB

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