myCoupon.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="content">
  3. <z-paging-swiper>
  4. <u-navbar
  5. slot="top"
  6. title-color="#fff"
  7. :custom-back="customBack"
  8. :border-bottom="false"
  9. back-icon-color="#CCE8FF"
  10. :background="{ background: '#008CFF' }"
  11. title="我的优惠券"
  12. >
  13. <view class="navbar-font" slot="right" @click="jumpPage('/pages/center/coupon/couponRules/couponRules')"> 规则 </view>
  14. </u-navbar>
  15. <z-tabs ref="tabs" slot="top" :list="tabList" :current="current" barWidth="90rpx" @change="tabsChange"></z-tabs>
  16. <swiper class="swiper" :current="current" @transition="swiperTransition" @animationfinish="swiperAnimationfinish">
  17. <swiper-item class="swiper-item" v-for="(item, index) in tabList" :key="index">
  18. <view class="search-part" v-if="current === 0">
  19. <u-input class="search-part-input" v-model="form.exchangeCode" placeholder="请输入兑换码" />
  20. <u-button class="search-part-btn" type="primary" shape="circle" size="medium" @click="handleExchange">兑换</u-button>
  21. </view>
  22. <swiper-list-item :tabIndex="index" :currentIndex="current" ref="swiperListItem"></swiper-list-item>
  23. </swiper-item>
  24. </swiper>
  25. <!-- 选择车牌 -->
  26. <u-select v-model="chooseVehicle" :list="vehicleList" @confirm="vehicleConfirm"></u-select>
  27. <u-toast ref="uToast" />
  28. </z-paging-swiper>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. tabList: [
  36. {
  37. name: '未使用',
  38. value: 0,
  39. list: []
  40. },
  41. {
  42. name: '已使用',
  43. value: 1,
  44. list: []
  45. },
  46. {
  47. name: '已失效',
  48. value: 2,
  49. list: []
  50. }
  51. ],
  52. current: 0,
  53. form: {
  54. exchangeCode: '',
  55. source: 1,
  56. vehicleNo: '京A88888'
  57. },
  58. vehicleList: [],
  59. chooseVehicle: false
  60. };
  61. },
  62. onLoad(options) {
  63. this.getCarsList();
  64. },
  65. methods: {
  66. // tabs通知swiper切换
  67. tabsChange(index) {
  68. this.current = index;
  69. },
  70. // swiper滑动中
  71. swiperTransition(e) {
  72. this.$refs.tabs.setDx(e.detail.dx);
  73. },
  74. //swiper滑动结束
  75. swiperAnimationfinish(e) {
  76. this.current = e.detail.current;
  77. this.$refs.tabs.unlockDx();
  78. },
  79. /**
  80. * 兑换
  81. * @date 2022-12-23
  82. * @returns {any}
  83. */
  84. handleExchange() {
  85. if (this.form.exchangeCode) {
  86. this.chooseVehicle = true;
  87. } else {
  88. this.$refs.uToast.show({
  89. title: '请输入兑换码',
  90. type: 'warning'
  91. });
  92. }
  93. },
  94. getCarsList() {
  95. this.$u.api.getMycars().then((res) => {
  96. this.vehicleList = res.data.rows.map((item) => {
  97. return { label: item.vehicleNo, value: item.vehicleNo };
  98. });
  99. });
  100. },
  101. /**
  102. * 车牌确认
  103. * @date 2022-12-23
  104. * @param {any} list
  105. * @returns {any}
  106. */
  107. vehicleConfirm(list) {
  108. this.form.vehicleNo = list[0].value;
  109. this.exchangeCoupon();
  110. },
  111. /**
  112. * 兑换优惠券
  113. * @date 2022-12-23
  114. * @returns {any}
  115. */
  116. exchangeCoupon() {
  117. this.$u.api.exchangeCouponApi(this.form).then((res) => {
  118. if (res.code === 200) {
  119. this.$refs.uToast.show({
  120. title: '兑换成功!',
  121. type: 'success'
  122. });
  123. this.$refs['swiperListItem'][this.current].reloadData();
  124. }
  125. });
  126. },
  127. jumpPage(url) {
  128. this.$u.route({
  129. url
  130. });
  131. },
  132. // tabbar 返回
  133. customBack() {
  134. this.$u.route({
  135. type: 'switchTab',
  136. url: 'pages/index/index'
  137. });
  138. }
  139. }
  140. };
  141. </script>
  142. <style lang="scss" scoped>
  143. @import './myCoupon.scss';
  144. </style>