phone.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <v-page>
  3. <v-header :title="`${user.phone?$t('safe.a0'):''} ${$t('safe.d2')}`"></v-header>
  4. <main class="layout-main bg-panel-4 m-t-md">
  5. <view class="form-item border-b p-md" v-if="!user.phone">
  6. <view class="label m-b-xs">{{$t('safe.d2')}}</view>
  7. <view class="input color-light">
  8. <v-input v-model="form.phone" :placeholder="$t('safe.d5')">
  9. <template #left>
  10. <v-country class="m-r-xs" ref="country" v-model="country_id" />
  11. </template>
  12. </v-input>
  13. </view>
  14. </view>
  15. <view class="form-item border-b p-md">
  16. <view class="label m-b-xs">SMS {{$t('safe.a7')}}</view>
  17. <view class="input color-light">
  18. <v-input v-model="form.sms_code" :placeholder="$t('safe.a6')">
  19. <template #right>
  20. <v-code url="/user/getCode" v-if="user.phone" :data="{type:1}" />
  21. <v-code
  22. url="/user/sendBindSmsCode"
  23. v-else
  24. :data="{phone:form.phone,country_code:$refs.country&&$refs.country.country_code}"
  25. />
  26. </template>
  27. </v-input>
  28. </view>
  29. </view>
  30. <view class="form-item border-b p-md" v-if="user.email_status==1">
  31. <view class="label m-b-xs">{{$t('safe.a5')}}</view>
  32. <view class="input color-light">
  33. <v-input v-model="form.email_code" :placeholder="$t('safe.a6')">
  34. <template #right>
  35. <v-code url="/user/getCode" :data="{type:2}" />
  36. </template>
  37. </v-input>
  38. </view>
  39. </view>
  40. <view class="form-item border-b p-md" v-if="user.google_status==1">
  41. <view class="label m-b-xs">google{{$t('safe.a7')}}</view>
  42. <view class="input color-light">
  43. <v-input v-model="form.google_code" :placeholder="$t('safe.a6')"></v-input>
  44. </view>
  45. </view>
  46. </main>
  47. <view class="p-md bg-panel-4">
  48. <v-button block class="w-max" type="theme" ref="btn" @click="changePhone">{{user.phone?$t('safe.a0'):$t('safe.e3')}}</v-button>
  49. </view>
  50. <van-toast id="van-toast" />
  51. </v-page>
  52. </template>
  53. <script>
  54. import Setting from "@/api/setting";
  55. import { mapState, mapActions } from "vuex";
  56. export default {
  57. data() {
  58. return {
  59. country_id: 195,
  60. form: {
  61. phone: "",
  62. country_code: "",
  63. email_code: "",
  64. sms_code: "",
  65. google_code: "",
  66. },
  67. };
  68. },
  69. computed: {
  70. ...mapState({
  71. user: "user",
  72. }),
  73. },
  74. methods: {
  75. ...mapActions({
  76. setUserInfo: "setUserInfo",
  77. }),
  78. changePhone() {
  79. this.form.country_code = this.$refs.country&&this.$refs.country.country_code;
  80. if (!this.user.phone && !this.form.phone) {
  81. this.$toast(this.$t('safe.d5'));
  82. return;
  83. }
  84. if (!this.form.sms_code) {
  85. this.$toast(this.$t('safe.d6'));
  86. return;
  87. }
  88. let changePhone = this.user.phone
  89. ? Setting.unbindPhone(this.form, { btn: this.$refs.btn })
  90. : Setting.bindPhone(this.form, { btn: this.$refs.btn });
  91. changePhone
  92. .then(() => {
  93. this.$toast.success(this.user.phone ? this.$t('safe.a8') : this.$t('safe.a9'));
  94. this.$back();
  95. this.setUserInfo();
  96. })
  97. .catch(() => {});
  98. },
  99. },
  100. };
  101. </script>
  102. <style lang="scss" scoped>
  103. </style>