bindMobile.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <div class="bindMobile">
  3. <el-dialog
  4. title="绑定手机号"
  5. :visible.sync="isShowToast"
  6. width="520px"
  7. :center="true">
  8. <div class="bindMobileContent">
  9. <div class="phoneNum">
  10. <p class="name">手机号</p>
  11. <el-input v-model="phone" placeholder="请输入手机号" class="input-with-select">
  12. <el-select v-model="preMobile" slot="prepend" placeholder="请选择" style="width: 140px;">
  13. <el-option
  14. v-for="(item,index) in selectList"
  15. :key="index+'sda'"
  16. :label="item.name"
  17. :value="item.pre">
  18. </el-option>
  19. </el-select>
  20. <div slot="append" @click="getCode" :class="{sendBtn: true, ok: !interval}">
  21. {{interval ? `${timeLoop}重新发送` : "发送验证码"}}
  22. </div>
  23. </el-input>
  24. </div>
  25. <div class="codeNum">
  26. <div class="name">验证码</div>
  27. <el-input placeholder="请输入验证码" v-model="scode"/>
  28. </div>
  29. </div>
  30. <span slot="footer" class="dialog-footer">
  31. <el-button @click="isShowToast = false">取 消</el-button>
  32. <el-button type="primary" @click="bindMobile">确 定</el-button>
  33. </span>
  34. </el-dialog>
  35. </div>
  36. </template>
  37. <script>
  38. const Max_Time = 60
  39. export default {
  40. props: [ "source" ],
  41. components: {},
  42. data() {
  43. return {
  44. phone: "",
  45. scode: "",
  46. isShowToast: false,
  47. timeLoop: Max_Time,
  48. preMobile: "+86",
  49. selectList: [],
  50. interval: null,
  51. };
  52. },
  53. computed: {},
  54. created() {
  55. this.getMobilePre()
  56. },
  57. mounted() {
  58. },
  59. methods: {
  60. open() {
  61. this.isShowToast = true
  62. },
  63. close() {
  64. this.isShowToast = false
  65. },
  66. handleSubmit() {
  67. },
  68. /** 发送验证码 **/
  69. getCode() {
  70. const {phone, preMobile} = this
  71. if ( (phone.toString().length != 11 && preMobile == 0 )
  72. || (preMobile > 0 && !/^\d{8,15}$/.exec(phone)) ) {
  73. this.$message.warning('请输入正确的手机号码');
  74. return false;
  75. }
  76. if (this.interval) {
  77. this.$message.info('请1分钟后再次发送')
  78. return false
  79. }
  80. let newPhone = preMobile + '-' + phone;
  81. this.$axios.post('/api/user/check_mobile_exist', {mobile: newPhone}).then(res=>{
  82. if (Number(res.data.status) === 1 && !res.data.data.exist) {
  83. this.sendCode()
  84. }
  85. })
  86. },
  87. /** 发送验证码 **/
  88. sendCode() {
  89. this.timeLoop = Max_Time
  90. const {phone, preMobile} = this
  91. let newPhone = phone;
  92. if (preMobile !== '+86') {
  93. newPhone = preMobile + '-' + phone;
  94. }
  95. this.$axios.post('/api/user/send_mobile_auth_code', {
  96. mobile: newPhone
  97. }).then(res=>{
  98. if (Number(res.data.status) === 1) {
  99. this.interval = setInterval(()=>{
  100. this.timeLoop--
  101. if (this.timeLoop <= 0) {
  102. clearInterval(this.interval)
  103. this.interval = null
  104. }
  105. }, 1000)
  106. }
  107. })
  108. },
  109. /** 获取数据 -- 手机号码前缀 **/
  110. getMobilePre() {
  111. this.$axios.get('/api/user/get_mobile_pre_arr').then(res=>{
  112. if (Number(res.data.status) === 1) {
  113. let list = res.data.data && res.data.data.mobilePreArr || [{id: 0, name: "中国 +86", pre: "+86"}]
  114. this.selectList = list
  115. }
  116. })
  117. },
  118. /** 开始绑定手机号 **/
  119. bindMobile() {
  120. const {phone, preMobile, scode} = this
  121. let newPhone = preMobile + '-' + phone;
  122. this.$axios.post('/api/user/update_info', {
  123. login_mobile: newPhone,
  124. auth_code: scode
  125. }).then(res=>{
  126. if (Number(res.data.status) === 1) {
  127. this.updateUserInfo()
  128. this.close()
  129. }
  130. })
  131. }
  132. }
  133. };
  134. </script>
  135. <style lang="scss">
  136. .bindMobile {
  137. .bindMobileContent {
  138. .phoneNum, .codeNum {
  139. margin-top: 20px;
  140. display: flex;
  141. align-items: center;
  142. .name {
  143. flex-shrink: 0;
  144. font-size: 14px;
  145. font-weight: 500;
  146. color: #19222e;
  147. line-height: 20px;
  148. }
  149. .el-input {
  150. flex-grow: 1;
  151. margin-left: 10px;
  152. .el-input-group__append {
  153. background-color: transparent;
  154. border: none;
  155. padding: 0;
  156. .sendBtn {
  157. background-color: #F5F7FA;
  158. color: #909399;
  159. vertical-align: middle;
  160. display: table-cell;
  161. position: relative;
  162. border: 1px solid #DCDFE6;
  163. border-radius: 4px;
  164. padding: 10px 20px;
  165. width: 1px;
  166. white-space: nowrap;
  167. cursor: pointer;
  168. border-top-left-radius: 0;
  169. border-bottom-left-radius: 0;
  170. &.ok {
  171. background-color: #308EFF;
  172. color: #fff;
  173. vertical-align: middle;
  174. display: table-cell;
  175. position: relative;
  176. border: 1px solid #308EFF;
  177. }
  178. }
  179. }
  180. }
  181. }
  182. }
  183. }
  184. </style>