index.vue 5.1 KB

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