bind-mobile.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view style="padding: 20px;">
  3. <sms-box v-model="postForm" ref="smsBox" :type="type == '1'?1:2"></sms-box>
  4. <view>
  5. <button v-if="type == '1'" type="primary" @click="doBind">确认绑定</button>
  6. <button v-if="type == '0'" type="warn" @click="unBind">确认解绑</button>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. import {
  12. bindMobile,
  13. unBindMobile
  14. } from '@/api/sys/user/bind'
  15. import SmsBox from '@/pages/login/components/SmsBox.vue'
  16. export default {
  17. components: {
  18. SmsBox
  19. },
  20. data() {
  21. return {
  22. type: null,
  23. postForm: {
  24. mobile: '',
  25. smsCode: '',
  26. captchaKey: '',
  27. captchaValue: ''
  28. }
  29. }
  30. },
  31. onLoad: function(option) {
  32. this.type = option.type;
  33. this.postForm.mobile = option.mobile;
  34. },
  35. methods: {
  36. // 绑定手机
  37. async doBind() {
  38. // 消息框
  39. const smsCheck = await this.$refs.smsBox.validate().then(res=>{return res});
  40. console.log('smsCheck', smsCheck)
  41. if(!smsCheck){
  42. return;
  43. }
  44. uni.showLoading({
  45. title: '加载中..'
  46. })
  47. bindMobile(this.postForm).then(() => {
  48. this.handleSuccess('手机号绑定成功!')
  49. }).catch(() => {
  50. uni.hideLoading()
  51. })
  52. },
  53. // 解绑手机
  54. async unBind() {
  55. // 消息框
  56. const smsCheck = await this.$refs.smsBox.validate().then(res=>{return res});
  57. console.log('smsCheck', smsCheck)
  58. if(!smsCheck){
  59. return;
  60. }
  61. uni.showLoading({
  62. title: '加载中..'
  63. })
  64. unBindMobile(this.postForm).then(() => {
  65. this.handleSuccess('手机号解绑成功!')
  66. }).catch(() => {
  67. uni.hideLoading()
  68. })
  69. },
  70. handleSuccess(msg) {
  71. uni.hideLoading()
  72. uni.showToast({
  73. title: msg,
  74. icon: 'none'
  75. })
  76. setTimeout(()=>{
  77. uni.navigateBack()
  78. }, 1500)
  79. }
  80. }
  81. }
  82. </script>
  83. <style scoped>
  84. </style>