CommonSendCode.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="div common-send-code">
  3. <flex-line :show-border="true">
  4. <text class="span line-name">验证方式</text>
  5. <view class="div" slot="right">
  6. <radio-group @change="radioChange">
  7. <label v-for="(item, index) in verifyTypeOptions" :key="index">
  8. <radio :value="item.value" :checked="verifyType==item.value" />
  9. <text>{{item.label}}</text>
  10. </label>
  11. </radio-group>
  12. </view>
  13. </flex-line>
  14. <flex-line class="field-line" :show-border="true"><text class="span field-name">验证码</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="verifyCode"></view><view slot="right"><view @click="sendAuthCode" class="btn div common-btn plain default ds-button-small" >{{sendStateText}}</view></view></flex-line>
  15. <view class="div common-btn ds-button-large mt-10" @click='checkAuthCode'>下一步</view>
  16. </view>
  17. </template>
  18. <script>
  19. import { mapState } from 'vuex'
  20. import { sendAuthCode, checkAuthCode } from '../../../api/memberSetting'
  21. import flexLine from '../../flexLine'
  22. export default {
  23. name: 'CommonSendCode',
  24. components:{
  25. flexLine,
  26. },
  27. data () {
  28. return {
  29. verifyType: 'email',
  30. verifyCode: '',
  31. canSend: true,
  32. sendStateText: '发送',
  33. verifyTypeOptions: []
  34. }
  35. },
  36. beforeDestroy: function () {
  37. clearInterval(this.time_interval)
  38. },
  39. created: function () {
  40. if (this.user.member_mobilebind && this.user.member_mobile) {
  41. this.verifyTypeOptions.push({
  42. label: '手机',
  43. value: 'mobile'
  44. })
  45. this.verifyType = 'mobile'
  46. }
  47. if (this.user.member_emailbind && this.user.member_email) {
  48. this.verifyTypeOptions.push({
  49. label: '邮箱',
  50. value: 'email'
  51. })
  52. }
  53. },
  54. computed: {
  55. ...mapState({
  56. user: state => state.member.info
  57. })
  58. },
  59. methods: {
  60. radioChange(e){
  61. this.verifyType=e.detail.value
  62. },
  63. sendAuthCode () {
  64. if (!this.canSend) {
  65. return
  66. }
  67. sendAuthCode(this.verifyType).then(res => {
  68. this.canSend = false
  69. let second = 60
  70. uni.showToast({icon:'none',title: res.message})
  71. let _this = this
  72. this.time_interval = setInterval(function () {
  73. if (second <= 0) {
  74. _this.canSend = true
  75. _this.sendStateText = '发送'
  76. clearInterval(_this.time_interval)
  77. } else {
  78. _this.sendStateText = second + 's'
  79. }
  80. second--
  81. }, 1000)
  82. }).catch(function (error) {
  83. uni.showToast({icon:'none',title: error.message})
  84. })
  85. },
  86. checkAuthCode () {
  87. checkAuthCode(this.verifyCode).then(res => {
  88. this.$emit('checkSuccess')
  89. }).catch(function (error) {
  90. uni.showToast({icon:'none',title: error.message})
  91. })
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. .common-send-code {
  98. position: relative;
  99. z-index: 100;
  100. padding:0 $pageSpace;
  101. }
  102. </style>
  103. <style lang="scss">
  104. .common-send-code {position:relative;z-index:100;top: 1px;
  105. .btn{width:4rem}
  106. .mint-radiolist {
  107. display: flex;
  108. .mint-cell {
  109. flex: 1;
  110. .mint-radio-input:checked + .mint-radio-core {
  111. background-color: $primaryColor !important;
  112. border-color: $primaryColor !important;
  113. }
  114. &:after{display: none}
  115. }
  116. }
  117. .field-input{text-align: left !important;}
  118. }
  119. </style>