index.vue 3.81 KB
Newer Older
潘琦 committed
1 2 3 4 5 6 7 8
<template>
  <div class="full-page">
    <div class="container">
      <div class="p-title">
        <span class="label">我的健康券</span>
        <span class="link" @click="goToVouchers">查看全部 <i class="glyphicon glyphicon-menu-right"></i></span>
      </div>
      <ul>
9
        <li v-for="(item, index) in voucherData" :key="index" @click="goToDetail(item.voucherId, item.makeId, item.voucherType)">
潘琦 committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23
          <CardItem :data="item"></CardItem>
        </li>
      </ul>
      <div class="p-title">
        <span class="label">我的福利</span>
      </div>
      <div @click="goToUser">
        <ListItem :data="userInfo"></ListItem>
      </div>
    </div>
  </div>
</template>

<script>
潘琦 committed
24
import store from '@/store'
潘琦 committed
25 26 27 28 29
// import store from '@/store'
import CardItem from '@/components/cardItem'
import ListItem from '@/components/listItem'
import { getUserCard, getunUsedCountById } from '@/api/apply/apply'
import { getUserInfoByUserId } from '@/api/basic/basic'
30
// import { wxpermission } from '@/wxpermission'
潘琦 committed
31 32 33 34 35 36
import _itemPoster from '../../assets/images/doctor.jpg'

export default {
  name: 'Home',
  data () {
    return {
潘琦 committed
37
      userId: store.getters.user_id,
潘琦 committed
38 39 40 41 42 43 44 45 46 47 48 49 50
      voucherData: [],
      userInfo: {
        name: '',
        subTitle: 0,
        itemPoster: _itemPoster,
        des: [
          '国家基本公卫服务;',
          '家庭医疗健康服务;'
        ]
      }
    }
  },
  created () {
51 52 53 54 55 56 57 58 59 60
    // let that = this
    // wxpermission(() => {
    //   // setTimeout(() => {
    //   //   that.$router.push({
    //   //     path: '/recommend'
    //   //   })
    //   // }, 2000)
    //   // window.location.href = 'http://' + location.host + '/#/recommend/list'
    // }, false)

潘琦 committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 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 120 121 122
    this.getUserCardByIdFn() // 获取当前用户待使用健康券(前3条)
    this.getUserInfoByUserIdFn() // 获取当前用户基本信息
    this.getunUsedCountByIdFn() // 获取当前用户待使用健康券数量
    // store.commit('SET_USERIFNO', {name: '1'})
  },
  mounted: function () {
  },
  computed: {
  },
  components: {
    CardItem,
    ListItem
  },
  methods: {
    getUserCardByIdFn () {
      let parmas = {
        states: [1],
        userId: this.userId
      }
      getUserCard(3, parmas).then(res => {
        if (res.code === 0) {
          this.voucherData = res.data
        }
      }).catch((error) => {
        this.$toast({
          message: error.message,
          position: 'center',
          duration: 3000
        })
      })
    },
    getUserInfoByUserIdFn () {
      getUserInfoByUserId(this.userId).then(res => {
        if (res.code === 0) {
          this.userInfo.title = res.data[0].name
          this.$store.commit('SET_USERIFNO', res.data[0])
        }
      }).catch((error) => {
        this.$toast({
          message: error.message,
          position: 'center',
          duration: 3000
        })
      })
    },
    getunUsedCountByIdFn () {
      let parmas = {
        states: [1],
        userId: this.userId
      }
      getunUsedCountById(parmas).then(res => {
        if (res.code === 0) {
          this.userInfo.subTitle = res.data
        }
      }).catch((error) => {
        this.$toast({
          message: error.message,
          position: 'center',
          duration: 3000
        })
      })
    },
123
    goToDetail (voucherId, makeId, voucherType) {
潘琦 committed
124 125 126 127
      this.$router.push({
        path: '/voucherDetail',
        query: {
          voucherId: voucherId,
128 129
          makeId: makeId,
          voucherType: voucherType
潘琦 committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
        }
      })
    },
    goToUser () {
      console.log('go to user page')
      this.$router.push({
        path: '/user',
        query: {
          userId: this.userId
        }
      })
    },
    goToVouchers () {
      this.$router.push({
        path: '/vouchers'
      })
    }
  }
}
</script>

<style scoped>
  .full-page {
    background-color: #f5f6f7;
  }
</style>