index.vue 5.2 KB

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