PhoneStepNew.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <div class="validation">
  3. <div class="container">
  4. <div class="content">
  5. <div class="content-top">
  6. <h3>验证手机</h3>
  7. <div class="step">
  8. <img src="/images/all/step02.png" alt=""/>
  9. <div class="step-item"><span class="active">账号验证</span><span class="active">新手机号码</span><span>设置完成</span></div>
  10. </div>
  11. </div>
  12. <div class="content-bottom">
  13. <div>
  14. <el-form :model="valid2" :rules="rules2" ref="valid2" label-width="100px" class="demo-ruleForm">
  15. <el-form-item prop="mobile">
  16. <el-input v-model="valid2.mobile"
  17. placeholder="新手机号码"></el-input>
  18. </el-form-item>
  19. <el-form-item prop="code">
  20. <el-input type="text" v-model="valid2.code"
  21. v-bind:class="{ active: secondStepCodeErrorChecked }"
  22. auto-complete="off"
  23. class="msg"
  24. placeholder="短信验证码"></el-input>
  25. <el-button type="primary" class="code"
  26. v-show="showSecondStepCode"
  27. @click="getSecondCheckCode"
  28. :disabled="getCodeBtnIsDisabled">获取验证码</el-button>
  29. <el-button type="primary" v-show="!showSecondStepCode" class="code code-send">已发送({{second_step_time}}s)</el-button>
  30. <span v-show="secondStepCodeErrorChecked" class="tip codeError-tip">{{secondCodeErrorMsg}}</span>
  31. </el-form-item>
  32. <el-form-item>
  33. <a class="btn finish"
  34. :disabled="!mobileSecondChecked || !secondCodeChecked"
  35. @click="setNewMobile">确认</a>
  36. </el-form-item>
  37. </el-form>
  38. </div>
  39. </div>
  40. </div>
  41. <loading v-show="isShowLoading"/>
  42. </div>
  43. </div>
  44. </template>
  45. <script>
  46. import Loading from '~components/common/loading/Loading.vue'
  47. export default {
  48. name: 'validation',
  49. components: {
  50. Loading
  51. },
  52. props: ['tokenId'],
  53. middleware: 'authenticated',
  54. data () {
  55. // 第二步验证手机
  56. var validateSecondMobile = (rule, value, callback) => {
  57. if (value === '') {
  58. callback(new Error('请填写正确的手机号'))
  59. this.getCodeBtnIsDisabled = true
  60. this.mobileSecondChecked = false
  61. } else {
  62. if (this.valid2.mobile !== '') {
  63. var reg = /^1[0-9]{10}$/
  64. if (!reg.test(value)) {
  65. callback(new Error('请填写正确的手机号'))
  66. this.getCodeBtnIsDisabled = true
  67. this.mobileSecondChecked = false
  68. } else {
  69. this.getCodeBtnIsDisabled = false
  70. this.mobileSecondChecked = true
  71. }
  72. }
  73. callback()
  74. }
  75. }
  76. var validateSecondCode = (rule, value, callback) => {
  77. if (value === '') {
  78. callback(new Error('请填写正确的验证码'))
  79. this.secondStepCodeErrorChecked = false
  80. this.secondCodeChecked = false
  81. } else {
  82. if (this.valid2.code !== '') {
  83. if (this.valid2.mobile === '') {
  84. callback(new Error('请先填写正确的手机号'))
  85. } else {
  86. if (this.secondToken) {
  87. let param = new FormData()
  88. param.append('mobile', this.valid2.mobile)
  89. param.append('code', this.valid2.code)
  90. param.append('token', this.secondToken)
  91. let config = {
  92. headers: {'Content-Type': 'multipart/form-data'}
  93. }
  94. this.$http.post(`/update/user/checkCode/mobile`, param, config)
  95. .then(response => {
  96. if (response.data.success) {
  97. this.secondCodeChecked = true
  98. this.secondStepCodeErrorChecked = false
  99. } else {
  100. this.secondStepCodeErrorChecked = true
  101. this.secondCodeChecked = false
  102. return Promise.reject(response.data)
  103. }
  104. }).catch(err => {
  105. this.secondCodeErrorMsg = err.errMsg
  106. })
  107. } else {
  108. callback(new Error('请先获取验证码'))
  109. this.codeChecked = false
  110. this.codeErrorChecked = false
  111. }
  112. }
  113. }
  114. callback()
  115. }
  116. }
  117. return {
  118. isShowLoading: false,
  119. second_step_time: 0,
  120. codeErrorChecked: false,
  121. secondStepCodeErrorChecked: false,
  122. secondCodeChecked: false,
  123. secondCodeErrorMsg: '',
  124. mobileSecondChecked: false,
  125. getCodeBtnIsDisabled: true,
  126. showSecondStepCode: true,
  127. mobileSecondExit: false,
  128. secondToken: '',
  129. valid2: {
  130. mobile: '',
  131. code: ''
  132. },
  133. rules2: {
  134. mobile: [
  135. {validator: validateSecondMobile, trigger: 'blur'}
  136. ],
  137. code: [
  138. {validator: validateSecondCode, trigger: 'blur'}
  139. ]
  140. }
  141. }
  142. },
  143. methods: {
  144. // 获取第二步手机验证码
  145. getSecondCheckCode () {
  146. this.isShowLoading = true
  147. this.$http.get(`/update/user/setMobile`, {params: {mobile: this.valid2.mobile, token: this.$route.query.token ? this.$route.query.token : this.tokenId}})
  148. .then(response => {
  149. this.isShowLoading = false
  150. if (response.data.success) {
  151. this.secondToken = response.data.content.token
  152. if (this.secondToken !== '') {
  153. this.$message({
  154. message: '验证码已经发送到您的手机,请注意查收',
  155. type: 'success'
  156. })
  157. this.showSecondStepCode = false
  158. this.second_step_time = 60
  159. var secondStepTime = setInterval(() => {
  160. this.second_step_time--
  161. if (this.second_step_time <= 0) {
  162. this.showSecondStepCode = true
  163. clearInterval(secondStepTime)
  164. }
  165. }, 1000)
  166. }
  167. } else {
  168. return Promise.reject(response.data)
  169. }
  170. }).catch(err => {
  171. this.isShowLoading = false
  172. this.$message.error(err.errMsg)
  173. })
  174. },
  175. // 设置新手机号
  176. setNewMobile () {
  177. if (this.mobileSecondChecked && this.secondCodeChecked) {
  178. this.isShowLoading = true
  179. let param = new FormData()
  180. param.append('mobile', this.valid2.mobile)
  181. param.append('code', this.valid2.code)
  182. param.append('token', this.secondToken)
  183. let config = {
  184. headers: {'Content-Type': 'multipart/form-data'}
  185. }
  186. this.$http.post(`/update/user/setMobile`, param, config)
  187. .then(response => {
  188. this.isShowLoading = false
  189. if (response.data.success) {
  190. this.$emit('stepEvent', 'last')
  191. this.$emit('lastEvent', 'last')
  192. } else {
  193. return Promise.reject(response.data)
  194. }
  195. }).catch(err => {
  196. this.$message.error(err.errMsg)
  197. this.isShowLoading = false
  198. this.secondStepCodeErrorChecked = true
  199. this.secondCodeChecked = false
  200. this.second_step_time = 0
  201. })
  202. }
  203. }
  204. }
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  208. .validation {
  209. margin: 0 auto;
  210. width: 100%;
  211. background: #eee;
  212. .container{
  213. padding-top: 50px;
  214. margin: 0 auto;
  215. width: 980px;
  216. text-align: center;
  217. .content{
  218. padding: 0 50px;
  219. margin: 50px auto 0;
  220. width: 100%;
  221. /*height: 540px;*/
  222. text-align: center;
  223. background: #fff;
  224. .content-top{
  225. height: 80px;
  226. line-height: 80px;
  227. h3{
  228. margin-bottom: 0;
  229. font-size: 24px;
  230. color: #000;
  231. border-bottom: 1px solid #dcdcdc;
  232. }
  233. .step{
  234. position: relative;
  235. margin-top: 10px;
  236. img{
  237. width: 315px;
  238. height: 46px;
  239. }
  240. .step-item{
  241. position: absolute;
  242. top: 45px;
  243. left: 265px;
  244. span{
  245. margin-right: 78px;
  246. font-size: 14px;
  247. color: #b4b4b4;
  248. }
  249. span.active {
  250. color: #0076ad;
  251. }
  252. }
  253. }
  254. }
  255. form {
  256. margin-top: 150px;
  257. padding-bottom: 44px;
  258. input{
  259. padding: 0 0 0 18px;
  260. width: 360px;
  261. height: 44px;
  262. line-height: 44px;
  263. font-size: 14px;
  264. color: #000;
  265. border-radius: 0;
  266. }
  267. input.answer {
  268. background: url("/images/all/more.png") no-repeat 325px center;
  269. cursor: pointer;
  270. }
  271. ul{
  272. display: none;
  273. position: absolute;
  274. top: 44px;
  275. left: 0;
  276. width: 360px;
  277. background: #fff;
  278. box-shadow: 0 0 5px rgba(0,0,0,.5);
  279. -moz-box-shadow: 0 0 5px rgba(0,0,0,.5);
  280. -o-box-shadow: 0 0 5px rgba(0,0,0,.5);
  281. -webkit-box-shadow: 0 0 5px rgba(0,0,0,.5);
  282. z-index: 10;
  283. li{
  284. padding-left: 18px;
  285. width: 100%;
  286. height: 30px;
  287. line-height: 30px;
  288. text-align: left;
  289. font-size: 14px;
  290. color: #000;
  291. cursor: pointer;
  292. &:hover{
  293. background: #0076ad;
  294. color: #fff;
  295. }
  296. }
  297. }
  298. span.tip{
  299. position: absolute;
  300. top: 0;
  301. right: -238px;
  302. font-size: 13px;
  303. color: #8c8c8c;
  304. a{
  305. font-size: 13px;
  306. color: #0076ad;
  307. }
  308. }
  309. span.tip.tip-mobile{
  310. top: 3px;
  311. right: -105px;
  312. color: #ff4949;
  313. font-size: 12px;
  314. }
  315. span.tip.codeError-tip{
  316. position: absolute;
  317. top: 3px;
  318. left: 378px;
  319. width: 200px;
  320. text-align: left;
  321. color: #ff4949;
  322. font-size: 12px;
  323. }
  324. i{
  325. position: absolute;
  326. top: 13px;
  327. left: 20px;
  328. font-size: 20px;
  329. color: #a0a0a0;
  330. }
  331. .btn {
  332. margin: 34px 0 16px 0;
  333. width: 360px;
  334. height: 44px;
  335. line-height: 44px;
  336. font-size: 16px;
  337. color: #fff;
  338. background: #0076AD;
  339. border-radius: 3px;
  340. }
  341. }
  342. .content-bottom{
  343. margin: 155px auto 0;
  344. padding-bottom: 50px;
  345. width: 360px;
  346. div.warp{
  347. padding-bottom: 65px;
  348. }
  349. p{
  350. font-size: 24px;
  351. color: #323232;
  352. img{
  353. margin-right: 20px;
  354. width: 30px;
  355. height: 28px;
  356. }
  357. }
  358. p.pass{
  359. font-size: 24px;
  360. color: #e77405;
  361. img{
  362. height: 30px;
  363. }
  364. }
  365. p.passed {
  366. color: #2ab300;
  367. img{
  368. height: 30px;
  369. }
  370. }
  371. span{
  372. display: inline-block;
  373. font-size: 14px;
  374. color: #8b8b8b;
  375. }
  376. span.close-tip{
  377. margin: 15px 0 140px 0;
  378. }
  379. .close-btn{
  380. margin: 0 auto;
  381. width: 200px;
  382. height: 36px;
  383. line-height: 36px;
  384. font-size: 14px;
  385. text-align: center;
  386. color: #323232;
  387. border: 1px solid #d2d2d2;
  388. border-radius: 3px;
  389. cursor: pointer ;
  390. }
  391. span.use{
  392. display: inline-block;
  393. margin-bottom: 30px;
  394. width: 360px;
  395. font-size: 14px;
  396. color: #000;
  397. text-align: left;
  398. em{
  399. font-size: 14px;
  400. font-style: normal;
  401. color: #000;
  402. }
  403. }
  404. .form-group {
  405. margin: 0 auto 16px;
  406. position: relative;
  407. width: 360px;
  408. height: 44px;
  409. line-height: 44px;
  410. input{
  411. padding: 0 0 0 18px;
  412. width: 360px;
  413. height: 44px;
  414. line-height: 44px;
  415. font-size: 14px;
  416. color: #000;
  417. border-radius: 0;
  418. }
  419. input.msg{
  420. float: left;
  421. width: 210px;
  422. padding: 0 0 0 18px;
  423. height: 44px;
  424. line-height: 44px;
  425. font-size: 14px;
  426. color: #000;
  427. border-radius: 0;
  428. }
  429. span.msg{
  430. float: right;
  431. margin: 0;
  432. width: 130px;
  433. height: 44px;
  434. line-height: 44px;
  435. text-align: center ;
  436. font-size: 14px;
  437. color: #5a5a5a;
  438. background: #f4f4f4;
  439. border: 1px solid #dcdcdc;
  440. cursor: pointer;
  441. }
  442. span.msg.send{
  443. background: #d2d2d2;
  444. color: #fff;
  445. }
  446. }
  447. .btn {
  448. margin: 34px 0 10px 0;
  449. width: 360px;
  450. height: 44px;
  451. line-height: 44px;
  452. font-size: 16px;
  453. color: #fff;
  454. background: #0076AD;
  455. border-radius: 3px;
  456. }
  457. }
  458. .choose{
  459. margin: 155px auto 0;
  460. padding-bottom: 44px;
  461. div{
  462. padding: 0 15px;
  463. margin: 0 auto 16px;
  464. width: 360px;
  465. height: 60px;
  466. line-height: 60px;
  467. text-align: left;
  468. overflow: hidden;
  469. border: 1px solid #d2d2d2;
  470. cursor: pointer;
  471. &:hover,&.active{
  472. border-color: #0076ad;
  473. span{
  474. color: #0076ad;
  475. }
  476. i.second {
  477. color: #0076ad;
  478. }
  479. }
  480. img.first{
  481. float: left;
  482. margin: 24px 20px 0 0;
  483. font-size: 20px;
  484. color: #323232;
  485. }
  486. img.first.mob{
  487. margin: 22px 20px 0 5px;
  488. font-size: 28px;
  489. }
  490. i.second {
  491. float: right;
  492. margin: 20px 0 0 5px;
  493. font-size: 20px;
  494. color: #323232;
  495. }
  496. span{
  497. float: left;
  498. font-size: 14px;
  499. color: #323232;
  500. }
  501. }
  502. }
  503. a.return{
  504. position: absolute;
  505. left: 0;
  506. top: -15px;
  507. img{
  508. width: 34px !important;
  509. height: 34px !important;
  510. }
  511. }
  512. }
  513. }
  514. }
  515. </style>