index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. ticketId: '',
  51. };
  52. },
  53. onShow() {
  54. this.pageList()
  55. },
  56. onLoad(opthios) {
  57. this.boxId = opthios.boxId
  58. if (opthios.ticketId) {
  59. this.ticketId = opthios.ticketId
  60. }
  61. if (opthios.couponId) {
  62. this.couponId = opthios.couponId
  63. this.radiovalue1 = opthios.couponId
  64. }
  65. },
  66. methods: {
  67. pageList() {
  68. this.list = []
  69. this.getList()
  70. },
  71. getList() {
  72. uni.showLoading({
  73. title: '加载中'
  74. });
  75. $http.post('/api/v1/mp/user/ticket/order/coupon/list', {}).then(
  76. res => {
  77. uni.hideLoading();
  78. if (res.code == 0) {
  79. this.listNum = res.data.length
  80. res.data.forEach(item => {
  81. let useAreaDesc = JSON.parse(item.useArea)
  82. item.useAreaDesc = useAreaDesc.desc
  83. })
  84. this.list = res.data
  85. }
  86. }).catch(() => {
  87. uni.hideLoading();
  88. })
  89. },
  90. // 点击切换事件
  91. changeChechk(e) {
  92. if (this.couponId == e) {
  93. this.radiovalue1 = -1
  94. this.couponId = []
  95. return
  96. } else {
  97. this.couponId = [e]
  98. return
  99. }
  100. },
  101. // 点击确认事件
  102. exchange() {
  103. let data = {
  104. userCouponIds: this.couponId,
  105. autoCoupon: 0,
  106. boxId: this.boxId,
  107. ticketId: this.ticketId,
  108. orderNum: 1
  109. }
  110. $http.post('/api/v1/mp/user/ticket/order/settle', data).then(res => {
  111. if (res.code == 0) {
  112. let pages = getCurrentPages()
  113. let page = pages[pages.length - 2]
  114. let payInfo = {
  115. ...res.data,
  116. picUrl: env.filePublic + res.data.picUrl,
  117. couponDiscount: res.data && res.data.couponList && res.data.couponList.length &&
  118. res
  119. .data.couponList[0].discount,
  120. couponId: res.data && res.data.couponList && res.data.couponList.length && res.data
  121. .couponList[0].id,
  122. listNum: this.listNum
  123. }
  124. page.$vm.payInfo = payInfo
  125. uni.navigateBack({
  126. delta: 1
  127. })
  128. }
  129. })
  130. }
  131. }
  132. }
  133. </script>
  134. <style lang="scss" scoped>
  135. .coupon {
  136. &-title {
  137. position: fixed;
  138. width: 100%;
  139. padding: 24rpx 32rpx;
  140. background-color: #FFFFFF;
  141. }
  142. &-list {
  143. margin-top: 100rpx;
  144. padding: 0 20rpx 100rpx;
  145. &-item {
  146. justify-content: space-between;
  147. padding: 20rpx;
  148. background-color: #FFFFFF;
  149. margin-bottom: 20rpx;
  150. &-info {
  151. flex: 1;
  152. justify-content: flex-start;
  153. height: 170rpx;
  154. image {
  155. width: 84rpx;
  156. height: 132rpx;
  157. margin-right: 20rpx;
  158. }
  159. .content {
  160. height: 132rpx;
  161. flex-direction: column;
  162. align-items: flex-start;
  163. justify-content: space-between;
  164. }
  165. .content .title {
  166. font-size: 32rpx;
  167. line-height: 50rpx;
  168. }
  169. .money {
  170. padding-right: 30rpx;
  171. font-weight: bold;
  172. text {
  173. font-size: 50rpx;
  174. }
  175. }
  176. }
  177. .circle {
  178. width: 40rpx;
  179. height: 40rpx;
  180. border-radius: 50%;
  181. border: 1px solid;
  182. }
  183. .action {
  184. width: 30rpx;
  185. height: 30rpx;
  186. border-radius: 50%;
  187. background-color: $uni-bg-color;
  188. }
  189. }
  190. }
  191. }
  192. .empty {
  193. height: 60vh;
  194. }
  195. .footer-fixed {
  196. position: fixed;
  197. bottom: var(--window-bottom);
  198. left: 0;
  199. right: 0;
  200. z-index: 11;
  201. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  202. background: #fff;
  203. // 设置ios刘海屏底部横线安全区域
  204. padding-bottom: constant(safe-area-inset-bottom);
  205. padding-bottom: env(safe-area-inset-bottom);
  206. .btn {
  207. padding: 20rpx 0;
  208. /deep/ button {
  209. width: 640rpx;
  210. height: 90rpx;
  211. line-height: 90rpx;
  212. font-size: 36rpx;
  213. color: #fff;
  214. background-color: $uni-bg-color;
  215. border: none;
  216. border-radius: 20rpx;
  217. }
  218. }
  219. }
  220. </style>