MyVip.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <el-row>
  3. <el-col :md="12">
  4. <el-card class="box-card">
  5. <div slot="header" class="clearfix">
  6. <span>我的小会员</span>
  7. </div>
  8. <div v-if="myVip !== null" class="text item">
  9. <el-row v-if="!myVip.isVip">
  10. 您当前还不是小会员, <el-button type="text" @click="showPlanDialog">成为小会员</el-button>
  11. </el-row>
  12. <el-row v-else>
  13. <el-row v-if="myVip.expired">
  14. 您的小会员已过期, <el-button type="text" @click="showPlanDialog">续费小会员</el-button>
  15. </el-row>
  16. <el-row v-else>
  17. 您的小会员还有 <span style="color: red">{{ myVip.expireIn }}</span> 天到期, <el-button type="text" @click="showPlanDialog">续费小会员</el-button>
  18. </el-row>
  19. </el-row>
  20. </div>
  21. </el-card>
  22. </el-col>
  23. <el-col>
  24. <div style="width: 500px; height: 100px; position: relative">
  25. <StampBadge
  26. size="small"
  27. color="warning"
  28. content="小会员"
  29. :rotate="0"
  30. />
  31. </div>
  32. <div style="width: 500px; height: 100px; position: relative">
  33. <StampBadge
  34. style="position: absolute; top: 0; right: 0"
  35. size="middle"
  36. color="success"
  37. content="已支付"
  38. :rotate="45"
  39. />
  40. </div>
  41. </el-col>
  42. <el-dialog
  43. title="小会员计划"
  44. append-to-body
  45. :visible.sync="planDialog"
  46. width="50%"
  47. center
  48. >
  49. <el-form ref="form" :model="planForm">
  50. <el-form-item>
  51. <el-radio-group v-for="(item, index) in vipPlans" :key="index" v-model="planForm.planId">
  52. <el-radio style="margin-right: 5px" :label="item.planId" border>
  53. {{ item.name }} (<span style="color: red">¥{{ item.price }}</span> 元)
  54. </el-radio>
  55. </el-radio-group>
  56. </el-form-item>
  57. <el-form-item>
  58. <el-button
  59. type="primary"
  60. @click="buy"
  61. >购买</el-button>
  62. </el-form-item>
  63. </el-form>
  64. </el-dialog>
  65. </el-row>
  66. </template>
  67. <script>
  68. import StampBadge from '@/components/StampBadge'
  69. import { getMyVip, getVipPlans, vip } from '@/api/account'
  70. export default {
  71. name: 'MyVip',
  72. components: { StampBadge },
  73. data() {
  74. return {
  75. planDialog: false,
  76. vipPlans: [],
  77. planForm: {
  78. planId: null,
  79. quantity: null
  80. },
  81. myVip: null
  82. }
  83. },
  84. created() {
  85. document.title = '我的小会员'
  86. getMyVip().then(resp => {
  87. if (resp.code === 0) {
  88. this.myVip = resp.data
  89. }
  90. })
  91. },
  92. mounted() {
  93. },
  94. methods: {
  95. showPlanDialog() {
  96. this.planDialog = true
  97. getVipPlans().then(resp => {
  98. if (resp.code === 0) {
  99. this.vipPlans = resp.data
  100. console.log(this.vipPlans)
  101. }
  102. })
  103. },
  104. buy() {
  105. this.planDialog = false
  106. vip(this.planForm).then(resp => {
  107. if (resp.code === 0) {
  108. this.$notify.info({
  109. message: '小会员已开通',
  110. duration: 3000
  111. })
  112. } else {
  113. this.$notify.error({
  114. message: resp.msg,
  115. duration: 3000
  116. })
  117. }
  118. })
  119. }
  120. }
  121. }
  122. </script>
  123. <style scoped>
  124. </style>