list.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <!-- 优惠劵列表 -->
  2. <template>
  3. <view class="page_box">
  4. <view class="head_box u-m-b-20">
  5. <shopro-navbar back-icon-color="#333" :background="{ backgroundColor: '#fff' }">
  6. <view slot="content" class="u-flex nav-wrap">
  7. <view class="nav-item u-flex-1 u-flex-col u-row-center u-col-center" v-for="nav in navbarHeadState" :key="nav.value" @tap="onHead(nav.value)">
  8. <view class="item-title" :class="{ 'title-active': navState === nav.value }">{{ nav.title }}</view>
  9. <text class="nav-line" :class="{ 'line-active': navState === nav.value }"></text>
  10. </view>
  11. </view>
  12. </shopro-navbar>
  13. <view class="coupon-nav u-flex" v-show="navState === 'user'">
  14. <button
  15. class=" cu-btn nav-btn u-flex-col u-row-center u-col-center"
  16. :class="{ 'btn-active': nav.id == stateCurrent }"
  17. v-for="nav in couponsState"
  18. :key="nav.id"
  19. @tap="onNav(nav.id)"
  20. >
  21. <view class="item-title">{{ nav.title }}</view>
  22. </button>
  23. </view>
  24. </view>
  25. <view class="content_box">
  26. <view class="coupon-list" v-for="(c, index) in couponList" :key="index" @tap="toCouponDetail(c)">
  27. <shopro-coupon :state="stateCurrent" :couponData="c"></shopro-coupon>
  28. </view>
  29. <!-- 缺省页 -->
  30. <shopro-empty marginTop="300rpx" v-if="isEmpty" :image="$IMG_URL + '/imgs/empty/empty_goods.png'" tipText="暂无此类优惠券"></shopro-empty>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. components: {},
  37. data() {
  38. return {
  39. stateCurrent: 0,
  40. isEmpty: false,
  41. navState: 'event',
  42. navbarHeadState: [
  43. {
  44. value: 'event',
  45. title: '领券中心'
  46. },
  47. {
  48. value: 'user',
  49. title: '我的优惠券'
  50. }
  51. ],
  52. couponsState: [
  53. {
  54. id: 1,
  55. title: '可使用'
  56. },
  57. {
  58. id: 2,
  59. title: '暂不可用'
  60. },
  61. {
  62. id: 3,
  63. title: '无效优惠券'
  64. }
  65. ],
  66. couponList: []
  67. };
  68. },
  69. computed: {},
  70. onLoad() {
  71. this.getCouponList();
  72. },
  73. methods: {
  74. onNav(id) {
  75. if (this.stateCurrent !== id) {
  76. this.stateCurrent = id;
  77. this.couponList = [];
  78. this.getCouponList();
  79. }
  80. },
  81. onHead(value) {
  82. if (this.navState !== value) {
  83. this.navState = value;
  84. if (value === 'event') {
  85. this.stateCurrent = 0;
  86. }
  87. if (value === 'user') {
  88. this.stateCurrent = 1;
  89. }
  90. this.couponList = [];
  91. this.getCouponList();
  92. }
  93. },
  94. jump(path, parmas) {
  95. this.$Router.push({
  96. path: path,
  97. query: parmas
  98. });
  99. },
  100. getCouponList() {
  101. let that = this;
  102. that.$http('coupons.list', {
  103. type: that.stateCurrent
  104. }).then(res => {
  105. if (res.code === 1) {
  106. that.couponList = res.data;
  107. that.isEmpty = !that.couponList.length;
  108. }
  109. });
  110. },
  111. //跳转优惠券详情
  112. toCouponDetail(data) {
  113. if (data.user_coupons_id) {
  114. this.jump('/pages/app/coupon/detail', { id: data.id, userCouponId: data.user_coupons_id });
  115. } else {
  116. this.jump('/pages/app/coupon/detail', { id: data.id });
  117. }
  118. }
  119. }
  120. };
  121. </script>
  122. <style lang="scss">
  123. .nav-item {
  124. flex: 1;
  125. height: 100%;
  126. .item-title {
  127. font-size: 30rpx;
  128. font-weight: 400;
  129. color: #666;
  130. }
  131. .title-active {
  132. font-size: 32rpx;
  133. font-weight: 500;
  134. color: #333;
  135. }
  136. .nav-line {
  137. width: 128rpx;
  138. height: 6rpx;
  139. border-radius: 3rpx;
  140. background: #fff;
  141. }
  142. .line-active {
  143. background: #e9b664;
  144. }
  145. }
  146. .nav-wrap {
  147. /* #ifdef MP-WEIXIN */
  148. width: 460rpx;
  149. /* #endif */
  150. /* #ifndef MP-WEIXIN */
  151. width: 100%;
  152. /* #endif */
  153. }
  154. .coupon-nav {
  155. background: #fff;
  156. height: 100rpx;
  157. padding: 0 30rpx;
  158. .nav-btn {
  159. margin-right: 10rpx;
  160. font-size: 26rpx;
  161. color: #666;
  162. }
  163. .btn-active {
  164. font-size: 26rpx;
  165. color: #fff;
  166. background-color: #faae0c;
  167. }
  168. }
  169. .coupon-list {
  170. margin: 30rpx 20rpx;
  171. }
  172. </style>