myCoupon.vue 3.6 KB

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