index.vue 2.75 KB
Newer Older
潘琦 committed
1 2 3 4 5 6 7
<template>
  <div class="full-page">
    <div class="container">
      <div class="p-title">
        <span class="label">我的健康券</span>
      </div>
      <ul>
8
        <li v-for="(item, index) in voucherData" :key="index" @click="goToDetail(item.voucherId, item.makeId, item.voucherType)">
潘琦 committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
          <CardItem :data="item"></CardItem>
        </li>
      </ul>
      <div class="pagination">
        <ul class="nav-pills">
          <li class="text-right">
            <a @click="filter(2)" :class="params.states[0]==2?'active':''">查看已使用的券</a>
          </li>
          <li class="text-left">
            <a @click="filter(4)" :class="params.states[0]==4?'active':''">查看已失效的券</a>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
27
import store from '@/store'
潘琦 committed
28 29 30 31 32 33 34 35 36 37
import { getUserCard } from '@/api/apply/apply'
import CardItem from '@/components/cardItem'
export default {
  name: 'vouchers',
  data () {
    return {
      voucherData: [],
      size: 10,
      params: {
        states: [1],
38
        userId: store.getters.user_id
潘琦 committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
      }
    }
  },
  created () {
    this.getUserCardByIdFn() // 获取当前用户待使用健康券(每页显示10条)
  },
  mounted: function () {
  },
  computed: {
  },
  components: {
    CardItem
  },
  methods: {
    getUserCardByIdFn () {
54 55 56 57 58 59 60 61 62 63 64 65 66
      if (this.params.userId && this.params.userId !== 'null' && this.params.userId !== '') {
        getUserCard(this.size, this.params).then(res => {
          if (res.code === 0) {
            this.voucherData = res.data
          }
        }).catch((error) => {
          this.$toast({
            message: error.message,
            position: 'center',
            duration: 3000
          })
        })
      } else {
潘琦 committed
67
        this.$toast({
68
          message: '缺少用户标识(user id为空)',
潘琦 committed
69 70 71
          position: 'center',
          duration: 3000
        })
72
      }
潘琦 committed
73 74 75 76 77 78 79 80 81 82
    },
    filter (state) {
      console.log(state)
      if (state === this.params.states[0]) {
        this.params.states = [1]
      } else {
        this.params.states = [ state ]
      }
      this.getUserCardByIdFn()
    },
83
    goToDetail (voucherId, makeId, voucherType) {
潘琦 committed
84 85 86 87
      this.$router.push({
        path: '/voucherDetail',
        query: {
          voucherId: voucherId,
88 89
          makeId: makeId,
          voucherType: voucherType
潘琦 committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
        }
      })
    }
  }
}
</script>

<style scoped>
  .full-page {
    background-color: #f5f6f7;
  }
  .pagination {
    padding: 1em 0;
    width: 100%;
  }
  .pagination ul li {
    width: 50%;
    margin: 0;
    padding: 0 1em;
  }
  .pagination ul li + li {
    border-left:1px solid #949595;
  }
  .pagination ul li > a {
    color: #949595;
  }
  .pagination ul li > a.active {
    text-decoration:underline;
  }
</style>