index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view>
  3. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="选择优惠券" ></u-navbar>
  4. <view class="coupon-title">可用优惠券:{{listNum}}</view>
  5. <view class="coupon-list">
  6. <u-radio-group v-model="radiovalue1" placement="column">
  7. <view class="flex coupon-list-item" v-for="(item,index) in list" :key="index">
  8. <view class="flex coupon-list-item-info">
  9. <view class="money">
  10. <view class="">¥<text>{{item.discount}}</text></view>
  11. </view>
  12. <view class="flex content">
  13. <view class="txt title">{{item.title}}</view>
  14. <view class="txt">
  15. 使用期限:{{ $parseTime(item.validStart, '{y}.{m}.{d}')}}-{{$parseTime(item.validEnd, '{y}.{m}.{d}')}}
  16. </view>
  17. <view class="txt">适用范围:{{item.useAreaDesc || '-'}}</view>
  18. </view>
  19. </view>
  20. <u-radio :customStyle="{marginBottom: '8px'}" :name="index"> </u-radio>
  21. </view>
  22. </u-radio-group>
  23. </view>
  24. <view class="flex empty" v-if="!list.length">
  25. <u-empty text="数据为空" mode="order" />
  26. </view>
  27. <view class="footer-fixed">
  28. <view class="flex btn">
  29. <button type="default" @click="exchange">确认</button>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import env from '../../config/env.js'
  36. import $http from '@/utils/request.js'
  37. export default {
  38. data() {
  39. return {
  40. checked: false,
  41. actionIndex: 0,
  42. pageNum: 1,
  43. total: 0,
  44. list: [],
  45. listNum: '',//可用优惠券数量
  46. radiovalue1: 0, //被选中的下标
  47. };
  48. },
  49. onShow() {
  50. this.getList()
  51. },
  52. methods: {
  53. getList() {
  54. uni.showLoading({
  55. title: '加载中'
  56. });
  57. $http.post('/api/v1/mp/user/ticket/order/coupon/list', {}).then(
  58. res => {
  59. uni.hideLoading();
  60. console.log(res)
  61. if (res.code == 0) {
  62. this.listNum = res.data.length
  63. res.data.forEach(item => {
  64. let useAreaDesc = JSON.parse(item.useArea)
  65. item.useAreaDesc = useAreaDesc.desc
  66. })
  67. this.list = this.list.concat(res.data)
  68. console.log(this.list)
  69. }
  70. }).catch(() => {
  71. uni.hideLoading();
  72. })
  73. },
  74. // 点击确认事件
  75. exchange() {
  76. for (var i = 0; i < this.list.length; i++) {
  77. if(i == this.radiovalue1){
  78. console.log(this.list[i])
  79. uni.navigateBack({data:this.list[i]})
  80. }
  81. }
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="scss" scoped>
  87. .coupon {
  88. &-title {
  89. position: fixed;
  90. width: 100%;
  91. padding: 24rpx 32rpx;
  92. background-color: #FFFFFF;
  93. }
  94. &-list {
  95. margin-top: 100rpx;
  96. padding: 0 20rpx 100rpx;
  97. &-item {
  98. justify-content: space-between;
  99. padding: 20rpx;
  100. background-color: #FFFFFF;
  101. margin-bottom: 20rpx;
  102. &-info {
  103. flex: 1;
  104. justify-content: flex-start;
  105. height: 170rpx;
  106. image {
  107. width: 84rpx;
  108. height: 132rpx;
  109. margin-right: 20rpx;
  110. }
  111. .content {
  112. height: 132rpx;
  113. flex-direction: column;
  114. align-items: flex-start;
  115. justify-content: space-between;
  116. }
  117. .content .title {
  118. font-size: 32rpx;
  119. line-height: 50rpx;
  120. }
  121. .money {
  122. padding-right: 30rpx;
  123. font-weight: bold;
  124. text {
  125. font-size: 50rpx;
  126. }
  127. }
  128. }
  129. .circle {
  130. width: 40rpx;
  131. height: 40rpx;
  132. border-radius: 50%;
  133. border: 1px solid;
  134. }
  135. .action {
  136. width: 30rpx;
  137. height: 30rpx;
  138. border-radius: 50%;
  139. background-color: $uni-bg-color;
  140. }
  141. }
  142. }
  143. }
  144. .empty {
  145. height: 60vh;
  146. }
  147. .footer-fixed {
  148. position: fixed;
  149. bottom: var(--window-bottom);
  150. left: 0;
  151. right: 0;
  152. z-index: 11;
  153. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  154. background: #fff;
  155. // 设置ios刘海屏底部横线安全区域
  156. padding-bottom: constant(safe-area-inset-bottom);
  157. padding-bottom: env(safe-area-inset-bottom);
  158. .btn {
  159. padding: 20rpx 0;
  160. /deep/ button {
  161. width: 640rpx;
  162. height: 90rpx;
  163. line-height: 90rpx;
  164. font-size: 36rpx;
  165. color: #fff;
  166. background-color: $uni-bg-color;
  167. border: none;
  168. border-radius: 20rpx;
  169. }
  170. }
  171. }
  172. </style>