Step2.vue 5.5 KB

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