76b07bbe411a61a7ad920a809e1b7668491d64a5.svn-base 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <div>
  3. <a-form-model ref="form" :model="model" :rules="validatorRules" class="password-retrieval-form" @keyup.enter.native="nextStep">
  4. <a-form-model-item label="手机" required prop="phone" :labelCol="{span: 5}" :wrapperCol="{span: 19}">
  5. <a-row :gutter="16">
  6. <a-col class="gutter-row" :span="20">
  7. <a-input v-model="model.phone" type="text" autocomplete="false" placeholder="请输入手机号">
  8. <a-icon slot="prefix" type="phone" :style="{ color: 'rgba(0,0,0,.25)'}"/>
  9. </a-input>
  10. </a-col>
  11. </a-row>
  12. </a-form-model-item>
  13. <a-form-model-item v-if="show" required prop="captcha" label="验证码" :labelCol="{span: 5}" :wrapperCol="{span: 19}">
  14. <a-row :gutter="16">
  15. <a-col class="gutter-row" :span="12">
  16. <a-input v-model="model.captcha" type="text" placeholder="手机短信验证码">
  17. <a-icon slot="prefix" type="code" :style="{ color: 'rgba(0,0,0,.25)'}"/>
  18. </a-input>
  19. </a-col>
  20. <a-col class="gutter-row" :span="8">
  21. <a-button
  22. tabindex="-1"
  23. size="default"
  24. :disabled="state.smsSendBtn"
  25. @click.stop.prevent="getCaptcha"
  26. v-text="!state.smsSendBtn && '获取验证码' || (state.time+' s')"></a-button>
  27. </a-col>
  28. </a-row>
  29. </a-form-model-item>
  30. <a-form-model-item :wrapperCol="{span: 19, offset: 5}">
  31. <router-link style="float: left;line-height: 40px;" :to="{ name: 'login' }">使用已有账户登录</router-link>
  32. <a-button type="primary" @click="nextStep" style="margin-left: 20px">下一步</a-button>
  33. </a-form-model-item>
  34. </a-form-model>
  35. </div>
  36. </template>
  37. <script>
  38. import {postAction} from '@/api/manage'
  39. export default {
  40. name: "Step2",
  41. props: ['userList'],
  42. data() {
  43. return {
  44. model: {},
  45. loading: false,
  46. // accountName: this.userList.username,
  47. dropList: "0",
  48. captcha: "",
  49. show: true,
  50. state: {
  51. time: 60,
  52. smsSendBtn: false,
  53. },
  54. formLogin: {
  55. captcha: "",
  56. mobile: "",
  57. },
  58. validatorRules: {
  59. phone: [
  60. { required: true, message: '请输入手机号码!' },
  61. { validator: this.validatePhone }
  62. ],
  63. captcha: [
  64. { required: true, message: '请输入短信验证码!' }
  65. ]
  66. },
  67. }
  68. },
  69. computed: {
  70. },
  71. methods: {
  72. nextStep() {
  73. let that = this
  74. that.loading = true
  75. this.$refs['form'].validate((success) => {
  76. if(success==true){
  77. let params = {
  78. phone: this.model.phone,
  79. smscode: this.model.captcha
  80. }
  81. postAction("/sys/user/phoneVerification", params).then((res) => {
  82. if (res.success) {
  83. console.log(res);
  84. let userList = {
  85. username: res.result.username,
  86. phone: params.phone,
  87. smscode: res.result.smscode
  88. };
  89. setTimeout(function () {
  90. that.$emit('nextStep', userList)
  91. }, 0)
  92. } else {
  93. this.cmsFailed(res.message);
  94. }
  95. });
  96. }
  97. })
  98. },
  99. getCaptcha(e) {
  100. e.preventDefault();
  101. const that = this
  102. that.$refs['form'].validateField('phone', err=>{
  103. if(!err){
  104. that.state.smsSendBtn = true;
  105. let interval = window.setInterval(() => {
  106. if (that.state.time-- <= 0) {
  107. that.state.time = 60;
  108. that.state.smsSendBtn = false;
  109. window.clearInterval(interval);
  110. }
  111. }, 1000);
  112. const hide = that.$message.loading('验证码发送中..', 0);
  113. let smsParams = {
  114. mobile: that.model.phone,
  115. smsmode: "2"
  116. };
  117. postAction("/sys/sms", smsParams).then(res => {
  118. if (!res.success) {
  119. setTimeout(hide, 1);
  120. that.cmsFailed(res.message);
  121. }
  122. setTimeout(hide, 500);
  123. })
  124. }else{
  125. that.cmsFailed(err);
  126. }
  127. })
  128. },
  129. cmsFailed(err) {
  130. this.$notification['error']({
  131. message: "验证错误",
  132. description: err,
  133. duration: 4,
  134. });
  135. },
  136. handleChangeSelect(value) {
  137. var that = this;
  138. console.log(value);
  139. if (value == 0) {
  140. that.dropList = "0";
  141. that.show = true;
  142. } else {
  143. that.dropList = "1";
  144. that.show = false;
  145. }
  146. },
  147. validatePhone(rule,value,callback){
  148. if(value){
  149. var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
  150. if(!myreg.test(value)){
  151. callback("请输入正确的手机号")
  152. }else{
  153. callback();
  154. }
  155. }else{
  156. callback()
  157. }
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="less" scoped>
  163. .stepFormText {
  164. margin-bottom: 24px;
  165. }
  166. .ant-form-item-label,
  167. .ant-form-item-control {
  168. line-height: 22px;
  169. }
  170. .getCaptcha {
  171. display: block;
  172. width: 100%;
  173. height: 40px;
  174. }
  175. </style>