MyWallet.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <el-main>
  3. <el-row class="movie-list">
  4. <el-col :md="8" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  5. <el-card class="box-card">
  6. <div slot="header" class="clearfix">
  7. <span>我的钱包</span>
  8. <el-button style="float: right; padding: 3px 0" type="text" @click="showChargeDialog">充值</el-button>
  9. </div>
  10. <div class="text item">
  11. <el-row>
  12. <h1>余额: <span style="color: red">¥{{ wallet.balance }}</span></h1>
  13. </el-row>
  14. </div>
  15. </el-card>
  16. </el-col>
  17. <el-col :md="16" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  18. <el-card class="box-card">
  19. <div slot="header" class="clearfix">
  20. <span>我的账单</span>
  21. </div>
  22. <el-table
  23. :data="billList"
  24. style="width: 100%"
  25. >
  26. <el-table-column
  27. prop="createAt"
  28. label="时间"
  29. />
  30. <el-table-column
  31. prop="type"
  32. label="类型"
  33. >
  34. </el-table-column>
  35. <el-table-column
  36. prop="quantity"
  37. label="金额"
  38. >
  39. </el-table-column>
  40. <el-table-column label="操作">
  41. <template slot-scope="scope">
  42. <el-button
  43. size="mini"
  44. @click="handleDetail(scope.$index, scope.row)"
  45. >详情</el-button>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. </el-card>
  50. </el-col>
  51. </el-row>
  52. <el-dialog
  53. title="充值"
  54. append-to-body
  55. :visible.sync="chargeDialog"
  56. width="30%"
  57. center
  58. >
  59. <el-form ref="form" :model="chargeForm">
  60. <el-form-item label="充值金额">
  61. <el-input-number v-model="chargeForm.quantity" :min="1" :max="100" style="margin-left: 5px" />
  62. </el-form-item>
  63. <el-form-item>
  64. <el-button
  65. type="primary"
  66. @click="chargeWallet"
  67. >确定</el-button>
  68. </el-form-item>
  69. </el-form>
  70. </el-dialog>
  71. </el-main>
  72. </template>
  73. <script>
  74. import { chargeWallet, getWallet, getWalletBill } from '@/api/mall'
  75. export default {
  76. name: 'MyWallet',
  77. data() {
  78. return {
  79. chargeDialog: false,
  80. chargeForm: {
  81. quantity: null
  82. },
  83. wallet: {
  84. balance: '0.00'
  85. },
  86. billList: []
  87. }
  88. },
  89. created() {
  90. document.title = '我的钱包'
  91. getWallet().then(resp => {
  92. if (resp.code === 0) {
  93. this.wallet = resp.data
  94. }
  95. })
  96. this.getBillRecord()
  97. },
  98. methods: {
  99. showChargeDialog() {
  100. this.chargeDialog = true
  101. },
  102. chargeWallet() {
  103. if (this.chargeForm.quantity === null) {
  104. this.$message('请填写充值金额')
  105. return
  106. }
  107. this.chargeDialog = false
  108. chargeWallet(this.chargeForm).then(resp => {
  109. if (resp.code === 0) {
  110. this.$notify.info({
  111. title: '充值请求已提交',
  112. duration: 3000
  113. })
  114. } else {
  115. this.$notify({
  116. title: '充值失败',
  117. message: resp.msg,
  118. type: 'error',
  119. duration: 3000
  120. })
  121. }
  122. }).catch(error => {
  123. this.$notify({
  124. title: '充值失败',
  125. message: error.message,
  126. type: 'error',
  127. duration: 3000
  128. })
  129. })
  130. },
  131. getBillRecord() {
  132. getWalletBill().then(resp => {
  133. if (resp.code === 0) {
  134. this.billList = resp.data
  135. }
  136. })
  137. },
  138. handleDetail(index, row) {
  139. this.$message.info('账单详情')
  140. }
  141. }
  142. }
  143. </script>
  144. <style scoped>
  145. .clearfix:before,
  146. .clearfix:after {
  147. display: table;
  148. content: "";
  149. }
  150. .clearfix:after {
  151. clear: both;
  152. }
  153. </style>