index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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" @change="changeChechk()">
  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 / 100 }}</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="item.id" activeColor="#E96737" size="24">
  21. </u-radio>
  22. </view>
  23. </u-radio-group>
  24. </view>
  25. <view class="flex empty" v-if="!list.length">
  26. <u-empty text="数据为空" mode="order" />
  27. </view>
  28. <view class="footer-fixed">
  29. <view class="flex btn">
  30. <button type="default" @click="exchange">确认</button>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import env from '../../config/env.js'
  37. import $http from '@/utils/request.js'
  38. export default {
  39. data() {
  40. return {
  41. checked: false,
  42. actionIndex: 0,
  43. pageNum: 1,
  44. total: 0,
  45. list: [],
  46. listNum: '', //可用优惠券数量
  47. radiovalue1: '', //选中项的下标
  48. couponId: '', //选中项的id
  49. boxId: '',
  50. };
  51. },
  52. onShow() {
  53. this.pageList()
  54. },
  55. onLoad(opthios) {
  56. this.boxId = opthios.boxId
  57. if (opthios.couponId) {
  58. this.couponId = opthios.couponId
  59. this.radiovalue1 = opthios.couponId
  60. }
  61. },
  62. methods: {
  63. pageList() {
  64. this.list = []
  65. this.getList()
  66. },
  67. getList() {
  68. uni.showLoading({
  69. title: '加载中'
  70. });
  71. $http.post('/api/v1/mp/user/ticket/order/coupon/list', {}).then(
  72. res => {
  73. uni.hideLoading();
  74. if (res.code == 0) {
  75. this.listNum = res.data.length
  76. res.data.forEach(item => {
  77. let useAreaDesc = JSON.parse(item.useArea)
  78. item.useAreaDesc = useAreaDesc.desc
  79. })
  80. this.list = res.data
  81. }
  82. }).catch(() => {
  83. uni.hideLoading();
  84. })
  85. },
  86. // 点击切换事件
  87. changeChechk(e) {
  88. this.couponId = e
  89. },
  90. // 点击确认事件
  91. exchange() {
  92. let data = {
  93. userCouponIds: [this.couponId],
  94. autoCoupon: 0,
  95. boxId: this.boxId,
  96. orderNum: 1
  97. }
  98. $http.post('/api/v1/mp/user/ticket/order/settle', data).then(res => {
  99. if (res.code == 0) {
  100. let pages = getCurrentPages()
  101. let page = pages[pages.length - 2]
  102. let payInfo = {
  103. ...res.data,
  104. picUrl: env.filePublic + res.data.picUrl,
  105. couponTitle: res.data && res.data.couponList && res.data.couponList.length && res
  106. .data.couponList[0].title,
  107. couponId: res.data && res.data.couponList && res.data.couponList.length && res.data
  108. .couponList[0].id
  109. }
  110. page.$vm.payInfo = payInfo
  111. uni.navigateBack({
  112. delta: 1
  113. })
  114. }
  115. })
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. .coupon {
  122. &-title {
  123. position: fixed;
  124. width: 100%;
  125. padding: 24rpx 32rpx;
  126. background-color: #FFFFFF;
  127. }
  128. &-list {
  129. margin-top: 100rpx;
  130. padding: 0 20rpx 100rpx;
  131. &-item {
  132. justify-content: space-between;
  133. padding: 20rpx;
  134. background-color: #FFFFFF;
  135. margin-bottom: 20rpx;
  136. &-info {
  137. flex: 1;
  138. justify-content: flex-start;
  139. height: 170rpx;
  140. image {
  141. width: 84rpx;
  142. height: 132rpx;
  143. margin-right: 20rpx;
  144. }
  145. .content {
  146. height: 132rpx;
  147. flex-direction: column;
  148. align-items: flex-start;
  149. justify-content: space-between;
  150. }
  151. .content .title {
  152. font-size: 32rpx;
  153. line-height: 50rpx;
  154. }
  155. .money {
  156. padding-right: 30rpx;
  157. font-weight: bold;
  158. text {
  159. font-size: 50rpx;
  160. }
  161. }
  162. }
  163. .circle {
  164. width: 40rpx;
  165. height: 40rpx;
  166. border-radius: 50%;
  167. border: 1px solid;
  168. }
  169. .action {
  170. width: 30rpx;
  171. height: 30rpx;
  172. border-radius: 50%;
  173. background-color: $uni-bg-color;
  174. }
  175. }
  176. }
  177. }
  178. .empty {
  179. height: 60vh;
  180. }
  181. .footer-fixed {
  182. position: fixed;
  183. bottom: var(--window-bottom);
  184. left: 0;
  185. right: 0;
  186. z-index: 11;
  187. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  188. background: #fff;
  189. // 设置ios刘海屏底部横线安全区域
  190. padding-bottom: constant(safe-area-inset-bottom);
  191. padding-bottom: env(safe-area-inset-bottom);
  192. .btn {
  193. padding: 20rpx 0;
  194. /deep/ button {
  195. width: 640rpx;
  196. height: 90rpx;
  197. line-height: 90rpx;
  198. font-size: 36rpx;
  199. color: #fff;
  200. background-color: $uni-bg-color;
  201. border: none;
  202. border-radius: 20rpx;
  203. }
  204. }
  205. }
  206. </style>