UnBindBank.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <el-dialog
  3. :visible.sync="visible"
  4. v-bind="modalOptions"
  5. append-to-body
  6. >
  7. <el-form
  8. ref="formData"
  9. :model="formData"
  10. :rules="formRules"
  11. size="mini"
  12. label-suffix=":"
  13. label-width="150px"
  14. >
  15. <el-form-item label="注册手机号" prop="phone">
  16. <el-input v-model="formData.phone" maxlength="11" placeholder="注册手机号" disabled style="width: 120px;" />
  17. <el-button style="margin-left: 10px;" type="primary" :loading="codeLoading" @click="handleSendCode(formData.phone)">
  18. <span v-if="!codeLoading">获取验证码</span>
  19. <span v-else>{{ codeCount }} s</span>
  20. </el-button>
  21. </el-form-item>
  22. <el-form-item label="验证码" prop="code">
  23. <el-input
  24. v-model="formData.code" oninput="value=value.replace(/[^\d]/g,'')" maxlength="6"
  25. style="width: 120px;"
  26. />
  27. </el-form-item>
  28. </el-form>
  29. <template #footer>
  30. <span class="dialog-footer">
  31. <el-button size="mini" @click="handleClose">取 消</el-button>
  32. <el-button type="primary" size="mini" @click="handleSubmit">确 定</el-button>
  33. </span>
  34. </template>
  35. </el-dialog>
  36. </template>
  37. <script>
  38. import { getCode, bankDelete } from '@/api/account'
  39. export default {
  40. name: 'UnBindBank',
  41. components: {
  42. },
  43. data() {
  44. return {
  45. modalOptions: {
  46. closeOnClickModal: false,
  47. width: '620px',
  48. title: ''
  49. },
  50. visible: false,
  51. formData: {
  52. phone: '',
  53. code: ''
  54. },
  55. formRules: {
  56. phone: [ { required: true, message: '缺少注册手机号' } ],
  57. code: [ { required: true, message: '请输入验证码' } ]
  58. },
  59. codeTimer: '',
  60. codeLoading: false,
  61. codeCount: ''
  62. }
  63. },
  64. methods: {
  65. handleClose() {
  66. this.visible = false
  67. },
  68. // 获取验证码
  69. async handleSendCode(phone) {
  70. if (phone === '') {
  71. this.$message.error('请填写电话号码')
  72. return
  73. } else if (!/^1[3-9]\d{9}$/.test(phone)) {
  74. this.$message({
  75. message: '请输入正确手机号',
  76. type: 'warning'
  77. })
  78. return false
  79. }
  80. if (!this.codeTimer) {
  81. const res = await getCode({ phone })
  82. if (res.code === '') {
  83. this.$message({
  84. message: '发送成功,请注意查看手机短信',
  85. type: 'success'
  86. })
  87. }
  88. this.codeLoading = true
  89. this.codeCount = 60
  90. this.codeTimer = setInterval(() => {
  91. if (this.codeCount > 0 && this.codeCount <= 60) {
  92. this.codeCount--
  93. } else {
  94. clearInterval(this.codeTimer) // 清除定时器
  95. this.codeTimer = null
  96. this.codeLoading = false
  97. }
  98. }, 1000)
  99. }
  100. },
  101. initList() {
  102. },
  103. handleOpen(params = {}) {
  104. this.modalOptions.title = '解绑银行卡'
  105. this.formData.phone = params.phone
  106. // this.formData = Object.assign(this.$options.data().formData, params)
  107. this.visible = true
  108. this.initList()
  109. this.$refs.formData && this.$refs.formData.resetFields()
  110. },
  111. handleSubmit() {
  112. this.$refs.formData.validate(async (valid) => {
  113. if (valid) {
  114. const loading = this.$loading({ text: '加载中' })
  115. try {
  116. const { ...otps } = this.formData
  117. const params = {
  118. ...otps
  119. }
  120. await bankDelete(params)
  121. loading.close()
  122. this.$message({ message: `解绑成功!`, type: 'success' })
  123. this.$emit('success')
  124. this.visible = false
  125. } catch (e) {
  126. loading.close()
  127. } finally {
  128. loading.close()
  129. }
  130. } else {
  131. this.$message({ message: '请输入相关信息', type: 'warning' })
  132. return false
  133. }
  134. })
  135. }
  136. }
  137. }
  138. </script>